Skip to content

compiler: an amsmath-provided math construct needs its package loaded - #247

Closed
GoKubar wants to merge 8 commits into
mainfrom
agent/kabir-claude/amsmath-construct-gating
Closed

GoKubar wants to merge 8 commits into
mainfrom
agent/kabir-claude/amsmath-construct-gating

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up lane to #230, which measured these 37 and deliberately left them. Stacked on #230, whose MathPackages, generated provider field and diagnose-instead-of-render fallback this reuses; that branch is merged in as this branch's second parent, so the diff below contains #230's commits as well as this one. Review 6d93d5c7.

The problem

math::command_atom applied the amsmath bundle's math constructs unconditionally. Nothing checked that the document wrote \usepackage{amsmath}, so \text, \binom, \boxed, \dfrac, \operatorname, \tag, \mod and 30 more rendered happily in a document that loaded no package at all, where pdflatex answers ! Undefined control sequence.

Wider blast radius than the symbol table #230 gated: \square and \nleq belong to documents that were going to load amssymb anyway, but \text and \dfrac appear in ordinary ones.

The measured list

I did not trust the 37. Every supported math command was probed with \ifcsname under TeX Live 2025 pdflatex with an empty preamble and then under amsmath, amstext, amsopn, amsbsy, amsfonts, amssymb and mathtools — the same method as #230:

commands
supported math commands probed 542
defined by base LaTeX2e 261
undefined in base, provided by amssymb/amsfonts (#230's gate) 225
undefined in base, provided by the amsmath bundle 37
undefined in base, provided by none of them 19

The 37 agree exactly with #230's count, and the probe splits them by declaring file, which matters because a document can load one without amsmath:

  • amstext.sty — \text
  • amsopn.sty — \operatorname, \operatornamewithlimits
  • amsbsy.sty — \boldsymbol
  • amsmath.sty (33) — \binom \boxed \cfrac \dbinom \dfrac \dotsb \dotsc \dotsi \dotsm \dotso \genfrac \iiint \iint \impliedby \implies \lVert \lvert \mod \notag \overleftrightarrow \overset \rVert \rvert \substack \tag \tbinom \tfrac \underleftarrow \underleftrightarrow \underrightarrow \underset \xleftarrow \xrightarrow

amsmath.sty line 78 is \RequirePackage{amstext,amsbsy,amsopn}, so \usepackage{amsmath} sets all four flags; \usepackage{siunitx} sets only amstext and \usepackage{bm} only amsbsy, both measured. The diagnostic names the \usepackage that actually fixes the document: \text requires \usepackage{amstext}.

The gate

One check before the dispatch, so it covers the table rows and the dedicated parser arms alike. That placement is the point: most of the 37 have their own command_atom arm, and several share that arm with a kernel command that must stay unconditional — \dots/\ldots/\cdots beside \dotsc, \stackrel beside \overset, \overline/\underline/\overbrace/\overrightarrow beside \boxed, \iff beside \implies, \nonumber beside \notag, \frac beside \dfrac, \mathbf beside \boldsymbol, \bmod/\pmod beside \mod. Gating at the arm would have had to split every one of them by hand; gating by name does not. A test locks all of those kernel neighbours as still rendering with nothing loaded.

\lvert, \rvert, \lVert and \rVert are the exception that needed a second site: they reach a fence through take_delimiter, not command_atom, so \left\lvert x\right\rvert walked straight past. Both paths are gated; \vert, \Vert, \lbrace, \langle, \lfloor and \lceil in the same list are the kernel's and stay unconditional.

Recovery is #230's: diagnose, then the same literal fallback every unsupported math command already uses.

The loader set — and a correction to #198's

Measured with \@ifpackageloaded, not only \ifcsname. That is the authoritative question, and the two disagree: \ifcsname binom\endcsname cannot tell "loads amsmath" from "defines \binom itself".

Eleven packages were missing from AMSMATH_PACKAGES, each confirmed as \@ifpackageloaded{amsmath} = yes with all four of \binom/\text/\operatorname/\boldsymbol defined: breqn, newtxmath, newpxmath, kpfonts, MnSymbol, libertinust1math, newtx, nicematrix, extarrows, yhmath. Classes were already right (amsart, amsbook, amsproc, acmart, beamer); article, report, book, memoir, scrartcl, elsarticle, IEEEtran, llncs, achemso, tufte-*, standalone, exam load nothing.

Two of those eleven are corrections worth stating plainly:

  • breqn was on the "does not load amsmath" list and that is wrong. \@ifpackageloaded{amsmath} is yes under it. What compiler: thread the loaded packages into math parsing; \colon takes amsmath's definition when amsmath is loaded #198's \colon-width probe actually saw is that breqn replaces \colon again through flexisym after loading amsmath: \hbox{$a a\colon b b$} is the kernel's 23.5995pt under breqn, while \pmod (45.2696pt) and \mod (40.14336pt) are amsmath's. One flag cannot say both. The flag means "amsmath.sty is loaded", so breqn now sets it and \colon under breqn takes amsmath's width — a stated residual, and the narrower of the two errors: a breqn document is far more likely to write \binom than \colon, and everything else about it diverges further than 2.8pt already.
  • libertinust1math stays deliberately absent from AMSSYMB_PACKAGES (it defines part of the symbol inventory itself) but does load amsmath, so the construct flags are set. The two halves are independent, and the existing test that asserted MathPackages::KERNEL for it is updated to say so.

Deliberately absent, measured: nath defines \binom and \text itself and loads no AMS file at all, so \operatorname, \boldsymbol, \colon and \pmod all stay the kernel's under it and neither answer the flag gives is right — the same call #230 made for libertinust1math/fourier/siunitx in the symbol list. amsthm, amscd, amsrefs, physics2, unicode-math, esint, cases, mathdots, thmtools, braket, cancel, tikz-cd, diagbox, stmaryrd, wasysym, mathrsfs, eucal, euler, mathpazo, mathptmx, mathdesign, dsfont, bbm, bbold, cmll, fourier, txfonts, pxfonts, mathabx, stix, stix2, tabularray, witharrows, accents, mleftright, units, ntheorem, mathalpha and the layout packages (hyperref, graphicx, xcolor, geometry, booktabs, natbib, biblatex, enumitem, caption, listings, tikz, pgfplots, float, csquotes, microtype, cleveref) all measured as loading no AMS file. 97 packages and 26 classes probed in total.

Sub-package loaders, each measured: amstext also from siunitx and xfrac (both \@ifpackageloaded{amstext} = yes), and from classes revtex4-1/revtex4-2, which define \text themselves without any AMS file — indistinguishable to a document, and the gate asks whether pdflatex would error, so they belong there. amsbsy also from bm and class apa7.

\mod, decided

#230 left it byte-for-byte. It is now both gated and fixed, because it was wrong in two ways at once.

amsmath.sty 910-911:

\DeclareRobustCommand{\mod}[1]{\allowbreak\if@display\mkern18mu
  \else\mkern12mu\fi{\operator@font mod}\,\,#1}

so an opening kern, an ordinary upright mod — a braced group, not \mathbin like \bmod — then \,\, and one argument. This compiler emitted a bare mod text atom that took no argument and was classified Bin by the same atom_class rule \bmod relies on: 4mu on each side where amsmath puts 12mu and 6mu, with the argument left outside.

Measured with TeX Live 2025 pdflatex at 10pt under amsmath:

box width
$x\mod{y}$ 40.14336pt
$x\mkern12mu\mathrm{mod}\,\,y$ 40.14336pt
$x\mkern12mu\mathrm{mod}\mkern6mu y$ 40.14336pt
$x\mod y$ (unbraced) 40.14336pt
$\mod{y}$ 34.42809pt
$\mkern12mu\mathrm{mod}\,\,y$ 34.42809pt
$x\mathrm{mod}y$ (ordinary control) 30.1436pt
$x\bmod y$ (untouched) 35.69902pt

\if@display is false inside $...$ even under \displaystyle — it is \everydisplay that sets it — so $\displaystyle x\mod{y}$ is 40.14336pt, the inline number. This compiler has no display flag on the atom, exactly as \pmod records, so 12mu is the definition that applies; real display math (\[x\mod{y}\], 18mu) is the residual, the same one \pmod already carries. The unbraced form is one token, which is what required_group takes.

What this does not gate, and why

  • \coloneqq and \xleftrightarrow — my probe found these two beyond the 37: undefined in base and amsmath, defined under mathtools. They are not gated here, because no single mathtools flag describes them: newpxmath, kpfonts and class apa7 define \coloneqq without mathtools, and extarrows defines \xleftrightarrow without it, so one flag would produce a false "requires mathtools" on real documents. Doing it right needs per-construct provider sets, which the amsmath family does not need. Measured and listed here; a coherent lane of its own.
  • The 26 amsmath-provided environments. \begin{align} and friends are the same bug on a different axis. An environment is usable only if both \X and \endX are defined, which is what makes matrix, pmatrix and cases look kernel-defined to a naive \ifcsname probe — plain TeX's leftover \matrix/\pmatrix/\cases satisfy the first half and not the second. Probed both halves under TeX Live 2025: equation*, gather, gather*, align, align*, alignat, alignat*, flalign, flalign*, multline, multline*, subequations, matrix, smallmatrix, pmatrix, bmatrix, Bmatrix, vmatrix, Vmatrix, cases, aligned, alignedat, split, gathered are amsmath's (24), dcases is mathtools', and of the remaining supported environments proof is amsthm's, lstlisting listings', multicols/multicols* multicol's. Not gated: the recovery for a missing environment is a different and much larger design question than for a command (pdflatex typesets the body as ordinary text and then errors again at \end), and it runs through the display/numbering machinery rather than command_atom. Deliberately left, with the list measured so the next lane does not have to re-derive it.
  • \bm, \num/\qty/\si/\SI/\ang/\sisetup (siunitx), \color/\textcolor (xcolor) — the other 19 undefined-in-base commands. Each needs its own package flag and loader set; out of this lane, listed so they are not lost.
  • \sgn is a different bug and is not this lane's. It is in OPERATOR_NAMES and renders unconditionally, but it is undefined under every preamble probed — base, amsmath, amssymb, amsfonts, mathtools, amsopn, amsbsy, amstext. No package in TeX Live provides it; it is the canonical \DeclareMathOperator example. pdflatex errors on \sgn always, and this renders it always. Reported, not touched.

Gates

Control is a checkout of this branch's own base (8ca1b1e2, i.e. #230 merged with current main), built and measured the same way in the same environment.

gate control this branch
crates/compiler cargo test --release 481 passed, 0 failed, 4 ignored 486 passed, 0 failed, 4 ignored
amsmath corpus 59/59 within 0.5 bp 59/59, output byte-identical
amssymb corpus 38/39 (32-braces-narrow) 38/39, same fixture, output byte-identical
HW1 render 3 pages, 0 errors, 0 overfull, 0 font diagnostics same
HW2 render 3 pages, 0 errors, 0 overfull, 0 font diagnostics same
real-world corpus 20 fixture×producer rows 0 rows differ — identical status, page count and full diagnostic set, row by row
crates/render-pipeline cargo test --release --no-fail-fast, both trees vendor-swapped 195 passed, 7 failed 194 passed, 8 failed
render-pipeline failing SET cm_less_symbols_are_painted_from_latin_modern_math font_family_fixtures_match_pdflatex footnotes_against_pdflatex inline_math_breaks_against_pdflatex mathbb_paints_from_new_computer_modern_when_bundled page_frame_against_pdflatex varnothing_sets_at_msbm_width_and_paints_from_new_computer_modern_when_bundled the same seven, plus array_rows_stack_on_the_strut_with_row_skips_and_columns_at_arraycolsep
the same, with the sibling pipeline PR applied — identical to the control's seven (math_grids 3/3, amsmath_inline 11/11)

The +5 compiler tests are this change's. Thirteen existing tests changed: each exercised an amsmath construct with MathPackages::KERNEL, i.e. stood for a document that used \binom/\text/\dfrac without loading amsmath, and each now passes the packages that document would really have. That is the change working, not a test weakened — every_amsmath_construct_is_diagnosed_without_its_package asserts the KERNEL behaviour for all 37 by name.

Zero font diagnostics on HW1 and HW2, asserted. The corpus run is not zero overall: article-twocolumn and input-bibliography carry 3 ec_metrics_unavailable between them, because ectt1000.tfm/ectt1200.tfm are not in this checkout's apps/mac/Fonts tree at all. Identical on both sides, pre-existing, environmental, and untouched by this change — reported rather than rounded to zero.

The render gates cannot see crates/compiler (the pipeline links vendor/compiler, a pinned mirror at ea4ee5c8), so they were measured through an uncommitted full vendor swap of crates/compiler/src over vendor/compiler/src, against a control swapped the same way. The swap also needs #231's one-line text_kern reverse-lookup fix and a two-argument parse_tokens call in tests/math_symbols.rs, both consequences of #230, both applied identically to the two trees and neither part of this PR.

Pipeline half

There is one, and it is small: crates/render-pipeline/tests/amsmath_inline.rs and two cases in tests/math_grids.rs build their documents as \documentclass{article}\begin{document}… and then use \binom, \dfrac, \substack, \operatorname, \text and cases — the exact bug this PR closes, written into the test fixtures. They pass today because the vendor pin predates the gate; they break at the re-pin. Sibling PR adds the \usepackage{amsmath} those documents always needed. It is correct on its own and independent of this one.

Measured under the swap, the one pipeline test that changes is math_grids::array_rows_stack_on_the_strut_…, and it changes on geometry (2\arraycolsep between columns: 14.205…), because its \text{(a)} now falls back to the literal recovery and widens the column. amsmath_inline's eleven tests pass unfixed, which is worth knowing on its own: assert_no_limitation_or_unsupported filters code == "math_limitation" || code.starts_with("unsupported"), but display::Diagnostic::from_compiler rewrites every compiler diagnostic's code to the literal "compiler", so that helper cannot see a compiler diagnostic at all. The construct diagnostic is really there — the same flashtex-render binary on the same document answers \binom requires \usepackage{amsmath}. Reported, not fixed here; it is why those fixtures could describe invalid LaTeX without any test noticing.

Every committed .tex in the repository was scanned: 0 documents use an amsmath construct without loading a package that provides it. Real documents load their packages, which is why no corpus fixture moved.

End to end

flashtex-compiler on the branch, one runtime-v1 compile per document:

document construct diagnostics
\documentclass{article} + \dfrac \text \binom \mod \left\lvert…\right\rvert all six, each naming its own package (amsmath, amstext)
the same under \usepackage{amsmath} none
\usepackage{siunitx} + \text + \binom \binom only — siunitx gives \text and nothing else
\usepackage{bm} + \boldsymbol + \operatorname \operatorname requires \usepackage{amsopn} only
\documentclass{amsart} + \dfrac + \operatorname none
\frac12 \dots \stackrel \overline \iff \bmod \pmod \mathbf with nothing loaded none

Draft; not for merge.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

GoKubar and others added 8 commits September 13, 2026 15:19
…amsmath's definition when amsmath is loaded

`math::parse_tokens` took no package context, so every construct a
package redefines silently got the LaTeX kernel's definition -- the
wrong one whenever the document actually loaded the package. `\colon`
is the case that forced this: the kernel declares it punctuation
(`fontmath.ltx` 400, `\DeclareMathSymbol{\colon}{\mathpunct}{operators}
{"3A}`, 0mu/3mu) and amsmath renews it (`amsmath.sty` 409-410) to
`\nobreak\mskip2mu\mathpunct{}\nonscript\mkern-\thinmuskip{:}\mskip6mu
plus1mu\relax`, whose empty punctuation atom's 3mu is cancelled by the
negative kern behind it -- leaving an *ordinary* `:` with 2mu before
and 6mu after. Most documents that write `\colon` load amsmath.

Measured with TeX Live 2025 pdflatex at 10pt, control `\hbox{$ab$}` =
9.57755pt:

| box | no amsmath | with amsmath | delta |
| --- | ---: | ---: | ---: |
| `\hbox{$\colon$}` | 2.77779pt | 7.22212pt | +8mu |
| `\hbox{$a\colon b$}` | 14.02196pt | 16.79967pt | +5mu |
| `\hbox{$a\colon=b$}` | 24.57747pt | 30.13289pt | +10mu |
| `\hbox{$a\colon+b$}` | 21.79976pt | 29.0218pt | +13mu |
| `\hbox{$f\colon A\to B$}` | 41.55893pt | 44.33664pt | +5mu |

The 10mu and 13mu rows are the class in evidence, not just the glue:
the kernel's punctuation atom turns a following `+` into an Ord
(TeXbook Chapter 17's Bin-after-Punct rule) where amsmath's ordinary
one leaves it a Bin. The three-atom model this emits -- `space(2/18)`,
a `:` forced Ord, `space(6/18)` -- was checked against amsmath's own
expansion inside one document and is identical to the scaled point in
text, display, script and scriptscript style, and for `\colon` at a
formula boundary, before a relation, before a binary, and doubled.

## The mechanism

`MathPackages` is a `Copy` value carried by `MathParser` and passed to
`parse_tokens` / `parse_tokens_reporting_unclosed` as a required
parameter, so a caller cannot forget it and silently fall back to the
kernel. `parser::P` folds it from `\documentclass` and each
`\usepackage` name into a `math_packages` field -- the shape
`P::colors` and `P::font_encoding` already use, and the one that can
capture package *options* later, since the parser reads and drops them
in the same place. It is deliberately not a global: siunitx's
thread-local `Settings` is the mistake this does not repeat, and one
process compiles many documents. `siunitx::typeset`/`Context` take it
too, because `Context::math` re-parses synthesized unit formulas and is
the one path into the math parser with no document in scope.

Which packages and classes carry amsmath's definitions in was measured,
not assumed: each name was compiled with pdflatex and
`\hbox{$a a\colon b b$}` compared against the kernel expansion
(23.5995pt) and the amsmath expansion (26.37721pt) in the same
document, so font metrics cancel. Loading amsmath: `mathtools`,
`empheq`, `physics`, `nccmath`, `aligned-overset`, `cool`, `commath`,
`mismath`, `mhchem`, `chemformula`, and the `amsart`/`amsbook`/
`amsproc`/`acmart`/`beamer` classes. Measured as leaving the kernel's
alone, and so deliberately absent: `amsthm`, `amssymb`, `amsfonts`,
`amsopn`, `amsbsy`, `amscd`, `amstext`, `bm`, `unicode-math`,
`siunitx`, `esint`, `breqn`, `cases`, `mathdots`, `thmtools`, `braket`,
`cancel`, `tikz-cd`, `diagbox`, and the `article`/`report`/`book`/
`memoir`/`scrartcl`/`scrbook`/`scrreprt`/`revtex4-2`/`elsarticle`/
`IEEEtran`/`letter`/`proc`/`slides`/`amsdtx` classes.

`\colon` was previously diagnosed `\colon is not supported in math
mode` and typeset literally, so both definitions are new behaviour; it
joins the supported-LaTeX inventory and the generated artefacts are
regenerated.

`math::AtomClass` and `MathAtom::class_override` become public. The
render pipeline re-derives the forced class today by reading the
control word back out of the source at the atom's span
(`typeset::class_override_of`), which cannot tell `\colon`'s two
definitions apart -- they are the same five characters of source. The
sibling pipeline PR reads the field instead, behind its own feature.

## Gates

`cargo test --release` in `crates/compiler`: 444 passed, 0 failed,
against 441 passed / 0 failed at the same base (590fd86) in a separate
control worktree -- the 3 new tests, no other change. (`--test
robustness`'s `deeply_nested_input_does_not_blow_the_stack` overflows
in a *debug* build on this machine identically on both sides; release
passes on both.)

Real-world corpus (`tools/real-world-corpus/run.py --no-oracle`, this
checkout's binaries): 20 fixture/producer pairs, status, page counts
and exact diagnostic message sets identical to the control. hw1 and hw2
render 3 pages each, 0 errors, 0 overfull.

`crates/render-pipeline` vendors its own pinned copy of this crate
(`flashtex-compiler = { path = "vendor/compiler" }`), so nothing here
reaches `flashtex-render` until that pin moves; the render gates were
therefore also run through an *uncommitted* vendor swap, together with
the sibling pipeline change. amsmath corpus 59/59, amssymb 38/39
(`32-braces-narrow`, 1.012 bp, fails at this base too), both with zero
font diagnostics. Through that full stack `\hbox{$X a\colon b X$}`
renders within 0.0001 bp of pdflatex with and without amsmath.

Implementation-Agent: Claude Code engine-engineer (linux-primary, NixOS)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
`apps/mac/scripts/sync-supported-latex.sh --check` and
`CompletionTests.testBundledInventoryMatchesTheCompiler` compare
`apps/mac/Sources/FlashTeXMac/Resources/supported-latex.json` against
`crates/compiler/supported/supported-latex.json` by sha256, so the
editor's completion vocabulary never drifts from the compiler. The two
were byte-identical at this branch's base (21eed5701677) and the
previous commit regenerated the compiler-side copy, so the bundled one
had to follow. Regenerated with the script, not by hand; the check now
reports `bundled copy is current (23d25a1ff459)`.

Implementation-Agent: Claude Code engine-engineer (linux-primary, NixOS)
Commit-Executor: git via Claude Code
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…context' into agent/kabir-claude/math-package-gating

# Conflicts:
#	docs/user/compiler.md
`math::command_atom` applied the amssymb/amsfonts table unconditionally, so
`\square`, `\nleq`, `\mho` and the other 218 commands it answers rendered
happily in documents that never loaded the package. Probed with `\ifcsname`
under TeX Live 2025, base LaTeX2e has **no definition for any of them** and
pdflatex answers "Undefined control sequence", so this was a 1:1 divergence
across the whole table, not a few symbols.

Each symbol now carries the file that declares it (`amssymb::Provider`,
generated, not hand-written: `gen_amssymb.py` collects the declarations from
both `.sty` files before the dedup that used to hide `amsfonts.sty` 141-147's
re-declaration of `\square`, `\lozenge`, `\rightsquigarrow`,
`\vartriangleright`, `\vartriangleleft`, `\trianglerighteq` and
`\trianglelefteq`). `MathPackages` gains `amssymb` and `amsfonts` flags beside
`amsmath`, and `command_atom` diagnoses the missing `\usepackage` instead of
rendering. The regenerated table is byte-identical to the committed one apart
from the new field.

The same gate covers the four commands with their own arms rather than a table
row — `\varnothing`, the dashed arrows, `\mathbb`/`\mathfrak` and the obsolete
`\Bbb`/`\bold` (`\mathbf`, which `\bold` stands for, is the kernel's and stays
unconditional).

Negative behaviour, measured rather than assumed:

* `\angle` and `\hbar` are the two commands here base LaTeX2e *does* define,
  as composites amsfonts replaces. Without the package they keep the kernel
  advance: `\hbox{$\angle$}` 6.37344pt against amssymb's 7.22223pt, and
  `\hbox{$\hbar$}` 5.76172pt against 5.40280pt. The `\hbar` composite
  reproduces exactly from its pieces (macron 5.00002 + `\mkern-9mu` -4.99988 +
  math italic h 5.76158). Neither changes atom class.
* Everything else in the table is diagnosed, because pdflatex errors.

Which package loads which was measured, not assumed: every candidate compiled
with pdflatex and probed for `\nleq` (amssymb only), `\ulcorner` (also
amsfonts) and `\binom` (amsmath). `txfonts`, `pxfonts`, `newtxmath`,
`newpxmath`, `mathabx`, `kpfonts`, `MnSymbol` and `cool` really do load
amssymb; `amsart`/`amsbook`/`amsproc` load amsfonts but not amssymb;
`acmart`/`beamer` load both. `libertinust1math`, `fourier` and `siunitx`
define part of the inventory themselves without either AMS package and are
deliberately absent.

Tier 1 of #198's audit, each measured before and after against pdflatex:

* `\pmod` inline opens with amsmath's `\mkern8mu`, not the kernel's 18mu:
  `$a\pmod{y}$` 50.82503pt -> 45.26960pt, matching `$a\mkern8mu(...)$`
  exactly. Display is 18mu under both (`\@displaytrue` puts amsmath back on
  50.82503), so display formulas are untouched.
* `\bmod` is 5mu on each side, not the 4mu of its Bin class, under every
  package: `$a\bmod b$` 34.29970 against an ordinary `mod` at 28.74428, and
  `$\bmod b$` 24.56947 against 23.45839 where the Bin degrades to Ord.
* Text-mode `\,`/`\!` take amsmath's `.1667em` when amsmath is loaded: 20sp
  wider at 10pt, 24sp at 12pt. `\:`/`\;` are identical under both, and the
  math-mode `\mskip` forms do not move.

The inventory now records which package each symbol needs, so
`supported-latex.json` and the Mac bundled copy say "needs amssymb" where they
used to claim an unconditional symbol.

Gates, `crates/compiler` `cargo test --release`: **457 passed, 0 failed**
against **448 passed, 0 failed** at the base (62200c0 + #198) in the same
worktree; the +9 are this change's tests. Through an uncommitted full vendor
swap into `crates/render-pipeline`, the amsmath corpus is 59/59 and the
amssymb corpus 38/39 (`32-braces-narrow`, 1.012 bp, fails at the base too) —
**byte-identical output files** to the same swap of the base, with zero font
diagnostics. Every real-world fixture compiles with no new diagnostic: they
all load their packages, including through the `\usepackage{amsmath,amssymb}`
comma form.

Stacked on #198, whose `MathPackages` this extends; the merge of that branch
is the first parent commit here.

Implementation-Agent: engine-engineer (Claude Opus 5), linux-primary worktree
Commit-Executor: engine-engineer direct Git (Cursor usage-limit fallback)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…th-package-gating

# Conflicts:
#	docs/user/compiler.md
`math::command_atom` applied the amsmath bundle's 37 math constructs
unconditionally. Nothing checked that the document wrote
`\usepackage{amsmath}`, so `\text`, `\binom`, `\boxed`, `\dfrac`,
`\operatorname`, `\tag`, `\mod` and 30 more rendered happily in a document
that loaded no package at all, where pdflatex answers
`! Undefined control sequence`.

Measured, not assumed: every supported math command was probed with
`\ifcsname` under TeX Live 2025 pdflatex with an empty preamble and then
under amsmath, amstext, amsopn, amsbsy, amsfonts, amssymb and mathtools.
Of 542 commands, base LaTeX2e defines 261, 225 are the amssymb/amsfonts
table `MathPackages::provides` already gates, **37 are these**, and 19
belong to packages outside the AMS bundle.

The four bundle files are distinguished, because a document can load one
without amsmath: `\usepackage{siunitx}` gives `\text` alone and
`\usepackage{bm}` gives `\boldsymbol` alone, so the diagnostic names the
`\usepackage` that actually fixes the document.

The gate sits before the dispatch, so it covers the table rows and the
dedicated parser arms alike -- most of these 37 have their own arm, several
shared with a kernel command that must stay unconditional (`\dots` beside
`\dotsc`, `\stackrel` beside `\overset`, `\overline` beside `\boxed`).
`\lvert`/`\rvert`/`\lVert`/`\rVert` reach a fence through `take_delimiter`
rather than `command_atom`, so that path is gated too.

Eleven packages measured as loading amsmath transitively were missing from
`AMSMATH_PACKAGES`: breqn, newtxmath, newpxmath, kpfonts, MnSymbol,
libertinust1math, newtx, nicematrix, extarrows, yhmath -- each confirmed
with `\@ifpackageloaded{amsmath}`, the authoritative question, which
`\ifcsname binom\endcsname` alone cannot answer (nath defines `\binom`
itself and loads no AMS file, and stays deliberately absent).

`\mod` is no longer left as it was. amsmath.sty 910-911 makes it
`\allowbreak\if@display\mkern18mu\else\mkern12mu\fi{\operator@font mod}\,\,#1`
-- an opening kern, an *ordinary* upright mod (a group, not `\mathbin` like
`\bmod`), 6mu, and one argument it did not take before. Measured at 10pt:
`$x\mod{y}$` 40.14336pt, identical to
`$x\mkern12mu\mathrm{mod}\mkern6mu y$`.

Implementation-Agent: engine-engineer (claude-opus-5), linux-primary
Commit-Executor: engine-engineer 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]>
@d-q222

d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Superseded — landed via 703cc445 + #230 (543bde5c).

Verified on origin/main: AMSMATH_PACKAGES and the "\{name} requires \usepackage{{package}}" diagnostic at math.rs:1005,1646,7994, with a test asserting "\sideset requires \usepackage{amsmath}".

Residual tracked, not lost: the \mod width fix never landed — main's own comment says it "is left exactly as it was" → #769.


Closed by the Commander after a stale-draft screening pass that required evidence in both directions — a landing SHA to close, an empty grep to keep open. If this verdict is wrong, say so on issue #2 and I will reopen: an asymmetric bar has produced wrong calls here in both directions before.

@d-q222 d-q222 closed this Sep 16, 2026
ItsAkilesh pushed a commit to ItsAkilesh/flashtex that referenced this pull request Sep 18, 2026
…tex#769)

Split out from PR flash-tex#247 (closed as superseded); the fix itself never landed
when flash-tex#247 was superseded by flash-tex#230/flash-tex#529/flash-tex#530. main still carried \mod as an
unconditional plain text atom, with a comment saying the gap was
deliberate.

- \mod is undefined in base LaTeX2e (amsmath.sty 910-911); gated the same
  way \sideset already is: `"mod" if !self.packages.amsmath =>
  self.missing_package(...)`.
- Under amsmath, \mod opens with \mkern12mu (inline; this compiler has no
  display flag, so the inline number is the one that applies, matching how
  \pmod already handles the same distinction), sets its argument as an
  ordinary (not Bin) upright "mod" via required_group + class_override,
  and puts 6mu before the argument. Two new constants,
  AMSMATH_MOD_OPENING_MU and AMSMATH_MOD_TRAILING_MU, mirror the existing
  AMSMATH_POD_MU/BMOD_EXTRA_MU pattern.

Verified against TeX Live 2025 pdflatex at 10pt (see the code comment for
the measured equivalences); added mod_needs_amsmath (mirrors
sideset_needs_amsmath) and a width test mirroring the existing pmod/bmod
style. cargo test --lib: 414 passed, 0 failed.

Commit-Executor: daniel-muse-lead (Claude Sonnet)
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