Skip to content

compiler: skip the [t]/[b]/[c] position argument of nested grids (#115 split, part 1) - #124

Merged
jay3332 merged 1 commit into
mainfrom
agent/kabir-claude/math-nested-grids-compiler
Sep 13, 2026
Merged

jay3332 merged 1 commit into
mainfrom
agent/kabir-claude/math-nested-grids-compiler

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Compiler-side half of #115, split out as the Commander asked on #2 (no vendor edits in feature PRs). Base: main 1d4604d. Commit: 59e5042, taken from #115's source commit 4d884b3.

What

  • crates/compiler/src/math.rs: the box-position argument of array/aligned/alignedat/gathered ([t], [b], [c]) comes before the preamble (latex.ltx \@array, amsmath \ams@start@box).
    • Before: it was parsed into the first cell as [, t, ].
    • Now: it is skipped, and the new unit test grid_position_argument_is_not_a_cell covers it.
  • amsmath oracle corpus: 17 new fixtures and pdfTeX refs (TeX Live 2026), 43–59, for grids nested in fractions, radicands, scripts, \overset, \left…\right bodies and other grids' cells.
  • No crates/math-layout changes. No vendor changes.

Gates (mac-m5pro-kabir)

  • compiler cargo test --release: green, every test binary ok.
    • This includes the supported_latex drift gate (8 passed). No regeneration was needed, because the supported inventory is unchanged.
  • The render-pipeline half is a stacked PR. It needs crates/render-pipeline/vendor/compiler re-pinned to this commit.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

The box-position argument of array/aligned/alignedat/gathered
(latex.ltx \@array, amsmath \ams@start@box) comes before the preamble
and is not a cell. It was parsed into the first cell as `[`, `t`, `]`.
The parser now skips it; the render pipeline reads the letter from the
source at \begin.

amsmath oracle corpus: 17 new fixtures (43-59) of grids nested inside
fractions, radicands, scripts, \overset, \left...\right bodies and
other grids' cells, refs from pdfTeX (TeX Live 2026).

Compiler-side split of #115 (source commit 4d884b3), rebased on main
1d4604d. The render-pipeline half is a separate stacked PR that needs
vendor/compiler re-pinned to this commit.

compiler cargo test --release green, including the supported_latex
drift gate (no regeneration needed: the supported inventory is unchanged).

Implementation-Agent: Claude Opus 5 (subagent kabir-claude rebase 114/115, 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
@jay3332

jay3332 commented Sep 13, 2026

Copy link
Copy Markdown
Member

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

@GoKubar
GoKubar deleted the agent/kabir-claude/math-nested-grids-compiler branch September 13, 2026 18:12
GoKubar added a commit that referenced this pull request Sep 14, 2026
… a space

The gap between a theorem-like head and its body was an interword space read
from the source newline after `\begin{...}` — and because the head ends in
`.`, a *sentence* space (`4.83948 plus 5.44014 minus 0.40297` at 11pt).
amsthm puts its own glue there and then `\ignorespaces`.

Measured against pdflatex (TeX Live 2025, oracle only, never in the product
path), `\documentclass[11pt]{article}` + `[T1]{fontenc}` + amsthm with
`\tracingoutput=1`:

* a `\newtheorem` environment's head ends with `\hskip\thm@headsep`
  (amsthm.sty `\@begintheorem`), `\thm@headsep = 5\p@ plus\p@ minus\p@`.
  The shipped page: `\T1/cmr/bx/n/10.95 .`, `\glue 5.0 plus 1.0 minus 1.0`,
  then the body. It is absolute — the same 5pt at 10, 11 and 12pt — and it
  stretches, which a sentence space's five-times-larger stretch does not
  reproduce on a line that is set loose;
* `proof` is not a `\newtheorem` style but a plain `\trivlist` `\item
  [\hskip\labelsep \itshape #1\@addpunct{.}]`, so the glue after its label
  is the `\hskip\labelsep` `\@item` appends after the label box, rigid:
  `\hbox(7.60416+2.12917)x67.05003` then `\glue 5.475` then `\penalty 0`.
  `\showthe\labelsep` prints 5.0pt / 5.475pt / 5.87494pt at 10 / 11 / 12pt,
  which is what `flashtex_document_style::list_level` already resolves.

New `src/amsthm.rs` recognises the head from the compiler's own output
rather than from a `\newtheorem` scan: `parser::begin_theorem`/`begin_proof`
are the only places that give a synthesised `Inline::Text` the span of a
`\begin` control word. It returns the glue and the byte the head ends at
(past `{<env>}` and any `[<note>]`); `items_from_inlines_styled` emits that
glue in place of the gap before the first inline at or after it, so the
source's own whitespace is dropped exactly as `\ignorespaces` drops it —
`\begin{theorem}Body`, `\begin{theorem}\n Body` and
`\begin{theorem}\label{k}\n Body` all give the same head (`\label`'s
`\@esphack` takes the glue off and puts it back with `\ignorespaces`).

`Item::HSpace` grows `stretch_pt`/`shrink_pt` and becomes `Glue::finite`
rather than `Glue::fixed`; `\hspace` keeps passing 0/0 and is unchanged.

## Gates

NixOS host, bundled `apps/mac/Fonts` with the explicit `FLASHTEX_TFM_DIRS`
spelling that reaches the rooted metrics reader; never the system TeX Live.

Real-world corpus, v2 display lists against an `origin/main` control: nine of
ten fixtures **byte-identical** (hw1, hw2, cv, inline-math,
input-bibliography, letter, math-sheet, unicode-accents, article-twocolumn),
`lecture-notes` the only one that moves. Its diagnostics are byte-identical
too (8, none of them a font substitution, 0 overfull); every status and page
count unchanged.

`lecture-notes` word geometry against the committed `reference.pdf`
(difflib-aligned words, |dx| in bp). The head is only *exact* with all three
parts in place, and the errors partly cancel, so every combination is
measured:

| build | median &#124;dx&#124; | ≤0.01 bp | ≤0.1 bp | ≤0.5 bp | lines |
|---|---|---|---|---|---|
| `main` | 7.6051 | 116 | 125 | 138 | 32/56 |
| + this PR | 7.2493 | 116 | 125 | 138 | 32/56 |
| + #190 | 0.1366 | 174 | 199 | 285 | 38/56 |
| + #190 + this PR | 0.0305 | 199 | 245 | 340 | 38/56 |
| + #190 + this PR + the compiler PR | **0.0048** | **235** | **284** | 339 | 38/56 |

No line is lost in any combination, and the 419 aligned words and the
`max |dx|` (112.737 bp, the pre-existing math-run/extraction outliers) are
the same throughout.

On the fixture's own `Definition 3.1.` line, body start against the oracle's
155.3717 bp: `main` + #190 155.8772 (+0.5055), with this PR 154.9534
(−0.4183), with the compiler PR as well **155.3744 (+0.0027)** — and the
whole rest of that line then lands inside 0.06 bp.

`cargo test --release --no-fail-fast` on `crates/render-pipeline`, with the
font environment: see the PR description for the failing-set comparison
against an `origin/main` control of the same base.

Implementation-Agent: engine-engineer (Claude Opus 5), linux-primary
Commit-Executor: engine-engineer (Claude Opus 5), direct git
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
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