Repository navigation
render-pipeline: read the atom's own forced math class instead of re-deriving it from the source text - #199
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pipeline half of the package-context lane. Compiler half is #198 (independent, both based on
main, no stacking).The problem
convert_math_classedlearned 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 keptMathAtom::class_overridecrate-private. That is lossy by construction: one control word can stand for two classes.\colonis where it breaks. The LaTeX kernel declares it punctuation (fontmath.ltx400) and amsmath renews it to an ordinary:with 2mu and 6mu of glue around it (amsmath.sty409-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\colonas 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 oneXadvance (9.03553 bp at 10pt):a\colon ba\colon b+ amsmatha\colon b+ mathtoolsf\colon A\to Bf\colon A\to B+ amsmatha:b(unchanged control)a\mathpunct{:}b(control)What changed
The class callback threaded through
convert_math_classed,grid_piecesandconvert_math_fencednow takes the atom rather than only its span. Behind the newmath-class-overridefeature it returns the compiler's ownMathAtom::class_override, mapped byml_class; without the feature it falls back toclass_override_ofexactly as before.The feature is off by default and builds only against a
vendor/compilerre-pinned past #198, which makesmath::AtomClassand the field public — the same arrangementamsmath-inline,compiler-text-nucleusandmath-glyph-spansalready use.class_override_ofalso gains acolonrow, 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 futureclass_overridethe 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 --releaseincrates/render-pipeline, withFLASHTEX_FONT_DIRS/FLASHTEX_TFM_DIRSpointed at the bundled Latin Modern and its three rooted metric trees: identical to this branch's base9abbf330measured 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/:32-braces-narrow, 1.012 bp, fails at the base too)\colonthroughflashtex-renderZero font diagnostics on every gate run, asserted per fixture.
Resume notes
agent/kabir-claude/math-class-override-pipeline, headc72e33fc, base9abbf330.agent/kabir-claude/math-package-context(compiler: thread the loaded packages into math parsing; \colon takes amsmath's definition when amsmath is loaded #198), head72d471d2.vendor/compileris re-pinned past it; turning it on is then a one-line default-feature change, exactly like theamsmath-inlinere-pin.FLASHTEX_FONT_DIRSandFLASHTEX_TFM_DIRSwith whatever--fontsis, so--fontsmust itself be the colon-joined list — the OTF directory first, thenapps/mac/Fonts/texmf/fonts/tfm/{public/lm,jknappen/ec,public/amsfonts/symbols}.--fonts apps/mac/Fontsalone, and a flat symlink-free copy of every.otf+.tfm, both producerequired_metrics_unavailableand score 0/59 while still exiting "recovered".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