Conversation
| } | ||
| 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))) { |
Contributor
There was a problem hiding this comment.
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.
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.
Summary
Extends the existing KaTeX renderer to handle
\(...\),\[...\], and recognizable equations inside bare parentheses/brackets.Preserves currency such as
$50and$61.75alongside 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.tsxRegisters the new math plugin alongside the existing Markdown and KaTeX plugins.
src/renderer/src/remark-model-math.tsAdds delimiter detection and currency handling. Protects code and links, then passes recognized equations to the existing KaTeX pipeline.
tests/unit/typescript/message-text.test.mjsUpdates 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
git diff --checkpassed.Before
After