Skip to content

render-pipeline: HW1/HW2 residual glyph offsets vs pdflatex - #171

Merged
jay3332 merged 5 commits into
mainfrom
agent/kabir-claude/hw-residuals-2
Sep 13, 2026
Merged

jay3332 merged 5 commits into
mainfrom
agent/kabir-claude/hw-residuals-2

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Draft. Per-word residuals of HW1/HW2 vs MacTeX pdflatex (oracle only), fixed one cause at a time. Evidence and reproduction script: crates/render-pipeline/docs/evidence/hw-residuals-2026-09-13/ (measure.sh <repo> <outdir> ref).

Results (words matched per line; dx = horizontal residual >0.1pt; dy = lines with median vertical offset >0.1pt)

doc page baseline dx / dy after 3 fixes dx / dy
HW1 1 4 / 25 4 / 0
HW1 2 2 / 16 2 / 0
HW1 3 12 / 9 2 / 0
HW2 1 11 / 25 11 / 0
HW2 2 48 / 19 38 / 0
HW2 3 41 / 8 30 / 0

Line breaks (per-line word sequences) are identical to the baseline and pdflatex, 0 overfull, 3 pages each.

Fixes

  1. \item labels are not expanded (0472358). The label sits in \@labels' hbox, so pdfTeX's hpack never adds char_stretch for it. \showbox shows the label glyphs as T1/cmr/m/n/10.95 while the line is (+20).
  2. microtype \leftprotrusion after \item labels (06390b8). microtype.sty patches \@item's \everypar{\leftprotrusion}, and \MT@get@prot adds \kern\leftmarginkern of the first character. \showbox shows \penalty 0 \kern -0.40285 A.
  3. em/ex of the EC body font for user \setlength and \setlist (93d5573). ecrm1095 has \fontdimen6 10.88789pt, not 10.95pt. pdflatex reports \parskip 7.07704pt; we drifted 0.04pt per paragraph.

Remaining causes (not in this PR)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 5 commits September 13, 2026 10:23
… (baseline on main c40d2a6)

Words compared per matched line: ours from the v2 display list, pdflatex
from content-stream glyphs (tools/visual-oracle/pdftext.py). Horizontal
residuals (dx) and whole-line vertical offsets (median dy) are reported
separately.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude HW residuals 2, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
LaTeX's \@item sets the label inside the zero-width \@labels hbox, so
pdfTeX's post-line-break hpack (pdftex.web, <Incorporate character
dimensions into the dimensions of the hbox>: add_char_stretch only for the
line's own char nodes) never expands the label glyphs, and they add no
font stretch/shrink to the line. Verified with \showbox on pdflatex
(TeX Live 2026): label glyphs stay T1/cmr/m/n/10.95 while the line's
characters are (+20).

HW2 words with dx >0.1pt: p2 48 -> 38, p3 41 -> 30 (the two item first
lines). HW1 unchanged; line breaks and overfull count unchanged.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude HW residuals 2, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
microtype.sty patches \@item's \everypar to \leftprotrusion
(\MT@patch@patch\@item{\everypar{}}{\everypar{\leftprotrusion}});
\MT@get@prot sets the item text's first group alone and adds
\kern\leftmarginkern of it after the label. pdfTeX's own left margin kern
cannot reach that character: find_protchar_left (pdftex.web) stops at the
\@labels box's glue. Verified with \showbox on pdflatex (TeX Live 2026):
'\penalty 0 \kern -0.40285 A' after the label on an item starting 'At'.

HW1 words with dx >0.1pt: p3 12 -> 2. Line breaks and overfull unchanged.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude HW residuals 2, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…etlist

Under \usepackage[T1]{fontenc} (no lmodern) the preamble's \setlength
and enumitem's \setlist keys are evaluated in t1cmr.fd's EC font, whose
\fontdimen6 is not the design size: tftopl gives ecrm1095 QUAD 0.994328
(10.88789pt), ecrm1000 0.999756, ecrm1200 0.978928. pdflatex reports
\parskip 7.07704pt, \itemsep 4.8995pt, \topsep 3.81082pt for HW1's
0.65em/0.45em/0.35em; we used 1em = 10.95pt, drifting every paragraph by
0.04pt. Class-load values (\labelsep .5em = 5.475pt in the showbox) stay
cmr-based.

HW1/HW2 lines with median dy >0.1pt: 102 -> 0 (all pages). Line breaks,
page count and overfull count unchanged.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude HW residuals 2, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…duals.py for any document

residuals.py takes <name>=<v2.json>=<reference.pdf> triples. On all nine
real-world fixtures, status/pages/diagnostics are unchanged and residual
counts are unchanged outside HW1/HW2, which only improve.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude HW residuals 2, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 13, 2026
#171 predates #151/#152 in every conflicting region; its three residual fixes were grafted onto the newer structure: parse_dimen_in/ec_em_ex threaded through #152's apply_sep_keys and list_labelsep, and the item-label protrusion kern plus label_recs bookkeeping added to #152's multi-word label box.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@jay3332
jay3332 merged commit 5618f54 into main Sep 13, 2026
12 of 18 checks passed
@GoKubar
GoKubar deleted the agent/kabir-claude/hw-residuals-2 branch September 13, 2026 18:12
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