Skip to content

FT-061: amsmath inline constructs (genfrac/binom, \big, phantoms, operators, substack, smallmatrix, dcases) — corpus 20/42 -> 40/42 - #103

Merged
jay3332 merged 4 commits into
mainfrom
agent/kabir-claude/amsmath-inline
Sep 13, 2026
Merged

jay3332 merged 4 commits into
mainfrom
agent/kabir-claude/amsmath-inline

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

FT-061 (kabir-claude). Base 3b2703aa, head 22a72093.

Oracle (crates/compiler/tests/amsmath_corpus)

passes
main binary, original oracle 20/42
main binary, fixed oracle 27/42
this branch (compiler + math-layout, --features amsmath-inline) 40/42

Still failing: 25-intertext (42 bp, \intertext unsupported), 28-xrightarrow (11.7 bp, \xrightarrow unsupported), both outside this lane's list.

Changes

  • compiler (math parsing only): new nuclei GenFraction (\dfrac \tfrac \binom \dbinom \tbinom \genfrac, amsmath.sty 237-312), Phantom (latex.ltx \ph@nt), Operator (\operatorname(*), \DeclareMathOperator(*), amsopn.sty 43-54; arg\,max body keeps its glue), SubArray (\substack, amsmath.sty 1030-1059); dcases grid env (mathtools \newcases).
  • math-layout: Rule 15e delimiters on Fraction; BigDelimiter (amsmath \bBigg@, \big@size = 1.2 x the text ( box); Phantom; SubArray (scriptstyle rows at fontdimen10+12 of scriptfont2, vcenter); Glue atoms that don't reset r_type; PositionedGlyph.width; char_box italic correction as a kern.
  • render-pipeline (no vendor edits): conversions behind new feature amsmath-inline (off by default, so it still builds against the pinned vendor). Ungated: smallmatrix pitch from amsgen \ex@ with \null\,, no strut; dcases spec; \openup also advances \lineskip/\lineskiplimit.
  • oracle: pdftext's ? for cmsy glyphs gets OMS text; cmex/lmex glyphs are compared as x columns (a Type 1 cmex origin sits at the box top, the LM Math OTF variant's doesn't, and piece counts differ); cluster ranges sliced as UTF-8 bytes. Fixture 14 now loads mathtools (without it the ref was pdflatex error recovery). Refs regenerated with the same pdfTeX 1.40.29; only intended text/column changes.

Re-pin needed

To show this in render-pipeline: re-pin vendor/compiler and vendor/math-layout from this branch, then turn on amsmath-inline (or make it default). Vendored math-layout db90047 has corpus.rs/json.rs that crates/math-layout doesn't; the pipeline doesn't use them.

Verification

  • cargo test --release: compiler, math-layout, render-pipeline (feature off, vendor) all green; render-pipeline with the feature against this branch's crates also green (local mirror, not committed).
  • HW1: within 0.5 bp 264 -> 268, math_limitation 2 -> 0. HW2: 232 -> 241, 2 -> 0. Unaligned words: HW1 117 -> 118, HW2 193 -> 205. That rise is all on the candidate side, because math advance_x is now the TFM width, which equals pdfTeX's /Widths; reference-side unaligned went down.
  • Known gap: \quad in math uses the family-2 quad instead of the text font's, about 0.25 bp per quad (37 and 38 still pass at 0.38 bp).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 4 commits September 13, 2026 04:40
…, smallmatrix, dcases

Compiler (math parsing only): \dfrac/\tfrac/\binom/\dbinom/\tbinom/\genfrac
become Nucleus::GenFraction (amsmath.sty 237-312), \phantom/\hphantom/
\vphantom Nucleus::Phantom (latex.ltx \ph@nt), \operatorname(*) and
\DeclareMathOperator(*) Nucleus::Operator (amsopn.sty 43-54), \substack
Nucleus::SubArray (amsmath.sty 1030-1059), dcases a grid environment
(mathtools.sty \newcases).

math-layout: Rule 15e delimiters on Fraction, BigDelimiter (amsmath
\bBigg@ with \big@size = 1.2 x the text '(' box), Phantom, SubArray
(\scriptstyle rows at fontdimen10+12 of scriptfont2, vcenter), Glue atoms
that do not reset r_type, PositionedGlyph.width.

render-pipeline: conversions behind the new `amsmath-inline` feature (off
until vendor/compiler and vendor/math-layout are re-pinned); smallmatrix
pitch from amsgen \ex@, \null\, spacing and no strut; dcases spec;
\openup also advances \lineskip/\lineskiplimit.

Oracle: OMS glyph text for pdftext's '?' symbols, extension-font glyphs
compared as x columns (origin convention differs between cmex Type 1 and
the Latin Modern Math OpenType variants), UTF-8 cluster slicing; fixture
14 loads mathtools (dcases); refs regenerated with the same pdfTeX 1.40.29.
amsmath corpus: 20/42 -> 40/42 (render-pipeline built against this
branch's compiler + math-layout with --features amsmath-inline).

Implementation-Agent: Claude Opus 5 (subagent kabir-claude FT-061, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
var_delimiter (math-layout) and mathgrid::delimiter (render-pipeline)
widened the glyph box by the italic correction; the same total width is
now a glyph box at its TFM width followed by a kern, so
PositionedGlyph.width (and the display list's math advance_x under
`amsmath-inline`) is the width pdfTeX writes to /Widths.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude FT-061, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
With `amsmath-inline` glue inside \left...\right or a sub-formula is a
math-layout Glue atom, so math_spacers asserts it is set (a quad inside
the fences, no math_limitation); without the feature the old
typed-limitation test still runs. rustfmt on this branch's hunks only.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude FT-061, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Conflict: crates/compiler/src/incremental.rs. Took main's in-place
shift_math_list (compiler-perf-r2) and added the GenFraction, Phantom,
Operator and SubArray arms in that style. FT-067's supported-LaTeX
inventory gains \genfrac, \phantom/\hphantom/\vphantom, \substack,
\operatornamewithlimits and \DeclareMathOperator; \dfrac/\tfrac/\binom
descriptions updated; artefacts regenerated with
render_supported_latex.sh.

Verified after the merge: compiler, math-layout and render-pipeline
cargo test --release green (pipeline with the feature off against main's
re-pinned vendor, and with --features amsmath-inline against this
branch's crates); amsmath corpus 40/42.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude FT-061, mac-m5pro-kabir)
Commit-Executor: Claude Code direct Git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar

GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

FT-061: amsmath inline constructs. Head 9cc8419f, based on 3b2703aa, with origin/main fe864d90 merged in.

amsmath oracle (0.5 bp): 40/42, up from 27/42 on current main under the fixed oracle (20/42 under the old one).

  • Oracle-side fixes (no engine change): 13-cases, 16–20 (p/b/B/v/Vmatrix), 27-overset-underset. These were word-pairing bugs: reference PDF symbols with no text, delimiter origins compared across different font formats, and multi-byte character slicing.
  • Engine fixes, worst error before → after in bp:
    • binom 85.3 → 0.005; hphantom/vphantom 64.3 → 0.005; substack 35.7 → 0.005; phantom 25.9 → 0.005
    • dfrac/tfrac 21.9 → 0.005; operatorname* 20.3 → 0.25; big family 19.5 → 0.005; bigl/bigr 13.6 → 0.005
    • smallmatrix 9.2 → 0.08; left/middle/right 3.3 → 0.005; DeclareMathOperator and spacing-thin now pair
    • dcases 231.1 → 0.13. The fixture was missing mathtools, so references were regenerated with the same pdfTeX version.
  • Still failing: 25-intertext, 28-xrightarrow (unsupported). Follow-up in progress on agent/kabir-claude/amsmath-inline-2.

Changes

  • Compiler (math parsing): atoms for generalized fractions (\dfrac/\tfrac/\binom family/\genfrac), phantoms, \operatorname*, \DeclareMathOperator, \substack; dcases as a grid environment; supported-LaTeX inventory and docs regenerated.
  • math-layout: fraction delimiters, fixed-size \big delimiters, phantoms, substack rows, spacing atoms inside groups, math glyphs carrying TFM widths. Sources are amsmath.sty, amsopn.sty, mathtools.sty and latex.ltx, with line numbers in the commits.

Gates: cargo test --release passes for compiler, math-layout and render-pipeline.

  • HW1: words within 0.5 bp 264 → 268; math_limitation 2 → 0.
  • HW2: words within 0.5 bp 241 → 251; math_limitation 2 → 0.
  • Unaligned words rose slightly (HW1 117 → 118, HW2 193 → 205), because math advances now equal pdfTeX's widths and split words where the reference does.

Re-pin needed. The pipeline integration sits behind a new amsmath-inline feature, off by default. Re-pin vendor/compiler and vendor/math-layout from 9cc8419f, then enable the feature. Measured with a scratch pipeline using this branch's crates.

Known gap: math \quad uses the wrong font's quad (about 0.25 bp per quad). The follow-up branch fixes it.

🤖 Generated with Claude Code

@jay3332
jay3332 merged commit 6fbd41d into main Sep 13, 2026
11 of 18 checks passed
@jay3332

jay3332 commented Sep 13, 2026

Copy link
Copy Markdown
Member

Merged to main via integration/2026-09-13f (Commander).

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