5

I've tried reading various sources (in particular Tex By Topic; I don't have a copy of the TeXBook) and experimenting on my own, but I'm still unclear as to how exactly the line spacing in and around a multiline math environment is determined by the parameters

  • \abovedisplayskip, \belowdisplayskip, \abovedisplayshortskip, \belowdisplayshortskip
  • \lineskip, \lineskiplimit
  • \jot

Can someone explain exactly how the skips are computed? (Ideally it should include a description of what happens if one or more of these parameters is made negative.)

I'm especially interested in \lineskip and \lineskiplimit, since I've seen some strange results from playing with these.

For a MWE, see the example given in Set a minimum space above and below displayed math

  • Neither of those answers seems fully to explain what happens in math mode. For instance, in the example from my other question, the space between the first two math lines increases drastically if I set \lineskiplimit=0.1pt\lineskip=6pt versus \lineskiplimit=0pt\lineskip=6pt, even though there appears to be considerably more than 0.1pt of vertical space separating them. – Charles Staats Jul 6 '14 at 20:32
  • 1
    Alignments use struts; if you set \lineskiplimit to 0pt, the mechanism will not come into play unless lines are too high or deep (third and fourth); it will if \lineskiplimit is set to 0.1pt (or even 2sp), because two consecutive lines as high and deep as a strut will be “too near”. – egreg Jul 6 '14 at 20:41
  • I don't suppose there's any way to set the height or depth of these struts, other than changing \baselineskip? – Charles Staats Jul 6 '14 at 21:01
  • The strut is automatically computed based on the current baselineskip – egreg Jul 6 '14 at 21:53
6

Your three categories of skip are almost entirely different in behaviour:

  • \abovedisplayskip, \belowdisplayskip, \abovedisplayshortskip,\belowdisplayshortskip
  • \lineskip, \lineskiplimit, \baselineskip
  • \jot

The first set are solely related to the boundary between (primitive) display math and the partial paragraph in which it is contained.

The second set (to which I added \baselineskip) are not directly related to math at all and control the way TeX stacks boxes in vertical mode, in particular (but not only) when stacking hboxes built from breaking a paragraph into lines.

The third, \jot, is dimen register declared in the latex format (copied from plain).

Unlike the lineskip group, which are essentially "target" lengths which specify how TeX should try position vertically stacked boxes, the displayskip group are simpler constructs: the specified lengths are added in full before and after a $$ display math construct. You ask about negative settings these are not handled differently, you always get the specified space.

\documentclass{article}
\usepackage{amsmath}
\showoutput
\showboxdepth3
\parindent0pt
\begin{document}
\baselineskip=12pt
\abovedisplayskip=10pt


aaa\dotfill aa
$$x$$
bb

\end{document}

produces

...\hbox(4.30554+0.0)x345.0, glue set 319.99992fill []% a line
...\penalty 10000

...\glue(\abovedisplayskip) 10.0

...\glue(\baselineskip) 7.69446
...\hbox(4.30554+0.0)x5.71527, shifted 169.64236, display []% x math
...\penalty 0
...\glue(\belowdisplayskip) 10.0 plus 2.0 minus 5.0
...\glue(\baselineskip) 5.05556
...\hbox(6.94444+0.0)x345.0, glue set 333.88885fil []% b line

the same document, changing the \abovedisplayskip to -10pt produces

...\hbox(4.30554+0.0)x345.0, glue set 319.99992fill []%a line
...\penalty 10000

...\glue(\abovedisplayskip) -10.0

...\glue(\baselineskip) 7.69446
...\hbox(4.30554+0.0)x5.71527, shifted 169.64236, display []%x math
...\penalty 0
...\glue(\belowdisplayskip) 10.0 plus 2.0 minus 5.0
...\glue(\baselineskip) 5.05556
...\hbox(6.94444+0.0)x345.0, glue set 333.88885fil []%b line

Which is exactly the same spacing, except that the math is 20pt higher, over-printing the line above.

TeX either inserts \abovedisplayskip and \belowdisplayskip or \abovedisplayshortskip and \belowdisplayshortskip (never a mixture) and (roughly) it uses the short form if the last line of the paragraph does not overlap the math so

