Skip to content

math-layout: the twelve kernel math delimiters, their cmex growth chains, and why lasy should not be bundled - #201

Closed
GoKubar wants to merge 2 commits into
mainfrom
agent/kabir-claude/kernel-delimiters-layout
Closed

GoKubar wants to merge 2 commits into
mainfrom
agent/kabir-claude/kernel-delimiters-layout

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Layout half of the LaTeX kernel math gap #180's sweep found. Compiler half is #200 (agent/kabir-claude/kernel-delimiters-compiler). Both are based on main 9abbf330 independently — no stacking, no file in common, either can merge first. Neither touches #180/#181/#185/#186's branches.

What changed

cm::delimiter_slot is the table that decides where a \left/\right fence's sizes come from: a small variant and a largesymbols growth chain var_delimiter walks. fontmath.ltx 457-505 declares twelve delimiters, and eight of them had no pair at all — so even once the compiler emitted them, the fence could not grow.

character command small large
U+21D5 \Updownarrow cmsy "6D cmex "77
U+27EE / U+27EF \lgroup / \rgroup cmex "3A / "3B the same slot
U+23B0 / U+23B1 \lmoustache / \rmoustache cmex "7A / "7B cmex "40 / "41
U+23D0 \arrowvert cmsy "6A cmex "3C
cm::ARROWVERT_DOUBLE \Arrowvert cmsy "6B cmex "3D
U+23AA \bracevert cmex "3E the same slot

The other four (\Vert \vert \backslash \updownarrow) already had a character row, because \left| and \left\| reach the same cmsy slots.

\lgroup, \rgroup and \bracevert name the same largesymbols slot as both variants, because cmex has no discrete sizes for them — only the extensible recipe that slot already carries, so the chain walk stops immediately and the one glyph serves as the small variant.

\Arrowvert is the one that cannot be spelled with a Unicode character. It sets \Vert's double bar but grows through cmex's extension recipe "3D (a bare repeated piece) rather than \Vert's delimiter recipe "0D, and Unicode names only the single vertical extension — U+23D0, which is \arrowvert. It travels as a BMP private-use code point, the convention render-pipeline already uses for \varnothing, and every consumer paints U+2016 for it. The difference is not cosmetic: around a fraction at 10pt pdfTeX gives \Arrowvert a 7.7778pt-wide fence and \Vert a 5.5556pt one.

Three oversights on rows that were already there, found while measuring:

  • fontmath.ltx 471-482 declares all six arrow delimiters \mathrel; only the horizontal ones were. \uparrow \downarrow \Uparrow \Downarrow were ordinaries.
  • \Uparrow/\Downarrow (U+21D1/U+21D3) had no delimiter pair, so \left\Uparrow had no sizes at all.
  • \bigtriangledown is \mathbin (267), not Ord.

Plus the slots the sibling's new symbols are set from: U+25B3/U+25BD at cmsy "34/"35 (fontmath.ltx 229/266-269 puts \triangle, \bigtriangleup and \varbigtriangleup on one slot and the two down forms on the other) and U+02DA at cmr "17 for \mathring (422). Both replace an OpenType-metrics fallback with the TFM box pdfLaTeX sets.

render-pipeline

  • \smallint (263) is cmsy "73, a text-size integral that never grows, where \int is cmex "52 with a chain. No face carries a second integral code point, so it travels as U+222B with the advance forced and SMALLINT_SENTINEL keeps the two apart for the metrics providers — exactly the shape VARNOTHING_SENTINEL uses for \emptyset. A forced class no longer bypasses that substitution: class and advance are independent, and \smallint needs both.
  • \lmoustache/\rmoustache are drawn from New Computer Modern Math, the secondary face \mathbb/\mathcal/\varnothing already use. Latin Modern Math has no glyph at U+23B0 or U+23B1 at all (checked against the bundled latinmodern-math.otf); without this they were reported math_glyph_unmapped and nothing was drawn.
  • class_override_of learns the kernel's second \DeclareMathSymbols for a slot another command owns (\vert \backslash \ldotp \cdotp \lvert \rvert \lVert \rVert \varbigtriangleup), \smallint's Op, and \varinjlim/\varprojlim's, which amsopn 98-103 wraps in \mathop. The \underrightarrow-shaped atom now honours a forced class — that 3mu is exactly what those two were missing (measured −1.6578 bp before, exact after).
  • accent_char is keyed by Accent::command() rather than by the enum variant, so \mathring maps as soon as vendor/compiler carries it while the crate still builds against the current pin. An accent the table does not know becomes U+FFFD, which math-layout reports as Limitation::MissingAccent rather than drawing something else.

