Skip to content

fix(ui): require $$ delimiters for markdown math (currency-safe) + document it#200

Merged
diegoscarabelli merged 3 commits into
mainfrom
fix/latex-dollar-delimiter
Jun 6, 2026
Merged

fix(ui): require $$ delimiters for markdown math (currency-safe) + document it#200
diegoscarabelli merged 3 commits into
mainfrom
fix/latex-dollar-delimiter

Conversation

@diegoscarabelli

Copy link
Copy Markdown
Owner

Why

The LaTeX feature in the unreleased v0.5.0 enabled remark-math in the shared Markdown component, 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:

MATH ⚠️  I paid $5 for lunch and $10 for dinner.   → "5 for lunch and 10" became an equation
MATH ⚠️  Prices: $5, $10, $20 each.

What

Set singleDollarTextMath: false so math uses $$…$$ only:

Input Result
$$E = mc^2$$ within a sentence inline math
$$ on its own lines display block
$5, $10, $100 literal currency (safe)
$x$ (single) literal text (no longer math)

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-scoped rehype-slug heading ids.

Tests

Updated Markdown.test.tsx: inline $$…$$, display $$ block, and a currency-safe case ($5/$10 stay literal). Full suite green (1138).

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.
Copilot AI review requested due to automatic review settings June 6, 2026 00:36

Copilot AI left a comment

Copy link
Copy Markdown

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 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-math with singleDollarTextMath: false so 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@diegoscarabelli diegoscarabelli merged commit caf8fde into main Jun 6, 2026
6 checks passed
@diegoscarabelli diegoscarabelli deleted the fix/latex-dollar-delimiter branch June 6, 2026 01:03
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.

2 participants