Skip to content

Fix math delimiter and currency handling in chat responses - #136

Open
jlee600 wants to merge 2 commits into
mainfrom
jinseo/katex-math-rendering
Open

jlee600 wants to merge 2 commits into
mainfrom
jinseo/katex-math-rendering

Conversation

@jlee600

@jlee600 jlee600 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Extends the existing KaTeX renderer to handle \(...\), \[...\], and recognizable equations inside bare parentheses/brackets.

Preserves currency such as $50 and $61.75 alongside existing $...$ math. Keeps Markdown formatting, code, links, and suggested questions intact. Malformed math remains readable without breaking the renderer.

File changes

  • src/renderer/src/MessageText.tsx
    Registers the new math plugin alongside the existing Markdown and KaTeX plugins.

  • src/renderer/src/remark-model-math.ts
    Adds delimiter detection and currency handling. Protects code and links, then passes recognized equations to the existing KaTeX pipeline.

  • tests/unit/typescript/message-text.test.mjs
    Updates the test setup to load the plugin and adds six regression tests for delimiters, currency, mixed formatting, code preservation, and malformed input.

No dependency, retrieval, calculation, prompt, or chat history changes.

Validation

  • All 134 TypeScript tests passed.
  • Both typechecks and the production build passed.
  • git diff --check passed.

Before

Screenshot 2026-09-13 at 9 45 00 PM

After

Screenshot 2026-09-13 at 9 55 15 PM

@jlee600 jlee600 changed the title Handle additional math delimiters Fix math delimiter and currency handling in chat responses Sep 15, 2026
@jlee600
jlee600 requested a review from jarulraj September 15, 2026 01:51
}
const value = source.slice(start, end)
// Never turn an expression spanning a code span or link into math.
if (end >= 0 && (!range || end < range[0]) && (explicit || looksLikeMath(value))) {

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.

Would matching bare () and [] be too broad? For example, a model could output (2024–2025) as a year range, which the current heuristic would render as math.

Have we observed model responses using bare delimiters that explicit \(...\), \[...\], and the existing $...$ / $$...$$ support do not cover? If not, I would prefer limiting conversion to explicit delimiters.

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.

3 participants