Measured against pdfTeX, not assumed

tests/kernel_delimiters.rs pins numbers from pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025) at 10pt, for all twelve:

  • \showthe\wd0/\ht0/\dp0 of \hbox{$\sym$} — the TFM box of the slot the small variant names. A wrong family or slot moves it.
  • the same three of \hbox{$\left\sym\vrule height 45pt depth 45pt width 0pt\right.$} less \nulldelimiterspace — a body far taller than any discrete size, so var_delimiter has reached the end of the chain and the numbers are the extensible recipe's, which is what the growth chain is for.
  • the recipe's own TOP/MID/BOT/REP slots, read from cmex10.tfm with tftopl.
  • the class, from \hbox{$a\sym b$} against the $ab$ control (9.57755pt at 10pt).

All five tests passed first run. The growth was also checked at six body heights (5, 10, 15, 20, 30, 45pt): \backslash is the one of the twelve with no extensible recipe — cmex "0F's chain ends at the largest discrete size "2D — which is why a very tall \left\backslash is the one that stays too small, in pdfTeX as here.

End to end, with vendor/math-layout and vendor/compiler locally swapped to this branch and its sibling (uncommitted, as the vendoring rules require), one paragraph per formula so each anchor's x is that formula's own width: all twelve agree within 0.004 bp, bare and as $\left\sym\frac{p}{q}\right\sym$.

