Skip to content

render-pipeline: size family 3 as amsmath declares it, not sfixed*cmex10 - #204

Merged
GoKubar merged 1 commit into
mainfrom
agent/nixos-math/cmex-designs
Sep 13, 2026
Merged

GoKubar merged 1 commit into
mainfrom
agent/nixos-math/cmex-designs

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Do not merge — main is frozen for the v0.1.2 release run. Draft for review.

What was wrong

TexMathMetrics::new always built its CmMathMetrics with
ExtensionSizing::Fixed, modelling the LaTeX kernel's omxcmex.fd
(<->sfixed*cmex10): family 3 — every large operator, every \left…\right
fence, every \big…\Bigg, the radical, and \fontdimen8, which sets the
fraction rule thickness — pinned to cmex10 at exactly 10pt in every style and
at every body size.

amsfonts.sty 36-41 and amsmath.sty 109-114 redeclare OMX/cmex/m/n
without sfixed, so family 3 is loaded at the math size, in amsfonts'
optical designs. Nothing in the pipeline noticed.

\fontname\textfont3 under pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025),
article:

packages 10pt 11pt 12pt
(none), amsthm, siunitx cmex10 cmex10 cmex10
amsmath / amsfonts / amssymb / mathtools / physics cmex10 cmex10 at 10.95pt cmex10 at 12.0pt
any of those + lmodern (either order) lmex10 lmex10 lmex10
[cmex10]{amsmath} cmex10 cmex10 cmex10

\scriptfont3 / \scriptscriptfont3 follow the same declaration —
cmex7 / cmex7 at 5.0pt at 10pt, cmex8 / cmex7 at 6.0pt at 11 and 12pt
— so even a 10pt document diverges from sfixed inside scripts.

lmodern wins in either load order because it rebinds the symbol font itself
(\DeclareSymbolFont{largesymbols}{OMX}{lmex}{m}{n}) rather than the cmex
shape amsmath redeclares, and omxlmex.fd keeps sfixed*lmex10.

Why it mattered here

The amsmath/amssymb corpora are 12pt documents that also load lmodern,
so they were already correct and do not move — which is exactly why this hid.

HW1 and HW2 are 11pt + amsmath,amssymb,amsthm with no lmodern. Their
committed reference PDFs carry cmex glyphs at 10.909 bp = 10.95pt; this
pipeline emitted them at 9.963 bp = 10pt.

Running the project's own reference-mactex2026.pdf regeneration against a
local pdflatex forced to sfixed*cmex10 (same binary both sides) isolates the
error on the real fixtures: 86 glyphs move on HW1 (worst 1.30 bp) and
56 on HW2 (worst 0.87 bp). Page count, overfull count and error count are
unchanged either way.

The fix

style::cmex_designs(packages, cmex10_option) decides from the package list
and amsmath's cmex10 option; TexMathMetrics::new takes it and applies
ExtensionSizing::Designs. math-layout already modelled this — Designs,
extension_design, and the embedded cmex7/8/9 all landed with #172 — but
nothing selected it.

Painting is corrected to match, because the four cmex designs are not
scaled copies of one another:

  • extension_box and the size-chain walk read the design the glyph was boxed
    from instead of always CMEX10. The next_larger chains and extensible
    recipes are identical across cmex7/8/9/10 (verified over all 128 slots), so
    the chain walk picks the same variant — but \fontdimen8 differs, which
    sets a delimiter's height/depth split and therefore the ink re-centring.
  • \widehat / \widetilde pick their horizontal variant from the real
    design. This is where the designs genuinely diverge: cmex7 "63 is
    1.139 em against cmex10's 1.000, so the old code chose a variant up to 19%
    too narrow at script sizes.
  • lm_name no longer reports lmex7/lmex8/lmex9 in the resource
    profile — fonts Latin Modern does not ship, and a document using those
    designs has by definition not loaded lmodern.

Before / after against pdflatex

Inline-math advance, article + amsmath,amssymb (no lmodern), measured as
the distance from the A before the formula to the Z after it. pdflatex is
truth; error in bp.

class formula pdflatex before after err before err after
10pt x_{\int a} 24.7150 25.9879 24.7149 +1.2729 −0.0001
10pt x^{\sum a} 27.7180 29.8623 27.7175 +2.1443 −0.0005
11pt a\int b 29.5402 28.9081 29.5391 −0.6321 −0.0011
11pt a\sum b 33.7822 32.7825 33.7815 −0.9997 −0.0006
11pt \left(\frac{\frac ab}{\frac cd}\right) 30.0290 28.8979 30.0284 −1.1311 −0.0006
11pt \Biggl(x\Biggr) 31.6900 30.1909 31.6894 −1.4991 −0.0006
11pt \sqrt{\frac ab} 25.9800 25.0335 25.9800 −0.9465 −0.0000
12pt a\sum b 36.5019 34.3983 36.5015 −2.1037 −0.0004
12pt a\prod b 35.1739 33.2913 35.1731 −1.8826 −0.0008
12pt \sqrt{\frac ab} 27.6200 25.6268 27.6193 −1.9932 −0.0007
12pt \Biggl(x\Biggr) 34.3570 32.8618 34.3563 −1.4952 −0.0007
12pt x^{\sum a} 30.7740 32.3509 30.7735 +1.5769 −0.0005

