Skip to content

parse: \char typesets a character by code, instead of dropping the formula - #9

Merged
tannevaled merged 2 commits into
mainfrom
math-char
Sep 1, 2026
Merged

parse: \char typesets a character by code, instead of dropping the formula#9
tannevaled merged 2 commits into
mainfrom
math-char

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

What

\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 (setting aside per-document user macros).

How

\char now 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 a tCtrl whose text is the character);
  • "<hex> — hexadecimal;
  • a plain decimal run.

Unparseable input remains a normal error, exactly as before.

Verification

  • New census-driven test: the corpus form \char`\^ plus the backtick-char, hex and decimal forms all render in both inline and display styles.
  • Full go-tex/math suite, go vet, gofmt all clean.

Part of a worst-first math-drop robustness pass (biblio: TeX82 \char). A follow-up will bump the engine's go-tex/math dependency so the 11 papers recover end-to-end.

🤖 Generated with Claude Code

tannevaled and others added 2 commits September 1, 2026 16:19
…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>
@tannevaled
tannevaled merged commit ab0f909 into main Sep 1, 2026
11 checks passed
@tannevaled
tannevaled deleted the math-char branch September 1, 2026 14:27
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.

1 participant