Two pre-existing findings the controls produced, both outside this lane:

  • \usepackage{amsmath} re-declares \textfont3. Without it a 12pt document has \fontname\textfont3 = cmex10 (omxcmex.fd's <->sfixed*cmex10); with it, cmex10 at 12.0pt. CmMathMetrics hard-codes ExtensionSizing::Fixed, so every family-3 glyph in a 12pt amsmath document is 1/6 too small: $a\int b$ −1.32 bp, $a\lgroup b$ −1.77 bp, every \left…\right fence 2–3.5 bp. ExtensionSizing::Scaled already exists for this case and nothing selects it. Measuring at 10pt removes the difference, which is why the numbers above are 10pt.
  • Vertical extensible assemblies are still unpainted. MathFonts reads MathVariants' horizontal assemblies (hassembly_parts) but not the vertical ones, so a recipe whose TOP/BOT pieces are not on the chain from its start — \updownarrow ("78/"79), \Updownarrow ("7E/"7F), \lgroup/\rgroup/\lmoustache/\rmoustache ("38/"39) — reports math_glyph_unmapped for those pieces and draws nothing for them. The metrics are exactly TeX's (the anchors above prove it); only the joining ink is missing, and the same is already true of \left( on a very tall body. This is the natural follow-up.

Gates

Base main 9abbf330. Font setup: the repo's own apps/mac/Fonts with FLASHTEX_FONT_DIRS and the three-directory FLASHTEX_TFM_DIRS, which is sufficient on this box — measured, with no texmf tree next to the binary and zero font diagnostics. (--font-dir apps/mac/Fonts alone is not: math_metrics_opentype + tfm_missing. That is the configuration the "the env is not enough on the kernel-math lane's box" note was measured in.)

cargo test was run with the fonts configured: a fontless run silently skips ~110 lm_available()-guarded tests across 40 files and reports a hollow pass. The control is a checkout of 9abbf330 in the same worktree.

gate control 9abbf330 this branch alone
crates/math-layout 56 passed, 0 failed 61 passed, 0 failed (5 new tests)
crates/compiler 444 passed 444 passed (untouched)
crates/render-pipeline 181 passed, 8 failed, 1 ignored same 181/8/1, identical failing set
amsmath corpus 59/59 59/59, per-fixture identical
amssymb corpus 38/39 38/39, same single failure (32-braces-narrow)
HW1 / HW2 3 / 3 pages 3 / 3 pages, 0 errors, 0 overfull, 0 font diagnostics
real-world corpus (10 fixtures × 2 producers) — 20/20 pairs identical

The eight render-pipeline failures are the partial-font control tests, which FontSet::new reads the global environment for, so configuring fonts is what fails them; they fail identically on the control. No vendor/* file is committed (git diff 9abbf330 -- crates/render-pipeline/vendor/ is empty).


Group 3: latexsym / lasy — recommendation

The nine remaining commands are \Box \Diamond \Join \leadsto \lhd \rhd \unlhd \unrhd \mho. Recommendation: do not bundle lasy. Three findings, in order of how decisive they are.

1. There is no OpenType lasy anywhere. TeX Live 2025 ships lasy only as Metafont source (fonts/source/public/latex-fonts/lasy*.mf), Type 1 (fonts/type1/public/amsfonts/latxfont/lasy10.pfb) and Type 3 bitmaps (fonts/type3/mpfonts/lasy10.t3). A search of the whole fonts/opentype tree returns one unrelated Indic face. The renderer resolves every glyph as an OpenType glyph id from a LoadedFace (font-engine TrueTypeFace); there is no Type 1 or bare-CFF path. So this is not a packaging decision — bundling lasy10.pfb would need a new font backend first.

2. The licence and provenance cannot be verified to the standard this bundle already documents. SUPPLEMENTARY-FACES.json pins every face with a source archive and its SHA-256, a byte-for-byte cross-check against a named TeX Live tree, the licence by name with its own SHA, and make-app.sh/bundle-texmf.py gates that refuse packaging on drift. The lasy TFM comes from the latex-fonts package and the Type 1 outlines from amsfonts; this box's TeX Live is a Nix store path with no font documentation or licence tree at all, so neither licence file can be read, let alone hashed. I am not asserting a licence I could not verify.

3. Substituting a bundled face would be visibly wrong, not merely imprecise. All nine code points are in the already-bundled New Computer Modern Math (U+2127 \mho, U+2A1D \Join, U+25A1 \Box, U+25C7 \Diamond, U+2933 \leadsto, U+22B2–U+22B5 for the four triangles), and six of the nine are in Latin Modern Math. But the metrics are not lasy's:

lasy10 NewCM Math at 10pt
\Box (lasy "32 / U+25A1) 0.74723 em 0.778 em 0.31 pt wider
\Diamond ("33 / U+25C7) 0.79168 em 1.025 em 2.33 pt wider
\Join ("31 / U+2A1D) 0.77778 em 0.929 em 1.51 pt wider
\mho ("30 / U+2127) 0.72222 em 0.722 em ~0

A 2.3pt advance error on a symbol is a line-breaking difference, not a rendering nicety — it is larger than every tolerance in this repo's gates.

What to do instead, in the order I would do it. (a) Nothing: latexsym is a legacy package, and every one of the nine has a modern amssymb equivalent (\square, \lozenge, \vartriangleleft/\vartriangleright/\trianglelefteq/\trianglerighteq, \mho, \rightsquigarrow) already fully supported from the bundled msam/msbm metrics, which is where a document written today gets them. (b) If latexsym documents must render: implement the eleven \DeclareMathSymbols against lasy10.tfm metrics — the slots are in latexsym.sty and are \mho"30 \Join"31 \Box"32 \Diamond"33 \leadsto"3B \sqsubset"3C \sqsupset"3D \lhd"01 \unlhd"02 \rhd"03 \unrhd"04 — paint them from New Computer Modern Math, and report the substituted design, exactly as \mathcal already does (newcm_math.rs's own module comment states the same limitation for cmsy10). That needs one small TFM in texmf/fonts/tfm/public/latex-fonts/, licence-verified on a machine that has the documentation tree, and no new font backend. (c) Only if pixel parity with lasy is ever required: a vertical-assembly-capable Type 1 path, which is a much larger piece of work than these nine symbols justify.

One related finding while checking: latexsym.sty also declares \sqsubset/\sqsupset, and so does amsfonts.sty 99-100 (AMSa "40/"41, msam — which is bundled). amssymb.sty 111-112 has them commented out, and the compiler's amssymb.rs is generated by scripts/gen_amssymb.py, which reads only amssymb.sty. Teaching the generator amsfonts.sty closes those two from metrics already in the bundle. It needs the TeX Live 2026 tree the committed table came from, so it is not in this pair.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 2 commits September 13, 2026 15:15
…ins, and the slots the new symbols need

`fontmath.ltx` 457-505 declares twelve `\DeclareMathDelimiter`s that
`cm::delimiter_slot` did not carry: `\Vert` `\vert` `\backslash`
`\updownarrow` `\Updownarrow` `\lgroup` `\rgroup` `\lmoustache`
`\rmoustache` `\arrowvert` `\Arrowvert` `\bracevert`. Four of the twelve
already had a *character* row, because `\left|` and `\left\|` reach the same
cmsy slots, but nothing named the pair for the other eight, so
`var_delimiter` had no chain to walk and the fence could not grow.

Each row is the pair `fontmath.ltx` declares — a small variant and a
`largesymbols` growth chain — not a look-alike character:

  U+21D5 `\Updownarrow`  (Symbol "6D, cmex "77)
  U+27EE/U+27EF `\lgroup`/`\rgroup`  (cmex "3A/"3B as both variants)
  U+23B0/U+23B1 `\lmoustache`/`\rmoustache`  (cmex "7A/"7B, cmex "40/"41)
  U+23D0 `\arrowvert`  (Symbol "6A, cmex "3C)
  U+23AA `\bracevert`  (cmex "3E as both variants)
  `cm::ARROWVERT_DOUBLE` `\Arrowvert`  (Symbol "6B, cmex "3D)

`\Arrowvert` is the one that cannot be spelled with a Unicode character:
it sets `\Vert`'s double bar but grows through cmex's *extension* recipe
"3D rather than `\Vert`'s delimiter recipe "0D, and Unicode names only the
single vertical extension (U+23D0, which is `\arrowvert`). It travels as a
BMP private-use code point, the convention render-pipeline already uses for
`\varnothing`, and is painted from U+2016.

Three oversights on rows that were already there, found while measuring:
`\uparrow` `\downarrow` `\updownarrow` `\Uparrow` `\Downarrow`
`\Updownarrow` are all `\mathrel` (471-482) and only the horizontal arrows
were; `\Uparrow`/`\Downarrow` had no delimiter pair at all, so `\left\Uparrow`
had no sizes; and `\bigtriangledown` is `\mathbin` (267), not Ord.

Also the slots the compiler's new symbols are set from: U+25B3/U+25BD at
cmsy "34/"35 (`\triangle`, `\bigtriangleup`, `\varbigtriangleup` and the
down forms all name that slot in `fontmath.ltx` 229/266-269) and U+02DA at
cmr "17 for `\mathring` (422).

render-pipeline:

* `\smallint` (`fontmath.ltx` 263) is cmsy "73, a text-size integral that
  never grows, where `\int` is cmex "52 with a chain. No face carries a
  second integral code point, so it travels as U+222B with the advance
  forced, and `SMALLINT_SENTINEL` keeps the two apart for the metrics
  providers exactly as `VARNOTHING_SENTINEL` does for `\emptyset`. A forced
  class no longer bypasses that substitution: class and advance are
  independent, and `\smallint` needs both.
* `\lmoustache`/`\rmoustache` are drawn from New Computer Modern Math, the
  secondary face `\mathbb`/`\mathcal`/`\varnothing` already use: Latin
  Modern Math has no glyph at U+23B0 or U+23B1 at all. Without this they
  were reported `math_glyph_unmapped` and nothing was drawn.
* `class_override_of` learns the kernel's second `\DeclareMathSymbol`s for a
  slot another command owns (`\vert` `\backslash` `\ldotp` `\cdotp`
  `\lvert` `\rvert` `\lVert` `\rVert` `\varbigtriangleup`), `\smallint`'s
  Op and `\varinjlim`/`\varprojlim`'s, which amsopn wraps in `\mathop`; the
  `\underrightarrow`-shaped atom now honours a forced class, which is the
  3mu those two were missing.
* `accent_char` is keyed by `Accent::command()` rather than by the variant,
  so `\mathring` maps as soon as `vendor/compiler` carries it and the crate
  still builds against the current pin. An accent the table does not know
  becomes U+FFFD, which math-layout reports as `MissingAccent`.

`tests/kernel_delimiters.rs` pins, for all twelve, the `\hbox{$\sym$}` box
and the extensible recipe pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025)
produces at 10pt, plus the classes and the two `\Vert`/`\Arrowvert`,
`\vert`/`\arrowvert` chain splits. All five tests passed first run.

Gates on this box, against a control checkout of origin/main, fonts
configured (a fontless `cargo test` silently skips ~110 guarded tests):
math-layout 56 -> 61 passed, 0 failed; render-pipeline 181 passed with the
same 8 pre-existing partial-font control failures on both sides; amsmath
59/59 and amssymb 38/39 (`32-braces-narrow`, which fails on main too),
per-fixture identical; HW1/HW2 3 pages each, 0 errors, 0 overfull, 0 font
diagnostics; real-world corpus 20/20 producer pairs identical.

Implementation-Agent: Claude Opus 5 (engine-engineer kernel-math lane, 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
… dots

The sibling compiler branch makes `\ldots`/`\cdots` the group of three
punctuation atoms `fontmath.ltx` 400-402 defines
(`\mathinner{\ldotp\ldotp\ldotp}`), instead of one three-character text run,
which lost both 3mu gaps — 1.66 bp each at 10pt in an ordinary
`$1, 2, \dots, n$`. `class_override_of` answers Inner for the eight command
names so the group is an inner atom rather than an ordinary one.

The three dots carry the command's span too, so this row answers for them as
well. That is not a compromise: TeX's chapter-18 table gives Punct-Punct and
Inner-Inner the same thin space, in the same text-styles-only way (this
crate's own `spacing::TABLE` rows agree), so the two gaps measure
identically either way. Verified against pdfTeX in both styles —
`$1, 2, \dots, n$` +0.0027 bp, `$x^{a \dots b}$` -0.0004 bp, `$\ldots$`
-0.0036 bp.

Gates unchanged from the first commit: math-layout 61 passed, 0 failed;
render-pipeline 181 passed with the same 8 pre-existing partial-font control
failures as the control; amsmath 59/59, amssymb 38/39, per-fixture
identical; HW1/HW2 3 pages, 0 errors, 0 overfull; real-world corpus 20/20
producer pairs identical.

Implementation-Agent: Claude Opus 5 (engine-engineer kernel-math lane, 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
@GoKubar

GoKubar commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — the work is already on main.

Replacement: \mathring and delimiter growth are on main; #227/#239 merged

Closed by the integration lane while clearing a 219-PR backlog (112 of them drafts). If this is wrong, reopen it and tell me — I would rather be corrected than leave stale work buried.

— orchestrator-astra (Commander)

@GoKubar GoKubar closed this Sep 15, 2026
@GoKubar
GoKubar deleted the agent/kabir-claude/kernel-delimiters-layout 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