Skip to content

math-layout: math fonts at every LaTeX text size, amsmath cmex designs, \prime, \epsilon/\varepsilon (size oracle 37/37) - #172

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

jay3332 merged 1 commit into
mainfrom
agent/kabir-claude/math-font-metrics

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Math font metric gaps reported by the siunitx (#163/#168), footnotes (#154), headings/TOC (#141/#151), algorithmic (#159/#162) and HW residuals (#171) lanes. Additive API only. Existing constructors (latex_10pt, latex_12pt) and ALL_FONTS ids are unchanged. Base main.

Changes

Sizes and designs (cm.rs)

  • declare_math_sizes(text_pt) gives the \DeclareMathSizes table from fontmath.ltx 75-86. Undeclared sizes use \calculate@math@sizes (.7/.5, TeX multiplication).
  • design_for(family, size) picks the design from the ot1cmr/omlcmm/omscmsy .fd files. It uses the lmodern ranges, which select the same designs at every declared size.
  • CmMathMetrics::for_text_size(pt) and with_extension(..) build the metrics for any text size. tfm_by_name looks up an embedded TFM.
  • Checked against pdfTeX's \fontname\textfont0..3 for every size command in 10/11/12pt articles.

Family 3 (ExtensionSizing::Designs)

  • With amsmath (or amsfonts/amssymb) and Computer Modern, OMX/cmex is not sfixed.
  • pdfTeX in an 11pt article: \textfont3 is cmex10 at 10.95pt, \scriptfont3 cmex8, \scriptscriptfont3 cmex7 at 6pt. HW1/HW2 are such documents. lmodern keeps lmex10 fixed (Fixed).

New embedded TFMs (generator extended)

  • cmr9, cmr17, cmmi9, cmsy9 (9pt notes in 11pt classes, \small in 10pt, \LARGE+).
  • cmex7, cmex8, cmex9.

Symbols

  • \prime U+2032 is cmsy "30. It used to fall back to Latin Modern Math's advance.
  • \varepsilon U+03B5 is cmmi "22 (was "0F, 0.64pt too narrow). \epsilon U+03F5 stays "0F. The compiler side is in a separate PR.

Layout

  • TeX §1186: a group holding one Ord without scripts is unpacked. {x}^2 places its scripts like x^2, and \mathop{x} is centred.
  • New Nucleus::TextChar(char) sets one upright fam0 character (\mathrm{K}) as a math character. The siunitx K^{-1} exponent sat 0.78bp high because it was treated as a box.
  • The pipeline never matches ml::Nucleus exhaustively, so the new variant needs no pipeline arm.

Oracle

tools/size_oracle.py (MacTeX 2026 pdflatex, oracle only) writes tests/size_oracle/expected.txt. tests/size_oracle.rs lays out the same 37 formulas and checks glyph font, code and size, plus positions within 0.5bp. It covers:

  • 10/11/12pt classes, with and without amsmath;
  • text sizes 8, 9, 10, 10.95, 12, 14.4, 17.28 and 24.88pt;
  • \mathrm{K}^{-1}, \mathrm{m}^2\,\mathrm{s}^{-1}, \mathrm{d}x, f', f'', \epsilon/\varepsilon;
  • amsmath \bmod/\pmod and the kernel \pmod;
  • \dots as dotsc, dotsb and before ), \cdots, the kernel \ldots;
  • \sin^2, \lim_{}, \frac, \sum, \sqrt at note/heading/\huge sizes, and digits and letters with scripts.

37/37 pass. 33 are within 0.005bp. \bmod/\pmod are off by 0.26-0.32bp because math-layout's multi-character Text does not apply cmr's o-d kern (pre-existing; the pipeline's text sink kerns).

cargo test (math-layout): all green (lib 10, golden 28, size_oracle 2).

Conflicts / follow-ups

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

…s, \prime, \epsilon/\varepsilon, one-character groups

- cm: `declare_math_sizes` (fontmath.ltx \DeclareMathSizes, latex.ltx
  \calculate@math@sizes), `design_for` (ot1cmr/omlcmm/omscmsy and the
  lmodern .fd ranges), `CmMathMetrics::for_text_size` and `with_extension`,
  `tfm_by_name`; `ExtensionSizing::Designs` for amsmath/amsfonts' sized
  OMX/cmex (cmex7/8/9/10 at the math size).
- Embedded TFMs gain cmr9, cmr17, cmmi9, cmsy9, cmex7, cmex8, cmex9
  (appended to ALL_FONTS, existing font ids unchanged).
- symbol_slot: \prime U+2032 = cmsy "30; U+03B5 (\varepsilon) = cmmi "22,
  U+03F5 (\epsilon) stays "0F.
- layout: TeX §1186 unpacks a one-Ord group (`{x}^2`, `\mathop{x}`), and
  `Nucleus::TextChar` sets one upright fam0 character (`\mathrm{K}`) as a
  math character for Rule 18a and make_op.
- tests/size_oracle: 37 pdflatex fixtures (10/11/12pt classes, 8-24.88pt
  text sizes, with and without amsmath): all glyph identities match and
  every glyph/rule is within 0.5bp (33 within 0.005bp; \bmod/\pmod 0.26-0.32bp
  from the cmr o-d kern math-layout's Text does not apply).

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
@jay3332
jay3332 merged commit d3a679a into main Sep 13, 2026
12 of 18 checks passed
@GoKubar
GoKubar deleted the agent/kabir-claude/math-font-metrics branch September 13, 2026 18:12
GoKubar pushed a commit that referenced this pull request Sep 15, 2026
…prime (#278) (#528)

What changed:
- The prime's box geometry already matched pdflatex (compiler #174 and
  math-layout #172): script size, sup shift, one superscript for f'',
  f'^2 joining it, f_1'/x'_a sub+sup. What was wrong was the painted
  glyph. The pipeline drew cmsy "30 with Latin Modern Math's cmap glyph
  for U+2032 (`minute`, ink 430..748/1000 em). That glyph is pre-raised
  for unscripted Unicode use, so at the superscript position it sat
  2.7-3.1bp too high at the bottom and 1.3-1.5bp at the top.
- mathfont.rs reads the face's GSUB `ssty` lookups (AlternateSubst, plus
  Single and Extension). mathtex.rs paints cmsy "30 with the first ssty
  alternate, `minute.st` (ink 96..549, cmsy's unraised design; lmsy7 is
  41..559).
- tests/math_primes.rs pins the pdflatex \showbox oracle (10pt and 12pt,
  inline and display, f'(x) f'' f''' f^{\prime} f'^2 f_1' x'_a) for
  placement, and lmsy7/lmsy8 AFM ink for the prime, at 0.5bp.

What was run:
- cargo test --test math_primes (before fix): test result: FAILED. 1 passed; 1 failed
- cargo test --test math_primes (after): test result: ok. 2 passed; 0 failed
- render-pipeline full suite: every failure (letter_class_geometry 5, uline 2,
  underline_sout 4, xcolor_oracle 1) panics at src/adapter.rs:1261, the
  par-leading debug_assert that open PR #517 fixes; no other failures
- math-layout and compiler: see PR

Next step: re-check the Mac app rendering of f'(x) once this lands.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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