mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-05 18:38:17 -05:00
[GH-ISSUE #23526] bug: balanced $$...$$ LaTeX display math is parsed unreliably and stray $$ can disrupt message rendering #20004
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @asf0 on GitHub (Apr 9, 2026).
Original GitHub issue: https://github.com/open-webui/open-webui/issues/23526
Check Existing Issues
Installation Method
Git Clone
Open WebUI Version
v0.8.12
Ollama Version (if applicable)
llamacpp 8703, models tested, Qwen3.5 35B, Gemma4 31B
Operating System
Ubuntu 25.10/Win11/Macos Sequoia
Browser (if applicable)
No response
Confirmation
README.md.Expected Behavior
...display math should always render correctly in chat messages....display math should render correctly.Actual Behavior
...display math is parsed unreliably and may fail to render.Steps to Reproduce
Paste the following prompt exactly as written into the chat input and submit it:
Solve these briefly and show your work using the math formatting you would normally use.
If a graph has
|E| = 58, what is the sum of all vertex degrees?Use the Handshaking Lemma to explain why
\sum \deg(v) = 2|E|.Compute
2 \times 58and explain the result.Suppose 5 vertices have degree 4, 6 vertices have degree 5, and 7 vertices have degree 6. Compute
din92 + 8d = 116.Write the final conclusion in one sentence using inline math like
d=3and|E|=58.Also restate this identity on its own line:
[
\sum_{v \in V} \deg(v) = 2|E|
]
Finally, include one more display equation in this exact style:
x^2 + y^2 = z^2Wait for the model response and inspect the rendered message output.
5. Check the rendering of:
|E| = 58andd=3\sum \deg(v) = 2|E|...x^2 + y^2 = z^2Logs & Screenshots
Without fix applied.
With fix applied.

Additional Information
The issue appears to be in the frontend markdown/math parsing pipeline rather than in KaTeX itself. Open WebUI uses a custom markdown tokenizer for math before content reaches the KaTeX renderer, and balanced "$
...$" segments are not beinghandled robustly in all cases, especially with multiline display math or delimiter-adjacent text. Unmatched or malformed delimiters can also propagate through the renderer path instead of being left as plain text, which suggests the tokenizer
is passing unstable math segments downstream rather than normalizing or rejecting them safely before KaTeX rendering.
@tjbck commented on GitHub (Apr 12, 2026):
Addressed in dev.
@asf0 commented on GitHub (Apr 12, 2026):
Glad to see this addressed. This matches the tokenizer approach I proposed in my PR (#23528).