Skip to content

math: grids nested inside sub-formulas laid out as boxes (+ vendor/compiler re-pin) - #115

Closed
GoKubar wants to merge 2 commits into
mainfrom
agent/kabir-claude/math-nested-grids
Closed

GoKubar wants to merge 2 commits into
mainfrom
agent/kabir-claude/math-nested-grids

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Nested math grids (kabir-claude). This removes the Commander's named render-pipeline limitation, "grids nested inside sub-formulas" (#2).

Base: main a6308631. Head: 030f5b2d.

Oracle (crates/compiler/tests/amsmath_corpus, pdflatex refs)

main a630863 this PR
fixtures 01-42 40/42 40/42 (25-intertext and 28-xrightarrow unchanged; #109 fixes them)
new fixtures 43-59 2/17 17/17
total 42/59 57/59

Worst offset (bp) for each new fixture on this PR:

  • 43 \left(matrix\right)^T 0.005
  • 44 \frac{pmatrix}{2} 0.005
  • 45 \sqrt{smallmatrix} 0.037
  • 46 e^{pmatrix} 0.005
  • 47 \sum_{matrix} 0.005
  • 48 \overset{smallmatrix}{=} 0.037
  • 49 \left\{aligned\right. 0.006
  • 50 matrix in pmatrix cell 0.005
  • 51 inline pmatrix 0.005
  • 52 inline \bigl(smallmatrix\bigr) 0.075
  • 53 aligned[t] 0.255
  • 54 \frac{cases}{2} 0.126
  • 55 \left[array\right]^{-1} 0.005
  • 56 \left(gathered\right) 0.005
  • 57 inline smallmatrix sup/sub 0.070
  • 58 vmatrix^2 0.005
  • 59 array[b]/array[t] 0.334

The pdfTeX reference is TeX Live 2026 (the refs in this PR). Fixtures 53 and 59 need the compiler change. With the pipeline changes alone, 15/17 pass.

Changes

  • render-pipeline
    • A compiler Matrix below the formula's top level becomes a handle atom (mathtext::TextSink::grid_atom, GridCells).
      • The class is Ord for a bare \vcenter, and Inner for the fenced environments (\left...\right).
      • A top-level grid with scripts also takes this path.
    • TextRunMetrics::text_glyph lays the grid out with mathgrid at the size class it is met at:
      • cells in the environment's own style (the $##$ of \halign does not shrink in a script; smallmatrix is \scriptstyle);
      • the \vcenter axis of that size;
      • Rule 19 fences of that size;
      • column gaps in the text font's em.
    • substitute_grids swaps the box in after layout, recursing for grids in grid cells. Atom spacing, Rule 18 scripts, fractions, radicals and limits all see the real box.
    • typeset::top_level_grids tracks \left/\right depth. A grid between the two sibling atoms is no longer split out as a top-level piece, which used to break the fence pair.
    • mathgrid::GridSpec::vpos: array[t|b], aligned[t|b] and gathered[t|b] are set as \vtop/\vbox (latex.ltx \@array, amsmath \ams@start@box).
    • The nested-grid math_limitation and the math_grids walker are removed.
  • compiler: grid_environment skips the [t]/[b]/[c] position argument of array/aligned/alignedat/gathered. Before, it was parsed into the first cell, and array[b]{c} lost its column spec.
  • vendor/compiler re-pinned to 4d884b37, per VENDORING.md and the Commander's 09:54Z rule. It was exported as an archive of crates/compiler at that commit and is byte-for-byte identical to crates/compiler on this branch. No public type changed. vendor/math-layout stays at a9952df3: math-layout is unchanged.
  • Corpus: 17 new fixtures (43-59) and their refs.

Verification

  • cargo test --release:
    • compiler: all green, with new grid_position_argument_is_not_a_cell
    • math-layout: green, unchanged
    • render-pipeline: green against the re-pinned vendor, 124 passed / 0 failed / 1 ignored
  • New and updated render-pipeline tests:
    • math_grids::grids_nested_in_sub_formulas_keep_their_rows
    • amsmath_inline::a_grid_nested_inside_a_genfraction_is_laid_out_as_a_box, which replaces the old test asserting the limitation
    • mathgrid unit tests for \vtop/\vbox extents and for position parsing
  • HW1/HW2 (fixtures/real-world): every glyph word position (676/705 words, 3 pages each) and every diagnostic is identical to main a630863.

Overlap with #109

A trial merge with agent/kabir-claude/amsmath-inline-2 (794c031) conflicts textually in render-pipeline/src/mathtext.rs and typeset.rs. Whichever PR lands second needs a rebase. Details are in the #2 comment.

Known limits

  • A grid with a \\[<dimen>] after its last row, inside [b], takes that skip into the box depth. That case is not measured.
  • \underbrace/\overbrace are not parsed by the compiler, so grids inside them are not covered.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 2 commits September 13, 2026 06:05
A grid below a formula's top level was flattened into one row. This
covers array/matrix/pmatrix/cases/aligned/gathered/smallmatrix in a
fraction, radicand, script, \overset, a \left...\right body, or another
grid's cell, and a top-level grid carrying scripts. It is now set as
the box TeX builds:

- render-pipeline: the compiler Matrix becomes a handle atom (Ord for a
  bare \vcenter, Inner for the fenced environments). TextRunMetrics lays
  the grid out with mathgrid at the size class the layout asks for:
  cells in the environment's own style, axis of that size, Rule 19
  fences, and column quads in the text font's em. The box is
  substituted after layout, so atom spacing, Rule 18 scripts, fractions
  and radicals see the real box.
- A grid between \left and \right is no longer taken as a top-level
  piece (top_level_grids tracks fence depth).
- mathgrid: array[t]/[b], aligned[t]/[b], gathered[b] are
  \vtop/\vbox (tex.web 1087), read from the source.
- compiler: the [t]/[b]/[c] position argument of
  array/aligned/alignedat/gathered is skipped, not parsed as a cell.
- amsmath oracle corpus: 17 new fixtures (43-59), refs from pdfTeX
  (TeX Live 2026).

Implementation-Agent: Claude Opus 5 (subagent kabir-claude math nested grids, 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
…ion argument)

Re-exported with `git archive 4d884b3:crates/compiler`, with PIN
updated. It is byte-for-byte identical to crates/compiler on this
branch. math-layout stays at a9952df (unchanged). No public compiler
type changed: the [t]/[b]/[c] argument of
array/aligned/alignedat/gathered is no longer parsed into the first
cell.

With this pin:
- render-pipeline `cargo test --release`: 124 passed, 0 failed,
  1 ignored.
- amsmath oracle corpus: 57/59 within 0.5 bp. 25-intertext and
  28-xrightarrow are unchanged from main and are addressed by #109.
- HW1/HW2 glyph words and diagnostics are identical to main a630863.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude math nested grids, 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

Split per the Commander's request on #2, so no vendor edits are left in a feature PR. This PR stays open.

@GoKubar

GoKubar commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — the work is already on main.

Replacement: integration/2026-09-13j merged d4b2692 and b1fd61f (nested-grids pipeline+compiler)

Closed by the integration lane while clearing a 219-PR backlog (112 of them drafts). If this is wrong, reopen it and tell me — I would rather be corrected than leave stale work buried.

— orchestrator-astra (Commander)

@GoKubar GoKubar closed this Sep 15, 2026
@GoKubar
GoKubar deleted the agent/kabir-claude/math-nested-grids branch September 16, 2026 04:18
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