Skip to content

render-pipeline: paint \prime with Latin Modern Math's unraised ssty prime; pin #278 geometry oracle - #528

Merged
GoKubar merged 1 commit into
mainfrom
agent/daniel-parent/primes-geometry
Sep 15, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/daniel-parent/primes-geometry

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

What

Refs #278. This verifies the geometry acceptance criteria against pdflatex and fixes the one mismatch it found: the glyph used to paint the prime.

  • Layout was already right. Compiler compiler: math primes as ^\prime, upright \mathrm, distinct \epsilon/\varepsilon #174 and math-layout math-layout: math fonts at every LaTeX text size, amsmath cmex designs, \prime, \epsilon/\varepsilon (size oracle 37/37) #172 lay primes out as TeX does. tests/math_primes.rs now pins that against a pdflatex \showbox oracle at 0.5 bp. It covers f'(x), f'', f''', f^{\prime}, f'^2, f_1' and x'_a, at 10pt and 12pt, inline and in display. It checks each glyph's x offset from the base, its rise, its font size, and the advance of the whole superscript box. Every value matched within 0.001 bp before this change.
  • The painted glyph was wrong. The pipeline painted cmsy "30 \prime with Latin Modern Math's cmap glyph for U+2032 (minute, ink 430..748 per mille). That glyph is pre-raised for unscripted Unicode use, so at the superscript position it was raised a second time. This matches the owner's report of a prime "sitting high".
  • The fix. mathfont.rs now reads the face's GSUB ssty lookups (AlternateSubst, plus SingleSubst and Extension). mathtex.rs::otf_gid paints cmsy "30 with its first ssty alternate, minute.st (ink 96..549). That is the unraised design cmsy uses (lmsy7 ink is 41..559).
  • A second test pins the prime's ink (bottom, top and horizontal centre) against pdflatex's lmsy7/lmsy8 AFM bounding boxes, placed at the \showbox position.

Why

Issue #278's gate asks for box widths and the prime's vertical position within 0.5 bp of pdflatex. #315 only fixed the diagnostics side, and nobody had measured the geometry.

Oracle (TeX Live pdflatex, article + T1 + lmodern, \showbox). Positions are relative to the base glyph's origin, converted to bp. The ink rows are for the prime and give distances above the baseline.

case pdflatex before after
12pt inline f': prime dx / rise / size 7.0465 / 4.3384 / 7.970 7.0464 / 4.3384 / 7.970 same
12pt display f': rise 4.9362 4.9362 same
10pt inline f': dx / rise / size 5.9500 / 3.6154 / 6.974 5.9500 / 3.6153 / 6.974 same
10pt display f': rise 4.1135 4.1135 same
10pt inline f_1': sub drop 2.4727 2.4728 same
10pt inline ink bottom / top 3.9013 / 7.5137 6.6141 / 8.8318 4.2849 / 7.4440
10pt display ink bottom / top 4.3994 / 8.0119 7.1123 / 9.3299 4.7830 / 7.9421
12pt inline ink bottom / top 4.6652 / 8.7937 7.7656 / 10.3001 5.1036 / 8.7140
12pt display ink bottom / top 5.2630 / 9.3915 8.3633 / 10.8978 5.7013 / 9.3118
10pt ink centre (x) 7.1599 7.3691 7.3691
12pt ink centre (x) 8.2619 8.6684 8.6684

Overlap check

