Skip to content

fix(ui): render dollar math with marked-katex-extension - #53513

Merged
Brendonovich merged 2 commits into
v2from
desktop-dollar-math
Oct 6, 2026
Merged

Brendonovich merged 2 commits into
v2from
desktop-dollar-math

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #38030

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Desktop has only rendered \(...\) inline math and $$ blocks on their own lines since #34850, so the $...$ and single-line $$...$$ that most models emit show up as raw LaTeX.

  • Uses marked-katex-extension (default mode) for $...$, $$...$$, and $$ blocks, replacing our block regex. Our \(...\) inline extension stays because the package doesn't support that syntax.
  • Its default rules keep prices as text: the opening $ must follow a space or line start, and the closing $ must be followed by a space or punctuation. So "$5 and $10", "$5-$10", and $HOME stay plain.
  • parseSmallMarkdown used to keep text on the main-thread fast path unless it contained \( or $$. That fast path has no math support, so short messages with $x$ would never reach KaTeX. Any text with two or more $ now goes to the worker; a lone $5 stays on the fast path.
  • The streaming block splitter now lexes with the same math extensions. Before, a $$ block containing a blank line was split into separately rendered blocks while streaming.

Known limits of the extension's default mode, captured in tests: tight inline math such as ($x$), $x$-axis, and CJK without spaces (因此$x^2$是) stays raw. A price and math on the same line (Pay $5 now, or $x$ later) can be read as one formula and render as a KaTeX error. \[...\] is still unsupported.

This takes a different approach from #52100.

How did you verify your code works?

  • packages/ui: bun test src/context (111 pass) and bun run typecheck
  • packages/session-ui: bun test src/components/markdown (88 pass) and bun run typecheck; the new stream test fails without the splitter change
  • packages/app: bun run typecheck
  • oxlint on the changed files: no new warnings
  • Checked that inputs which backtrack badly with a naive $ regex (unclosed $ followed by thousands of backslashes) parse in about 13ms

Screenshots / recordings

Not captured in the app; verified at the parser and stream-splitter level.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Requested by: @Brendonovich (Brendan via Slack)

@opencode-agent
opencode-agent Bot force-pushed the desktop-dollar-math branch from c517b36 to 9eb8b67 Compare October 6, 2026 10:36
@Brendonovich
Brendonovich merged commit a7523ac into v2 Oct 6, 2026
20 checks passed
@Brendonovich
Brendonovich deleted the desktop-dollar-math branch October 6, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant