You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: An unescaped % in a LaTeX formula leaves the whole equation as raw source #29493
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.
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 @ 8657eec. 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{}.
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.
Supersedes the earlier request-changes assessment: the author merged our reviewed multiline/linear-scan/test-completion correction from meutex#2 into #29511 at ff2604b. 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.
Activity
meutex commentedon Nov 2, 2026
Hi! I'd like to work on this issue. I'll investigate the math rendering fallback in
MathTypeset.tsxand work on a fix to handle unescaped%characters in LaTeX formulas. I'll share a PR once I have it ready.ElliotDrel commentedon Nov 4, 2026
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 meutex#2 into #29511 at ff2604b. 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.