Repository navigation
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 <noreply@anthropic.com>
|
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. |
|
The following comment was made by an LLM, it may be inaccurate: |
|
Please merge this, working with maths is really annoying in the web UI at the moment |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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