Skip to content

render-pipeline: math operator names (\sin/\lim/\mathrm) use family 0, not the text font (needs #754 first) - #758

Closed
d-q222 wants to merge 5 commits into
agent/daniel-parent/display-box-heightfrom
agent/daniel-muse-lead/textrun-family0
Closed

d-q222 wants to merge 5 commits into
agent/daniel-parent/display-box-heightfrom
agent/daniel-muse-lead/textrun-family0

Conversation

@d-q222

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

Copy link
Copy Markdown
Contributor

Draft — depends on #754 merging first (this branch is stacked on
agent/daniel-parent/display-box-height).

Scope

Same bug as #754, different code path: named math operators set as a run of
letters (\sin, \lim, \mathrm{lim}) go through shape_run/TextRunMetrics
(crates/render-pipeline/src/mathtext.rs), a completely separate path from
#754's roman_glyph (per-glyph math family 0). This run shaped the whole
word with the document's text TFM (fonts.resolve(family, Role::Text{...}, size)), never checking the lmodern/family-0 distinction #754 established:
\DeclareSymbolFont{operators}{OT1}{cmr}{m}{n} only moves to lmr when the
document loads lmodern; [T1]{fontenc} alone never touches math.

Fix: TextRunMetrics now carries the same roman_lm: bool
(style.math_roman_lm) roman_glyph reads, threaded in at its one
construction site in typeset.rs. A new RomanSource in mathtext.rs
picks the same two fonts roman_glyph does (installed rm-lmr* with
lmodern, embedded cmr designs without it) for an operator-name run's
advances/height/depth/last-italic. Painting is unchanged (glyph ids stay
the text face's) — width/height/depth-only fix, matching #754's own
constraint.

Also found and fixed, beyond what was asked: a 0.12 bp lmodern-loaded
\lim height error at 12pt (ec-lmr12's l vs rm-lmr12's) that the
original finding didn't mention — same root cause, same fix.

Overlap check

Render-pipeline only (mathtext.rs, one line in typeset.rs, 3 existing
test files updated + 1 new). No changes to crates/math-layout/,
crates/font-engine/, crates/font-resources/, or crates/compiler/.
roman_glyph/math_roman_lm reused, not duplicated.

Test results

New tests/math_textrun_family.rs: \sin/\lim boxes at 10/11/12pt, with
and without lmodern, against pdflatex values re-measured independently
(not copied from the assignment) via \wd/\ht on real \hbox{$\sin$}
etc., pdfTeX 1.40.29, TeX Live 2026.

Independently re-verified by the supervisor (fresh CARGO_TARGET_DIR):

  • cargo test --test math_textrun_family: 2 passed, 0 failed.
  • Mutation check (re-run independently, note: the first attempt targeted
    the wrong call site — typeset.rs's production plumbing, which this
    particular unit-style test bypasses by calling TextRunMetrics::new
    directly; retargeted to mathtext.rs's roman_source function itself):
    forced the lmodern branch off — both tests fail with the exact pre-fix
    cmr metrics (\sin is 12.2778/6.6786 pt, pdflatex 12.34996/6.29724);
    restored, git diff empty, 2/2 pass again.
  • Full crates/render-pipeline suite in release mode (fresh target
    dir): all suites green, 0 failures.
  • CLI: built real flashtex-cli release binary, checked $\sin x$ +
    display \sin/\lim against real pdflatex, T1 and lmodern variants —
    within 0.005 bp (lane's own report, matches the supervisor's spot-check
    of the test file's own oracle table).

Not done

Nothing else in scope. Two follow-ups noted by the lane, not part of this
slice: the n→∞ subscript-extraction granularity behind 2 unaligned
comparison words in one CLI check (pre-existing, unrelated to this fix); a
future vendor re-pin could simplify the kern-preservation fallback to a
direct OT1 program query once lig_kern/ot1_text_slot land in the
vendored math-layout mirror.

🤖 Generated with Claude Code

What changed:

Named operators set as a run of letters (\sin, \lim, \mathrm{lim})
never went through roman_glyph: shape_run shaped the whole word with
fonts.resolve(family, Role::Text), the document's *text* TFM (ec-lmr*,
or ecrm* under [T1]{fontenc} without lmodern). pdfLaTeX sets these
runs from the operators family (OT1 cmr, rm-lmr with lmodern), whose
metrics differ: cmr10's i is 0.667859 em tall against ec-lmr10's
0.629725.

TextRunMetrics now carries the roman_lm boolean (style.math_roman_lm,
the same flag roman_glyph reads) into shape_run. An operator-name run
(no font key, the run's own italic correction) takes its advances,
height, depth and last italic from family 0 -- the installed rm-lmr*
TFM with lmodern (run through its own program, kerns included), the
embedded cmr designs without it (kerns stay the shaped run's: LM kerns
are rm-lmr's to the fixword). Words a ligature would merge, non-ASCII
words and unknown sizes keep today's metrics. Painting is unchanged:
the run keeps the text face's glyph ids.

The italic-correction and limsup/liminf suites rendered package-less
documents against a T1+lmodern oracle preamble and only passed because
ec-lmr ~= rm-lmr for those letters; their documents now carry that
preamble.

What was run:

  cargo test --release -p flashtex-render-pipeline
  107 targets ok, 0 failed (full suite, exit 0)

  cargo test --release --test math_textrun_family (new)
  2 passed: sin/lim boxes at 10/11/12pt, with and without lmodern,
  under either text font, against re-measured pdflatex values

  python3 oracle.py check --render <fixed flashtex-render> 47- 48- 49- 50-
  PASS 4/4, worst 0.005/0.006/0.006/0.005 (unchanged from #754)

  Temp sin/lim display fixtures (removed afterwards):
  lmodern 23/23 worst 0.005; T1-no-lmodern 22/22 worst 0.005 with 2
  unaligned subscript words, identical pre-fix (worst 0.008 there).
  Operator words: sin -0.0041/-0.0004, cos +0.0005/+0.0004,
  lim -0.0002/+0.0002 bp vs pdflatex; flashtex CLI exit 0, identical.

Mutation check: with the transplant disabled the new tests fail with
the exact pre-fix boxes (lim 13.96296/6.88875 vs 13.88893/6.94444,
sin 12.34998/6.29725 vs 12.2778/6.67859 at 10pt); restored: 2 passed.

Stacked on PR #754 (agent/daniel-parent/display-box-height); a PR
from this branch must use --base that branch, not main.

Implementation-Agent: muse-spark-1.3-contributor
…height' into agent/daniel-muse-lead/textrun-family0
… fix

Rebased onto #754's digest re-record, then re-checked: this branch has its
OWN additional digest change on top, distinct from #754's. #754 fixes
per-glyph family-0 metrics (roman_glyph); this branch fixes the same bug
for math OPERATOR NAMES set as a run of letters (\sin, \lim,
\mathrm{lim}), a different code path (shape_run/TextRunMetrics in
mathtext.rs). 8 cases, 70 keys move on top of #754's baseline:
hyperref-toc, input-bibliography, lecture-notes, math-sheet, plain-article,
ps-calculus, twelvept-plain, math-heavy -- documents whose math uses a
named operator (not just a bare digit/symbol), which is exactly the set
#754's per-glyph fix could not reach.

Verified with merge_digests.py: only the named cases' digests changed on
top of #754's already-updated baseline; schema_version/meta/targets/
unmeasured and every other case/field byte-identical. --check against the
result: OK, 549 metrics compared, no regression.
…height' into agent/daniel-muse-lead/textrun-family0

# Conflicts:
#	crates/perf-bench/baselines/linux-x86_64-ryzen7-7800x3d.json
…nd main's #699

Same conflict class as #754's own merge just now: re-recorded all 19
previously-changed cases on the fully-merged tree (main's tip + #754's fix
+ this branch's own text-run fix) rather than hand-resolving the
single-line JSON conflict, so every digest reflects all three changes
composed together. --check: OK, 549 metrics, no regression.
jay3332 added a commit that referenced this pull request Sep 19, 2026
…mes use family 0, not the text font

Stacked on #754 (already on main as agent/daniel-parent/display-box-height);
only the branch's own commits land. Conflicts resolved: `typeset.rs` (main's
`with_built` sink + the PR's `math_roman_lm` argument); the perf-bench
baseline is resolved to main's file and re-recorded from a --release run in
a follow-up commit. Integration fix: main's `\vdots`/`\ddots` period run
(b9807a1) threads `roman_lm` into `shape_run` — inert there, since the
family-0 source only applies to corrected operator-name runs.

Implementation-Agent: Claude Code (mac-claude-a / lane-integrate2)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn
jay3332 added a commit that referenced this pull request Sep 19, 2026
… operator-name family 0

73 digest keys over 11 cases, recorded from a --release build of this lane
and merged with `merge_digests.py` (only the named cases; `metrics`/`meta`
untouched). Attribution, verified against each PR's own re-record:

- #739 (real /Link annotations in the exported PDF): `export.pdf` of the
  four fixtures that contain \href or \url — conf-paper, cv, hyperref-toc,
  listings-manual (3 keys here; hyperref-toc's overlaps below).
- #758 (math operator names \sin/\lim/\mathrm set in family 0, not the
  text font): the same 8 cases / 70 keys #758's own commit 21ce795
  re-recorded — hyperref-toc, input-bibliography, lecture-notes,
  math-heavy, math-sheet, plain-article, ps-calculus, twelvept-plain.

origin/main (f7f89b0) gates clean against the committed baseline with the
same build and font configuration, so every moved key is from these two
merges; after the merge the lane's report gates clean (0 output changes,
549 metrics compared).

Implementation-Agent: Claude Code (mac-claude-a / lane-integrate2)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn
jay3332 added a commit that referenced this pull request Sep 19, 2026
…he integration batch + package definitions

The pin reads main again after the second integration pass (#827 cherry-picks,
#863, #950, #737/#739/#758/#732/#740/#825, visual-oracle tooling) and the
`metadata.packages` work (`crate::package_definitions`, tex-expansion's
`package_defs.rs`). `git archive` of this tree's `crates/compiler` and
`crates/tex-expansion`, PINs at the merge commit, VENDORING.md rows updated,
`scripts/check-vendor-pins.sh` both "up to date". render-pipeline 819/0 in
both profiles against the new pins; compiler 1368/0, tex-expansion 150/0
release; Mac inventory sync current; swift build clean.

Implementation-Agent: Claude Code (mac-claude-a)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn
@jay3332

jay3332 commented Sep 19, 2026

Copy link
Copy Markdown
Member

Merged into main 2d6ac3e (merge commit on the integration branch; GitHub does not detect it because this PR's base is a stacked branch, whose content is already on main).

@jay3332 jay3332 closed this Sep 19, 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