[Tex/LaTex] Why doesn’t lineno number a paragraph when it is followed by an “align” equation environment without a space

amsmathequationsline-numberingspacing

lineno skips the line numbering in this case:

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{lineno}
\linenumbers
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit: 
\begin{align}
1+1=2
\end{align}
\end{document}

but is fine with

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{lineno}
\linenumbers
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit: 

\begin{align}
1+1=2
\end{align}
\end{document}

Note that though this sounds a lot like this question. I don't believe the answer is related, since this doesn't use $$. Is the latter somehow more correct?

Best Answer

In essence, this is the same, since align issues $$ before assembling the environment contents. Here is the definition of the align environment in amsmath:

\newenvironment{align}{%
  \start@align\@ne\st@rredfalse\m@ne
}{%
  % <removed \end{align} part for brevity>
}

So, at \begin{align} is equivalent to

\start@align{\@ne}{\st@rredfalse}{\m@ne}

where \start@align is defined to take three parameters and condition appropriately. In the definition of \start@align, I've marked the conditionals, as well as the final $$ for entering display math mode:

\def\start@align#1#2#3{%
    \let\xatlevel@#1% always \z@, \@ne, or \tw@
    \maxfields@#3\relax
    \ifnum\maxfields@>\m@ne % <------------------- FALSE
        \checkat@true
        \ifnum\xatlevel@=\tw@
            \xxat@true
        \fi
        \multiply\maxfields@\tw@
    \else % <------------------------------------- TRUE
        \checkat@false
    \fi
    \ifingather@ % <------------------------------ FALSE
        \iffalse{\fi\ifnum0=`}\fi
        \DN@{\vcenter\bgroup\savealignstate@\align@#2}%
    \else % <------------------------------------- TRUE
        \ifmmode % <------------------------------ FALSE
          \if@display
             \DN@{\align@recover}%
          \else
            \nomath@env
            \DN@{\@namedef{end\@currenvir}{}\@gobble}%
          \fi
        \else % <--------------------------------- TRUE
            $$% <--------------------------------- enter display math mode
            \let\split\insplit@
            \DN@{\align@#2}%
        \fi
    \fi
    \collect@body\next@
}

The conclusion? Use an empty line (or paragraph break). The output with or without is the same, except in this case with lineno.