GeezerVison is showing github.com — fix(app): render \[...\] LaTeX display math delimiters by simonechecchia · Pull Request #35951 · anomalyco/opencode
Conversation
Issue for this PR
Closes #24426
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
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:
- the marked tokenizer extension (
blockKatex), used for the main JS render path
- the native-parser HTML post-processing fallback (
renderMathInText)
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.ts covering:
- inline
\(...\) and display \[...\] / $$...$$ math on both render paths
- fenced code blocks containing
\[...\]-like text are not touched
- a markdown table with math in cells (the exact shape that triggers CommonMark's backslash-escape stripping)
Ran bun test (all passing) and bun run typecheck (clean) in packages/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
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
1024th reacted with thumbs up emoji
|
The following comment was made by an LLM, it may be inaccurate:
Potential Related PR Found
PR #34642: fix(ui): fallback math rendering for multiline $$ blocks
Why it's related: This PR addresses similar math rendering issues. PR #35951 (current) adds support for \[...\] display math delimiters alongside the existing $$...$$ path. PR #34642 appears to handle fallback math rendering for $$ blocks. Both PRs are improving LaTeX math rendering in the app's UI, specifically in the marked tokenizer and HTML post-processing. You should verify whether #34642 already addresses the \[...\] case or if it's complementary work.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jul 24, 2026
|
Automated PR Cleanup
Thank you for contributing to opencode.
Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.
This PR was closed because it matched the following cleanup criteria:
- The PR was created more than 1 month ago
- The PR had fewer than 2 positive reactions
- Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR
PRs created within the last month are not affected by this cleanup.
If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.
Thanks again for taking the time to contribute.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|