parse: \char typesets a character by code, instead of dropping the formula - #9
Merged
Conversation
…rmula \char is a TeX primitive that typesets the character at a code point. It reaches the math layer mostly through macro expansion — \char`\^ for a literal caret is the commonest form — so an unknown \char dropped the *whole* enclosing formula. In the 200-paper arXiv census it is the top structural math-drop cause by document count: 11 papers, 118 occurrences. \char now parses the TeX number forms that reach math — `<char> and `\<sym> (the code point of that one character; the tokenizer turns a control symbol like \^ into a tCtrl whose text is the character), "<hex>, and a decimal run — and emits the glyph at that code point. Unparseable input is a normal error, as before. Verified: the corpus form \char`\^ and the hex/decimal/backtick-char forms all render in both inline and display styles; full suite, go vet and gofmt clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The first test exercised the happy paths; add the rejecting paths (no number, non-digit, a lone or dangling backtick, a superscript after the backtick, an empty control name, above-U+10FFFF and int32-overflow codes) and a hex form with letters, so parseCharCode and isBaseDigit are fully covered and the coverage gate holds. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Sep 1, 2026
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.
What
\charis a TeX primitive that typesets the character at a code point. It reaches the math layer mostly through macro expansion —\char`\^for a literal caret is the commonest form — so an unknown\chardropped the whole enclosing formula. In the 200-paper arXiv census it is the top structural math-drop cause by document count: 11 papers, 118 occurrences (setting aside per-document user macros).How
\charnow parses the TeX number forms that reach math and emits the glyph at that code point:`<char>and`\<sym>— the code point of that one character (the tokenizer turns a control symbol like\^into atCtrlwhose text is the character);"<hex>— hexadecimal;Unparseable input remains a normal error, exactly as before.
Verification
\char`\^plus the backtick-char, hex and decimal forms all render in both inline and display styles.go-tex/mathsuite,go vet,gofmtall clean.Part of a worst-first math-drop robustness pass (biblio: TeX82
\char). A follow-up will bump the engine'sgo-tex/mathdependency so the 11 papers recover end-to-end.🤖 Generated with Claude Code