Skip to content

render-pipeline: a list's \topsep/\partopsep/\itemsep/\parsep are glue, not kerns - #405

Merged
GoKubar merged 3 commits into
mainfrom
lane/nixos-vertical-drift-list-glue
Sep 14, 2026
Merged

GoKubar merged 3 commits into
mainfrom
lane/nixos-vertical-drift-list-glue

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Stacked on #401 (which is itself stacked on #400). The three changes are independent mechanisms but share adapter.rs/typeset.rs hunks; review the third commit only.

render-pipeline: a list's \topsep/\partopsep/\itemsep/\parsep are glue, not kerns

The adapter carried every list skip as a bare f64 (Unit::vspace_before,
Unit::addvspace_before), and add_vspace turned it into rigid glue
((pt, 0.0, 0.0)). The natural width was right — which is why the within-page
spacing already matched — but the page builder then saw far less \pagestretch
and \pageshrink than pdfTeX does, and chose different breakpoints.

Oracle evidence (\showoutput on fixtures/real-world/plain-article, TeX Live
2025 pdflatex, oracle only). Summed over that document's page 2, pdfTeX's
vertical list carries 47.1943 pt of stretch and 28.7222 pt of shrink; ours
carried 38.1943 / 21.7222 — exactly the \@plus2\p@ \@minus\p@ of four
\itemseps and the \@plus2\p@ \@minus4\p@ of one \topsep. At the
\@secpenalty breakpoint before \section{Cost Comparison} the page is 61.09 pt
short, so the missing stretch is the whole decision:

badness(61.09, 38.19) = 408  ->  cost 408 - 300 =  108   (we skipped it)
badness(61.09, 47.19) = 216  ->  cost 216 - 300 =  -84   (pdfTeX takes it)

and the next breakpoint, three lines later, costs 1. With the glue restored our
page builder reports stretch 47.1943 / shrink 28.7222 at that breakpoint —
pdfTeX's numbers to the last recorded digit — and breaks where pdfTeX breaks.

ListSeps now keeps a crate::style::Skip for each of \topsep,
\partopsep, \itemsep and \parsep; Block::Paragraph/Unit carry an
addvspace_flex/vspace_flex pair beside the two natural-width scalars, and
add_skip attaches them. An explicit enumitem topsep=/itemsep=/parsep=
value stays rigid, because that key assigns a dimen; nosep/noitemsep zero
the skips outright. Where \@xaddvskip keeps the previous block's larger
trailing skip, its stretch is what survives, so the list skip's is not added on
top of it.

Real-world corpus (22 documents, tools/visual-oracle/rank.py), on top of the
two earlier commits on this branch:

dy   <= 0.5 bp   72.0% -> 75.4%
both <= 0.5 bp   65.3% -> 69.0%
dx   <= 0.5 bp   85.2% -> 85.2% (unchanged)
page counts      20/22 -> 21/22

Per fixture: plain-article dy 47.9 -> 99.7 / both 38.8 -> 90.0, conf-paper
dy 85.5 -> 99.9 / both 81.1 -> 95.4, twelvept-plain now sets 3 pages like the
reference instead of 4 (its dy reads 68.3 -> 63.1 only because the 15 words
that used to spill onto a fourth page are now aligned on page 3 and counted).
No other fixture moves.

Gates: cargo test --release --no-fail-fast on crates/render-pipeline green,
new adapter::tests::list_skips_keep_their_stretch_and_shrink; amsmath 59/59,
tabular 106/106, HW1 and HW2 3 pages / 0 errors, zero font-FAILURE diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-vertical-drift, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-Authored-By: Claude Opus 5 [email protected]
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 3 commits September 14, 2026 11:29
… discretionary

TeX appends `\interlinepenalty + \clubpenalty + \widowpenalty + \brokenpenalty`
after each line of a paragraph (§890 `if disc_break then pen:=pen+broken_penalty`);
the page builder had every term but `\brokenpenalty` (latex.ltx sets it to 100),
so a page could break for free right after a hyphenated line.

Oracle evidence (`\showoutput` on `fixtures/real-world/lmodern-report`, TeX Live
2025 pdflatex, oracle only): page 1's vertical list carries `\penalty 100` after
the line ending `Man-`, and pdflatex breaks one line *later*, at badness 2 with
the page shrunk (`\vbox(650.43001+0.0)x469.75502, glue set - 0.26439`), rather
than at the hyphenated break whose badness alone is 1. Without the penalty this
crate took the cheaper-looking earlier break, every line of page 2 landed one
`\baselineskip` (13.55 bp) low, and page 1 stood at its natural height instead
of shrinking (the +1.83…+2.33 bp drift down that page).

With the penalty the page builder now reports natural 652.76429 and glue-set
ratio -0.26440 for that page, against pdflatex's 652.7643 / -0.26439.

