21

As a follow-up to Why is \[ ... \] preferable to $$ ... $$?, what really is wrong with the vertical spacing as stated in l2tabu introduced by using $$...$$ instead of \[...\]?

As there does not seem to be an elaboration of this in l2tabu except for the remark that vertical spacing is modified and rendered inconsistent, illustrative examples comparing the different outputs would be appreciated.

2 Answers2

16

The only difference as far as spacing is concerned is that \[...\] will use \abovedisplayskip and \belowdisplayskip instead of \abovedisplayshortskip and \belowdisplayshortskip that would be used by $$...$$ in case the math display is started in vertical mode. The code

\setbox0=\vbox{\hrule height 0pt % to avoid gobbling vskips
\[a=b\]
A word.}
\showthe\ht0

\setbox0=\vbox{\hrule height 0pt % to avoid gobbling vskips
$$a=b$$
A word.}
\showthe\ht0
\showthe\abovedisplayskip
\showthe\belowdisplayskip
\showthe\abovedisplayshortskip
\showthe\belowdisplayshortskip

will give the following information:

?
> 44.0pt.
l.27 \showthe\ht0

? 
> 30.0pt.
l.32 \showthe\ht0

? 
> 10.0pt plus 2.0pt minus 5.0pt.
l.33 \showthe\abovedisplayskip

? 
> 10.0pt plus 2.0pt minus 5.0pt.
l.34 \showthe\belowdisplayskip

? 
> 0.0pt plus 3.0pt.
l.35 \showthe\abovedisplayshortskip

? 
> 6.0pt plus 3.0pt minus 3.0pt.
l.36 \showthe\belowdisplayshortskip

The 14pt difference is exactly the result of (10+10)-(0+6). Actually the \hrule height 0pt here does almost nothing because of \abovedisplayshortskip=0pt.

This doesn't happen when amsmath is loaded (the "short" skips are used in this case).

The definition of \[ in the LaTeX kernel is

\def\[{%
\relax\ifmmode
  \@badmath
\else
  \ifvmode
    \nointerlineskip\makebox[.6\linewidth]{}
  \fi
  $$
\fi}

that explains why the "non short" skips are used at the beginning of a paragraph: the LaTeX kernel starts a paragraph with an empty line long enough to prevent the use of the "short" skips. I believe that this has been added by Lamport to cope with authors that leave an empty line before \[.

egreg
  • 1,121,712
  • Seems like a better choice for Lamport would have been to just make \abovedisplayshortskip equal to \abovedisplayskip. – TH. Jun 20 '11 at 10:20
  • @TH I'd say no: when the document is properly written, the settings are good. Setting the "short" skip equal to the "normal" one would be wrong, causing a big hole when the line preceding the paragraph is short. – egreg Jun 20 '11 at 10:55
  • @TH: I'd also say no, for the same reasons. @egreg: Does your answer mean that the accepted answer to the question behind the link in the OP is wrong? (By the way, I do agree with your comment, but I think the implementation of \belowdisplayshortskip is rather strange.) – Hendrik Vogt Jun 20 '11 at 17:07
  • 1
    @Hendrik, egreg: I think you both misunderstood. I'm not saying that Lamport's decision to effectively ignore the \abovedisplayshortskip was a good one. I was just saying that an easier way to have them behave the same was to set them equal, not make sure that the short version would ever be used. – TH. Jun 20 '11 at 20:19
  • 1
    @Hendrik: it's not wrong, but incomplete. The real reason why $$ should not be used is that it hinders LaTeX (and amsmath) in doing what they should do to displays. – egreg Jun 20 '11 at 20:24
  • 1
    @Jasper: with amsmath the two vboxes would give the same result; but using $$ with amsmath can break many other things. – egreg Jun 20 '11 at 23:45
  • @TH: I have now read your last comment a few times, but I still don't get it. Maybe it contains some typos? Or my brain is permanently bungled? – Hendrik Vogt Jun 25 '11 at 14:21
  • @Hendrik: Yeah, typo. The last sentence should be, "I was just saying that an easier way to have them [them being display math when the previous line was short and when it was long] behave the same was to set them [them being \abovedisplayskip and \abovedisplayshortskip] equal, not make sure the short version would not ever be used. – TH. Jun 26 '11 at 02:40
10

You should avoid empty lines before and after displayed equations. Compare:

\documentclass[twocolumn,a5paper,12pt]{article}
\begin{document}

Equation using \LaTeX\ notation
%
\[ y = x^{2} \]
%
Equation using \TeX\ notation
%
$$ y = x^{2} $$
%
end of the part without empty lines\newpage

Equation using \LaTeX\ notation

\[ y = x^{2} \]

Equation using \TeX\ notation

$$ y = x^{2} $$

end of the part with empty lines
\end{document}

...

  • 1
    in this case there is no difference. But as already mentioned in some other cases there will be a difference. –  Jun 21 '11 at 07:00
  • 1
    "You should avoid empty lines before and after displayed equations." Is this advice intended strictly, or is it acceptable to skip a line after a displayed equation if you actually want to start a new paragraph? – Charles Staats Aug 20 '12 at 22:46