fix(app): render \[...\] LaTeX display math delimiters#35951
fix(app): render \[...\] LaTeX display math delimiters#35951simonechecchia wants to merge 2 commits into
Conversation
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PR FoundPR #34642: Why it's related: This PR addresses similar math rendering issues. PR #35951 (current) adds support for |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
There was a problem hiding this comment.
Pull request overview
This PR fixes LaTeX display-math rendering for \[...\] delimiters in the UI markdown pipeline, aligning with common model output conventions and preventing CommonMark backslash-escape from mangling intended math blocks.
Changes:
- Extend math rendering to treat
\[...\]as display math alongside existing$$...$$support. - Update the Marked tokenizer extension to recognize
\[...\]as a block KaTeX token. - Add unit tests covering both render paths, code-fence non-interference, and the reported issue repro.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/ui/src/context/marked.tsx | Adds \[...\] display-math handling in both the HTML post-processing renderer and the Marked block tokenizer path. |
| packages/ui/src/context/marked.test.ts | Adds coverage for inline + display math across both parsing paths, including code-fence safety and issue repro. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Issue for this PR
Closes #24426
Type of change
What does this PR do?
Model output often uses
\(...\)/\[...\]for LaTeX math instead of$...$/$$...$$. Inline\(...\)was already handled by the existing katex tokenizer, but\[...\]was not, so it fell through to CommonMark's backslash-escape rule (which strips\[and\]to plain[/]) and rendered as mangled text instead of math.I added a
\[...\]block-math path alongside the existing$$...$$one, in both places math is currently handled:blockKatex), used for the main JS render pathrenderMathInText)Code fences and inline code spans are left untouched in both paths (verified in tests).
How did you verify your code works?
Added unit tests in
packages/ui/src/context/marked.test.tscovering:\(...\)and display\[...\]/$$...$$math on both render paths\[...\]-like text are not touchedRan
bun test(all passing) andbun run typecheck(clean) inpackages/ui.Screenshots / recordings
Not a UI change (no new components/styles), just extends the existing katex delimiter handling in
packages/ui/src/context/marked.tsx.Checklist