Hi! I'd like to work on this issue. I'll investigate the math rendering fallback in MathTypeset.tsx and work on a fix to handle unescaped % characters in LaTeX formulas. I'll share a PR once I have it ready.
[Bug]: An unescaped % in a LaTeX formula leaves the whole equation as raw source#29493
Note
🤖 Claude Opus 5.5 responding on behalf of Elliot
Before submitting
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area
apps/web (the same message on apps/mobile is unverified)
Root cause
An unescaped % makes KaTeX reject the whole formula, and the chat then shows the entire equation as raw TeX.
Models write % in prose-like labels such as \text{3.18% dividend yield}. TeX treats % as a comment, even inside \text{}, so the rest of that line is discarded, including the closing }}. KaTeX then throws Unexpected end of input in a macro argument.
apps/web/src/components/chat/MathTypeset.tsx calls KaTeX with throwOnError: true, catches the error, and renders MarkdownMath's source fallback. That fallback was built for unfinished formulas during streaming, so a completed message stays raw permanently, with no sign that one character caused it.
Steps to reproduce
- Turn on Settings → Appearance → Render math.
- Render an assistant message containing:
| 1 | \[ |
| 2 | R_e=\underbrace{\frac{1.0176}{32}}_{\text{3.18% dividend yield}} |
| 3 | +\underbrace{6\%}_{\text{growth}} |
| 4 | =\boxed{9.18\%} |
| 5 | \] |
Expected behavior
The equation typesets, with the % displayed as a literal percent sign.
Actual behavior
The whole equation displays as raw TeX. An earlier display equation in the same message, which writes 3.18\%, renders correctly.
KaTeX 0.16.47 with the options from MathTypeset.tsx:
| Input | Result |
|---|---|
| Equation above, as emitted | ParseError: Unexpected end of input in a macro argument, expected '}' |
Same equation with 3.18\% | Renders |
Impact
Minor bug or occasional failure
Version or commit
Code inspected at main @ 8657eecb. Math rendering was added in #18735.
Environment
Windows 11, Codex gpt-6.1-sol
Suggested fix
Keep the first KaTeX parse unchanged. If it fails, retry once with every unescaped % escaped, and fall back to source only if the retry also fails. Valid TeX comments keep working because the retry only runs on formulas that already failed, and the copied source stays as authored.
The retry result should go through the existing typesetCache, so a failed formula is not parsed twice on every remount.
Mobile renders through native Enriched Markdown and RaTeX rather than this code path, so it needs its own check. This fix has not been implemented or tested in the app.
Workaround
Tell the agent to always write \% in math, including inside \text{}.
Note
🤖 gpt-6.1-sol responding on behalf of Elliot
Supersedes the earlier request-changes assessment: the author merged our reviewed multiline/linear-scan/test-completion correction from https://github.com/meutex/t3code/pull/2 into https://github.com/pingdotgg/t3code/pull/29511 at ff2604b060c4d22daf1cf53b9a6ae0e56add3d24. I verified the merge ancestry and incorporated source; eight required checks pass on this head. One older addressed review thread still awaits repository-authorized resolution; the multiline thread is resolved. The upstream PR is open, so this issue should remain open until that implementation lands. Native mobile and a repeated real-client pass by this agent are not verified.