# [Tex/LaTex] Why align and equation environment do not tolerate empty lines

amsthmmath-mode

The following code does not compile:

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\begin{align}

\eta_{m} = & \omega_{m1}D_{1} + \omega_{m2}D_{2} + \dots + \omega_{mT}D_{T} \\
\eta_{a} = & \omega_{a1}D_{1} + \omega_{a2}D_{2} + \dots + \omega_{aT}D_{T}

\end{align}

\end{document}


However, if I remove empty lines, it does. (Same with equation environment). Why? Why would it be problematic for a code to allow spaces? Convention?

For reference, the error in TexStudio is quite dramatic, for an apparent trivial issue:

line 7: Paragraph ended before \align was complete.
line 7: Missing \$ inserted.
line 7: Missing \endgroup inserted.
line 7: Display math should end with . line 8: Misplaced alignment tab character &. & line 8: Missing  inserted. & \omega line 9: Misplaced alignment tab character &. & line 10: Missing  inserted. line 11: Misplaced \cr. \end{align} line 11: Misplaced \noalign. \end{align} line 11: Misplaced \noalign. \end{align} line 11: Extra }, or forgotten \endgroup. \end{align} line 11: Missing  inserted. \end{align} line 11: Display math should end with. \end{align}


NOTE: I am aware of this, this, and this question. But none of them explains why empty lines are problematic (besides a trivial and rather tautological answer like "the code does not allow it").

The error message tells exactly why it is problematic:

Paragraph ended before \align was complete.


In standard (La)TeX, an empty line signifies a paragraph break.

Since it does not make sense to start a new paragraph inside a single math display, the display math environments were not implemented with paragraph breaks in mind (a simplification, but we might think of this in this way: they are not "long" environments).

Because these environments were not created allowing paragraph breaks, when TeX encounters an empty line (a paragraph break with a "standard" catcode setup), it assumes that the user forgot to close the environment, closes it (thereby leaving display math), starts a new paragraph, and moves happily along.

Then it finds all these other math-mode tokens, but we are no longer in math mode because of the above paragraph. So that is the cause of all the errors following the first one.

As requested, elaborating a bit on the following statement:

[I]t does not make sense to start a new paragraph inside a single math display[.]

Depending on one's chosen/preferred style, a displayed equation or group of equations is either

• part of a single sentence unit, or
• a standalone unit roughly equivalent to a sentence.

The former case is most common in mathematical and technical writing. Here, the equation(s) fit in with the surrounding wording and include punctuation so they can be read continuously with the surrounding text. In this case, we would not start a new paragraph within an equation any more than we would start a new paragraph within a single sentence.

In the latter case, which is less common, a single equation could be its own paragraph, but it is more likely to have some text sentences around it introducing it or explaining it, so the displayed equation is usually "attached" to some body copy, so it belongs to the paragraph of that body copy. (Just as a single sentence could be its own paragraph, but it is more common for multiple sentences to make up a paragraph.) Either way, again, we would not start a new paragraph within an equation any more than we would start a new paragraph within a single sentence.

For groups of equations in a single display environment, the very fact that they are logically grouped means they are related and part of the same "idea" in some way. Just as we group sentences together to form paragraphs, equations grouped in this way should belong to the same "idea" or paragraph. If you really intend to start a new "idea" or paragraph within a group of equations, I would argue that the group of equations should be split at this point rather than trying to introduce a paragraph break inside the group of equations.

Hopefully this helps to explain why I said that it doesn't make sense to start a new paragraph inside a math display environment.