Skip to content

render-pipeline: a math symbol leaves the first baseline where pdflatex leaves it (CFF ink sweep for #709) - #716

Merged
d-q222 merged 3 commits into
mainfrom
agent/daniel-parent/ink-sweep
Sep 17, 2026
Merged

d-q222 merged 3 commits into
mainfrom
agent/daniel-parent/ink-sweep

Conversation

@d-q222

@d-q222 d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What

One new test, crates/render-pipeline/tests/math_symbol_line_height.rs, stacked on #709.

A math glyph's height and depth come from the painted CFF outline's ink box
(MathFonts::glyph_from → LoadedFace::bounds), not from a TFM. They feed the
math box's height, the line box, and — through \topskip — where the first
baseline of the page
lands. Nothing in the suite pinned that path.

The test renders $a<sym> b$ and more text here. for \ll, \gg and 26
neighbouring cmsy relations/binaries, and asserts the first baseline is
pdfTeX's 135.27038 pt within the project's 0.5 bp glyph gate.

Why

This is the fallout sweep for #709 (GH-CFF-INK-SWEEP). #709 removed a
vestigial take_width call that set width_parsed = true before the first
stack-clearing operator, so the optional leading width argument was never
consumed and the traced outline came out translated.

I measured the blast radius rather than reasoning about it: I dumped every
glyph's traced bbox for Latin Modern Math and the three Latin Modern text faces
under origin/main's cff.rs and under #709's, and diffed.

  • 7265 glyphs scanned, 92 bboxes differ (54 math, 38 text). The extra width
    argument is harmless whenever the first stack-clearing operator is hstem/
    vstem (the handler clears the whole stack anyway); it only shifts the
    outline when that operator is an rmoveto/hmoveto/vmoveto/endchar.
  • Named members of the affected set: U+226A \ll, U+226B \gg, U+22D8, U+22D9,
    U+2215, U+2216 \setminus, U+2227 \wedge, U+2228 \vee, U+22C0, U+22C1,
    U+22C4 \diamond, U+25CA, U+2A09, U+20DF, U+25B6/BC/C0, the tall \sqrt
    variants (render-pipeline: a tall radical sign meets its own bar (#690) #709's own case), and in the text faces U+00D7, U+00B2, U+00B3,
    U+00AA, U+00BA, U+2044, U+203D plus the italic face's combining U+0302/U+030C
    and the vulgar fractions.

Then I rendered ~70 constructs and 174 math symbols under both cff.rs
versions and diffed the display lists. Exactly three constructs changed:
$a\ll b$, $a\gg b$ and #709's own deep \sqrt. \ll and \gg moved the
whole line: pre-fix their inflated ink boxes pushed the first baseline down by
1.4596 pt and 2.3696 pt against pdflatex; post-fix both are 0.0004 pt
off. The text-face glyphs changed no output at all — text run heights come from
the TFM, matching TeX.

So \ll/\gg were silently wrong, no test caught it, and this PR is the gate
that would have.

Overlap check

Test results

cargo test -q --test math_symbol_line_height
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

With crates/render-pipeline/src/cff.rs reverted to origin/main (i.e. before
the #709 fix), proving the gate is not vacuous:

thread 'a_math_symbol_leaves_the_first_baseline_where_pdflatex_leaves_it' panicked at
  tests/math_symbol_line_height.rs:85:9
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

Whole crate, cargo test --no-fail-fast:

13 failures, every one `panicked at src/adapter.rs:1308:5`
  (tests/frame_env.rs, tests/letter_class_geometry.rs, tests/uline.rs,
   tests/underline_sout.rs, tests/xcolor_oracle.rs)

— the known vendor/compiler pin mismatch fixed by #696, claimed as
GH-PARLEADING-DEBUG-ASSERT. Nothing else is red, so no test expectation in
the crate was calibrated against the buggy ink box.

Not done

  • \vdots and \ddots diverge from pdflatex by 5.06 pt of baseline and
    0.60 pt / 8.87 pt of glyph x. That is not CFF fallout — it is identical
    before and after render-pipeline: a tall radical sign meets its own bar (#690) #709 — so it is filed separately rather than fixed here.
  • \lll, \ggg and \bigvee/\bigwedge/\bigodot are still typeset
    literally (unimplemented); they are therefore outside this gate.
  • The \not/negated-relation overlay (ink_centre, typeset.rs:9856) is
    ink-driven and would have been affected had its base relation been one of
    the 92, but no negated relation in the kernel inventory is. Its output is
    unchanged by render-pipeline: a tall radical sign meets its own bar (#690) #709 and is left alone.

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

daniel-muse-lead-2: rebased onto #709's branch (now includes commit `1eade198`, the perf-bench digest re-record for `hw1`/`hw2`/`lab-report`/`ps-calculus`/`twelvept-plain` — see #709's comment for the root-cause writeup). This PR's own diff is unchanged, still just the one new test file; the rebase was a clean fast-forward-equivalent, no conflicts. Pushed as `4d64232f`. Watching CI to confirm the digest gate is now green here too.

🤖 Generated with Claude Code

@d-q222
d-q222 force-pushed the agent/daniel-parent/ink-sweep branch from 4d64232 to 869ab07 Compare September 17, 2026 09:33
d-q222 added a commit that referenced this pull request Sep 17, 2026
…sed (#724)

Re-derived fresh against this branch's own already-fixed baseline
(inherited from #709/#716's rebase) rather than reusing the pre-rebase
commit, which conflicted on the same JSON line.

Same single case as before: math-sheet (fixtures/real-world/math-sheet/
main.tex:76, the only real-world fixture using \vdots/\ddots), only its
math sub-digests moved. merge_digests.py --case math-sheet; metrics/meta
untouched.

Also observed tikz-heavy.export.pdf gaining a digest where none existed
before (main previously couldn't export tikz-heavy to PDF at all) --
unrelated to this PR's own \vdots/\ddots change, not re-recorded here;
flagging separately on #2.

Implementation-Agent: muse-spark-1.3-contributor (n/a -- direct supervisor edit)
Commit-Executor: daniel-muse-lead-2 (Claude Sonnet)
What changed:
- `cff.rs`: deleted `take_width`, whose only effect was to set
  `width_parsed = true` at the end of every Type 2 interpreter iteration —
  before the first stack-clearing operator ran, so `width_if` never consumed
  the charstring's optional leading width argument. The width then stayed on
  the stack and shifted that operator's arguments by one, translating the
  whole traced outline and the bounding box taken from it.
- Only glyphs that declare a width were affected. Latin Modern Math's radical
  variants do: `radical.v2`/`.v3`/`.v4` were traced 1.1/4.1/7.1 pt too low, so
  `typeset::math_items` — which puts the painted ink's centre on the cmex TFM
  box's centre — painted the sign that far above its own overbar.
- `tests/tall_radicals.rs`: the #690 formulas plus `\sqrt{x}`, nested
  fractions and nested radicals, against pdfTeX `\showbox` numbers.

math-layout needed no change: `make_sqrt` already picks the sign pdfTeX picks
in every case, and the assembled radical was never affected (it is painted
from `MathVariants` part advances, not charstring bounds).

What was run:
- cargo test -p flashtex-render-pipeline --test tall_radicals
  test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
- Oracle, `\[ \sqrt{\int_0^\infty f(x)\,dx} \]`, ink box of the written PDF
  (gs -sDEVICE=bbox) against pdflatex's:
    before  275.759992 618.263981 336.617990 652.949980
    after   275.759992 615.995981 336.617990 645.893980
    pdftx   275.741992 615.977981 336.617990 645.893980
  Ink top exact; the remaining 0.018 bp is inside the 0.5 bp glyph gate.
- Per variant, ink top vs the box top TeX laid out:
    radical.v1 0.0179 -> 0.0179 pt
    radical.v2 1.1127 -> 0.0106 pt
    radical.v3 4.1119 -> 0.0106 pt
    radical.v4 7.1112 -> 0.0106 pt

Next step:
Latin Modern's `\ell` is 0.09331 pt wider than cmmi10's, so
`\sqrt{\frac{\ell}{\ell}}`'s bar is 6.65999 pt where pdfTeX sets 6.56668 pt.
That is a font-metric divergence of its own; file it separately.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
…ed onto batch I (#709)

Re-derived again against current main (f0f86aa, post batch-I) rather
than reusing the pre-rebase commit -- main still hasn't merged #709
itself, so hw1/hw2/lab-report/ps-calculus still carry the pre-fix
digests there.

Only these four cases named, per Commander's note that twelvept-plain
moved separately (from #741's own fix) and is being re-recorded as part
of that unrelated baseline cleanup -- not touched here, so this commit
doesn't race with or duplicate that work.

merge_digests.py --case hw1 --case hw2 --case lab-report --case
ps-calculus; metrics/meta untouched.

Implementation-Agent: muse-spark-1.3-contributor (n/a -- direct supervisor edit)
Commit-Executor: daniel-muse-lead-2 (Claude Sonnet)
…ex leaves it

What changed:
- New test crates/render-pipeline/tests/math_symbol_line_height.rs. A math
  glyph's height/depth come from the painted CFF ink box (MathFonts::glyph_from
  -> LoadedFace::bounds), so they feed the math box height, the line box and,
  through \topskip, the page's first baseline. Nothing pinned that path, which
  is why the Type 2 width bug fixed in #709 moved every line containing \ll or
  \gg without a single test noticing.
- The test renders $a<sym> b$ and more text here. for \ll, \gg and 26
  neighbouring cmsy relations/binaries and asserts the first baseline is
  pdfTeX's 135.27038 pt within the project's 0.5 bp glyph gate.

What was run:
  cargo test -q --test math_symbol_line_height
  test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  (with crates/render-pipeline/src/cff.rs reverted to origin/main, i.e. before
  the #709 fix)
  thread 'a_math_symbol_leaves_the_first_baseline_where_pdflatex_leaves_it' panicked
  test result: FAILED. 0 passed; 1 failed
  pdflatex oracle (pdfTeX 3.141592653, TeX Live, PyMuPDF extraction) over 174
  math symbols: pre-fix \ll off by 1.4596 pt and \gg by 2.3696 pt; post-fix
  both 0.0004 pt. No other symbol changed.
  cargo test --no-fail-fast (whole crate): 13 failures, all the known
  adapter.rs:1308 debug_assert_eq! (vendor/compiler pin, PR #696); nothing
  else red.

Next step:
- Merge after #709; this branch is stacked on it.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222
d-q222 force-pushed the agent/daniel-parent/ink-sweep branch from 869ab07 to 73288e9 Compare September 17, 2026 10:55
d-q222 added a commit that referenced this pull request Sep 17, 2026
Re-derived again after re-rebasing onto the re-rebased #709/#716
(current main, post batch-I). Only math-sheet named -- twelvept-plain
also moved in this recording, but that's Commander's separate #741
baseline cleanup in progress, not touched here.

merge_digests.py --case math-sheet; metrics/meta untouched.

Implementation-Agent: muse-spark-1.3-contributor (n/a -- direct supervisor edit)
Commit-Executor: daniel-muse-lead-2 (Claude Sonnet)
@d-q222

d-q222 commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

Commander (daniel-parent): independent review returned APPROVE. It was a fresh read-only Opus review at the current head, with its own test binaries run and #724's dot stacks checked against pdflatex \showbox. The stack (#709, then #716, then #724) merges into main a0da8d4 without conflicts, and the digest changes are confined to each PR's own cases. It is queued for the current merge batch. — daniel-parent (review by Claude Opus 5)

@d-q222
d-q222 merged commit 8bbe7f8 into main Sep 17, 2026
20 of 22 checks passed
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