fix(ui): require $$ delimiters for markdown math (currency-safe) + document it#200
Merged
Conversation
remark-math was enabled in the shared Markdown component (chat, modals, artifacts), and single-dollar inline math meant any line with two $ signs (e.g. "I paid $5 and $10") rendered the text between them as an equation. Set singleDollarTextMath: false so math uses $$…$$ only: $$…$$ inside a sentence renders inline, on its own lines renders a display block, and single $ stays literal (currency-safe). Refines the unreleased v0.5.0 LaTeX feature; tests cover inline, display, and the currency-safe case.
Update developer docs (ui.md, artifacts.md) to describe the Markdown wrapper's remark-math/rehype-katex ($$…$$) and viewer-scoped rehype-slug heading ids. Add agent-facing guidance in agents.md so agents author math with $$…$$ (single $ is literal) and use in-page anchor links in markdown artifacts.
There was a problem hiding this comment.
Pull request overview
This PR adjusts the shared UI Markdown renderer so LaTeX math is only parsed with $$…$$ delimiters (disabling single-$ inline math) to prevent currency amounts like $5 and $10 from being misinterpreted as equations across chat, modals, and the artifact viewer.
Changes:
- Configure
remark-mathwithsingleDollarTextMath: falseso only$$…$$renders math. - Update unit tests to cover inline
$$…$$, display$$blocks, and a currency-safety regression case. - Document the delimiter requirement and heading-anchor behavior in agent guidance + UI/artifact docs + changelog.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/ui/components/Markdown.tsx | Disables single-$ text math via remark-math options so currency remains literal. |
| src/ui/components/Markdown.test.tsx | Updates/extends tests to validate $$…$$ inline + display rendering and currency safety. |
| src/server/agents/agents.md | Adds agent-facing guidance on using $$…$$ for math and viewer-scoped anchor links. |
| docs/ui.md | Documents markdown pipeline (GFM + math + KaTeX) and delimiter/heading-id behavior. |
| docs/artifacts.md | Documents markdown artifact rendering features including $$…$$ math and anchor links. |
| CHANGELOG.md | Updates the v0.5.0 entry to reflect the $$…$$-only math delimiter behavior and rationale. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ection Add a Formatting note where the Guide reads about user-facing chat, so the $$…$$ math convention (single $ is literal) and the viewer-only scope of anchor links are discoverable at the point of composing chat, not only in the Artifacts section. Addresses the chat-discoverability gap for the only agent whose chat is user-facing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
The LaTeX feature in the unreleased v0.5.0 enabled
remark-mathin the sharedMarkdowncomponent, so single-dollar inline math is live in chat and modals too. That misparses currency: any line with two$signs renders the text between them as an equation.Verified against the real renderer:
What
Set
singleDollarTextMath: falseso math uses$$…$$only:$$E = mc^2$$within a sentence$$on its own lines$5,$10,$100$x$(single)This keeps math available everywhere (chat + artifacts) while making dollar signs safe. Folded into the unreleased v0.5.0 (no version bump — 0.5.0 hasn't been published).
Docs + agent guidance
So agents actually use it:
src/server/agents/agents.md— tells agents to author math with$$…$$(single$is literal) and use[text](#section)anchor links in markdown artifacts.docs/ui.md,docs/artifacts.md— describe remark-math/rehype-katex ($$…$$) and the viewer-scopedrehype-slugheading ids.Tests
Updated
Markdown.test.tsx: inline$$…$$, display$$block, and a currency-safe case ($5/$10stay literal). Full suite green (1138).