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.

3
  • 5
    Since the bigger problem with $$...$$ is that it won't work with anything that modifies displayed math (e.g. the [fleqn] option) how important is it to worry about the vertical spacing issue?
    – Alan Munn
    Commented Jun 20, 2011 at 3:43
  • 1
    possible duplicate of Why is \[ ... \] preferable to $$?. Arg. I didn't see that you already cited this question. I am sleepy.
    – Lev Bishop
    Commented Jun 20, 2011 at 4:47
  • 5
    I think this is a fine question and you got a good answer to it.
    – TH.
    Commented Jun 20, 2011 at 10:21

2 Answers 2

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}

...

2
  • 1
    in this case there is no difference. But as already mentioned in some other cases there will be a difference.
    – user2478
    Commented Jun 21, 2011 at 7: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? Commented Aug 20, 2012 at 22:46
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 \[.

8
  • Seems like a better choice for Lamport would have been to just make \abovedisplayshortskip equal to \abovedisplayskip.
    – TH.
    Commented Jun 20, 2011 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
    Commented Jun 20, 2011 at 10:55
  • 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.
    Commented Jun 20, 2011 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
    Commented Jun 20, 2011 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
    Commented Jun 20, 2011 at 23:45

You must log in to answer this question.