Repository navigation
Conversation
GoKubar
force-pushed
the
engine/math-operator-sgn
branch
from
September 14, 2026 05:41
f889465 to
0ac39dc
Compare
… spacing real
`math::OPERATOR_NAMES` carried 33 entries. 32 are LaTeX2e's log-like
functions (`fontmath.ltx` 455-503). The 33rd, `\sgn`, is defined by no LaTeX
layer at all: probed name by name under TeX Live 2025 with `amsmath` and
`amssymb` loaded, it is the only undefined one of the 33. FlashTeX rendered
it as upright "sgn" with zero diagnostics and published it as
`"renders": true` in the generated inventory the Mac editor completes from,
so a user could accept the completion, see it render here, and have pdflatex
answer "Undefined control sequence".
Deleting the row alone is not enough, because the edit-distance suggester
answers `\sin` for `\sgn` (one substitution) -- confidently wrong advice for
a name the author spelled correctly. `UNDECLARED_OPERATORS` gives it the
diagnostic it deserves instead: still `unknown_command` (pdflatex's own
answer), but with `\DeclareMathOperator{\sgn}{sgn}` as the suggestion --
amsopn's own documented example for exactly this name. It is deliberately an
`if` rather than a `match` arm, so `tests/supported_latex.rs` does not
require an inventory row for it and republish the claim being retracted.
`\DeclareMathOperator` is already a host-prelude definition
(`expansion::HOST_PRELUDE`): `\cmd` becomes `\operatorname{text}`, the
starred form `\operatorname*{text}`, and both land on the same
`Nucleus::Operator { body, limits }`. So the declared route was there -- but
amsopn's own worked example set the wrong glyphs:
\DeclareMathOperator*{\argmax}{arg\,max} -> arg,max
\operatorname*{arg\,max} -> arg max
printing a comma the author never wrote. The cause is not in the operator
machinery: the lexer encodes a control symbol's escape in its *span width*
(`\,` becomes `Word(",")` spanning two source bytes) and `math::MathParser::
atom`, `\|` and the text kerns all tell `\,` from a literal comma by that
width alone. A token copied out of a macro's replacement text carries the
*invocation's* span, so the test failed and every `\,` `\;` `\!` `\:` in
every `\newcommand` body decayed into the bare character -- `\DeclareMath
Operator` was only the most visible victim.
`parser::math_token` hands math the token's own definition bytes when they
really are `\<c>` (checked against the source text, not just the width).
Only the span moves, never the token kind, and `definition`/
`maps_to_invocation` are left alone so the expansion-site mapping is
untouched.
Oracle (pdflatex, TeX Live 2025, never in the product path): pdflatex sets
`\DeclareMathOperator*{\argmax}{arg\,max}` at glyph positions identical to
the written-out `\operatorname*{arg\,max}` -- `arg` at 133.768, `max` at
149.436 -- which is the equality this now reproduces.
- `crates/compiler` `cargo test --release --no-fail-fast`: 0 failed; empty
failing set, so nothing to compare against a control. 6 new tests.
- `tests/math_operators.rs` proved non-vacuous: with the `parser.rs` hunk
stashed, `a_declared_operator_keeps_the_math_glue_written_in_its_text` and
`control_symbols_survive_a_macro_body` both FAIL.
- real-world corpus, all 22 fixtures, compiler producer: status, page count
and full diagnostic set byte-identical to a control build of the same base
(`5e6c65be`). No fixture uses an undeclared `\sgn` or a control symbol in
a macro body; `math-sheet`'s `\operatorname{sgn}` is legal LaTeX and
unaffected.
- `crates/render-pipeline` and the amsmath/amssymb oracle corpora read
`vendor/compiler`, not this crate, so they cannot move until an integrator
re-pins; none of them is affected by this change either way.
`apps/mac/Sources/FlashTeXMac/Resources/supported-latex.json` is a
byte-identical copy of the compiler's inventory -- that is the whole point of
it, and `CompletionTests.testBundledInventoryMatchesTheCompiler` compares the
two by sha256, as does `apps/mac/scripts/sync-supported-latex.sh --check` in
`make-app.sh`. So this PR must carry the re-synced copy or it turns that gate
red; it is produced by that script and is exactly the one deleted row.
That copy is the completion vocabulary `Completion.Vocabulary` decodes, so
the concrete user-visible change is: the Mac editor no longer autocompletes
`\sgn` as a supported command. Accepting that completion used to produce a
document FlashTeX rendered cleanly and pdflatex refused -- the worst failure
shape for an engine whose contract is matching pdflatex.
**This is a class of bug, not a one-off.** Another lane found the same shape
in `supported.rs` for `\rotatebox`, `\scalebox`, `\resizebox` and
`\reflectbox`: advertised to the editor as supported when the pipeline never
applies them. `\sgn` differs only in being *undefined everywhere* rather
than *defined but not applied*; the fix is the same in both cases -- the
inventory must describe what actually happens, because it is API. Those four
are being handled separately.
Also found and left alone: all six real amsmath operators (`\injlim`,
`\projlim`, `\varinjlim`, `\varprojlim`, `\varliminf`, `\varlimsup`) are
absent everywhere, so real amsmath is reported as a typo -- the inverse gap.
`amsopn.sty` defines them in limits mode and sets `\injlim` as `inj\,lim`,
so adding them as plain text atoms would produce wrong output; it needs
doing properly.
Implementation-Agent: claude-opus-5 (engine lane, linux-primary/NixOS).
Commit-Executor: claude-opus-5 direct git (Cursor usage-limit fallback).
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar
force-pushed
the
engine/math-operator-sgn
branch
from
September 14, 2026 05:51
0ac39dc to
6c99d5c
Compare
This was referenced Sep 14, 2026
Contributor
Author
|
Closed under the old-engine freeze (DESIGN.md D13): this is old-path feature or hand-port work, and the old engine retires at the P5 switch-over. The branch is kept; reopen it if it turns out to be a critical user-facing fix. — kabir-claude (Commander), nightly review 2026-09-30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
compiler: retract the fabricated \sgn and make \DeclareMathOperator's spacing real
math::OPERATOR_NAMEScarried 33 entries. 32 are LaTeX2e's log-likefunctions (
fontmath.ltx455-503). The 33rd,\sgn, is defined by no LaTeXlayer at all: probed name by name under TeX Live 2025 with
amsmathandamssymbloaded, it is the only undefined one of the 33. FlashTeX renderedit as upright "sgn" with zero diagnostics and published it as
"renders": truein the generated inventory the Mac editor completes from,so a user could accept the completion, see it render here, and have pdflatex
answer "Undefined control sequence".
Deleting the row alone is not enough, because the edit-distance suggester
answers
\sinfor\sgn(one substitution) -- confidently wrong advice fora name the author spelled correctly.
UNDECLARED_OPERATORSgives it thediagnostic it deserves instead: still
unknown_command(pdflatex's ownanswer), but with
\DeclareMathOperator{\sgn}{sgn}as the suggestion --amsopn's own documented example for exactly this name. It is deliberately an
ifrather than amatcharm, sotests/supported_latex.rsdoes notrequire an inventory row for it and republish the claim being retracted.
\DeclareMathOperatoris already a host-prelude definition(
expansion::HOST_PRELUDE):\cmdbecomes\operatorname{text}, thestarred form
\operatorname*{text}, and both land on the sameNucleus::Operator { body, limits }. So the declared route was there -- butamsopn's own worked example set the wrong glyphs:
printing a comma the author never wrote. The cause is not in the operator
machinery: the lexer encodes a control symbol's escape in its span width
(
\,becomesWord(",")spanning two source bytes) andmath::MathParser:: atom,\|and the text kerns all tell\,from a literal comma by thatwidth alone. A token copied out of a macro's replacement text carries the
invocation's span, so the test failed and every
\,\;\!\:inevery
\newcommandbody decayed into the bare character --\DeclareMath Operatorwas only the most visible victim.parser::math_tokenhands math the token's own definition bytes when theyreally are
\<c>(checked against the source text, not just the width).Only the span moves, never the token kind, and
definition/maps_to_invocationare left alone so the expansion-site mapping isuntouched.
Oracle (pdflatex, TeX Live 2025, never in the product path): pdflatex sets
\DeclareMathOperator*{\argmax}{arg\,max}at glyph positions identical tothe written-out
\operatorname*{arg\,max}--argat 133.768,maxat149.436 -- which is the equality this now reproduces.
crates/compilercargo test --release --no-fail-fast: 0 failed; emptyfailing set, so nothing to compare against a control. 6 new tests.
tests/math_operators.rsproved non-vacuous: with theparser.rshunkstashed,
a_declared_operator_keeps_the_math_glue_written_in_its_textandcontrol_symbols_survive_a_macro_bodyboth FAIL.and full diagnostic set byte-identical to a control build of the same base
(
5e6c65be). No fixture uses an undeclared\sgnor a control symbol ina macro body;
math-sheet's\operatorname{sgn}is legal LaTeX andunaffected.
crates/render-pipelineand the amsmath/amssymb oracle corpora readvendor/compiler, not this crate, so they cannot move until an integratorre-pins; none of them is affected by this change either way.
apps/mac/Sources/FlashTeXMac/Resources/supported-latex.jsonis abyte-identical copy of the compiler's inventory -- that is the whole point of
it, and
CompletionTests.testBundledInventoryMatchesTheCompilercompares thetwo by sha256, as does
apps/mac/scripts/sync-supported-latex.sh --checkinmake-app.sh. So this PR must carry the re-synced copy or it turns that gatered; it is produced by that script and is exactly the one deleted row.
That copy is the completion vocabulary
Completion.Vocabularydecodes, sothe concrete user-visible change is: the Mac editor no longer autocompletes
\sgnas a supported command. Accepting that completion used to produce adocument FlashTeX rendered cleanly and pdflatex refused -- the worst failure
shape for an engine whose contract is matching pdflatex.
This is a class of bug, not a one-off. Another lane found the same shape
in
supported.rsfor\rotatebox,\scalebox,\resizeboxand\reflectbox: advertised to the editor as supported when the pipeline neverapplies them.
\sgndiffers only in being undefined everywhere ratherthan defined but not applied; the fix is the same in both cases -- the
inventory must describe what actually happens, because it is API. Those four
are being handled separately.
Also found and left alone: all six real amsmath operators (
\injlim,\projlim,\varinjlim,\varprojlim,\varliminf,\varlimsup) areabsent everywhere, so real amsmath is reported as a typo -- the inverse gap.
amsopn.stydefines them in limits mode and sets\injlimasinj\,lim,so adding them as plain text atoms would produce wrong output; it needs
doing properly.
Implementation-Agent: claude-opus-5 (engine lane, linux-primary/NixOS).
Commit-Executor: claude-opus-5 direct git (Cursor usage-limit fallback).
Co-Authored-By: Claude Opus 5 [email protected]
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu