Skip to content

compiler: \colon as math punctuation, \mathbb as a real msbm alphabet, the largesymbols operators and \neg - #180

Closed
GoKubar wants to merge 2 commits into
mainfrom
agent/kabir-claude/math-symbols-compiler
Closed

GoKubar wants to merge 2 commits into
mainfrom
agent/kabir-claude/math-symbols-compiler

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Compiler half of the math-symbol lane. Pipeline half is the sibling PR on agent/kabir-claude/math-symbols-pipeline (independent, both based on main, no stacking).

What changed

\colon was diagnosed \colon is not supported in math mode and typeset literally. fontmath.ltx 400 declares it \DeclareMathSymbol{\colon}{\mathpunct}{operators}{"3A} — the same character as a bare : (declared \mathrel on line 385), in the punctuation class. command_atom now forces AtomClass::Punct on a ":" symbol atom, the shape \bot/\perp already use.

Measured with TeX Live 2025 pdflatex at 12pt:

box width vs f{:}A
\hbox{$f{:}A$} 19.14496pt —
\hbox{$f\colon A$} 21.14493pt +3mu
\hbox{$f:A$} 25.81152pt +10mu

\mathbb already produced the blackboard capitals — the premise that it is "dropped" is wrong on current main; measured against pdflatex, $\mathbb{Z} a$ … $\mathbb{W} f$ lands within 0.013 bp. What it got wrong was everything outside A–Z, where it raised \mathbb supports only capital letters A-Z and set the argument as plain text. amsfonts.sty 114 declares \mathbb a math alphabet (\DeclareMathAlphabet{\mathbb}{U}{msb}{m}{n}), so each character keeps its own class and is set at its own slot of msbm10. Only "41–"5A hold blackboard capitals; the rest hold unrelated AMSb symbols, which pdfLaTeX sets silently — no "Missing character". Verified at 12pt:

  • \mathbb{1} ≡ \nVdash: both 8.66669pt
  • \mathbb{x} ≡ \curvearrowleft: both 12.00003pt
  • a\mathbb{1}b = 19.83043pt = a{\nVdash}b, not a\nVdash b (26.497pt) — the alphabet keeps the character's Ord class, it does not take the symbol's Rel class.

\mathbb now emits that msbm symbol with the class forced back to Ord, with a warning naming the symbol rather than an error. An empty argument stays an error.

Eight largesymbols operators + \neg/\lnot. fontmath.ltx 420–431 and 372–373. \bigcup, \bigcap, \bigvee, \bigwedge, \bigodot, \bigoplus, \bigotimes, \coprod and \neg/\lnot had no rows and were all diagnosed unsupported. Adobe Symbol carries only the binary union/intersection/logicalor/logicaland glyphs, never the n-ary ones, so the eight come from the pinned Latin Modern Math resource like \setminus, with advances read from the exact bundled font program (tests/lm_math_binding.rs re-reads it and fails on drift). math-layout's cm::symbol_slot and default_class already carry all eight at their cmex10 slots with \mathop limits, so no math-layout change was needed. \neg is Adobe Symbol's logicalnot, added to export::SYMBOL_ENCODING so the base-14 PDF writer encodes it instead of reporting it unrepresentable.

Gates

Erratum on the first commit message: its gate numbers (0/59, 0/39) were measured before I knew that flashtex-render silently falls back to OpenType MATH metrics when it cannot find the TFMs, which is what happens on NixOS when texmf-dist path components are symlinks. Everything below is re-measured on a symlink-free flat copy of the repo's own apps/mac/Fonts plus its bundled texmf TFMs, after asserting every gate run reports zero font_unavailable / required_metrics_unavailable diagnostics. The commit message's numbers are superseded by this table.

gate main this branch
crates/compiler cargo test --release 395 passed 398 passed, 0 failed (3 new tests)
amsmath corpus (amsmath_corpus/oracle.py check) 59/59 59/59, per-fixture identical
amssymb corpus (amssymb_corpus/oracle.py check) 38/39 38/39, per-fixture identical
real-world corpus (10 fixtures × 2 producers) — no behavioural change: status, pages, error/warning counts and exact diagnostic message sets identical
HW1 / HW2 (render) 3 / 3 pages 3 / 3 pages, 0 errors, 0 overfull
crates/paragraph-layout cargo test --test hyphenation_oracle 5 passed 5 passed, incl. thirty_paragraphs_break_like_pdflatex

32-braces-narrow (amssymb, brace extents, worst 1.012 bp) fails on main too. The real-world corpus's 3 ec_metrics_unavailable + 3 font_outline_substituted are pre-existing and identical on both sides: the bundled Fonts dir ships no lmmono*.otf and no ectt* T1 typewriter metrics.

New drift-gate artefacts regenerated (crates/compiler/scripts/render_supported_latex.sh, apps/mac/scripts/sync-supported-latex.sh); supported_latex.rs::generated_artifacts_are_current passes.

What the sweep found and this PR does not fix

I swept 509 math commands — every \DeclareMathSymbol / \DeclareMathDelimiter / \mathchardef in fontmath.ltx, plain.tex, latexsym.sty, amssymb.sty, plus the common amsmath/mathtools macros — through the compiler and collected the diagnostics. 115 were unsupported. Notably, amssymb itself is essentially complete (the generated amssymb.rs carries all 219 declarations; the 6 names it omits are commented out in amssymb.sty, so the kernel definitions apply). The real gap is the LaTeX kernel / plain TeX symbol set.

After this PR, 105 remain. Tiered by what each needs:

Two operators that need one crates/math-layout row each (a cm::symbol_slot + default_class entry), which the render pipeline vendors, so they belong with a pipeline change rather than here:

command cmex10 slot Unicode LM Math advance
\bigsqcup "46 U+2A06 833
\biguplus "55 U+2A04 833

Forty-four more \DeclareMathSymbols that need a cm::symbol_slot row plus a COMMAND_GLYPHS row, all mechanical now that the pattern is established (fontmath.ltx family/slot on the left, unicode-math code point on the right):

\amalg (sym "71, U+2A3F), \asymp ("10, U+224D), \clubsuit ("7C, U+2663), \dagger ("79, U+2020), \ddagger ("7A, U+2021), \diamondsuit ("7D, U+2662), \flat (letters "5B, U+266D), \frown ("5F, U+2322), \heartsuit ("7E, U+2661), \imath ("7B, U+1D6A4), \jmath ("7C, U+1D6A5), \leftharpoondown ("29, U+21BD), \leftharpoonup ("28, U+21BC), \mathdollar (ops "24), \mathparagraph ("7B, U+00B6), \mathsection ("78, U+00A7), \natural ("5C, U+266E), \nearrow ("25, U+2197), \nwarrow ("2D, U+2196), \odot ("0C, U+2299), \ominus ("09, U+2296), \oslash ("0B, U+2298), \prec ("1E, U+227A), \preceq ("16, U+2AAF), \rightharpoondown ("2B, U+21C1), \rightharpoonup ("2A, U+21C0), \searrow ("26, U+2198), \sharp ("5D, U+266F), \smile ("5E, U+2323), \spadesuit ("7F, U+2660), \sqcap ("75, U+2293), \sqcup ("74, U+2294), \sqsubseteq ("76, U+2291), \sqsupseteq ("77, U+2292), \star ("3F, U+22C6), \succ ("1F, U+227B), \succeq ("17, U+2AB0), \swarrow ("2E, U+2199), \triangleleft ("2F, U+25C1), \triangleright ("2E, U+25B7), \uplus ("5D, U+228E), \wr ("6F, U+2240).

All 44 advances are present in the bundled latinmodern-math.otf (measured with the repo's own TrueTypeFace).

Sixty-one that are macros, delimiters or package constructs, not plain symbols — each needs its own arm, not a table row: \Vert/\vert/\backslash/\Updownarrow/\updownarrow/\lgroup/\rgroup/\lmoustache/\rmoustache/\arrowvert/\Arrowvert/\bracevert (delimiters); \Box/\Diamond/\Join/\leadsto/\lhd/\rhd/\unlhd/\unrhd/\mho (latexsym); \hookleftarrow, \longmapsto, \surd, \sqsubset, \sqsupset, \bullet, \diamond, \bigcirc, \varrho, \smallint, \intop, \ointop, \owns, \not, \lnot-family leftovers \ldotp/\cdotp/\lhook/\rhook/\mapstochar/\varbigtriangleup/\varbigtriangledown/\sqrtsign/\braceld/\bracelu/\bracerd/\braceru; \mathring, \dddot, \ddddot, \pmb, \mathscr, \iiiint, \idotsint, \nobreakdash, \pod, \injlim, \projlim, \varinjlim, \varprojlim.

Known difference this PR deliberately does not close

amsmath redefines \colon (amsmath.sty 409–410):

\DeclareRobustCommand{\colon}{\nobreak\mskip2mu\mathpunct{}\nonscript
  \mkern-\thinmuskip{:}\mskip6muplus1mu\relax}

That is 2mu before and 6mu after, not the kernel's 0mu/3mu. Measured at 12pt: \hbox{$f\colon A$} is 21.14493pt without amsmath and 24.47821pt with it — a 5mu difference. The compiler's math parser is package-agnostic (math::parse_tokens takes no package context; the same is true of every amsmath construct it already implements unconditionally), so the kernel definition is what is implemented. Closing this needs package context threaded into the math parser — a separate change, worth doing since amsmath is loaded by most documents that use \colon.

Resume notes

  • Branch agent/kabir-claude/math-symbols-compiler, head 00242508 (8e286aa0 + a clean merge of origin/main 89e49fed, generated artefacts regenerated after the merge).
  • Sibling: agent/kabir-claude/math-symbols-pipeline, head ab4dd82a.
  • Reproduce the gates: build crates/render-pipeline --release --bin flashtex-render, then the three oracle.py check / run.sh commands in the table, with --fonts pointing at a symlink-free directory holding the repo's apps/mac/Fonts/*.otf and every .tfm under apps/mac/Fonts/texmf. Assert zero font_unavailable / required_metrics_unavailable in the output before trusting any number.
  • To see the compiler change through the pipeline, copy crates/compiler/src/{export,lm_math,math,supported,vocabulary}.rs over crates/render-pipeline/vendor/compiler/src/ (uncommitted; those five files are byte-identical to main before this branch). Do not commit the vendor swap.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 2 commits September 13, 2026 12:22
…wn slot, the eight largesymbols operators and \neg/\lnot

`\colon` was diagnosed "not supported in math mode" and typeset literally.
`fontmath.ltx` 400 declares it `\DeclareMathSymbol{\colon}{\mathpunct}
{operators}{"3A}`: the same character as a bare `:` (declared `\mathrel` on
line 385), in the punctuation class. `command_atom` now forces `AtomClass::
Punct` on a ":" symbol atom, the same shape `\bot`/`\perp` already use, so
`f\colon A` sets 3mu after the colon instead of the relation's 5mu on both
sides. Measured against TeX Live 2025 pdflatex at 12pt: `f\colon A` is
21.14493pt, `f:A` 25.81152pt, `f{:}A` 19.14496pt — exactly the +3mu / +10mu
the new unit test asserts.

`\mathbb` already produced the blackboard capitals; what it got wrong was
everything else, where it raised "\mathbb supports only capital letters A-Z"
and typeset the argument as plain text. amsfonts.sty 114 declares `\mathbb`
a math *alphabet* (`\DeclareMathAlphabet{\mathbb}{U}{msb}{m}{n}`), so each
character keeps its own class and is set at its own slot of msbm10. Only
"41-"5A hold blackboard capitals; the rest hold unrelated AMSb symbols, and
pdfLaTeX sets them silently with no "Missing character". Verified with
pdflatex at 12pt: `\mathbb{1}` and `\nVdash` both box at 8.66669pt,
`\mathbb{x}` and `\curvearrowleft` both at 12.00003pt, and `a\mathbb{1}b`
(19.83043pt) matches `a{\nVdash}b`, not `a\nVdash b` (26.497pt) — the
alphabet keeps the character's Ord class. `\mathbb` now emits that msbm
symbol with the class forced back to Ord, with a warning naming the symbol
instead of an error. An empty argument is still an error.

The eight `largesymbols` operators of fontmath.ltx 420-431 that had no rows
(`\bigcup`, `\bigcap`, `\bigvee`, `\bigwedge`, `\bigodot`, `\bigoplus`,
`\bigotimes`, `\coprod`) and `\neg`/`\lnot` (372-373) join COMMAND_GLYPHS.
Adobe Symbol carries only the binary `union`/`intersection`/`logicalor`/
`logicaland` glyphs, so the eight n-ary ones are drawn from the pinned Latin
Modern Math resource like `\setminus`, with advances read from the exact
bundled font program (`tests/lm_math_binding.rs` re-reads it). math-layout's
`cm::symbol_slot` and `default_class` already carry all eight at their cmex10
slots with `\mathop` limits, so no math-layout change is needed. `\neg` is
Adobe Symbol's `logicalnot`, added to `export::SYMBOL_ENCODING` so the
base-14 PDF writer encodes it rather than reporting it unrepresentable.

`\bigsqcup` (cmex "46, U+2A06) and `\biguplus` (cmex "55, U+2A04) are the two
operators left out: they also need a `cm::symbol_slot`/`default_class` row in
crates/math-layout, which the render pipeline vendors, so they belong with
the pipeline change rather than here.

Gates (TeX Live 2025 on NixOS; the committed corpus refs were generated with
MacTeX, so their absolute scores are not reproducible here — these are
before/after comparisons against the same checkout):
- crates/compiler `cargo test --release`: 398 passed, 0 failed (was 395).
- amsmath corpus (crates/compiler/tests/amsmath_corpus/oracle.py check):
  0/59 before and after, every fixture's aligned/within-tol/unaligned/
  worst_bp/extension-column counts bit-identical.
- amssymb corpus (39 fixtures): 0/39 before and after, per-fixture identical.
- real-world corpus (tools/real-world-corpus/run.sh --no-oracle, 10 fixtures
  x 2 producers): status, page counts, error/warning counts and the exact
  diagnostic message sets identical before and after; hw1 3 pages and hw2
  3 pages (render) with 0 errors and 0 overfull on both sides.
- crates/paragraph-layout `cargo test --test hyphenation_oracle`: 5 passed,
  `thirty_paragraphs_break_like_pdflatex` (the HW1/HW2 line-break oracle) ok.

Implementation-Agent: kabir-claude (engine-engineer, linux-primary)
Commit-Executor: kabir-claude direct git (Cursor usage limit fallback)

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Co-authored-by: GoKubar <[email protected]>
GoKubar added a commit that referenced this pull request Sep 13, 2026
…n atoms

Two spacing bugs the algorithm-floats lane measured in ordinary prose, both
of which the `\ldotp`/`\cdotp` rows this branch already adds make
straightforward to fix properly.

`\ldots` and `\cdots` are `\mathinner{\ldotp\ldotp\ldotp}` and
`{\cdotp\cdotp\cdotp}` (`fontmath.ltx` 400-402): three *punctuation* atoms,
so TeX puts 3mu between each pair. Setting them as one three-character text
run loses both gaps — 1.66 bp each at 10pt. pdfTeX's `\hbox{$\ldots$}` is
11.66661pt where three bare `\ldotp`s side by side would be 8.33337pt.
They are now the group of three punctuation atoms the kernel defines, as an
Inner atom.

`\bmod` is amsopn's `\nonscript\mskip-\medmuskip\mkern5mu\mathbin
{\operator@font mod}\penalty900\mkern5mu\nonscript\mskip-\medmuskip`. The
`-\medmuskip` exactly cancels the binary's own inter-atom glue, so what is
left is 5mu on each side whatever the neighbours are — and `\mkern`, unlike
`\mskip`, is not suppressed in script styles. Classifying the word `mod` as
a binary gets 4mu in text style and 0 in scripts; worse, the render pipeline
does not read the compiler's atom class for a *text* nucleus at all, so it
got neither, which is the 2.77 bp missing on each side of `$a \bmod b$`.
The two kerns are now explicit, so both producers and every style agree.
`\mod` keeps its own arm rather than sharing `\bmod`'s: amsmath's `\mod`
takes an argument and has different kerns, and this compiler does not model
it yet.

Measured at 10pt against TeX Live 2025 pdfTeX, through the same harness as
the rest of this branch (one paragraph per formula), with both halves
vendored:

  $r \gets a \bmod b$   -0.0009 bp     (was -5.55, 2.77 each side)
  $a \bmod b$           -0.0037 bp
  $x^{a \bmod b}$       +0.0004 bp     script style, where \mkern still applies
  $1, 2, \dots, n$      +0.0027 bp     (was -3.33, 1.66 per gap)
  $a \dots b$           -0.0008 bp
  $a \cdots b$          -0.0008 bp
  $x^{a \dots b}$       -0.0004 bp     script style, where the 3mu is suppressed
  $\ldots$              -0.0036 bp

A bare `$\dots$`/`$\cdots$` with amsmath loaded still measures 1.66 bp
narrow, and that one is not a bug in this change: amsmath makes `\dots`
context-sensitive, and with nothing following it expands to `\dotso`, which
appends a thin space (pdfTeX, amsmath loaded: `\dots` 13.33324pt, `\ldots`
11.66661pt; without amsmath both are 11.66661pt). This compiler's math
parser is package-agnostic, so it implements the kernel definition — the
same known difference #180 recorded for `\colon`. Every in-context shape,
which is what a document actually contains, is exact.

Gates unchanged from the first commit: compiler 449 passed, 0 failed;
amsmath 59/59 and amssymb 38/39 per-fixture identical to the control;
HW1/HW2 3 pages, 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
GoKubar added a commit that referenced this pull request Sep 14, 2026
#472)

* compiler: mathtools colon relations (eqqcolon, Coloneqq, Eqqcolon, vcentcolon, dblcolon)

Adds the five sibling relation symbols to mathtools' existing colon
family (\coloneqq already worked). \vcentcolon and \dblcolon are built
from the same plain ":" glyph #180 uses for kernel \colon (Rel instead
of Punct), not a separate Unicode lookalike; \Coloneqq/\Eqqcolon build
compositionally from the same ":"/"=" glyphs, for font/kerning fidelity
with what pdfLaTeX actually draws. All five are gated on
\usepackage{mathtools} (mathtools.sty defines them; base LaTeX2e does
not -- verified against TeX Live 2025 with \ifcsname).

Regenerates crates/compiler/supported/supported-latex.json,
docs/user/compiler.md and the byte-identical apps/mac bundled copy for
the four new inventory entries.

Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane mathtools-colons, slice 1)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Muse-Lane-Head: fcffef63
Co-authored-by: muse-spark-1.3-contributor <[email protected]>

* compiler: build mathtools colon relations with their real .sty kerns

Fixes a real correctness bug in the earlier commit: \dblcolon,
\Coloneqq, \Eqqcolon and \eqqcolon were built with no kern between
their component glyphs, and \eqqcolon used a precomposed U+2255
lookalike instead of building from = and \vcentcolon. Real
mathtools.sty (486-507, legacycolonsymbols) defines all four with
explicit \mkern:

  \dblcolon   = \vcentcolon \mathrel{\mkern-.9mu} \vcentcolon
  \Coloneqq   = \dblcolon \mathrel{\mkern-1.2mu} =
  \Eqqcolon   = = \mathrel{\mkern-1.2mu} \dblcolon
  \eqqcolon   = = \mathrel{\mkern-1.2mu} \vcentcolon

Adds a small `mkern(mu, span)` helper (mu/18 em, the same conversion
the "colon" arm above already uses for amsmath's measured 6mu/2mu
split) and rebuilds all four as Nucleus::Space kerns interspersed with
the existing vcentcolon_atom()/plain "="/":" glyphs inside their
relation groups. A Nucleus::Space atom lays out with zero items and no
class, so it replaces (not adds to) the normal inter-atom spacing
between the two glyphs it separates -- matching what a real \mkern
atom does.

Rewrites both tests that covered this family so their expected values
are independent of the implementation: the width test now derives
`own` from raw `width(":", SIZE)`/`width("=", SIZE)` glyph metrics
plus the literal .sty mu values (not from calling into the atoms'
own reported width), and the parse-structure test explicitly asserts
each kern's exact em value.

Independently cross-checked against real pdflatex + mathtools at 10pt
(kpsewhich mathtools.sty for the source, then measuring
\setbox0=\hbox{$a<cmd> b$} against a \hbox{$ab$} control for
\vcentcolon/\dblcolon/\eqqcolon/\Coloneqq): the implementation's
predicted widths match the real \wd measurements to within manual
arithmetic rounding.

Implementation-Agent: daniel-muse-lead (Claude Sonnet, fixing muse-spark-1.3-contributor's earlier commit per daniel-parent's review)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)

* compiler: centre the mathtools vcentcolon ink on the math axis

Fixes daniel-parent's re-review of #417: mathtools defines \vcentcolon
as \mathrel{\mathop\ordinarycolon} -- the \mathop centres the colon's
ink on the math axis, but the plain ":" glyph this compiler drew it
with sits on the baseline like any other symbol, so \vcentcolon,
\dblcolon, \Coloneqq, \Eqqcolon and \eqqcolon all came out too low.

layout_nucleus now raises exactly the atoms vcentcolon_atom makes (a
plain ":" with a forced Rel class -- kernel \colon is Punct, amsmath's
is Ord, a literal ":" carries no override, so none of those move) by
MATH_AXIS_EM * size minus half the text face's real x-height (the
colon's dots span baseline..x-height, so half that height is the
ink's own center above the glyph's baseline) -- the same axis-minus-
visual-centre pattern already used for fence baselines, using the same
real x_height_pt() metric layout_accent already relies on, not a
guessed constant. The two mathtools compound relations nest these same
atoms in their groups, so the fix propagates to them automatically.

Also drops the now-dead ('\u{2255}', 906) row added in the prior
commit: \eqqcolon now renders as "=" + kern + the centred colon, never
that precomposed glyph.

Verified independently by the reviewer on this exact commit:
- `cargo test --lib math::`: 84 passed, 0 failed (80 in math.rs + 2
  lm_math::tests + 2 newcm_math::tests -- a substring-matched filter,
  not pure math.rs count).
- Mutation check: zeroing the raise fails
  vcentcolon_centres_the_colon_ink_on_the_math_axis; restoring passes.
- Full `cargo test` in crates/compiler: 0 FAILED across all suites.

Implementation-Agent: muse-spark-1.3-contributor (Muse Code, lane fix417, slice 1)
Commit-Executor: daniel-muse-lead (Claude Sonnet)
Reviewed-by: daniel-muse-lead (Claude Sonnet)
Co-authored-by: muse-spark-1.3-contributor <[email protected]>

---------

Co-authored-by: d-q222 <[email protected]>
Co-authored-by: muse-spark-1.3-contributor <[email protected]>
@GoKubar

GoKubar commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded — the work is already on main.

Replacement: \colon arms are on main in crates/compiler/src/math.rs and typeset.rs

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/math-symbols-compiler 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