Repository navigation
Unknown LaTeX control words end at their letters - #12
Merged
Merged
Conversation
simonebortolin
force-pushed
the
claude/latex-unknown-command-space-42f4d4
branch
from
November 8, 2026 14:27
e441dd2 to
0b6574b
Compare
|
|
An unknown control word swallowed the space after it and the reader re-emitted it bare, so UnicodeMath read the next word as part of it: \sgn r became the text \sgnr, a \backslash b lost the b, and strict mode named \sgnr. The LaTeX reader now ends such a word with a space where a letter or digit follows, and text read from LaTeX quotes the word without that space (UnicodeMath itself keeps it, as UnicodeMathML does). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
simonebortolin
force-pushed
the
claude/latex-unknown-command-space-42f4d4
branch
from
November 9, 2026 18:21
0b6574b to
9c542f1
Compare
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.
Depends on 0bebb37 ("Content MathML read through ctop.xsl; amssymb symbols in LaTeX", local branch
claude/content-mathml, not pushed yet). The branch is built on that commit, so this diff includes it until it lands. Retarget or rebase this PR once it does. This PR's own change is the last commit, e441dd2.The bug
When the LaTeX reader met a control word it didn't know, it dropped the space after it and wrote the word back without that space, so UnicodeMath then read the next letters as part of the word:
\sgn r<mtext>\sgnr</mtext><mtext>\sgn</mtext><mi>r</mi>a \backslash b𝑎"\backslashb"(theblost)𝑎,\backslash,𝑏\lg d,\liminf v,\sgn2\foo xUnknown control word \fooxUnknown control word \fooThe fix
LaTeXReader.Convert: an unknown control word is followed by a space only where a letter or digit comes next, the one place where UnicodeMath would otherwise merge them. Elsewhere it gets no space, so\text{\foo}and Word's\textrm{\f }stay stable when read back.UnicodeMathInput.ResolveControlWordstakes a newtexflag, which the translator passes for LaTeX input. With it, an unknown word is quoted without its terminating space ("\sgn", not"\sgn "), since in TeX that space only ends the word. UnicodeMath input keeps the ported behaviour, which the UnicodeMathML corpus checks.This does not add any of the missing commands (
\sgn,\backslash, …); a separate session handles those. Public API is unchanged.[no-new-version].Tests
LaTeXReaderTests.EndsUnknownControlWordsAtTheirLetters(lenient: onemtextwith just the command, then the following letter or digit).RejectsUnknownControlWordsWhenStrictnow covers these cases, and its existing\foo xexpectation is corrected from\fooxto\foo.dotnet test --solution SharpEquations.slnx: 2752 total, 0 failed (net10.0 and net481),RoundTripPropertyTestsincluded.🤖 Generated with Claude Code