Skip to content

compiler: drop unresolved math commands instead of typesetting their names (#846) - #856

Merged
jay3332 merged 2 commits into
mainfrom
muse/math-literal-leak
Sep 19, 2026
Merged

jay3332 merged 2 commits into
mainfrom
muse/math-literal-leak

Conversation

@d-q222

@d-q222 d-q222 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #846. In math mode, a control sequence FlashTeX could not resolve was printed into the PDF as its literal name — a reader saw \varrho rendered as visible text where a Greek letter belonged, 188 times in one real arXiv paper.

text mode math mode
pdflatex Text mode: here. Math mode: +1.
FlashTeX before Text mode: here. ✅ Math mode: \alsonotreal + 1. ❌
FlashTeX after Text mode: here. Math mode: +1. ✅

Text-mode recovery was already correct. The two paths disagreed inside one engine: having correctly decided it could not render the command — the error[unknown_command] diagnostic is right and unchanged — the math path then rendered the command's name.

Measured across 30 real-world documents, controlled against pdflatex

Counting \[A-Za-z]{2,} tokens in extracted text and subtracting pdflatex's own count — essential, because LaTeX manuals legitimately print command names:

11 of 30 documents affected. Worst 912 leaks (arxiv-quantum-entanglement-revtex: \varrho×188, \rmT×86, \dagger×82), then 241, 132, 86, 54, 48. Control: tufte-handout shows 11 leaks but pdflatex prints 35, so it is correctly excluded.

Oracle edge cases — one corrected my brief

The lane checked eight forms against pdflatex (\documentclass{article}, TeX Live 2026) and found that pdflatex KEEPS the argument — $\notreal{x}+1$ extracts as x + 1., because the braces are just a group. My task description had not specified that correctly. Also verified: $\notreal$ → ., $a \notreal b$ → ab., $\notreal^2$ → 2 ., $a\notreal^2$ → a2 ., $\notreal_2$ → 2 ., and both leading and trailing positions.

Tests

Full crates/compiler suite: 1,051 passed / 0 failed across 85 binaries. The new regression test failed before the fix with nucleus: Symbol("\\alsonotreal") — the leak, observed directly — and passes after.

One disclosure the lane made itself

It changed a recovery-note string in RECOVERY.md (message and code byte-identical). Its reasoning: leaving it would now misdescribe the behaviour. If "do not change the diagnostic" is read as covering that field, say so and it reverts. I judged the change correct — the note describes recovery, and recovery is exactly what changed.

Also noted, not fixed here

The leaked names are mostly user-defined macros (\dang, \half, \inv, \id from evan.sty; \dmodel from a paper's own preamble), which points at .sty-defined and \newcommand macros not expanding in math mode. The leak is the symptom; missing expansion is the cause. Worth its own issue.

⚠️ Not verifiable end-to-end yet

No live tex-to-PDF route exists without the frozen vendor/compiler snapshot, currently 14 commits behind. Proof here is at compiler level; PDF-level proof awaits that re-pin.

Base

Merged origin/main (7054ee41) before publishing — the lane branched pre-#840, so its raw diff would have reverted the TAB catcode fix. Caught by the publish gate, which now refuses that automatically.

Implemented by a sandboxed Muse lane; reviewed and published by the Commander.

🤖 Generated with Claude Code

In math mode an unresolvable control sequence fell back to emitting
its literal name (e.g. visible \varrho where a Greek letter belongs),
while text mode already dropped it. pdflatex answers 'Undefined
control sequence' and typesets nothing, so the math path now emits a
zero-width classless atom -- the same nothing the null delimiter and
the invisible currentlabel marker use -- keeping the unknown_command
diagnostic, the following group argument, and following scripts.

Implementation-Agent: muse-spark-1.3-contributor
Commit-Executor: muse-spark-1.3-contributor
@jay3332

jay3332 commented Sep 18, 2026

Copy link
Copy Markdown
Member

Verified independently on this machine (mac-claude-a): an agent of mine reached the identical core fix (space(0.0, span) in the (None, None) arm) before I found this PR, so I withdrew it in favour of #856 — the unit test here is more thorough.

One residual path it noticed that this PR leaves as-is: missing_package in math.rs (~L1682, e.g. $\varnothing$ without amssymb) still emits symbol("\\name"), so literal command names keep leaking there; pdflatex sets nothing for an undefined control sequence in that case too. The doc comment says the literal is deliberate ("so the divergence is visible"), so maybe intentional — flagging for a follow-up rather than blocking. render-pipeline/tests/math_symbols.rs's doc comment and flashtex-cli/src/report.rs's fixture note still reference the old literal-name wording.

@jay3332
jay3332 merged commit 82aae20 into main Sep 19, 2026
21 of 22 checks passed
GoKubar added a commit that referenced this pull request Sep 21, 2026
)

#856 stopped math mode typesetting an unresolved control sequence's name;
what it left is the dropped command itself. Re-measured on main
(13285fe) with `tools/real-world-corpus/math_leaks.py` over the public
documents of #846's table (Green–Tao amsart, the Horodecki revtex4
review, the transformer paper, amsldoc, tufte, three Evan Chen handouts
with today's evan.sty): the PDF-text leak of names is 0 everywhere, and
the `\X is not supported in math mode` count per name is

  379 \varrho, 228 \cal, 203 \bf, 192 \rm, 56 \ensuremath, 50 \Vert,
  10 \mkern, 6 \pmb, 4 \framebox, 4 \columnwidth, 3 \backslash,
  2 \bigvee, 2 \smash, 2 \hdotsfor, 2 \varliminf, 1 each of \coprod,
  \bigotimes, \bigoplus, \bullet, \prec, \longmapsto, \kern, \vert,
  \negmedspace, \negthickspace, \leftroot, \uproot, \injlim, \projlim,
  \varinjlim, \varprojlim, \varlimsup, \iiiint, \idotsint,
  \varGamma..\varOmega (11), \it (2)

evan.sty's `\dang`/`\half`/`\dg` rows of the original table are gone
since .sty reading landed; `\dagger` since #441.

Implemented, each per fontmath.ltx / latex.ltx / amsmath.sty (TeX Live
2026), line numbers in the arms:

* `COMMAND_GLYPHS` rows for the kernel symbols math-layout already boxes
  from their cmmi/cmsy/cmex slots (9bdcd5c) but the compiler never
  named: \varrho, \bullet, \prec, \succ, \preceq, \succeq, \coprod,
  \bigvee, \bigwedge, \biguplus, \bigcap, \bigcup, \bigotimes, \bigoplus,
  \bigodot, \bigsqcup, \longmapsto — with their classes in `symbol_class`,
  display limits in `takes_display_limits`, and Latin Modern Math
  advances (read from the bundled latinmodern-math.otf) for the base-14
  export route.
* `\backslash`: Ord over the \setminus glyph (cmsy "6E). The six `vert`
  spellings with forced Open/Close/Ord classes — the arm first written for
  #298, which never landed.
* `\ensuremath` in math (the group) and in text (inline math over the
  braced argument, `Parser::ensuremath`).
* `\mkern`/`\mskip` mu glue (`take_mu_glue`); amsmath's `\medspace`,
  `\thickspace`, `\negmedspace`, `\negthickspace` (gated); `\thinspace`/
  `\negthinspace` (kernel .16667em text kern, 3mu under amsmath);
  `\hdots` (amsmath alias of \ldots).
* `\rm \bf \it \sf \tt \cal \mit` in math as `\DeclareOldFontCommand`'s
  math branch (`\@fontswitch`, latex.ltx 14312): the rest of the current
  group re-read as `\mathrm{...}` etc. (`rest_of_group_alphabet`; the
  group ends at `}`, an enclosing `\right`, `&` or `\\`). `{\bf 1}_S`,
  `${\cal H}_A$` and `\inf_{\sigma\in\rm SEP}` all come out as pdflatex
  sets them.
* `missing_package` recovery drops the command instead of typesetting its
  literal name, as pdflatex and #856 do.
* `\mathbf` with a non-plain argument parses it as math instead of
  keeping a control word's *name* as bold text (`\mathbf{\alpha}` printed
  `\alpha`; the revtex idiom `\bf\sigma` surfaced it): lowercase Greek
  passes through unchanged as in pdflatex, and letters/digits that
  pdflatex would embolden are reported as not set bold.
* Generated inventory (`render_supported_latex.sh`) regenerated.
* `tools/real-world-corpus/math_leaks.py`: the re-measurement harness
  (pdflatex is the oracle only; never in the product path).

Verified: `cargo test` and `cargo test --release` in crates/compiler,
0 failures (both profiles, --no-fail-fast; 528 unit tests, with new
ones for the group boundary of `\rm`/`\bf`/`\cal` and `\mkern`'s mu glue). Oracle fixtures for glyph
identity and positions land with the render-pipeline re-pin.

Left out, with root causes: \pmb (amsbsy triple overprint), \smash,
\framebox/\parbox/\columnwidth in math, \kern<dimen>, \leftroot/\uproot,
\hdotsfor (unimplemented constructs, 1–6 uses, all in amsldoc);
\varGamma..\varOmega and the \varliminf/\injlim family (amsmath
declarations needing cmmi italic capitals and \mathop{\underline{\lim}}
builds, 1 use each); \xymatrix/\ar (xypic, unsupported package).

Implementation-Agent: Claude Fable 5.1 (kabir-claude GH846, mac-m5pro-kabir)
Commit-Executor: Claude Fable 5.1 via Claude Code (direct git)
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 22, 2026
…w recover by skipping

8bf063d changed the recovery of an unsupported math-mode command from
"typeset the command literally and continued" to "skipped the command
and continued" -- true since #856 stopped math mode typesetting an
unresolved name. The fixture's 24 `\hwin` and 32 `\hwbolt` (via `\Z`/`\R`)
diagnostics therefore count as skipped regions: 57 + 56 = 113 of the 114
diagnostics, all but the microtype package warning. The fixture's
diagnostic total and every other count are unchanged.

Implementation-Agent: Claude Opus 5 (kabir-claude MAIN-CI-GREEN, mac-m5pro-kabir)
Commit-Executor: Claude Opus 5 via Claude Code (direct git)
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
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