Skip to content

fix(app): render \[...\] LaTeX display math delimiters#35951

Open
simonechecchia wants to merge 2 commits into
anomalyco:devfrom
simonechecchia:fix/latex-bracket-delimiters
Open

fix(app): render \[...\] LaTeX display math delimiters#35951
simonechecchia wants to merge 2 commits into
anomalyco:devfrom
simonechecchia:fix/latex-bracket-delimiters

Conversation

@simonechecchia

@simonechecchia simonechecchia commented Jul 8, 2026

Copy link
Copy Markdown

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

Copilot AI review requested due to automatic review settings July 8, 2026 19:10
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jul 8, 2026
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 8, 2026
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Laxtex rendering in opencode web ui

2 participants