Skip to content

render-pipeline: read the atom's own forced math class instead of re-deriving it from the source text - #199

Merged
GoKubar merged 1 commit into
mainfrom
agent/kabir-claude/math-class-override-pipeline
Sep 13, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/kabir-claude/math-class-override-pipeline

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Pipeline half of the package-context lane. Compiler half is #198 (independent, both based on main, no stacking).

The problem

convert_math_classed learned an atom's forced class by reading the control word back out of the document at the atom's span (typeset::class_override_of), because the compiler kept MathAtom::class_override crate-private. That is lossy by construction: one control word can stand for two classes.

\colon is where it breaks. The LaTeX kernel declares it punctuation (fontmath.ltx 400) and amsmath renews it to an ordinary : with 2mu and 6mu of glue around it (amsmath.sty 409-410) — the same five characters of source, two different classes, chosen by whether the document loaded amsmath. No amount of reading the span back can tell them apart, so the pipeline classified \colon as the bare : it found there: a relation, 5mu on each side, wrong for both definitions.

Measured

TeX Live 2025 pdflatex against flashtex-render's own rendering-v2 display list, as the \hbox{$X <body> X$} X-to-X span minus one X advance (9.03553 bp at 10pt):

formula pdflatex before after
a\colon b 23.0052 26.8794 (+7mu) 23.0051
a\colon b + amsmath 25.7725 31.3072 (+10mu) 25.7726
a\colon b + mathtools 25.7725 31.3072 25.7726
f\colon A\to B 50.4392 — 50.4392
f\colon A\to B + amsmath 53.2066 — 53.2067
a:b (unchanged control) 26.8794 26.8794 26.8794
a\mathpunct{:}b (control) 23.0052 23.0051 23.0051

What changed

The class callback threaded through convert_math_classed, grid_pieces and convert_math_fenced now takes the atom rather than only its span. Behind the new math-class-override feature it returns the compiler's own MathAtom::class_override, mapped by ml_class; without the feature it falls back to class_override_of exactly as before.

The feature is off by default and builds only against a vendor/compiler re-pinned past #198, which makes math::AtomClass and the field public — the same arrangement amsmath-inline, compiler-text-nucleus and math-glyph-spans already use.

class_override_of also gains a colon row, so a re-pin that does not turn the feature on still gets the kernel's punctuation class right rather than a relation. It cannot get amsmath's right; the comment says so.

This removes a whole bug class, not just \colon: every future class_override the compiler sets is now visible to the renderer without also being added to a hardcoded 12-name string table in another crate.

Gates

cargo test --release in crates/render-pipeline, with FLASHTEX_FONT_DIRS/FLASHTEX_TFM_DIRS pointed at the bundled Latin Modern and its three rooted metric trees: identical to this branch's base 9abbf330 measured in a separate control worktree — same suite counts, and the same single pre-existing failure (font_families_oracle::font_family_fixtures_match_pdflatex, the LMSans / LMRomanCaps family selection, which fails at the base too).

The feature path cannot be built against the committed vendor pin, so it was built and measured through an uncommitted vendor swap of #198's four changed files over vendor/compiler/src/:

gate result
amsmath corpus 59/59 within 0.5 bp
amssymb corpus 38/39 (32-braces-narrow, 1.012 bp, fails at the base too)
\colon through flashtex-render the table above, within 0.0001 bp

Zero font diagnostics on every gate run, asserted per fixture.

