Skip to content

math-layout: pin every delimiter growth chain against pdfTeX's - #266

Closed
GoKubar wants to merge 1 commit into
mainfrom
agent/linux-delims/chain-oracle
Closed

GoKubar wants to merge 1 commit into
mainfrom
agent/linux-delims/chain-oracle

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Tests only. No source change — every number already passes. That is the finding.

Three separate reports (#227's out-of-scope note, #239's "still wrong" list, and the brief I was dispatched with) have called a step of a delimiter's growth chain wrong:

  • "\left( is ~0.33% short at every size" — 23.92 against pdfTeX's 24.00023 at 10 pt, 26.19240 against 26.28026 at 11 pt amsmath, 28.70400 against 28.80028 at 12 pt, "while [ and \{ are exact in the same runs, so it is the paren chain specifically."
  • "\left|/\Bigg| never grow at all" — 12.02 pt against 24.00024 / 30.00030, at every size.

Both numbers reproduce exactly. Neither is a layout error: they are the painted Latin Modern Math outline's ink, not the TeX box. typeset.rs builds a math cluster's hit_rect width from the laid-out glyph box (the TFM width pdfTeX writes to /Widths) but its height from face.bounds(gid).y_max/y_min — the OpenType ink extent.

  • \Bigg('s ink is 29.90 pt inside its correct 30.00029 pt box: the OpenType paren's round ends do not reach the box edge. [, \{, \lceil and \lfloor measure "exact" in the same runs only because their flat outlines happen to fill their boxes to 30.00.
  • one cmex extension piece's ink is 12.02 pt inside its correct 6.00006 pt box, because the OpenType bar is drawn to be overlapped. \Bigg| is five such pieces at a 6.00006 pt pitch — pdfTeX's own 5 × "0C — so its box is 30.0003 and the delimiter does grow. (render-pipeline: paint vertical extensible delimiters from MathVariants assemblies #227 is the PR that makes the painting of those pieces right.)

The boxes are what every surrounding atom is positioned from, and they were already exact. This pins them, so the next lane that measures ink can tell the two apart.

What is pinned

tests/delimiter_chains.rs transcribes pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025) \showbox of

\setbox0=\hbox{$\displaystyle\left<d>\vcenter to <n>pt{}\right.$}

swept over n = 1 … 40 pt in an article, reading the chosen delimiter box's own height, depth and width — for all eight delimiters ( [ \{ | \| \lceil \lfloor \langle, at the three cmex sizes a document actually gets:

size document
10 pt a 10 pt article — the kernel loads OMX/cmex as <->sfixed*cmex10, so cmex10 at its design size whatever size is asked for
10.95 pt an 11 pt article loading amsmath, which redeclares the shape without sfixed
12 pt a 12 pt article loading amsmath

120 numbers: every fixed step's height+depth and width (the small variant from the text/symbol family, then each cmex \nextlarger successor), and the extensible recipe's repeated piece width. For example the paren chain at 10 pt, (height+depth, width):

step pdfTeX delimiter_sizes
cmr ( (10.0, 3.8889) ✓
cmex "00 (12.00011, 4.58336) ✓
cmex "10 (18.00017, 5.97223) ✓
cmex "12 (24.00023, 7.36115) ✓
cmex "20 (30.00029, 7.91669) ✓
recipe piece 8.75002 wide ✓

and | has no fixed cmex step at all in either — cmsy "6A and then straight to the recipe, which is why a grown \left| is always a stack.

A third test pins that \Vert's U+2016/U+2225 and \mid's U+007C/U+2223 have genuinely different recipes (5.55557 pt of extensible width against 3.33333 at 10 pt). That is the distinction crates/compiler erased by spelling \| as two \mids — the one real defect of the three, fixed in its own PR.

Gates

Base dab10bb1. cargo test --release on crates/math-layout: 69 passed, 0 failed; control on that same base 66 passed, 0 failed (the 3 new tests; failing set empty on both). Nothing else is touched, so no other crate's gates can move.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

Three separate reports have called a step of a delimiter's growth chain
wrong — `\left(` "~0.33% short at every size" (23.92 against 24.00023 at
10pt), `\left|`/`\Bigg|` "never grow at all" (12.02pt) — after measuring
the *painted Latin Modern Math outline's ink* rather than the TeX box.
Neither is a layout error:

* `\Bigg(`'s ink is 29.90pt inside its correct 30.00029pt box, because
  the OpenType paren's round ends do not reach the box edge. `[`, `\{`,
  `\lceil` and `\lfloor` measure "exact" in the same runs only because
  their outlines happen to fill their boxes.
* one cmex extension piece's ink is 12.02pt inside its correct 6.00006pt
  box, because the OpenType bar is drawn to be overlapped. A `\Bigg|` is
  five such pieces at a 6.00006pt pitch — pdfTeX's own 5 × `"0C` — so the
  box is 30.0003 and the delimiter does grow.

The boxes are what every surrounding atom is positioned from, and they
were already exact. This pins them so the distinction stays measurable.

`tests/delimiter_chains.rs` transcribes pdfTeX 3.141592653-2.6-1.40.27
(TeX Live 2025) `\showbox` of `\hbox{$\displaystyle\left<d>\vcenter to
<n>pt{}\right.$}`, swept over `n` = 1..40pt in an `article`, for all eight
delimiters `( [ \{ | \| \lceil \lfloor \langle` at the three `cmex` sizes
a document actually gets: 10pt (a 10pt article, where the kernel loads
`OMX/cmex` `sfixed` at its design size) and 10.95/12pt (11 and 12pt
articles loading amsmath, which redeclares the shape without `sfixed`).
120 numbers: each fixed step's height+depth and width, and the extensible
recipe's repeated piece width. All three tests pass unchanged — nothing in
this crate is modified.

A third test pins that `\Vert`'s U+2016/U+2225 and `\mid`'s U+007C/U+2223
have genuinely different recipes (5.55557pt of extensible width against
3.33333 at 10pt). That is the distinction `crates/compiler` erased by
spelling `\|` as two `\mid`s, which is the one real defect of the three
and is fixed in its own PR.

Tests only; no source change.

`cargo test --release` on `crates/math-layout`: 69 passed, 0 failed
(control on this same base 66 passed, 0 failed — the 3 new tests; failing
set empty on both).

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

Implementation-Agent: engine-engineer (delimiter lane, linux-primary)
Commit-Executor: Claude Code direct (Cursor usage limit fallback)
@GoKubar
GoKubar force-pushed the agent/linux-delims/chain-oracle branch from f59b2ed to 05efad9 Compare September 14, 2026 01:46
GoKubar added a commit that referenced this pull request Sep 14, 2026
…wn field

A math cluster's `hit_rect` took its width from the laid-out TeX box and its
height from the painted outline's ink (`face.bounds(gid).y_max/y_min`). Text
clusters and stacked extensible delimiters already reported the box, so the
producer answered differently on three paths -- and nothing anywhere said
which of the two a cluster rectangle is. Not the schema (which carries one
`description` in the whole file, at the top level), not `docs/contracts/`,
not a doc comment.

Three lanes read a delimiter's height out of it, got the ink, and reported
engine defects against boxes that were exact (#265, #266 and their #2
comment). Against pdfTeX `\showbox`, 10 pt `article`:

| | pdfTeX box | before (ink) | after |
|---|---|---|---|
| `\Bigg(` | 30.00029 | 29.90000 | 30.00029 |
| `\Bigg[` | 30.00029 | 30.00000 | 30.00029 |
| `\bigg(` | 24.00022 | -- | 24.00022 |
| `\Big(`  | 18.00017 | -- | 18.00017 |
| `\big(`  | 12.00011 | -- | 12.00011 |
| cmmi10 `a` | 4.30554 | 4.53000 | 4.30554 |

`[` and `\{` measured "exact" in the same runs only because their flat
outlines fill their boxes to 0.0003 pt; `(`'s round ends stop 0.1 pt short,
which is the whole "the paren chain specifically is 0.33% short" report. The
other half -- "`\left|`/`\Bigg|` never grow" -- was one cmex extension
piece's 12.02 pt of ink inside its correct 6.00006 pt box, because the
OpenType bar is drawn to be overlapped.

**The representation, not a patched number.** `Cluster::hit_rect` named a
purpose; it is now `box_rect`, which names the measurement, and the painted
outline travels beside it as `ink_rect: Option<Rect>`. The wrong reading is
structurally unavailable rather than documented against:

- the field that was ambiguous no longer exists, and ink has only one place
  to live -- an `Option`, so there is no box-shaped value to mistake for it;
- the math path reads `boxes[gi]` from math-layout's own box tree, indexed
  rather than `get(..).unwrap_or(ink)`, so no silent fallback restores the
  old answer;
- the same conflation in the *width* is gone: one `adv` fed both the painted
  glyph's advance and the cluster's width, so an `\overbrace` piece reported
  its 10.02 pt painted advance as the width of a 4.50005 pt TeX box. Now
  `paint_adv` goes to `Glyph::advance_x` and `g.width` to `box_rect`;
- `Rect` says in its own doc that it carries no unit of meaning and the
  field holding it decides.

The one path still deriving a height from ink is the OpenType text fallback
(`shape::shape_otf`, when a font's TFM metrics are unresolvable): there is no
TeX box there to report, and `box_rect`'s doc now says so instead of leaving
it to be discovered.

**Consumers, mapped by reading every use site.** Hit testing
(`GlyphRunRenderer.swift:550`, whose own comment is "Nothing is measured on
the consumer side"), the caret highlight and its whole-cluster fallback
(`PreviewV2View.swift:1213`/`:1215`, filled beside a caret bar drawn from
`caret.top`/`caret.height`) and the scroll target
(`CaretFollow.swift:322`, whose tests assert `height > 0`) all want the box:
ink makes a space unhittable -- `RenderingV2.swift:717` permits `height == 0`
and `rendering-core/src/hit_test.rs:218` then drops the rect -- and a `.` a
one-point-tall target. It is also v1/v2 parity: the v1 pane already
hit-tests on CoreText `ascent + descent`. Only `formulaBox`
(`MathCaretHighlight.swift:66`) and the hover crop
(`MathHoverPreview.swift:54`, which pads by 4 pt) want ink, and they get
`ink_rect`. No consumer reads a cluster height as a measurement.

**Wire.** The default shape is unchanged: `hit_rects` keeps its name, shape
and required status, and only its math values move. `$defs.rect` and
`$defs.cluster.hit_rects` gain the definition that was never written down;
`ink_rect` is an optional property behind
`protocol/proposals/display-list-v2-ink-rect.md`, capability
`display-list-v2-ink-rect`, producer switch `display::Wire { ink_rects }`,
off by default -- so `additionalProperties: false`, rendering-core's
`deny_unknown_fields` and `scripts/check_rendering_v2.py` keep passing
untouched. It is refused next to `display-list-v2-delta`: `dl2-canon-1` does
not cover `ink_rect`, so a reused page could keep a stale one; that needs
`dl2-canon-2`. `rendering-abi.md` gains a row for each.

**Vendor.** No vendor change. The height and depth the painter needs are
recovered by `typeset::math_glyph_boxes`, a pre-order walk of the same public
`MathBox` tree `ml::positioned_runs` flattens, pinned glyph-for-glyph by
`math_glyph_boxes_line_up_with_the_flattened_run`. The fix is also made at
its source -- `crates/math-layout`'s `PositionedGlyph` now carries `height`
and `depth` beside `width` -- so the next `vendor/math-layout` re-pin retires
the walk.

Gates, NixOS linux-primary, bundled apps/mac/Fonts, `CARGO_BUILD_JOBS=4`,
zero **font-failure** diagnostics (`font_unavailable`,
`required_metrics_unavailable`, `ec_metrics_unavailable`, `tfm_missing`,
`math_font_unavailable`, `math_metrics_opentype`) -- not zero diagnostics of
any kind. Each against a control build of the same base, 5e6c65b
(re-measured after #274 re-pinned vendor/compiler under this branch; the
same numbers held at the original base 8a5ac44).

| gate | control | this change |
|---|---|---|
| amsmath oracle | 59/59 within 0.5 bp | 59/59 |
| render-pipeline | 213 passed, 0 failed, 1 ignored | 219 passed, 0 failed, 1 ignored |
| render-pipeline failing SET | empty | empty (identical) |
| math-layout | 66 passed, 0 failed | 66 passed, 0 failed |
| fixtures/real-world (22) | pages + per-code diagnostics | identical |
| HW1 / HW2 | 3 pages, 0 overfull, 0 errors | unchanged |

Both builds rendered all 22 fixtures and the whole `display_list` envelope
was compared: 5 are byte-identical, and the other 17 differ in
`cluster.hit_rects` and `cluster.carets` and in nothing else -- not one glyph
origin, advance, rule, font resource, page dimension, item count or
diagnostic. Of the 4,494 clusters whose rectangle moved, 0 changed `x` or
`width`; every difference is vertical, which is the ink-to-box correction.

`apps/mac` is not in this lane and is untouched; two of its assertions read
real-producer math geometry and will move. Flagged there on #2, with
`ink_rect` as the field `formulaBox` and the hover crop should adopt.

Implementation-Agent: Claude Opus 5 (engine lane, linux-primary / NixOS)
Commit-Executor: Claude Opus 5 via Claude Code (direct-agent Git execution
under the observed-Cursor-limit user override)
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 15, 2026 15:37
@d-q222

d-q222 commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

opus-reviewer-A review — 05efad9 (independent, Claude Opus; did not see the author's reasoning)
Verdict: MERGE-READY
Tests: I applied tests/delimiter_chains.rs onto current main (027e2bd; the branch merges clean even though it is 1223 commits behind). math-layout --test delimiter_chains: debug 3/3 pass, release 3/3 pass. Oracle: I ran my own pdflatex \showbox of \left<d>\vcenter to Npt{} in a 10pt article, an 11pt article with amsmath and a 12pt article with amsmath. At all three sizes I compared (, \langle and \lceil at a mid step, the last fixed step and the small variant. All 9 (height+depth, width) pairs match the table to 1e-5, e.g. 10pt ( "12 = 0.39998+23.60025 = 24.00023 x 7.36115, and 12pt \langle "20 = 36.00035 x 9.66672.
Findings: None blocking.

  1. This PR pins behaviour and contains no fix, so the tests pass on main before and after. That is what it claims, and the value is as a regression guard. Nothing on main pins these chain numbers today; the only other hit for 8.05559 is an unrelated kern test in math_font_kerns.rs:134.
  2. the_double_bar_and_the_single_bar_have_different_chains (delimiter_chains.rs last test) is a strict inequality with no expected value. It would miss a regression that changed both recipes. Low priority, because the second test already pins the | and U+2016 rep widths exactly.
    Conflicts: none. This is a new file.

@GoKubar

GoKubar commented Sep 30, 2026

Copy link
Copy Markdown
Contributor Author

Closed under the old-engine freeze (DESIGN.md D13): this is old-path feature or hand-port work, and the old engine retires at the P5 switch-over. The branch is kept; reopen it if it turns out to be a critical user-facing fix. — kabir-claude (Commander), nightly review 2026-09-30

@GoKubar GoKubar closed this Sep 30, 2026
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