[Tex/LaTex] \nonumber but keep the count

alignnumberingtags

I want to number some lines in an align environment (or align* and use \numberthis (see below)) but keeping the same number as if all lines were numbered.

I know I'm not clear so here is an example :

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\begin{document}
\begin{align}
    A & = & 1 \notag\\
    B & = & 2 
\end{align}
\end{document}

Here, the second line has the number 1 but I want the number 2.

(\numberthis, thanks its creator, I don't remember who)

\newcommand\numberthis{\stepcounter{equation}{1}\tag{\theequation}}

EDIT: If I had another system, I want the counter starts again with 1. For instance, for the code below, I want two number 2 (and maybe, a number for the system itself to be able to say: the 2nd equation for the system one is blabla)

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}

\newcommand\nonumberthis{\refstepcounter{equation}\nonumber}

\begin{document}

\begin{align}
    A & = & 1 \nonumberthis\\
    B & = & 2 
\end{align}

\begin{align}
    A & = & 1 \nonumberthis\\
    B & = & 2 
\end{align}

\end{document}

Best Answer

Your question has two parts:

  • You want to omit the number for a line in your equation, but still count this line in the numbering of all lines. As suggested in the comments, define a command that increases the equation counter by 1 and calls the \nonumber macro:

    \newcommand\nonumberthis{\refstepcounter{equation}\nonumber}
    
  • You want to number the lines in each align block starting from 1. In other words, you want to reset the equation counter to 0 at the start of every align environment. You can achieve this easily with the macro \AtBeginEnvironment from the etoolbox package:

    \usepackage{etoolbox}
    \AtBeginEnvironment{align}{\setcounter{equation}{0}}
    

Full example:

\documentclass{article}

\usepackage{amsmath}
\usepackage{etoolbox}

\AtBeginEnvironment{align}{\setcounter{equation}{0}}
\newcommand\nonumberthis{\refstepcounter{equation}\nonumber}

\begin{document}

\begin{align}
    a&=1 \nonumberthis \\
    b&=2 \\
    c&=3 \nonumberthis
\end{align}

\begin{align}
    \alpha&=1 \\
    \beta&=2 \nonumberthis \\
    \gamma&=3
\end{align}

\end{document}

enter image description here