Skip to content

math-layout: box the cmsy square relations from their real TFM slots ("74-"77) - #211

Merged
GoKubar merged 1 commit into
mainfrom
engine/math-layout-square-slots
Sep 13, 2026
Merged

GoKubar merged 1 commit into
mainfrom
engine/math-layout-square-slots

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

cm::symbol_slot had no entry for U+2291–U+2294, so \sqsubseteq, \sqsupseteq, \sqcup and \sqcap could not be boxed from the cmsy TFM at all. The pipeline fell through to the OpenType fallback and set them at Latin Modern Math's advances instead of the metrics pdfLaTeX uses.

These are base LaTeX2e kernel symbols, not amssymb. fontmath.ltx:

279: \DeclareMathSymbol{\sqcup}{\mathbin}{symbols}{"74}
278: \DeclareMathSymbol{\sqcap}{\mathbin}{symbols}{"75}
301: \DeclareMathSymbol{\sqsubseteq}{\mathrel}{symbols}{"76}
302: \DeclareMathSymbol{\sqsupseteq}{\mathrel}{symbols}{"77}

Oracle evidence

pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025): \show gives \mathchar"2274, "2275, "3276 and "3277 both with and without amssymb loaded, pinning family 2 (cmsy) and the four slots. amsfonts does not redefine them — it adds only the strict \sqsubset/\sqsupset, which are msam and never reach this table.

The new test asserts the slots and then reads the widths back out of the bundled TFM:

slot TFM width at 10pt pdflatex \hbox{$\sym$}
"74 \sqcup 6.66669pt 6.66669pt
"75 \sqcap 6.66669pt 6.66669pt
"76 \sqsubseteq 7.77780pt 7.7778pt
"77 \sqsupseteq 7.77780pt 7.7778pt

So the mapping is confirmed from both ends rather than only asserted: the slot numbers come from fontmath.ltx, and the metrics they produce independently match what pdflatex measures.

Scope

Metrics only. Atom classes (Bin for "74/"75, Rel for "76/"77) live on the compiler side and ship in a separate PR against COMMAND_GLYPHS/symbol_class. All PRs in this set are based on main and none are stacked. End-to-end output needs both plus a render-pipeline vendor re-pin (done locally, left uncommitted per instruction).

Gates

cargo test on crates/math-layout: 57 passed, 0 failed vs a control checkout of the same base at 56 passed, 0 failed. The +1 is this PR's new test; no failures on either side.

No fixture in the real-world, amsmath or amssymb corpora uses any of these four commands, so those gates are untouched by construction (verified by grep with word boundaries).

Draft — not for merge while main is in the release sequence.

…("74-"77)

`cm::symbol_slot` had no entry for U+2291-U+2294, so `\sqsubseteq`,
`\sqsupseteq`, `\sqcup` and `\sqcap` could not be boxed from the cmsy TFM
at all; the pipeline fell through to the OpenType fallback and set them at
Latin Modern Math's advances instead of the metrics pdfLaTeX uses.

These are base LaTeX2e kernel symbols, not amssymb. `fontmath.ltx`:

    279: \DeclareMathSymbol{\sqcup}{\mathbin}{symbols}{"74}
    278: \DeclareMathSymbol{\sqcap}{\mathbin}{symbols}{"75}
    301: \DeclareMathSymbol{\sqsubseteq}{\mathrel}{symbols}{"76}
    302: \DeclareMathSymbol{\sqsupseteq}{\mathrel}{symbols}{"77}

Verified against pdfTeX 3.141592653-2.6-1.40.27 (TeX Live 2025): `\show`
gives \mathchar"2274, "2275, "3276 and "3277 both with and without
amssymb loaded, pinning family 2 (cmsy) and the four slots. amsfonts does
not redefine them -- it adds only the strict `\sqsubset`/`\sqsupset`,
which are msam and never reach this table.

The new test asserts the slots and then reads the widths back out of the
bundled TFM: 6.66669pt for "74/"75 and 7.77780pt for "76/"77 at the 10pt
text size. Those are the same numbers pdflatex reports for `\hbox{$\sqcup$}`
(6.66669pt) and `\hbox{$\sqsubseteq$}` (7.7778pt), so the mapping is
confirmed from both ends rather than only asserted.

Atom classes (Bin for "74/"75, Rel for "76/"77) live on the compiler side
and ship in a separate PR against `COMMAND_GLYPHS`/`symbol_class`; this
change is metrics only. End-to-end output needs both plus a
render-pipeline vendor re-pin.

Implementation-Agent: engine-engineer (Claude Opus 5), linux-primary
Commit-Executor: engine-engineer (Claude Opus 5), direct git

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
@GoKubar

GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

End-to-end gate results

Verified locally with all three PRs of this set applied together (#210 compiler kernel relations, #211 math-layout slots, #212 generator) plus a local, uncommitted render-pipeline vendor re-pin — the four vendored files (vendor/compiler/src/{math,lm_math,amssymb}.rs, vendor/math-layout/src/cm.rs) were byte-identical to main beforehand, so the re-pin is a straight file copy and no vendor change is committed anywhere.

Environment: bundled fonts only (FLASHTEX_FONT_DIRS=apps/mac/Fonts, FLASHTEX_TFM_DIRS = bundled lm + ec + amsfonts/symbols). The system TeX Live is used as an oracle only, never in the product path. CARGO_BUILD_JOBS=8.

gate control (same base, 08f49796) with these PRs
crates/compiler 438 passed, 1 failed 440 passed, 1 failed
crates/math-layout 56 passed, 0 failed 57 passed, 0 failed
crates/render-pipeline 186 passed, 3 failed 186 passed, 3 failed
amsmath corpus 59/59 59/59
amssymb corpus 38/39 38/39
HW1 3 pages, 0 overfull, 0 errors 3 pages, 0 overfull, 0 errors
HW2 3 pages, 0 overfull, 0 errors 3 pages, 0 overfull, 0 errors
real-world corpus 10 fixtures identical pages and diagnostic counts in every fixture

Failing sets are identical to the control, not just the counts:

  • compiler: canonical_names_outside_the_inventory_are_diagnosed (assertion failed: !BUILT_INS.contains(&name), parser.rs:5227), plus tests/robustness.rs's deeply_nested_input_does_not_blow_the_stack, which overflows its stack on this NixOS host. Both fail identically on main.
  • render-pipeline: font_family_fixtures_match_pdflatex, footnotes_against_pdflatex, page_frame_against_pdflatex — the env-contaminated controls.
  • amssymb: the single failure is 32-braces-narrow, worst 1.012 bp, identical on the control.

Note cargo test stops at the first failing test binary, so every run above used --no-fail-fast; without it the compiler crate reports only ~399 of its tests.

Corpus references are MacTeX 2026 and were not regenerated (--no-oracle); the amsmath/amssymb oracle checks ran against the committed refs.

Font diagnostics on the gates: HW1, HW2 and the amsmath/amssymb corpora report zero. The corpus-wide run shows 3 pre-existing ec_metrics_unavailable diagnostics (missing ectt1000/ectt1200 T1 typewriter TFMs) in article-twocolumn and input-bibliography only — identical on the control, unrelated to this work.

Before/after on the actual commands

A probe document ($a\sqcup b$ … $\angle$ $\hbar$ $\mho$) through the control compiler binary built from 08f49796:

unknown_command | \sqcup is not supported in math mode
unknown_command | \sqcap is not supported in math mode
unknown_command | \sqsubseteq is not supported in math mode
unknown_command | \sqsupseteq is not supported in math mode
unknown_command | \sqsubset is not supported in math mode
unknown_command | \sqsupset is not supported in math mode
unknown_command | \rightleftharpoons is not supported in math mode
unknown_command | \mho is not supported in math mode

With these PRs: zero unknown_command diagnostics, and the render reports msam10/msbm10 resource profiles, confirming the amsfonts symbols take the msam/msbm path rather than a fallback.

So eight commands move from hard-unsupported to rendering; \angle and \hbar rendered before but from a generic Latin Modern glyph matching neither of pdfLaTeX's two answers, and now take their declared msam/msbm slots.

Coverage gap worth a follow-up

No fixture in the real-world, amsmath or amssymb corpora uses any of these ten commands (checked by word-boundary grep). That is why the gates are unmoved — but it also means the 39-fixture amssymb corpus never exercised the symbols the generator was dropping, and there is no position-level oracle fixture for them yet. Adding one is the natural next step, and would give these symbols the same 0.5 bp treatment the rest of the corpus gets.

@GoKubar
GoKubar marked this pull request as ready for review September 13, 2026 21:43
@GoKubar
GoKubar merged commit 6c73834 into main Sep 13, 2026
20 checks passed
@GoKubar
GoKubar deleted the engine/math-layout-square-slots branch September 16, 2026 04:17
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