[Tex/LaTex] Where does the space before \align* come from

alignamsmathspacing

In the following MWE, what is responsible for the large space before the align environment? How can I remove it (it doesn't appear if I change to \[ \] and remove amsmath) ?

\documentclass{article}

\usepackage[english]{babel}
\usepackage{amsmath,amssymb}
\usepackage{lipsum}

\begin{document}
\setlength{\parskip}{0pt}
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}

\lipsum*[2]

\lipsum*[2]

\begin{align*}1, 2, 3\end{align*}

\lipsum*[2]

\lipsum*[2]
\end{document}

I have read Spacing around align environments (but it doesn't cover the case in which there's a \par before \align and Remove vertical space around align (but it attributes the space to \parskip, which seems wrong: setting \parskip to 0 pt doesn't remove the space). I also read Remove extra vertical space in amsmath's align environment and Remove vertical space around align equations, but they just say that one shouldn't leave a \par before an \align. I'm curious to know what actually causes this blank space, even with all seemingly relevant lengths set to zero.

Edit for Reopen

Why does LaTeX insert space before formulas? is related, but it doesn't address the why: it says that leaving a blank line in the source causes the space but it doesn't say who is adding this space (and it's clearly an amsmath-specific this: the regular displaymath doesn't do that).

Unwanted space before align*

Best Answer

You ask,

Where does the [vertical] space before \align* come from?

It comes from an input mistake -- not a syntax error, mind you, but a mistake nevertheless -- in your code: Display-math environments should never, ever occur at the start of a paragraph.

In the following code, which preserves your \setlength instructions, the instance of align* that is not preceded by a paragraph break features no extra vertical whitespace; in contrast, the instance of align* that is preceded by a paragraph break does feature the dreaded extra whitespace. Observe that this happens even though the five length parameters have been set to 0pt.

To recap: Never begin a paragraph with a display-math environment. Not only is it poor practice from a typographic standpoint, it's also poor practice from a discursive/explanatory standpoint.

enter image description here

\documentclass{article}
\usepackage{amsmath,lipsum}

\begin{document}
\setlength{\parskip}{0pt}
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}
\lipsum*[2] 
\begin{align*}1, 2, 3\end{align*} % no paragraph break before  this 'align*'
\lipsum*[2] 

\begin{align*}1, 2, 3\end{align*} % paragraph break before this 'align*'
\lipsum*[2]
\end{document}
Related Question