Skip to content

math-layout: source spans and attribute ids on placed glyphs and rules - #161

Merged
jay3332 merged 1 commit into
mainfrom
agent/kabir-claude/math-glyph-spans
Sep 13, 2026
Merged

jay3332 merged 1 commit into
mainfrom
agent/kabir-claude/math-glyph-spans

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

What

Math glyphs currently map only to the whole formula, so colour, hyperlinks and click-to-source can't reach inside math (see #150/#158, #131). This adds provenance to math-layout, additively:

  • SourceTag { span: Option<SourceSpan { document, start, end }>, attr: Option<u32> } (new source.rs).
  • Atom::tag and Atom::delimiter_tags (own tags for \left/\right or \genfrac delimiters), with with_tag / with_delimiter_tags builders.
  • MathBox::tag (set on glyph/rule leaves), PositionedGlyph::tag, PositionedRule::tag.

Layout copies each atom's tag onto the leaves it produces that no inner atom already tagged (innermost first, per field). Result:

  • scripts, numerators, radicands, subarray rows, accent bases and bodies keep their own atoms' spans;
  • fraction bars, radical signs (extensible pieces included) and vincula, accent marks (including the scripted-character path), operator text, big operators, extensible arrow pieces, over/underbrace pieces and fill rules map to the command that built them;
  • \left/\right delimiters (extensible pieces included) map to their own commands when delimiter_tags are set, otherwise to the atom;
  • attr (colour or link id) inherits independently of span, so {\color{red} a {\color{blue} b}} gives a red and b blue while each keeps its own bytes.

Geometry is untouched

Tags are never read for layout. tests/source_spans.rs lays out every fixture plus \xrightarrow, \substack, \overbrace, \binom and \big( in display, text and script style, fully tagged and untagged. The box trees are equal once tags are stripped, and every glyph and rule position matches bit for bit (f64::to_bits). Goldens are unchanged (10 + 28 pass), plus 11 new span tests; clippy is clean. crates/font-engine (the other consumer of ../math-layout) tests pass unchanged.

Consumers / merge notes

Implementation-Agent: Claude Opus 5 (subagent kabir-claude math glyph spans, mac-m5pro-kabir)

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…d rules

Atoms gain a `SourceTag { span: Option<SourceSpan>, attr: Option<u32> }`
(plus `delimiter_tags` for \left/\right and \genfrac delimiters). Layout
copies it onto every glyph and rule leaf the atom produces that no inner
atom already tagged (innermost first, per field), and `positioned_runs`
exposes it as `PositionedGlyph::tag` / `PositionedRule::tag`. Consumers
can now map math glyphs to their own source bytes (click-to-source,
link rectangles) and paint per-glyph attributes such as colour.

Coverage: scripts, fractions (bar -> \frac), radicals (sign, extensible
pieces and vinculum -> \sqrt), \left/\right (each side its own command,
extensible pieces included), genfrac delimiters, accents (incl. the
scripted-character path), operator text and \operatorname lists, big
operators, extensible arrows, over/underbraces (pieces and fill rules),
subarrays, styled bodies, overline/underline.

Additive only; tags are never read for geometry. tests/source_spans.rs
lays out every fixture (plus ext arrow, substack, brace, binom, \big) in
three styles fully tagged and untagged: box trees equal after stripping
tags and every glyph/rule position bit-identical; goldens unchanged.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude math glyph spans, 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 added a commit that referenced this pull request Sep 13, 2026
…ession handoff)

Stage 1 partly done: #131, #137, #153 (incl. #142), #144, #147, #149, #150,
#155, #159, #163, #164 merged with conflicts and post-expansion fixes recorded
in docs/evidence/integration-2026-09-13b/merge-log.md. Remaining: #166, #169,
#148, #161, then the inventory regeneration and stages 2-4. The helper scripts
under tools/ hard-code the original worktree path.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, 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 added a commit that referenced this pull request Sep 13, 2026
Conflicts against #148: MathBox::glue_flex (SourceTag plus stretch/shrink) and the mathlist.rs imports. math-layout 54 tests pass.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude integration, nixos-pc-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 merged commit 9363843 into main Sep 13, 2026
12 of 18 checks passed
@GoKubar
GoKubar deleted the agent/kabir-claude/math-glyph-spans branch September 13, 2026 18:12
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