Skip to content

Chat shows LaTeX math as raw text ($...$ / $$...$$ not rendered) #45

Closed

Description

@xiuguangli

Summary

Varro renders Markdown in chat, but LaTeX math is left as plain text. Inline math keeps the $ delimiters and backslash commands, and display math ($$...$$) is shown literally as a normal paragraph. Math-heavy answers (papers, statistics, ML) become hard to read.

Environment

  • Varro: 0.33.15
  • VS Code: 1.121.0
  • OpenCode: v2.0.32
  • OS: Linux 6.8.0-138-generic (x64)

Steps to reproduce

  1. Open a chat session in Varro.
  2. Ask the model to answer with LaTeX, for example: "Write the Gaussian density and a Kalman-style update in LaTeX, using $...$ for inline math and $$...$$ for display math."
  3. Look at the rendered reply. The TeX source is shown verbatim.

A minimal example of the rendered content:

Inline: $\mathcal{N}(\mu_t^{(p)}, \Sigma_t^{(p)})$

$$
\hat\mu_t^{(p)} = A_t^{(p)}\mu_t^{(p)} + b_t^{(p)}, \qquad
\hat\Sigma_t^{(p)} = A_t^{(p)}\Sigma_t^{(p)}(A_t^{(p)})^\top
$$

Actual

The message shows the source text instead of formulas:

  • $\mathcal{N}(\mu_t^{(p)},\Sigma_t^{(p)})$ appears with visible dollar signs;
  • $$\hat\mu_t...$$ appears as a normal paragraph, including \hat, \mu, \Sigma, \qquad, and \top;
  • long display equations wrap mid-expression, which makes them hard to parse.

Chat message showing raw LaTeX delimiters and commands

Expected

  • $...$ renders as inline math.
  • $$...$$ renders as a centered display block.
  • Math inside code spans and fenced code blocks stays literal.
  • Plain currency such as $5 is not interpreted as math.
  • Rendering works offline, follows the current light/dark theme, and respects the existing HTML sanitization/CSP rules.

Additional context

I had a quick look at the source: src/webview/components/MarkdownRenderer.tsx configures marked with GFM and custom renderers, but there is no math extension, and neither KaTeX nor MathJax is a chat dependency (katex only appears as a mermaid override in package.json). So this looks like missing support rather than a regression. A typical fix would be marked-katex-extension with bundled KaTeX CSS/fonts, keeping the generated HTML inside the current sanitizer and CSP rules. I am happy to test a build if that helps.

Activity

  1. koltyakov commented on Oct 22, 2026

    @koltyakov
    Owner

    Thank you @xiuguangli for the feature request and contributing the PR (#46)!

    LaTeX support is a great addition for math-heavy conversations, and I’ve implemented it based on your contribution.

    I integrated the feature manually because review uncovered two parsing cases that needed fixes:

    • Display equations immediately following prose stayed literal unless separated by a blank line.
    • Blank lines inside equations caused the streaming renderer to split the formula.
    • Streaming and performance optimizations.

    Both are now covered by regression tests. I also used KaTeX 0.19.0 with direct Marked integration, since marked-katex-extension currently requires KaTeX below 0.19.

    Inline and display math now render with bundled offline fonts, and wide equations scroll within the chat column. Thanks for the clear examples and for getting this feature started!

    Image Image

    The feature will be published in v0.33.17

  2. koltyakov commented on Oct 22, 2026

    @koltyakov
    Owner

    @xiuguangli the update is published, please check how it works for you.

  3. xiuguangli commented on Oct 23, 2026

    @xiuguangli
    Author

    Thanks @koltyakov for the quick update and for carrying this forward. I appreciate the streaming fixes and the direct KaTeX 0.19 integration.

    I checked 0.33.17. Display math works, but inline math still renders as literal text when it follows Chinese text or punctuation without a space:

    0.33.17 showing raw inline formulas and a rendered display formula

    To reproduce, ask the agent to output:

    下面是一些行内公式:
    
    - 高斯分布:$p(x\mid z)=\mathcal{N}(x;\mu,\Sigma)$
    - Softmax:$\operatorname{softmax}(z_i)=\dfrac{e^{z_i}}{\sum_j e^{z_j}}$
    
    行间公式:
    
    $$
    p(\mathbf{x}\mid\boldsymbol{\mu},\boldsymbol{\Sigma})
    =\frac{1}{(2\pi)^{d/2}|\boldsymbol{\Sigma}|^{1/2}}
    \exp\left[-\frac12(\mathbf{x}-\boldsymbol{\mu})^\top
    \boldsymbol{\Sigma}^{-1}(\mathbf{x}-\boldsymbol{\mu})\right]
    $$

    Adding a space after : makes the inline formulas render. The opening boundary currently accepts whitespace, (, [, {, but not :, ,, 。, ;, !, ?, 、, or CJK text; the closing side already accepts CJK punctuation.

    Thanks again for the fast turnaround.

  4. koltyakov commented on Oct 23, 2026

    @koltyakov
    Owner

    Interesting edge case...

    Before:

    Image

    After:

    Image

    Should be good now.

    Published the update, v0.33.19.

    Happy mathing!

  5. xiuguangli commented on Oct 23, 2026

    @xiuguangli
    Author

    Thanks @koltyakov, confirmed on 0.33.19. The inline formulas from the report now render correctly next to Chinese punctuation and CJK text, and display math still works.

    Appreciate the quick fix and the added regression coverage for CJK boundaries and streaming. This resolves the issue for me.

  6. koltyakov commented on Oct 23, 2026

    @koltyakov
    Owner

    Nice! Thanks for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions