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.

In the following example, the space after the red equation is much larger than the space after the black one.

\documentclass[12pt]{article}
\usepackage{xcolor}
\begin{document}
\[ a = b \]

The quick brown fox jumps over the lazy dog.
\color{red}
\[ a = b \]
\color{black}

The quick brown fox jumps over the lazy dog.
\end{document}

It appears to me that the presence of \color{black} fools TeX into thinking there is something on the line after the equation, so the paragraph break causes a spurious blank line before the text. Section 3.7 of grfguide mentions spacing problems, but doesn't really explain the situation. What is on the line after the red equation?

Note that there is already a question asking how to deal with this problem; I want to understand what is going on.

share|improve this question
    
I don't think this has to do with the color command. If you replace \color{black} with, for example, \marginpar{test} you get the same result, regardless of how much colour changing occurs. –  cmhughes Mar 6 '12 at 22:13
    
@cmhughes not just color but the fact that color (unlike a font change) acts by putting an item in the list. You get similar effects from other things: floats and marginpars put \inserts there, \label would put a \write there, all these nodes can affect vertical positioning, –  David Carlisle Mar 7 '12 at 9:29
    
@DavidCarlisle thanks for the details! :) Is it another occurrence of a trivlist? –  cmhughes Mar 7 '12 at 16:58
add comment

1 Answer

up vote 10 down vote accepted

TeX puts a \special (or pdftex colour primitive which is equivalent) which inserts the commands to switch the colour, however unlike a font change this is an actual item on the vertical list, so it "hides" boxes and spaces that occur immediately before it so that decisions made by the vertical display code do not see the same detail of the preceding paragraph. It's normally better to try to get the color switch in to horizontal mode, for example

The quick brown fox jumps over the lazy dog.\color{red}
\[ a = b \]

\leavevmode\color{black}The...

One way to see what is happening is to put \showoutput into the document and then compare the log file a) without colour b) with color commands in vertical mode c) with colour commands just in horizontal mode.

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.