Resume notes

  • Branch agent/kabir-claude/math-class-override-pipeline, head c72e33fc, base 9abbf330.
  • Sibling: agent/kabir-claude/math-package-context (compiler: thread the loaded packages into math parsing; \colon takes amsmath's definition when amsmath is loaded #198), head 72d471d2.
  • Merge order: this PR is safe to merge on its own (feature off ⇒ no behaviour change). The feature only becomes usable after compiler: thread the loaded packages into math parsing; \colon takes amsmath's definition when amsmath is loaded #198 lands and vendor/compiler is re-pinned past it; turning it on is then a one-line default-feature change, exactly like the amsmath-inline re-pin.
  • Font environment on NixOS: the corpus oracles override both FLASHTEX_FONT_DIRS and FLASHTEX_TFM_DIRS with whatever --fonts is, so --fonts must itself be the colon-joined list — the OTF directory first, then apps/mac/Fonts/texmf/fonts/tfm/{public/lm,jknappen/ec,public/amsfonts/symbols}. --fonts apps/mac/Fonts alone, and a flat symlink-free copy of every .otf + .tfm, both produce required_metrics_unavailable and score 0/59 while still exiting "recovered".
  • To reproduce the feature path: for f in math.rs parser.rs siunitx.rs supported.rs; do git show agent/kabir-claude/math-package-context:crates/compiler/src/$f > crates/render-pipeline/vendor/compiler/src/$f; done, then build --features math-class-override. Do not commit the vendor swap.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…deriving it from the source text

`convert_math_classed` learned a forced atom class by reading the
control word back out of the document at the atom's span
(`class_override_of`), because the compiler kept
`MathAtom::class_override` crate-private. That is lossy by
construction: one control word can stand for two classes.

`\colon` is where it breaks. The LaTeX kernel declares it punctuation
(`fontmath.ltx` 400) and amsmath renews it to an ordinary `:` with 2mu
and 6mu of glue around it (`amsmath.sty` 409-410) -- the same five
characters of source, two different classes, chosen by whether the
document loaded amsmath. No amount of reading the span back can tell
them apart, so the pipeline classified `\colon` as the bare `:` it
found there: a relation, 5mu on each side.

Measured with TeX Live 2025 pdflatex at 10pt against
`flashtex-render`'s own display list, as `\hbox{$X <body> X$}` minus
one `X` advance (9.03553 bp):

| formula | pdflatex | before | after |
| --- | ---: | ---: | ---: |
| `a\colon b` | 23.0052 | 26.8794 (+7mu) | 23.0051 |
| `a\colon b` + amsmath | 25.7725 | 31.3072 (+10mu) | 25.7726 |
| `f\colon A\to B` | 50.4392 | — | 50.4392 |
| `f\colon A\to B` + amsmath | 53.2066 | — | 53.2067 |
| `a:b` (unchanged control) | 26.8794 | 26.8794 | 26.8794 |
| `a\mathpunct{:}b` (control) | 23.0052 | 23.0051 | 23.0051 |

The class callback threaded through `convert_math_classed`,
`grid_pieces` and `convert_math_fenced` now takes the atom rather than
only its span. Behind the new `math-class-override` feature it returns
the compiler's own `MathAtom::class_override`, mapped by `ml_class`;
without the feature it falls back to `class_override_of` exactly as
before. The feature is off by default and builds only against a
`vendor/compiler` re-pinned past the sibling compiler PR, which makes
`math::AtomClass` and the field public -- the same arrangement
`amsmath-inline`, `compiler-text-nucleus` and `math-glyph-spans`
already use.

`class_override_of` also gains a `colon` row, so a re-pin that does not
turn the feature on still gets the kernel's punctuation class right
rather than a relation. It cannot get amsmath's right; the comment says
so.

## Gates

`cargo test --release` in `crates/render-pipeline`, with
`FLASHTEX_FONT_DIRS`/`FLASHTEX_TFM_DIRS` pointed at the bundled Latin
Modern and its three rooted metric trees: identical to this branch's
base `9abbf330` measured in a separate control worktree -- same suite
counts, and the same single pre-existing failure
(`font_families_oracle::font_family_fixtures_match_pdflatex`, the
LMSans/LMRomanCaps family selection, which fails at the base too).

The feature path cannot be built against the committed vendor pin, so
it was built and measured through an *uncommitted* vendor swap of the
sibling compiler branch's four changed files: amsmath corpus 59/59,
amssymb 38/39 (`32-braces-narrow`, 1.012 bp, fails at the base too),
both with zero font diagnostics, and the `\colon` table above.

Implementation-Agent: Claude Code engine-engineer (linux-primary, NixOS)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar
GoKubar marked this pull request as ready for review September 13, 2026 23:36
@GoKubar
GoKubar merged commit f761962 into main Sep 13, 2026
16 of 20 checks passed
@GoKubar
GoKubar deleted the agent/kabir-claude/math-class-override-pipeline branch September 16, 2026 04:17
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