Conversation
The katex extension only recognized \(...\) inline math and block math
requiring newlines right after the opening $$ and before the closing $$.
Most LLM chat output uses $..$ for inline math and single-line $$..$$
for display math, so those formulas currently render as raw source.
Extend the existing extension rather than adding a new one:
- inline: try $..$ after \(...\) fails, with display mode for $$..$$
- block: accept single-line and same-line $$..$$ alongside the existing
newline-delimited form
- start hints: report the earliest $ for inline math and \n$$ for block
math so marked can split paragraphs around glued display math
Currency guards keep money amounts as plain text: the opening $ must
not be followed by whitespace, the closing $ must not be preceded by
whitespace nor followed by a digit, and the content cannot contain $
or newlines ("costs $5 and $10", "$1,000 to $2,000" stay literal).
Unclosed delimiters are left as text; invalid latex renders as an
inline error via the existing throwOnError:false path.
Co-Authored-By: Claude Code <[email protected]>
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
The following comment was made by an LLM, it may be inaccurate: |
3 of 6 tasks
This branch has not been deployed
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.
Issue for this PR
Closes #51725
Type of change
What does this PR do?
The katex extension only recognized
\(...\)inline math and block math requiring newlines right after the opening$$and before the closing$$. Most LLM chat output uses$..$for inline math and single-line$$..$$for display math, so those formulas render as raw source (#51725).This extends the existing extension rather than adding a new one:
$..$after\(...\)fails, with display mode for$$..$$$$..$$alongside the existing newline-delimited form$for inline math and\n$$for block math so marked can split paragraphs around glued display math$..$was dropped in #34850 because the old matcher had no currency guards; this reopens that ruling with the guards it lacked. The opening$must not be followed by whitespace, the closing$must not be preceded by whitespace nor followed by a digit, and the content cannot contain$or newlines — "costs $5 and $10" and "$1,000 to $2,000" stay plain text. Unclosed delimiters are left as text; invalid latex renders as an inline error via the existingthrowOnError: falsepath.Supersedes #52087 (same branch and commits; auto-closed for missing the PR template) and the earlier dev-based #51989.
How did you verify your code works?
On
v2: full suite 34/34 green, typecheck (tsgo) clean.marked-parser.test.tsgrew from 4 to 15 cases: single-$inline (symbol-heavy, CJK inside\text{}), single-line and glued$$blocks, display math inside a paragraph, money amounts staying literal, unclosed delimiters, invalid latex as inline error, dollar signs inside code spans, and plain markdown unaffected.Screenshots / recordings
Textual before/after for the repro from #51725:
The distance is $d_i = \sqrt{(x_i-\bar{x})^\top S^{-1}(x_i-\bar{x})}$.shows the dollar signs and LaTeX source literally.$$E = mc^2$$renders as display math.Checklist