blah blah blah blah
        x=1

would get \abovedisplayskip but

blah 
       x=1

would get \abovedisplayshortskip

the exact rule for what counts as an overlap is complicated by the possible presence of equation numbers and other details, which I'll ignore for now, although it's worth noting that the mechanism here is the only way available in classic TeX to measure the length of the last line in a paragraph which is exposed as \predisplaysize inside the display math, several packages use hidden display math blocks just for this use.

The above box output also shows the effect of \baselineskip but unlike \abovedisplayskip, \baselineskip is not usually added in full, it is the target spacing for the baselines of vertically stacked boxes.

here the a...a line has zero depth (the 0.0 in ...\hbox(4.30554+0.0)x345.0) and the math x has height 4.3pt (the 4.30554 in ...\hbox(4.30554+0.0)x5.71527 so to arrange that these boxes have baselines 12pt apart (the specified value of \baselineskip) TeX inserts 12pt-4.3pt=7.7pt as shown by ...\glue(\baselineskip) 7.69446 Note that it does this calculation purely on the depth of the previous box and the height of the current box, ignoring any other glue (\abovedisplayskip here) that may be inserted for other reasons.

The automatic \baselineskip glue that is inserted is never less than \lineskiplimit If it would fall below that (as the previous line has great depth or the current line has great height) then TeX gives up trying to force equally spaced lines and just inserts \lineskip glue (in full) between the lines.

LaTeX by default sets \lineskiplimit to 0pt and \lineskip to 1pt (again following plain) these settings are perhaps a little odd really as they give rise to a discontinuity in spacing, as you gradually reduce \baselineskip two boxes get closer together, as close as the invisibly small 1sp, but then if they would touch they are spaced apart by 1pt. setting \lineskiplimit and \lineskip to the same value gives a spacing that is continuous in the value of \baselineskip, however the intention of setting \lineskiplimit to 0pt is probably to try "until the last minute" to maintain baseline spacing.

These settings come into play in alignments as the alignments are typically \halign constructs with inline (but \displaystyle) math in each row. the rows of an \halign are stacked just like the limes of a paragraph and are subject \baselineskip and \lineskip spacing.

However before starting the display latex (again, following plain) increases \baselineskip, \lineskip and \baselineskip by \jot.

So although a 10pt LaTeX document is normally set with a \baselineskip of 12pt within a align it is 15pt (and \lineskip is 4pt with a \lineskiplimit of 3pt (assuming the standard \jot of 3pt)

\documentclass{article}
\usepackage{amsmath}
\showoutput
\showboxdepth3
\parindent0pt
\begin{document}
\baselineskip=12pt



aaaa\dotfill aa
\begin{align}1\\
2
\showthe\baselineskip
\showthe\lineskiplimit
\showthe\lineskip
\\3
\end{align}

\jot=10pt

aaa\dotfill aa
$$x$$
bb

aaaa\dotfill aa
aaaa\dotfill aa
\begin{align}1\\
2
\showthe\baselineskip
\showthe\lineskiplimit
\showthe\lineskip
\\3
\end{align}


\end{document}

the first align shows

> 15.0pt.
<argument> 1\\ 2 \showthe \baselineskip 
> 3.0pt.
<argument> ...aselineskip \showthe \lineskiplimit 
> 4.0pt.
<argument> ...e \lineskiplimit \showthe \lineskip 

and the second

> 22.0pt.
<argument> 1\\ 2 \showthe \baselineskip 
> 10.0pt.
<argument> ...aselineskip \showthe \lineskiplimit 
> 11.0pt.
<argument> ...e \lineskiplimit \showthe \lineskip 

typesetting as

enter image description here

  • Also, it should be “a...a line”, I guess… – GuM Nov 6 '16 at 23:06
  • @GustavoMezzetti thanks (and 0,0 not 0,0 :-) – David Carlisle Nov 6 '16 at 23:31
  • @jfbu only two typos? not bad for me (not counting the ones Gustavo fixed:-) I'll seek them out:-) – David Carlisle Nov 7 '16 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.