Test results

  • cargo test --test math_primes, before the fix: test result: FAILED. 1 passed; 1 failed (ink test, 40 failures such as 10pt inline f': prime ink bottom 6.6141 bp, pdflatex 3.9013 bp)
  • cargo test --test math_primes, after: test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
  • render-pipeline, all other targets: 12 failures, all the same panic at src/adapter.rs:1261 (letter_class_geometry 5, uline 2, underline_sout 4, xcolor_oracle 1). That is the par-leading debug_assert_eq!(leadings.len(), parsed.blocks.len()) (left: 14 right: 13), which open PR compiler: boxed arguments and letter \ps no longer leave phantom paragraph leadings #517 addresses, and it is unrelated to math paint. There were no other failures: the lib and the 41 targets from line_break_skip_macro on gave 273 passed, 7 failed; the targets before that passed apart from letter_class_geometry.
  • math-layout: 8 suites, 66 passed, 0 failed (unchanged crate)
  • compiler: 57 suites, 669 passed, 0 failed (unchanged crate)

Not done

  • Residual design difference. minute.st is not exactly lmsy's outline. After the fix, ink bottom is +0.38 bp at 10pt and +0.44 bp at 12pt, and the ink centre is +0.21 / +0.41 bp. All are within 0.5 bp, but the 12pt ink right edge is +0.53 bp. This comes from the design and is not a placement error; Latin Modern Math has no glyph closer to lmsy8's prime.
  • OTF-metrics fallback path. MathFonts::glyph, used when the TFMs are missing, still maps U+2032 to minute. The default TFM path is fixed here; the fallback is not.
  • Other gates not run. HW1/HW2 and the amsmath corpus 59/59 weren't run. The Mac app render wasn't checked.
  • Issue not closed. The Commander or owner decides.

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

…prime (#278)

What changed:
- The prime's box geometry already matched pdflatex (compiler #174 and
  math-layout #172): script size, sup shift, one superscript for f'',
  f'^2 joining it, f_1'/x'_a sub+sup. What was wrong was the painted
  glyph. The pipeline drew cmsy "30 with Latin Modern Math's cmap glyph
  for U+2032 (`minute`, ink 430..748/1000 em). That glyph is pre-raised
  for unscripted Unicode use, so at the superscript position it sat
  2.7-3.1bp too high at the bottom and 1.3-1.5bp at the top.
- mathfont.rs reads the face's GSUB `ssty` lookups (AlternateSubst, plus
  Single and Extension). mathtex.rs paints cmsy "30 with the first ssty
  alternate, `minute.st` (ink 96..549, cmsy's unraised design; lmsy7 is
  41..559).
- tests/math_primes.rs pins the pdflatex \showbox oracle (10pt and 12pt,
  inline and display, f'(x) f'' f''' f^{\prime} f'^2 f_1' x'_a) for
  placement, and lmsy7/lmsy8 AFM ink for the prime, at 0.5bp.

What was run:
- cargo test --test math_primes (before fix): test result: FAILED. 1 passed; 1 failed
- cargo test --test math_primes (after): test result: ok. 2 passed; 0 failed
- render-pipeline full suite: every failure (letter_class_geometry 5, uline 2,
  underline_sout 4, xcolor_oracle 1) panics at src/adapter.rs:1261, the
  par-leading debug_assert that open PR #517 fixes; no other failures
- math-layout and compiler: see PR

Next step: re-check the Mac app rendering of f'(x) once this lands.

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 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

daniel-parent independent review (subagent)

Verdict: APPROVE

Reviewed in a detached worktree (fae38040), CARGO_TARGET_DIR=target-review-52x, cleaned up after.

  1. GSUB ssty parsing, script vs scriptscript. Input: Latin Modern Math's GSUB ssty feature for minute (dumped with fontTools). Expected (per OpenType's ssty semantics, first alternate = level-1/script, second = level-2/scriptscript): the code should pick alternate 0 at script style and alternate 1 at scriptscript style. Actual: parse_script_alternates's AlternateSubst arm ((3,1) => ... u16_at(g, set + 2)) always takes alternate index 0, and otf_gid calls script_alternate unconditionally for cmsy "30, with no SizeClass/nesting-depth input at all — minute.sts (the font's second alternate) is parsed into nothing and never used. Confirmed via fontTools: minute GSUB-substitutes to ['minute.st', 'minute.sts']; only .st is ever reachable.

    • Checked whether this fails the gate for a genuine nested case, x^{y'}$ (pdflatex \showbox confirms the prime is drawn \OMS/lmsy/m/n/5 at 10pt / /n/6 at 12pt — real scriptscript, not script). Measured via the PR's own math_glyphs harness against lmsy5/lmsy6 AFM ink: bottom-ink diff 0.29–0.34 bp, top-ink diff 0.05–0.06 bp, both comfortably under the 0.5 bp gate at both sizes.
    • Also checked whether the "textbook" fix (use alternate 1 at scriptscript) would do better: it doesn't. minute.sts's own ink (94..634 permille) is farther from pdflatex's real lmsy5/6 range (~38/39..559 permille) than minute.st's (96..549) is, so switching would widen the top-ink diff to ~0.37-0.45 bp — closer to the 0.5 bp edge, not further. Always using .st is empirically the safer choice against this oracle, not just an oversight, even though it's not a spec-complete ssty implementation. Non-blocking; worth a one-line code comment recording that this was checked, so a future "fix" doesn't regress it.
  2. Non-ssty fallback / TFM route. Input: MathFonts::glyph (the OTF-metrics-only path used when TFMs are missing). Expected per PR's "Not done": still paints raised minute. Actual: confirmed — glyph() calls base_gid directly, never otf_gid, so it's untouched by this fix, matching the disclosure. Also confirmed the in-otf_gid fallback (self.otf.script_alternate(gid).unwrap_or(gid)) degrades silently (no diagnostic) to the pre-fix raised glyph if a math face ever lacks a ssty GSUB entry — fine for the shipped Latin Modern Math (which has one), just noting it's silent for any future face without it.

  3. amsmath corpus gate (oracle command found via PR render-pipeline: re-pin vendor/compiler to main (6a47ed49), implement CleverReference, default math-class-override #477's evidence: crates/compiler/tests/amsmath_corpus/oracle.py). Ran it myself against a release build of this branch's flashtex-render: TOTAL 59/59 within 0.5 bp. No regression; the PR had disclosed this as not run.

  4. Test suite. cargo test --test math_primes: both tests pass as claimed. Full cargo test -p flashtex-render-pipeline: same 4 pre-existing failing targets as disclosed (letter_class_geometry 5, uline 2, underline_sout 4, xcolor_oracle 1 — 12 total, exact match), all the same debug_assert_eq! panic at adapter.rs:1261 (open PR compiler: boxed arguments and letter \ps no longer leave phantom paragraph leadings #517's territory), nothing new.

  5. Ink spot-check. Independently reproduced with real pdflatex \showbox + AFM bounding boxes (not just trusting the PR's table): the 10pt/12pt nested-prime case above is itself two independent ink spot-checks (bottom and top) against a fresh pdflatex run, both passing.

No blocking findings.

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