Skip to content

feat: render single-dollar and inline double-dollar LaTeX math with KaTeX - #40878

Closed
Cl-VII wants to merge 1 commit into
anomalyco:devfrom
Cl-VII:feat/web-latex-rendering
Closed

feat: render single-dollar and inline double-dollar LaTeX math with KaTeX#40878
Cl-VII wants to merge 1 commit into
anomalyco:devfrom
Cl-VII:feat/web-latex-rendering

Conversation

@Cl-VII

@Cl-VII Cl-VII commented Aug 6, 2026

Copy link
Copy Markdown

Issue for this PR

Related to #40508 (LaTeX rendering in OpenCode). This PR brings ChatGPT-style single-dollar inline math to the web/desktop rendering pipeline, which already renders KaTeX for \(...\) and block ... but not single $...$.

Type of change

  • New feature

What does this PR do?

The web/desktop markdown pipeline (packages/ui/src/context/marked-parser.tsx) registers KaTeX extensions for \(...\) (inline) and ... (block, own-paragraph). Model replies commonly use single-dollar inline math ( = \beta_0 + \beta_1 x$) and inline ... — both currently render as raw LaTeX source.

This PR adds two marked inline extensions:

  • inlineDollarKatex: renders $...$ via KaTeX
  • inlineDoubleDollarKatex: renders inline (non-own-paragraph) ... via KaTeX

Edge cases handled (with tests):

  • Currency/placeholder protection: today, .02/GB, $ 5 are left untouched
  • Formulas starting with a number still render: (L_{ur}-L_r)\sim\chi^2(Q)$
  • Unclosed $ does not swallow the rest of the text (streaming-safe)
  • Escaped \$ inside math works
  • Formulas do not cross newlines
  • The existing block ... (own-paragraph, display mode) and \(...\) behavior is unchanged

How did you verify your code works?

  • Added 9 unit tests covering rendering, currency guard, unclosed dollar, escaped dollar, newline boundary, number-leading formulas — all pass (bun test packages/ui: 35/35)
  • tsgo --noEmit typecheck passes
  • Verified against a full econometrics lecture note (23 formulas: LPM, Probit/Logit, MLE, delta method, LR/Wald tests): all 23 render as KaTeX with zero leftover $ pairs
  • Streaming check: partially-streamed $... stays as plain text until closed, then renders — no flicker or swallowed text

Screenshots / recordings

N/A (HTML output verified; KaTeX renders mathml + html dual output for accessibility)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on the search results, here are the potentially related PRs:

  1. PR feat: render LaTeX math as Unicode in TUI #40867 - feat: render LaTeX math as Unicode in TUI

    • Related work on LaTeX rendering, but for TUI instead of web/desktop
    • Addresses the same issue domain (LaTeX math display) but in a different UI layer
  2. PR fix(app): render \[...\] LaTeX display math delimiters #35951 - fix(app): render \[...\] LaTeX display math delimiters

    • Earlier fix for LaTeX display math delimiters
    • May be a predecessor to this work
  3. PR fix(ui) latex dollar render #38829 - fix(ui) latex dollar render

    • Appears to be a previous attempt at handling dollar-sign LaTeX rendering
    • Could be related or superseded by this PR

The most relevant is PR #40867, which is recent and addresses LaTeX rendering in a complementary way. The other PRs appear to be historical or related attempts at the same problem.

@Cl-VII

Cl-VII commented Aug 6, 2026

Copy link
Copy Markdown
Author

Closing: conflicts with official design decision #34850 (single-dollar math intentionally disabled). Author requested removal.

@Cl-VII Cl-VII closed this Aug 6, 2026
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.

1 participant