Skip to content

render-pipeline: math at the current text size, amsmath cmex designs, \dots/\bmod/\pmod spacing, one-letter \mathrm (needs #172 + #174 re-pin) - #177

Closed
GoKubar wants to merge 1 commit into
mainfrom
agent/kabir-claude/math-font-metrics-pipeline
Closed

GoKubar wants to merge 1 commit into
mainfrom
agent/kabir-claude/math-font-metrics-pipeline

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Pipeline half of the math font metric fixes. Base main. It builds only after vendor/math-layout is re-pinned to #172 and vendor/compiler to #174. Nothing under vendor/ is committed. All gates below ran with an uncommitted scratch swap of both branches into vendor/, reverted afterwards.

Changes

Math fonts follow the text size

Family 3 follows the packages

  • Computer Modern with amsmath, mathtools, amsfonts or amssymb loads OMX/cmex at the math size (cmex7/8/9/10), for example cmex10 at 10.95pt in HW1/HW2.
  • lmodern and the kernel keep sfixed cmex10.
  • extension_box reads the design actually used.

rewrite_math_spacing (reads the source, like fence_of/class_override_of)

  • \dots, \ldots, \cdots and \dotsc..\dotsi become \mathinner groups of three \ldotp/\cdotp (Inner via class_override_of). amsmath's \dots context rules apply (amsmath.sty 494-627): \dotsc, \dotsb, \dotso, the trailing \, before a right delimiter or $, and \dotsi's \!.
  • \bmod gets 5mu on each side, amsmath \mod 12/6mu, amsmath inline \pmod 8mu. The kernel \pmod keeps 18mu.

One-letter \mathrm

Tests

Gates (swapped vendor vs main bffd168a)

HW1/HW2 (#171's measure.sh, MacTeX pdflatex oracle)

  • 3 pages each, 0 overfull, line breaks identical.

  • Words with dx > 0.1pt, main → this:

    page HW1 HW2
    p1 4 → 4 11 → 11
    p2 2 → 2 48 → 39
    p3 12 → 12 41 → 28
  • Fixed: HW2 p3 \ldots (−5.52pt), HW2 p2 line 467.2 (\varepsilon width), HW2 p3 polynomial ±1.82pt. No word got worse.

amsmath corpus (crates/compiler/tests/amsmath_corpus/oracle.py check): 59/59 before and after.

Real-world corpus (run.py --no-oracle --no-pixels): status and page counts unchanged for all 9 fixtures.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…signs, \dots/\bmod/\pmod spacing, one-letter \mathrm

- TexMathMetrics::for_text_size builds on math-layout's
  CmMathMetrics::for_text_size (\DeclareMathSizes + .fd designs, rm-lmr of
  the same design); math_box takes the paragraph's text size and providers
  are cached per size, so a \footnotesize note in an 11pt class sets 9/6/5pt
  math (cmmi9/cmsy9) and body math is unchanged.
- Family 3 follows the packages: Computer Modern with amsmath/mathtools/
  amsfonts/amssymb loads cmex7/8/9/10 at the math size (ExtensionSizing::
  Designs, e.g. cmex10 at 10.95pt in HW1/HW2); lmodern and the kernel keep
  sfixed cmex10. extension_box reads the design actually used.
- rewrite_math_spacing (source-driven, like fence_of/class_override_of):
  \dots/\ldots/\cdots and amsmath \dotsc..\dotsi become \mathinner groups
  of three \ldotp/\cdotp with amsmath's \dots context rules and trailing
  \, or leading \!; \bmod 5mu each side, amsmath \mod 12/6mu, amsmath inline
  \pmod 8mu. The compiler's text "..." left HW2 p3 5.52pt short.
- One-letter \mathrm (compiler Text at a \mathrm span) is math-layout's
  TextChar, so K^{-1} places its exponent like pdfTeX.
- tests/math_font_sizes.rs: glyph origins vs pdflatex (size oracle) for
  a,\dots,b, (1,\ldots,n), a\bmod b, f'(x), \mathrm{K}^{-1},
  \epsilon+\varepsilon, and footnote math sizes.

Needs vendor/math-layout re-pinned to #172 and vendor/compiler to #174.

Implementation-Agent: Claude Opus 5 (subagent kabir-claude math font metrics, 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
…er microtype

Under `\usepackage{microtype}` pdfTeX expands the character nodes of an
inline formula with the rest of the line and lets a formula's first or last
character protrude into the margin. We handed the microtype line breaker one
opaque box per formula, so every glyph after the first formula on a line sat
up to 1.7pt away from pdflatex's.

`math_top_nodes` flattens math-layout's root into paragraph-layout's
`MathNode`s. It opens the atom hboxes that are siblings in TeX's list
(`[char, italic kern]`, `[nucleus, shifted script]`) and leaves every other
hbox a box, so scripts, fractions, `\sum`, `\sin` and `\left..\right` stay
unexpanded exactly as pdfTeX has them. `MathRec.shape` (`List`, `Kerned`,
`Opaque`) records where the top-level hlist lives; a formula holding a
top-level grid stays opaque. Top-level text-size roman characters get
`OT1/{cmr|lmr}/m/n` microtype parameters resolved from the roman TFM, which
is what microtype.cfg's `expansion=alltext-nott` selects. The painter then
moves the top-level nodes to the positions the packer chose.

New oracle `fixtures/microtype-math` (5 documents, 15 justified paragraphs,
`generate.py`; MacTeX pdfTeX 1.40.29) and `tests/microtype_math.rs`.

Measured on this machine against the committed expectations, same fonts and
metrics on both sides:

| fixture | main `1222354e` | with this commit |
|---|---|---|
| 01-digits-parens | 15/15 lines, **54** pen positions > 0.1pt, worst 1.678pt | 15/15, **0**, worst 0.026pt |
| 02-letters-relations | 15/15 lines, **38** > 0.1pt | 15/15, **0**, worst 0.066pt |
| 04-line-edges | **line breaks differ** | **17/17 lines**, 0 > 0.1pt, worst 0.049pt |

03 and 05 are `#[ignore]`d with their measured causes: `\sum` is 1.003pt
narrow (cmex10 at its 10pt design size, not the math size) and `\cdots`
5.475pt narrow (three `\cdotp`s, not `\mathinner`) — both PR #177; and the
compiler drops `\mathbb{Z}` and sets `\colon` literally — the compiler lane.
Neither is font expansion. Every other construct in those fixtures (`\frac`,
`\sqrt`, scripts, `+`, `=`, `\quad`, `\mid`, `\max`, `!`) is within 0.12pt.

Inline math's `\medmuskip`/`\thickmuskip` stretch and the Bin/Rel breakpoints
are `a2f85bfa`/`2c373747` on main, not this commit; this only adds expansion
and protrusion on top of them.

Gates (this machine; `apps/mac/Fonts` + a dereferenced TeX Live 2025 metric
tree whose four digest-bound TFMs are byte-identical to MacTeX's):

- render-pipeline `cargo test --release`: no suite differs from main except
  `microtype_math` (main 0/5, here 3 passed + 2 ignored). `inline_math_breaks`
  still 39/46 with no overfull line; `microtype_fixtures` 8/8.
- paragraph-layout `cargo test --release`: all green.
- compiler `cargo test --release`: 395 passed, 0 failed (same as main).
- amsmath corpus (`oracle.py check`): **59/59** within 0.5bp, same as main.
- Real-world corpus, all 10 fixtures with a reference PDF: line-for-line
  identical to main, 0 overfull each. HW1 and HW2: 3 pages, 0 overfull,
  identical to main. None of them loads microtype, so this is a no-change
  gate, as intended.

Nothing under `vendor/` is committed; the gates above ran with an
uncommitted scratch copy of this branch's `crates/paragraph-layout` in
`vendor/paragraph-layout`, reverted afterwards. `vendor/paragraph-layout`
must be re-pinned to the commit before this one for the pipeline to build
standalone.

Implementation-Agent: claude-opus-5 (kabir-claude lane, linux-primary)
Commit-Executor: claude-opus-5 direct git (Cursor usage limit fallback)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar

GoKubar commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Closing: the substance of this draft is on main. math_fonts_at/size-aware math_box (math at the current text size) are in crates/render-pipeline/src/typeset.rs (landed with 479d2c2, the #154/#282 rebase, and later work); \bmod/\mod/\pmod and one-letter \mathrm run handling is at typeset.rs:6199-6236; the amsmath cmex designs switch landed with #172 (merged) and TexMathMetrics on main takes cmex_designs. The branch itself is pinned against a pre-#172 vendor snapshot and is two vendor generations stale. Anything genuinely residual should be re-derived against main rather than re-pinned here.

@GoKubar GoKubar closed this Sep 15, 2026
@GoKubar
GoKubar deleted the agent/kabir-claude/math-font-metrics-pipeline 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