Over the full grid of 12 formulas x 3 class sizes:

mean |error| 0.8415 bp → 0.0004 bp; worst 2.1443 bp → 0.0011 bp.

10pt text-style formulas were already exact and stay exact; the 10pt rows that
move are the script-size ones, as the font table predicts.

Gates

gate result
amsmath corpus 59/59 within 0.5 bp
amssymb corpus 38/39 (32-braces-narrow fails on main too)
math-layout suite all green
compiler suite 39 test binaries, 0 failures
render-pipeline suite failing set identical to a control build of the base commit under the same font environment (the 8 pre-existing partial-font tests)
HW1 / HW2 3 pages each, 0 overfull, 0 errors; geometry moves toward pdflatex

Committed oracle data was not regenerated.

Note on the brief

The assignment predicted HW1/HW2 would be untouched and that the 12pt amsmath
corpus would move. It is the other way round: the corpus loads lmodern and
was already right, and HW1/HW2 are the 11pt no-lmodern documents that were
wrong. The measurements above are the evidence.

The companion side-fix the brief suggested — applying tools/visual-oracle/fontenv.py
to the amsmath/amssymb oracle.py — is already on main (#193, 7715e8a1);
both harnesses call fontenv.render_env and honour the caller's font
environment. Nothing to do.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

The LaTeX kernel loads the math extension family from `omxcmex.fd`'s
`<->sfixed*cmex10`, so family 3 is cmex10 at exactly 10pt in every style.
`TexMathMetrics::new` modelled only that, for every document.

amsfonts.sty 36-41 and amsmath.sty 109-114 redeclare `OMX/cmex/m/n` without
`sfixed`, so a document loading amsmath, amsfonts, amssymb, mathtools or
physics gets family 3 at the math size, in amsfonts' designs. Measured with
`\fontname\textfont3` under pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025):

  packages                        10pt     11pt                12pt
  (none), amsthm, siunitx         cmex10   cmex10              cmex10
  amsmath / amsfonts / amssymb    cmex10   cmex10 at 10.95pt   cmex10 at 12.0pt
  any of those + lmodern          lmex10   lmex10              lmex10
  [cmex10]{amsmath}               cmex10   cmex10              cmex10

`\scriptfont3`/`\scriptscriptfont3` follow the same declaration (cmex7 and
cmex7 at 5pt at 10pt; cmex8 and cmex7 at 6pt at 11 and 12pt), which is why
even a 10pt document differs from `sfixed` inside scripts.

`lmodern` wins in either load order: it rebinds `largesymbols` to the `lmex`
family, which `omxlmex.fd` keeps `sfixed`, rather than the `cmex` shape
amsmath redeclares. That is why the amsmath and amssymb corpora — 12pt
documents that load lmodern — do not move.

math-layout already models this (`ExtensionSizing::Designs`, `cmex7/8/9`
embedded, PR #172); nothing selected it. `style::cmex_designs` decides from
the package list and amsmath's `cmex10` option, and `TexMathMetrics::new`
applies it.

Painting is corrected to match: `extension_box`, the `\widehat`/`\widetilde`
horizontal variant and the size-chain walk read the design the layout boxed
the glyph from instead of always CMEX10. The chains and extensible recipes
are identical across cmex7/8/9/10 (verified over all 128 slots), but the
accent widths are not — cmex7 "63 is 1.139 em against cmex10's 1.000 — and
neither is `\fontdimen8`, which sets a delimiter's height/depth split and so
the ink re-centring. `lm_name` no longer reports `lmex7/8/9`, fonts Latin
Modern does not ship.

Inline-math advance against pdflatex, `article` + amsmath,amssymb, measured
as the distance from the `A` before the formula to the `Z` after it, over 12
formulas x 3 class sizes: mean |error| 0.8415 bp -> 0.0004 bp, worst
2.1443 bp -> 0.0011 bp. The committed HW1/HW2 references (11pt, amsmath,
no lmodern) carry their cmex glyphs at 10.909 bp = 10.95pt; this pipeline
emitted them at 9.963 bp = 10pt and now emits 10.909 bp.

Gates: amsmath corpus 59/59, amssymb 38/39 (`32-braces-narrow` fails on main
too), math-layout and compiler suites all green, render-pipeline failing set
identical to a control build of the base commit under the same font
environment (8 pre-existing partial-font tests).

Implementation-Agent: Claude Opus 5 (engine-engineer, linux-primary NixOS)
Commit-Executor: Claude Opus 5 via Claude Code (Cursor quota unavailable)
Co-Authored-By: Claude Opus 5 <[email protected]>
Co-authored-by: GoKubar <[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.

1 participant