Does $$…$$ produces wrong spacing in plain TeX

displaystyleplain-tex

In the ConTeXt FAQ, one can read

Does $$…$$ work for display math, like in (La)TeX?
No; the spacing above and below the equation will be wrong, and maybe other aspects too.

Moreover in LaTeX, a good practice is to replace the $$…$$ syntax by \[…\] source.

I was thus wondering if the double-dollar-sign syntax produced unsatisfactory output even in plain TeX. If so, can I see an example of that? And why Don Knuth didn't fix it since he is so strict about typography?

Best Answer

The spacing for $$ is the same in plain TeX as in LaTeX and is only wrong if you use incorrect input with a blank line before the display. in LaTeX it's also wrong to leave a blank line before \[ but it makes some attempt to catch that case.

A plain TeX example is

\tracingonline2
\tracingoutput2
\showboxdepth2
\showboxbreadth100

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$$x=1$$

\bigskip

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

$$x=2$$



\bye

Producing

enter image description here

with the default settings with a small \parskip and \abovedisplayskip of similar size to \baselineskip the spacing betweeen the two aaaaa and the following display may look similar in this image (they are actually the same) but the second one is completely incorrect.

The log for the first shows

..\hbox(4.30554+0.0)x469.75499, glue set 119.75398fil []
..\penalty 10000
..\glue(\abovedisplayskip) 12.0 plus 3.0 minus 9.0
..\glue(\baselineskip) 5.55556
..\hbox(6.44444+0.0)x24.04851, shifted 222.85324, display []

That is a line of text (aaa..) a no break penalty, then because the line was long and overlapped the formula, \abovedisplayskip is inserted then a baselineskip to the formula x=1.

The second equation spacing is constructed completely differently:

..\hbox(4.30554+0.0)x469.75499, glue set 119.75398fil []
..\glue(\parskip) 0.0 plus 1.0
..\glue(\baselineskip) 12.0
..\hbox(0.0+0.0)x469.75499, glue set 449.75499fil []
..\penalty 10000
..\glue(\abovedisplayshortskip) 0.0 plus 3.0
..\glue(\baselineskip) 5.55556
..\hbox(6.44444+0.0)x24.04851, shifted 222.85324, display []

That is,

the line of text aaa
\parskip spacing (0pt here) and
\baselineskip spacing to a spurious invisible paragraph
a single line paragraph consisting of an indentation box and parfillskip and no text
a nobreak penalty
\abovedisplayshortskip as the empty paragraph does not overlap the formula
\baselineskip to the formula
The formula text

Apart from the fact that the visible space in the second case consists of \abovedisplaysmallskip and \baselineskip Notable here is there is no nobreak penalty after the second line of aaa, a page break can happen there in which case the empty paragraph line will not be discarded at the page break as it is not vertical space so the equation will not start at the top of the page but be a line too low.

If a setting with a non zero \parskip is used this will affect the second form. The spaces in the image are only the same as (ignoring stretch and shrink) \abovedisplayskip is equal in plain TeX defauts to \abovedisplaysmallskip+\baselineskip`.

LaTeX's \[ tries to catch the second case as it does

\DeclareRobustCommand\[{%
   \relax\ifmmode
      \@badmath
   \else
      \ifvmode
         \nointerlineskip
         \makebox[.6\linewidth]{}%
      \fi
      $$%%$$ BRACE MATCH HACK
   \fi
}%

so it inserts a box over half of the linewidth to avoid abovedisplayshortskip being used, and avoids glue (and so a page break possibility) being added before this box.