Skip to content

Every display equation contributes 13.1pt too much vertical glue (the first attributable cause of #622) #683

Closed

Description

@tannevaled

Every display equation costs 13.1pt too much — and it is not the formula

The first attributable cause of the +50 page bias (#622), found with probes that need
no page alignment at all, so none of #622's measurement traps apply.

The witness, in six lines

\documentclass[10pt]{article}
\begin{document}
\setbox0=\vbox{\begin{equation} E = \sum_{i=1}^{n} \frac{x_i^2}{\sqrt{1+y_i}} \end{equation}}
\message{[EQH=\the\ht0][EQD=\the\dp0]}
x
\end{document}
hauteur du vbox
gotex 49.441pt
tectonic 36.313pt
écart +13.13pt par display, +36 %

It is NOT the mathematics

The same formula as a plain box:

\setbox0=\hbox{$\displaystyle E = \sum_{i=1}^{n} \frac{x_i^2}{\sqrt{1+y_i}}$}
hauteur profondeur total
gotex 16.071pt 13.370pt 29.44pt
tectonic 16.514pt 12.799pt 29.31pt

0.13pt apart. go-tex/math sets the formula correctly; the excess is entirely in
what the equation environment packs around it:

emballage vertical
gotex 49.441 − 29.44 = 20.0pt
tectonic 36.313 − 29.31 = 7.0pt

Our \abovedisplayskip and \belowdisplayskip both read 10.0pt plus 2.0pt minus 5.0pt
— the reference's values — and 10 + 10 = the 20pt measured. So the parameters are right
and the contribution is wrong: something adds both skips where the reference adds
about one baseline's worth.

What it costs on a page

\loop\advance\n by1 \P \begin{equation} E_{\the\n} = … \end{equation} \ifnum\n<40 \repeat
pages
gotex 6
tectonic 5

40 displays × 13.13pt = 525pt, against a \textheight of 550pt: one page, exactly as
measured.
A paper with a hundred displays gains two and a half.

The controls that make this attributable

Three probes where the two engines agree exactly, so the fourth is not a general
divergence:

probe gotex tectonic
300 one-line paragraphs 7 pages 7 pages
80 multi-line prose paragraphs 6 pages 6 pages
40 \sections + prose 6 pages 6 pages
40 display equations + prose 6 pages 5 pages

And the page geometry is identical before any of it — read out of both engines on the
same document:

[TH=550.0pt][TS=10.0pt][BS=12.0pt][MD=5.0pt][VS=550.0pt][TW=345.0pt]   gotex
[TH=550.0pt][TS=10.0pt][BS=12.0pt][MD=5.0pt][VS=550.0pt][TW=345.0pt]   tectonic

So: same box, same prose capacity, same section cost, same formula — and 13.1pt of extra
glue per display.

Found along the way

\showthe is undefined in this engine, which is why measure dimens reads nothing
from it and refuses (correctly) rather than reporting zeros. It is a TeX primitive, and
our own measurement tooling wants it; every number above had to go through
\message{\the…} instead. Worth its own issue.

🤖 Generated with Claude Code

Activity

  1. tannevaled commented on Nov 4, 2026

    @tannevaled
    ContributorAuthor

    A hypothesis checked and discarded, and the real location narrowed

    What I thought it was

    tex.web:22578-22585 chooses between the long and short display skips:

    if (d+s <= pre_display_size) or l then   {not enough clearance}
      begin g1:=above_display_skip_code; g2:=below_display_skip_code; end
    else
      begin g1:=above_display_short_skip_code; g2:=below_display_short_skip_code; end
    

    displayskip.go uses \abovedisplayskip and \belowdisplayskip unconditionally, and
    the LaTeX 10pt values make the arithmetic look conclusive: (10 + 10) − (0 + 6) = 14pt
    against a measured 13.1pt.

    Why that is wrong

    The rule keys on \predisplaysize, and this engine does not have it:

    nous:       PDS-COURT=\the \predisplaysize     ← printed literally, unexpanded
    tectonic:   PDS-COURT=48.37pt   PDS-LONG=93.77pt
    

    So the rule cannot be evaluated here — that part is real. But measuring what the
    reference actually chose kills the hypothesis: with \predisplaysize at 48.37pt and a
    centred display's d+s ≈ 0, d+s <= pre_display_size is true, so tectonic took the
    long skips in both cases. The short-skip branch was never reached.

    Confirmed independently by the control, once I read it properly:

    ligne précédente nous tectonic écart
    courte 57.241pt 43.583pt +13.66
    longue 69.601pt 55.363pt +14.24

    The gap is the same in both. If the short-skip rule were the cause it would appear in
    one case and not the other. (That control was also confounded on first reading — the
    "long" line wrapped, so the two cases differ by a text line as well; the gap being
    constant is what survives.)

    Where it actually is

    Both engines use the same two skips, with the same values, and the formula box agrees to
    0.13pt. The 13–14pt therefore sits in the interline contribution around the display,
    which displayskip.go:80-88 adds deliberately and documents:

    TeX does not suppress that glue: after appending the skip it calls append_to_vlist
    for the display box like any other (tex.web:22602) … Suppressing it here cost a whole
    \baselineskip per display: measured against tectonic on one \[…\] between two lines
    of text, baseline to baseline across the display, reference 43.95pt against our 32.02pt.

    That reasoning and that measurement are sound. The open question is whether the
    correction overshot — 13pt is close to a \baselineskip of 12pt plus change — and the
    measurement that settles it is the same one quoted there, re-run now: baseline to
    baseline across a display between two text lines, both engines.

    Still true and still worth fixing on its own

    \predisplaysize is absent, so the long/short choice cannot be made at all. It is a TeX
    primitive, the rule above is unimplementable without it, and the short branch does exist
    in real documents — a display after a line that ends before the display's left edge.
    That is a separate defect from the 13pt, and this issue should not be closed by fixing
    only one of them.

    🤖 Generated with Claude Code

  2. tannevaled commented on Nov 4, 2026

    @tannevaled
    ContributorAuthor

    Located: we add a full \baselineskip on top of the skip, above the display

    Baseline to baseline across one display between two text lines — the same measurement
    displayskip.go:80-88 rests on — read off both PDFs with gotex-linediff:

    \noindent Ligne avant le display.
    $$E = 1$$
    \noindent Ligne apres le display.
    tectonic nous
    texte avant y = 134.76 y = 134.74
    display y = 146.72 y = 156.66
    texte après y = 164.65 y = 178.58
    avant → display display → après total
    tectonic 11.96 17.93 29.89pt
    nous 21.92 21.92 43.84pt
    écart +9.96 +3.99 +13.95

    +13.95pt, agreeing with the +13.13 and +13.66/+14.24 measured two other ways. Three
    independent probes, one number.

    The shape of it

    Above the display the reference's net advance is 11.96pt — exactly one
    \baselineskip
    , with the 10pt \abovedisplayskip absorbed: append_to_vlist adds
    \baselineskip − prev_depth − height(b) (tex.web §679), which goes to zero or negative
    once the skip and the display's own height are counted, so the skip does not simply add.

    We produce 21.92 = 11.96 + 9.96: the skip on top of a full baselineskip.

    ⚠ And the numbers in the existing comment are the mirror image of today's

    displayskip.go:86-88 justifies adding the interline glue with:

    measured against tectonic on one \[…\] between two lines of text, baseline to
    baseline across the display, reference 43.95pt against our 32.02pt.

    Today, by the same measurement: reference 29.89pt, ours 43.84pt. Our current value is
    within 0.1pt of the number that comment attributes to the reference, and the
    reference's current value is near the one it attributes to us.

    I am not asserting the two sides were swapped — the earlier probe used \[…\] where
    mine uses $$…$$, and the fonts differ (ours resolves STIXTwoMath here, the reference
    LMRoman) — but the coincidence is close enough that the fix this comment justifies should
    not be trusted until that measurement is re-run in its original form. If the sides were
    swapped, the correction moved us to the reference's wrong-side number, which would
    explain a 13.95pt excess that no parameter accounts for.

    Next

    Re-run the original \[…\] probe, same fonts both sides, before changing any code. The
    defect is confirmed and reproducible either way; what is not yet settled is whether the
    remedy is to remove the added interline glue or to compute it the way §679 does.

    🤖 Generated with Claude Code

  3. tannevaled commented on Nov 4, 2026

    @tannevaled
    ContributorAuthor

    Re-run in the comment's own form: the earlier measurement does not reproduce

    The previous note held off on code because two things differed from the probe
    displayskip.go:86-88 cites: it used \[…\] where I used $$…$$, and the fonts
    resolved differently. Both are now controlled.

    The probe form makes no difference at all

    Same document with \[E = 1\] instead of $$E = 1$$, both engines:

    tectonic nous
    texte avant 134.76 134.74
    display 146.72 156.66
    texte après 164.65 178.58

    Byte-identical to the $$ run on both sides. The two spellings produce the same
    geometry here, so the form the earlier probe used cannot explain anything.

    The font is excluded by the measurement itself

    Our run resolves STIXTwoMath-Regular where the reference uses LMRoman10-Regular, and
    that is worth excluding rather than arguing about — so look at the first baseline,
    which is placed before any display is involved:

    tectonic  y = 134.76
    nous      y = 134.74
    

    0.02pt apart. Whatever the font changes vertically on this page, it changes it by two
    hundredths of a point. It cannot account for 13.95.

    So

    total ligne-à-ligne à travers le display
    tectonic, aujourd'hui 29.89pt
    nous, aujourd'hui 43.84pt
    le commentaire, « reference » 43.95pt
    le commentaire, « our » 32.02pt

    Measured in the comment's own form, with the font excluded, the reference is at 29.89
    and we are at 43.84
    — each within ~2pt of the value the comment assigns to the other
    side.

    I still cannot prove the sides were swapped: I did not run that earlier probe and
    cannot see its inputs. What I can say is that its result does not reproduce, and that
    the interline glue added on its authority is the whole of a 13.95pt excess that no
    parameter accounts for.

    ⇒ The remedy is not "remove the glue" either — that was tried before and is what the
    comment was written to prevent. It is to compute the contribution the way tex.web §679
    does, \baselineskip − prev_depth − height(b) floored by \lineskip, and then measure
    this same three-baseline probe against the reference's 11.96 / 17.93. That is a code
    change with a known target number, which is the state this issue should be in before
    anyone writes it.

    🤖 Generated with Claude Code

  4. tannevaled commented on Nov 4, 2026

    @tannevaled
    ContributorAuthor

    One more narrowing, from the code rather than a probe

    interlineGlue (paragraph.go:362-371) already implements tex.web §679 exactly:

    gap := e.baselineskip - prevDepth - height
    if gap < e.lineskiplimit {
        gap = e.lineskip
    }

    and the parameters read correctly: \lineskip 1.0pt, \lineskiplimit 0.0pt,
    \baselineskip 12.0pt.

    So the formula is not the defect. The excess has to be in what placeDisplay hands
    it — the prevDepth in force when the display box is contributed, or the height of the
    box it contributes — not in how the glue is computed from them.

    That is where a fix should start looking, and it is a smaller search than the one this
    issue opened with.

    A probe that did not work, recorded so no one repeats it

    Reading \the\prevdepth just before the display returns −999.99998pt
    (ignore_depth), because the message is expanded in horizontal mode: the paragraph has
    not been contributed yet, so \prevdepth still describes the enclosing vertical list,
    not the state the display will see. Instrumenting this from inside the document does not
    reach the quantity in question; it has to be read from the engine's own node list.

    🤖 Generated with Claude Code

  5. tannevaled commented on Nov 4, 2026

    @tannevaled
    ContributorAuthor

    ⛔ I was wrong to discard the short-skip hypothesis. It is the cause, to the hundredth of a point

    Read out of the engine's own vertical list, which is where I said this quantity had to
    come from:

    baselineskip=12.000  lineskip=1.000  lineskiplimit=0.000
    
     0 box    h=6.730  d=2.350      ← « Ligne avant. »
     1 glue   w=10.000              ← \abovedisplayskip
     2 glue   w= 3.080              ← interligne: 12.000 − 2.350 − 6.570 ✓
     3 box    h=6.570  d=0.000      ← le display
     4 glue   w=10.000              ← \belowdisplayskip
     5 glue   w= 5.270              ← interligne: 12.000 − 0.000 − 6.730 ✓
     6 box    h=6.730  d=2.350      ← « Ligne apres. »
    

    interlineGlue is right in both places. Our baseline-to-baseline above the display is
    2.350 + 10.000 + 3.080 + 6.570 = 22.00pt, against the 21.92 measured off the PDF.

    Now put the short skips in instead:

    au-dessus en dessous
    \abovedisplayshortskip = 0pt, \belowdisplayshortskip = 6pt 2.350 + 0 + 3.04 + 6.570 = 11.96 0 + 6 + 5.270 + 6.730 = 18.00
    mesuré sur le PDF de tectonic 11.96 17.93

    Exact above, 0.07pt below. 10pt + 4pt = the 13.95pt excess, accounted for entirely.

    Why I talked myself out of it

    The rule is tex.web:22580:

    if (d+s <= pre_display_size) or l then   {not enough clearance}
       g1 := above_display_skip_code   …
    else
       g1 := above_display_short_skip_code   …
    

    I read \predisplaysize as 48.37pt, assumed d+s ≈ 0 for a centred display, concluded
    d+s <= pre_display_size was true, and therefore that tectonic had taken the long
    skips. d+s is not zero — it is the display's left edge. On this page the display
    starts at x=292.53 while the previous line ends at x=230.83: the line ends before the
    display begins, there is clearance, and the condition is false → the short skips.

    So the measurement I offered as a refutation (“the gap is the same whether the preceding
    line is long or short”) was measuring two cases that both take the short branch, because
    both lines end well before a centred display's left edge. It could not have separated
    them.

    What the fix is, with its target numbers

    Implement tex.web:22578-22585: track \predisplaysize (the effective width of the last
    line before the display), compare it against the display's d+s, and choose
    \abovedisplayshortskip/\belowdisplayshortskip when there is clearance. Both parameters
    already exist here with the right values (0.0pt plus 3.0pt and 6.0pt plus 3.0pt minus 3.0pt); displayskip.go simply never selects them, and \predisplaysize is absent.

    Target for the three-baseline probe: 11.96 above, 17.93 below, against our present
    22.00 and 22.00.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions