Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
try enclosing your math environment by \begin{linenomath} and \end{linenomath} (see documentaion for lineno). –  prettygully Feb 7 '12 at 4:18
add comment

3 Answers

up vote 7 down vote accepted

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.

share|improve this answer
    
I think the solution(s) by Werner and tohecz are very nice but the output in not exactly the same with and without the paragraph break. With it, more blank space is left before the math environment. On the contrary, the solution given at the link by mbudusic seems to reproduce the same behaviour as the equation without space before, but with compatibility with lineno –  Federico Rotolo Jul 10 '12 at 12:07
    
@FedericoRotolo: As your answer is more like a comment, I converted it. –  Stefan Kottwitz Jul 10 '12 at 15:44
add comment

Put this in your preamble, at the end (after the math package are loaded):

\makeatletter
% Make a copy of macros responsible for entering display math mode
\let\start@align@nopar\start@align
\let\start@gather@nopar\start@gather
\let\start@multline@nopar\start@multline
% Add the "empty line" command to the macros
\long\def\start@align{\par\start@align@nopar}
\long\def\start@gather{\par\start@gather@nopar}
\long\def\start@multline{\par\start@multline@nopar}
\makeatother

It actually adapts the trick that @Werner speaks about, just without the need of changing every display math in your document.

share|improve this answer
    
This and the answer by Werner are both excellent, his for avoiding this error in the future and yours to avoid manually fixing existing documents. wish I could accept both, thanks. –  cboettig Feb 9 '12 at 19:55
add comment

I've found this answer too. It gives a command that you can use to patch math environments as needed. I figure it does the same thing as presented above, but it doesn't hurt to have several solutions.

I cannot see the difference in line spacing when it is included in preamble or not, but the line numbers that aren't shown before, show up after it is added.

http://phaseportrait.blogspot.com/2007/08/lineno-and-amsmath-compatibility.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.