Real-world corpus (22 documents, word positions vs the pinned pdflatex
references, `tools/visual-oracle/rank.py`):

    dy  <= 0.5 bp   65.2% -> 70.4%
    both <= 0.5 bp  58.7% -> 63.8%
    dx  <= 0.5 bp   84.5% -> 84.5% (unchanged)

lmodern-report alone: dy 26.4% -> 81.8%, both 26.4% -> 81.1%. No other fixture
moves in either direction; page counts are unchanged everywhere.

Gates: `cargo test --release --no-fail-fast` on crates/render-pipeline all green;
amsmath 59/59, tabular 106/106, HW1 and HW2 3 pages / 0 errors, zero
font-FAILURE diagnostics across the corpus.

Implementation-Agent: Claude Opus 5 (lane nixos-vertical-drift, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…dent, bold label)

`description` was missing from the four hard-coded lists of list environments
in `adapter.rs` (`list_stack_at`, `list_env_after_begin`, `gap_has_list_end`,
`list_end_adjust`/`list_end_skip`), so an `\item[...]` of one got no `\list`
treatment at all: no `\partopsep` when the environment opened in vertical mode,
no `\@endparenv` skip at `\end{description}`, no `\leftmargin` hanging indent,
no `\itemindent`, and a medium-weight label.

article.cls builds it exactly like `itemize`:

    \newenvironment{description}
      {\list{}{\labelwidth\z@ \itemindent-\leftmargin
               \let\makelabel\descriptionlabel}}{\endlist}
    \newcommand*\descriptionlabel[1]{\hspace\labelsep \normalfont\bfseries #1}

so the four things that follow are now all implemented: the class list skips,
`\labelwidth\z@` (a short label is never padded out), `\itemindent-\leftmargin`
(the item's first line is flush at the margin, continuation lines hang in), and
`\descriptionlabel`'s `\labelsep` + `\bfseries`.

Oracle evidence (TeX Live 2025 pdflatex, oracle only). A probe with two
wrapping items and a one-line item, before -> after, against the reference:

    first item baseline   -2.99 bp (the missing \partopsep, 3 pt)  ->  0.00
    paragraph after the list  -14.95 bp (that plus the whole
                              missing \@endparenv skip, 12 pt)     ->  0.00
    label x               -5.46 bp (no \descriptionlabel \labelsep) ->  0.00
    continuation line x  -27.27 bp (no \leftmargin)                ->  0.00

The same -2.99 bp and -27.28 bp are the two largest deltas on page 3 of
`fixtures/real-world/lmodern-report`; that page is now exact.

A second defect surfaced while measuring: a multi-word label was shaped as one
run, so the gap between its words was the **T1 visible-space glyph's** advance
(6.27 bp for `\bfseries` Latin Modern at 11 pt) rather than `\fontdimen2`
(4.18 bp), pushing everything after the label 2.1 bp right. `label_box` now
builds the label the way `number_box` already built amsmath tags — one shaped
run per word, joined by TeX's interword glue — and the two share `word_box`.

Real-world corpus (22 documents, `tools/visual-oracle/rank.py`), on top of the
`\brokenpenalty` fix:

    dy   <= 0.5 bp   70.4% -> 72.0%
    both <= 0.5 bp   63.8% -> 65.3%
    dx   <= 0.5 bp   84.5% -> 85.2%

Per fixture, only the four `description` documents move: lmodern-report
dy 81.8 -> 100.0 / both 81.1 -> 98.9, enumitem-worksheet dx 49.5 -> 51.3,
listings-manual dx 42.7 -> 43.6, plain-article dx 83.4 -> 89.6. plain-article's
dy reads 50.3 -> 47.9: its page 2 already carried a pre-existing glue-shrink
ramp (our page 2 is over-full and shrinks where pdflatex's is `\raggedbottom`
and stretches, because we break three lines later at `\section{Cost
Comparison}`), and the old `description` skips happened to cancel part of it.
The ramp is unchanged by this commit — measured identical on the previous
binary — and the page-break difference is a separate defect. Page counts are
unchanged everywhere (20/22).

Gates: `cargo test --release --no-fail-fast` on crates/render-pipeline green,
new `tests/description_env.rs`; amsmath 59/59, tabular 106/106, HW1 and HW2
3 pages / 0 errors, zero font-FAILURE diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-vertical-drift, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…e, not kerns

The adapter carried every list skip as a bare `f64` (`Unit::vspace_before`,
`Unit::addvspace_before`), and `add_vspace` turned it into rigid glue
(`(pt, 0.0, 0.0)`). The natural width was right — which is why the *within-page*
spacing already matched — but the page builder then saw far less `\pagestretch`
and `\pageshrink` than pdfTeX does, and chose different breakpoints.

Oracle evidence (`\showoutput` on `fixtures/real-world/plain-article`, TeX Live
2025 pdflatex, oracle only). Summed over that document's page 2, pdfTeX's
vertical list carries 47.1943 pt of stretch and 28.7222 pt of shrink; ours
carried 38.1943 / 21.7222 — exactly the `\@plus2\p@ \@minus\p@` of four
`\itemsep`s and the `\@plus2\p@ \@minus4\p@` of one `\topsep`. At the
`\@secpenalty` breakpoint before `\section{Cost Comparison}` the page is 61.09 pt
short, so the missing stretch is the whole decision:

    badness(61.09, 38.19) = 408  ->  cost 408 - 300 =  108   (we skipped it)
    badness(61.09, 47.19) = 216  ->  cost 216 - 300 =  -84   (pdfTeX takes it)

and the next breakpoint, three lines later, costs 1. With the glue restored our
page builder reports stretch 47.1943 / shrink 28.7222 at that breakpoint —
pdfTeX's numbers to the last recorded digit — and breaks where pdfTeX breaks.

`ListSeps` now keeps a `crate::style::Skip` for each of `\topsep`,
`\partopsep`, `\itemsep` and `\parsep`; `Block::Paragraph`/`Unit` carry an
`addvspace_flex`/`vspace_flex` pair beside the two natural-width scalars, and
`add_skip` attaches them. An explicit `enumitem` `topsep=`/`itemsep=`/`parsep=`
value stays rigid, because that key assigns a dimen; `nosep`/`noitemsep` zero
the skips outright. Where `\@xaddvskip` keeps the *previous* block's larger
trailing skip, its stretch is what survives, so the list skip's is not added on
top of it.

Real-world corpus (22 documents, `tools/visual-oracle/rank.py`), on top of the
two earlier commits on this branch:

    dy   <= 0.5 bp   72.0% -> 75.4%
    both <= 0.5 bp   65.3% -> 69.0%
    dx   <= 0.5 bp   85.2% -> 85.2% (unchanged)
    page counts      20/22 -> 21/22

Per fixture: plain-article dy 47.9 -> 99.7 / both 38.8 -> 90.0, conf-paper
dy 85.5 -> 99.9 / both 81.1 -> 95.4, twelvept-plain now sets 3 pages like the
reference instead of 4 (its dy reads 68.3 -> 63.1 only because the 15 words
that used to spill onto a fourth page are now aligned on page 3 and counted).
No other fixture moves.

Gates: `cargo test --release --no-fail-fast` on crates/render-pipeline green,
new `adapter::tests::list_skips_keep_their_stretch_and_shrink`; amsmath 59/59,
tabular 106/106, HW1 and HW2 3 pages / 0 errors, zero font-FAILURE diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-vertical-drift, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar
GoKubar changed the base branch from lane/nixos-vertical-drift-description to main September 14, 2026 16:11
@GoKubar
GoKubar merged commit fb79c64 into main Sep 14, 2026
9 of 20 checks passed
GoKubar added a commit that referenced this pull request Sep 14, 2026
…its term flush too (#409)

#405 gave `description` its `\list` geometry — `\labelwidth\z@
\itemindent-\leftmargin`, the class `\leftmargin`, the separations and the
bold `\descriptionlabel`. One path did not get it: when the item's body
opens with a display (`\item[Term] \[...\]`), `\@item` holds the label in
`\@labels` and `\everypar` sets it on a line of its own, and that line is
built by `display_opener_block`, which still placed the term at
`\leftmargin - \labelsep`.

`list_geometry` already returns the innermost `\leftmargin` for exactly
this; `display_opener_block` was discarding it (`let (hang, labelwidth, _)`).

Measured against pdflatex (TeX Live 2025) on a two-item `description` whose
first item opens with `\[ x + y = z \]`: the term was at x 91.925 against
the reference's 72.000, dx **+19.925 bp** (= `\leftmargin` 24.907 −
`\labelsep` 4.981) on all three of its words. After, all 58 words on the
page are within 0.005 bp in x and y — the probe is exact, including the
display's own position and the text hanging at `\leftmargin` below it.

**No corpus movement, and that is the honest summary of its reach:** no
fixture in `fixtures/real-world/` has a `description` item that opens with
a display, so the 22-document corpus is unchanged to the last word
(dx 85.74%, dy 75.93%, both 69.79%, 14054 aligned, page counts 21/22, all
identical before and after). This is a probe-verified correctness fix, not
a parity gain.

Gates: `cargo test --release --no-fail-fast` on render-pipeline 268 passed
/ 0 failed / 2 ignored (one new `description_display` test),
class-geometry 4/0, compiler 581/0/4; amsmath 59/59, tabular 106/106, HW1
and HW2 3 pages / 0 errors / 0 font-FAILURE diagnostics.

Implementation-Agent: Claude Opus 5 (lane nixos-graphics-sectioning, linux-primary)
Commit-Executor: Claude Opus 5 (direct git, observed Cursor usage limit)
@GoKubar
GoKubar deleted the lane/nixos-vertical-drift-list-glue branch September 16, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant