Skip to content

render-pipeline: charge \brokenpenalty, and set the float column's glue (vertical parity) - #356

Closed
GoKubar wants to merge 1 commit into
mainfrom
agent/linux-vertical-parity/topskip
Closed

GoKubar wants to merge 1 commit into
mainfrom
agent/linux-vertical-parity/topskip

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Vertical parity lane (linux-primary). Draft. Base origin/main @ 06007472.

Issue #2 split the corpus error by axis and found the vertical miss is mostly a
rigid per-page offset: |dx| ≤ 0.5bp 73.1%, |dy| ≤ 0.5bp 29.5%, but
62.3% once each page's own median dy is subtracted. This is the two bugs
behind most of that offset.

Where the first divergence is, with the \showoutput evidence

lmodern-report page 1, the clean case from the issue: dx_mean 0.004bp,
every word 1.83bp low, growing to 110bp by page 4.

pdflatex's own page-1 vertical list (\showoutput, pdfTeX 1.40.27; my local
run reproduces the committed reference.pdf word-for-word on all four pages):

..\vbox(650.43001+0.0)x469.75502, glue set - 0.26439

Summing that box's items: natural 652.76431pt in a 650.43001pt
\@colht, excess 2.3343pt against 8.82867pt of available shrink — ratio
0.26439, exactly the glue set TeX printed. Our vertical list is the same
list
: our last page-1 baseline plus one \baselineskip is 652.764pt, the
natural total to 0.001pt. So the list was never the problem.

Per line, the first three divergences on that page and what each is:

line ref gap ours Δ
Contents (\section* after \maketitle) 44.499 46.327 +1.828
1 Executive Summary 34.123 34.372 +0.249
2 Background 34.123 34.372 +0.249

Those are precisely the shrink shares: the \section before-skip is
3.5ex plus 1ex minus .2ex = 16.50078 plus 4.71451 minus 0.94289, and
0.94289 × 0.26439 = 0.2493pt = 0.2484bp. The Contents gap additionally
spans \@maketitle's center, whose \@endparenv contributes
\topsep + \partopsep = 12pt plus 4pt minus 6pt; 6.94289 × 0.26439 = 1.8356pt = 1.829bp. Everything on the page is the natural layout of the
correct list.

What I fixed

1. \brokenpenalty was never charged. tex.web §890 puts it in the same
penalty node as \interlinepenalty/\clubpenalty/\widowpenalty whenever
the line just finished ended at a discretionary; LaTeX sets it to 100
(\showthe\brokenpenalty). In the log it is the \penalty 100 between
"…frustration. Man-" and "agement commissioned…". Tracing our page builder at
the same two breakpoints:

i=115  total=639.16429  goal=650.43000  stretch=47.22938  c=1     <- we broke here
i=117  total=652.76429  goal=650.43000  shrink=8.82871   c=2

Cost 1 beats 2, so we ended the page at the hyphen. pdflatex compares
1 + 100 against 2 — and the glue after a penalty is not itself a legal
breakpoint, so there is no third option. VBlock::broken_penalty now carries
it per line from Line::hyphenated, which is exactly §882's disc_break.
Table cells are deliberately excluded: their lines are not breakpoints of the
page's vertical list, so charging them would move longtable's row breaks with
no oracle behind it.

2. The float column builder never set its columns' glue. \@makecol
packs every column \vbox to\@colht. break_pages_regions and make_column
both do this; floatpage::paginate's no-footnote branch — which is the branch
every page of a document that has a float and no footnote takes — advanced
by each glue's natural width, with no ratio at all. So even after the break
was right, the page stayed at natural size and ran past the text area.

Before / after

22 real-world fixtures, 12 261 aligned words, zero font-failure
diagnostics
, measured with the per-axis harness from PR #344 against the
committed pdflatex references.

before after
|dx| ≤ 0.5bp 73.7% 73.6%
|dy| ≤ 0.5bp 30.8% 34.8%
both axes 24.3% 28.4%

Per document, |dy| ≤ 0.5bp:

document before after
lmodern-report 3.1% (36/1161) 46.8% (520/1111)
every other fixture unchanged unchanged

lmodern-report page by page (median dy, bp):

page before after
1 +1.83 (3.6% of words within 0.5bp) −0.00 (100.0%, all 431 words, both axes)
2 +13.55 (0.3%) −0.86 (30.7%)
3 −112.25 −150.81
4 −110.03 −157.95

Page 1 is now exact. Pages 2–4 are downstream of a different, already-filed
gap: floats.rs::prepare drops a tabular inside a float (issue #2 §5), so
our Table 1 box is 25.2bp tall where pdflatex's is 120.5bp. Everything on
those pages is carried by that 95bp.

v2 output changed for exactly three fixtures — lmodern-report,
article-twocolumn, conf-paper, i.e. the corpus documents that have both a
float and a page that does not land exactly. The other 19 are byte-identical,
HW1 and HW2 included.

Residual per-page constants

After this change, the median dy still left on each page — the "this class is
N bp low" number for the next lane. |dy − page median| is how much is not
the rigid offset.

document pages per-page median dy (bp) |dy−med| ≤ 0.5
unicode-accents 1/1 +0.01 100.0%
hw1 3/3 +0.04, +0.01, +0.00 99.8%
hw2 3/3 +0.04, +0.01, +0.00 99.0%
input-bibliography 2/2 +0.02, +0.02 99.6%
inline-math 2/2 +0.16, +0.04 99.2%
thesis-chapter 4/5 +0.01, +0.00, −339.12, +36.06 84.9%
hyperref-toc 3/4 −10.21, −176.96, −242.33 83.7%
natbib-review 3/3 −22.17, −27.10, −22.52 73.3%
lmodern-report 4/4 −0.00, −0.86, −150.81, −157.95 71.1%
plain-article 3/3 −12.56, −0.00, −81.60 69.2%
lab-report 2/3 −11.80, −443.11 62.2%
twelvept-plain 4/3 −14.43, −7.38, −0.00 54.0%
siunitx-tables 2/2 −36.96, −179.43 40.8%
cv 1/1 +11.96 40.0%
enumitem-worksheet 3/3 −45.98, −62.87, −82.77 39.1%
listings-manual 3/3 +4.51, +63.76, +97.64 29.6%
ps-calculus 3/3 −21.37, −62.59, −101.28 28.5%
lecture-notes 2/2 −40.93, −17.93 26.0%
article-twocolumn 1/2 −87.91 25.3%
letter 1/1 −165.62 22.9%
math-sheet 2/2 −105.53, −98.18 16.4%
conf-paper 2/4 −136.60, −251.95 15.4%

The large ones are page-count mismatches, not page geometry: every document
whose page count matches and whose first page is right is at 70–100%.

Tests

crates/render-pipeline/tests/page_column_shrink_oracle.rs, two fixtures,
each failing before its own fix and separating the two behaviours:

  • page-break-hyphen — the break moves: ten words go to the next page once
    the penalty is charged.
  • page-column-shrink — the break is the same either way (all 358 page-1
    words align before and after); only the vertical placement moves. Before:
    overfull_vbox 4.01pt and every line under the first shrinkable skip
    1.47–1.87bp low. After: exact.

Expected data is pinned pdflatex word geometry read by
tools/visual-oracle/pdftext.py; no TeX runs in the Rust tests.

Gates

  • crates/render-pipeline cargo test --release: 228 passed, 0 failed
  • amsmath 59/59 within 0.5bp
  • tabular_oracle 106/106
  • HW1 and HW2: 3 pages, 0 errors, 0 overfull, v2 JSON byte-identical
  • zero font-failure diagnostics across all 22 fixtures
  • no vendor changes; crates/render-pipeline/vendor/ untouched

Method note

One intermediate sweep of mine reported 54 "regressions" on no-float
documents. It was invalid: I ran it without exporting FLASHTEX_FONT_DIRS/
FLASHTEX_TFM_DIRS, and the two binaries sit at different paths, so they
resolved metrics differently. Re-run with the environment set, the same sweep
reports 0 differing configurations. Font substitution, not layout —
exactly the failure mode tools/visual-oracle/fontenv.py was written for.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

The dominant real-world parity error is vertical and mostly a rigid per-page
offset (issue #2: |dx| <= 0.5bp 73.1%, |dy| <= 0.5bp 29.5%, 62.3% once each
page's median dy is removed). `lmodern-report` was the clean case: page 1
horizontally exact, every word 1.83bp low, growing to 110bp by page 4.

`\showoutput` on that document says what pdflatex did. Page 1's body vbox is
`\vbox(650.43001+0.0), glue set - 0.26439`: 652.76431pt of material in a
650.43001pt `\@colht`, shrunk by 2.3343pt out of 8.82867pt available. Our
vertical list was byte-for-byte the same list -- the natural total matched to
0.001pt -- and we still put the page's last line on page 2 and laid the rest
out at natural size. Two independent causes:

1. `\brokenpenalty` was never charged. tex.web 890 adds it to the same penalty
   node as `\interlinepenalty`/`\clubpenalty`/`\widowpenalty` whenever the
   line just finished ended at a discretionary; LaTeX sets it to 100. Without
   it a hyphenated line is an ordinary breakpoint, and on this page it was the
   cheaper one: our cost at the hyphen was 1 against 2 for the line after it,
   so we ended the page one line early. pdflatex sees 101 against 2.
   `VBlock::broken_penalty` now carries it per line, from `Line::hyphenated`
   (which is exactly 882's `disc_break`), for every block built from a real
   paragraph. Table cells are left alone: their lines are not breakpoints of
   the page's vertical list, so charging them would move longtable's row
   breaks with no oracle behind it.

2. The float column builder never set its columns' glue. `\@makecol` packs
   every column `\vbox to\@colht`, and both `break_pages_regions` and
   `make_column` do; `floatpage::paginate`'s no-footnote branch -- the branch
   every page of a document with a float and no note takes -- advanced by each
   glue's natural width. A page needing shrink therefore came out low by the
   whole shrink and overfull.

Effect, measured against the committed pdflatex references (22 real-world
fixtures, 12261 aligned words, zero font-failure diagnostics):

  |dy| <= 0.5bp   30.8% -> 34.8%      both axes   24.3% -> 28.4%
  lmodern-report   3.1% -> 46.8%, page 1 now 431/431 words exact on both axes
                                      (was 420 aligned, all 1.829bp low)

v2 output changed for exactly three fixtures -- `lmodern-report`,
`article-twocolumn`, `conf-paper`, the corpus documents that have both a float
and a page that does not land exactly. The other 19, HW1 and HW2 included, are
byte-identical.

Oracle tests (`tests/page_column_shrink_oracle.rs`), each failing before its
own fix and separating the two: `page-break-hyphen` moves ten words to the
next page once the penalty is charged; `page-column-shrink` keeps the same
break either way and only moves vertically -- 4.01pt overfull with every line
under the first shrinkable skip 1.47-1.87bp low before, exact after.

Gates: render-pipeline `cargo test --release` 228 passed / 0 failed;
amsmath 59/59; tabular_oracle 106/106; HW1 and HW2 3 pages, 0 errors,
0 overfull, v2 byte-identical. pdflatex is an oracle only.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@d-q222

d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Superseded — both of this PR's two fixes are on main, with matching code comments.

Verified on origin/main: broken_penalty field and logic landed via #400 (5c003da0); the float column glue-set ratio (\@makecol packing to \@colht) landed via 84d104cb.


Closed by the Commander after a stale-draft screening pass that required evidence in both directions — a landing SHA to close, an empty grep to keep open. If this verdict is wrong, say so on issue #2 and I will reopen: an asymmetric bar has produced wrong calls here in both directions before.

@d-q222 d-q222 closed this Sep 16, 2026
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.

2 participants