6

I am using the xcolor package to color text and math in an amsart document. I have noticed that starting a new paragraph after a colored displayed equation produces extra vertical spacing.

Here is a MWE:

\documentclass{amsart}
\usepackage{xcolor}
 
\begin{document}
Some text.
    \begin{equation*}
\text{A formula: }a=b+c.
    \end{equation*}

Some more text, starting new paragraph.
\begin{equation*}
\color{blue} \text{Another formula: }d=e-f.
\end{equation*}

Some more text, starting new paragraph.
\end{document}

It typesets as:enter image description here

Does anybody know why this happens? How can we fix it?

1

2 Answers 2

9

This has nothing to do with amsart, but it's how LaTeX has to specify colors.

If you do \color{blue} inside a group, LaTeX will issue a suitable \color instruction after the group ends in order to restore the color that was in force before the change. This is done via a “whatsit”, because TeX has no color support by itself.

In your case, this whatsit is part of the text after the math display and thus will produce an empty line before the end-of-paragraph command (the empty line) is scanned.

Solution: use \begingroup...\endgroup so the whatsit will be placed inside the display. Or, equivalently, \mathcolor.

%\documentclass{amsart}
\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
 
\begin{document}

Some text.
\begin{equation*}
\text{A formula: }a=b+c.
\end{equation*}

Some more text, starting new paragraph.
\begin{equation*}
\mathcolor{blue}{\text{Another formula: }d=e-f.}
\end{equation*}

Some more text, starting new paragraph.

Some more text, starting new paragraph.
\begin{equation*}
\color{blue}\text{Another formula: }d=e-f.
\end{equation*}
Some more text, not starting new paragraph.

Some more text, starting new paragraph.
\begin{equation*}
\begingroup\color{blue}\text{Another formula: }d=e-f.\endgroup
\end{equation*}

Some more text, starting new paragraph.

\end{document}

The example shows various alternatives.

enter image description here

Another possibility is to not leave a blank line, and use \indent in front of the text.

Such cases should be rare: how many times do you need to start a new paragraph after a display?

5

Egreg said the essential information about this issue. I add a little more.

Why the "whatsit" after display mode (which restores the previous color but does nothing else) creates an empty paragraph?

The display mode finishes its work by putting the formula to the vertical list and starting interrupted paragraph, i.e. it opens a new horizontal mode (like after \noindent). Then the group of display mode is finished.

In your first example, after this group is \par (empty line), so there is empty horizontal mode immediately closed by \par (similar as \noindent\par). TeX does not create a paragraph in this case.

In your second example, after this group is "whatsit" followed by \par. I.e. the horizontal mode in not empty when \par is processed. The single-line paragraph is created. This line includes this "whatsit" which restores previous color.

Note, that Context has not this problem, because it manages color using LuaTeX's attributes, not by \aftergroup primitive (which is used in color LaTeX package).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .