Skip to content

CLI: LaTeX math formulas rendered as raw text instead of being rendered in terminal #34407

Closed as duplicate

Description

@yearzen1

Description

When the LLM returns a response containing LaTeX math formulas (both \$...$\ and \\(...\\)\ formats), the opencode CLI displays them as raw LaTeX source code instead of rendering them as formatted math expressions. For example, instead of seeing a properly rendered fraction \�/b, the terminal shows \\(\\frac{a}{b}\\)\ or \$\\frac{a}{b}$.

Environment

  • Mode: opencode CLI (terminal)
  • Model: opencode zen / DeepSeek V4 Flash Free
  • Platform: Windows 11 (PowerShell 7)
  • OpenCode version: latest

Expected behavior

LaTeX math expressions should be rendered in the terminal (e.g., via Unicode approximations, or a terminal-compatible math renderer). Common approaches used by other CLI tools include:

  1. Converting LaTeX to Unicode (e.g., \\\mu\ → \μ, \\\sum\ → \∑, \x^2\ → \x²)
  2. Using terminal-compatible math rendering libraries (e.g., \sympy\ pretty-print style)
  3. At minimum, instructing the LLM system prompt to avoid LaTeX syntax and use plain Unicode math or ASCII alternatives when in CLI mode

Actual behavior

Raw LaTeX source is displayed verbatim in the terminal, making formulas difficult or impossible to read.

Related issues

Suggested fix

The system prompt for CLI mode should instruct models to output math using Unicode characters or plain-text alternatives instead of LaTeX delimiters, since there is no LaTeX renderer in the terminal. Alternatively, implement a lightweight terminal-side LaTeX-to-Unicode converter.

Activity

  1. github-actions commented on Jun 29, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If the underlying cause or fix would be the same, consider adding to that issue instead.

  2. 3nricoMarinelli commented on Jul 9, 2026

    @3nricoMarinelli

    I have the same issue. Would be great to have LaTeX rendering.

  3. YannikG commented on Jul 20, 2026

    @YannikG

    Harness note (yannik-opencode)

    We tracked this for study/tutor UX: Obsidian-style $…$ / $$…$$ in TUI chat.

    Conclusion: cannot ship a KaTeX chat renderer from an OpenCode plugin pack — TUI plugins have no chat-markdown slot; rendering lives in OpenTUI MarkdownRenderable + OpenCode TextPart.

    Contribution specs we keep in-repo until this lands:

    • OpenTUI: lexer for $/$$ + KaTeX → terminal graphics (Kitty/iTerm-class)
    • OpenCode: wire TextPart + instruct CLI agents to prefer $/$$ over \(...\) / \[...\]

    Until a release documents TUI $/$$ rendering, our harness keeps forbidding those delimiters in chat (Unicode/plain text only; $/$$ for Obsidian notes).

    Happy to align with maintainers if there is a preferred design (flag name, image protocol, inline vs display-only first).

  4. jitinnair1 commented on Jul 22, 2026

    @jitinnair1

    Found this PR in the opentui repo that might address this: anomalyco/opentui#1148

  5. Ondre119 commented on Aug 4, 2026

    @Ondre119

    +1, same pain point here. When the model outputs display math like

    $$O_{new} = O_{old} \cdot \frac{\ell_{old}}{\ell_{new}} \cdot e^{m_{old} - m_{new}} + \frac{1}{\ell_{new}}\sum_{i \in block} e^{x_i - m_{new}} v_i$$
    

    the TUI shows the raw LaTeX source, which is barely readable.

    Proposal: convert LaTeX math to Unicode plain text in the TUI markdown renderer (e.g. a TeX→Unicode pass similar to unicodeit / flatlatex). Example of the desired output:

    O_new = O_old · (ℓ_old / ℓ_new) · e^(m_old − m_new) + (1/ℓ_new) · Σ(i∈block) e^(xᵢ − m_new) · vᵢ
    

    Why this approach:

    • Works in every terminal, no image protocol (Kitty/Sixel/iTerm2) support required — much lower complexity than rendering formulas to images.
    • Covers the most common cases well: sub/superscripts, Greek letters, fractions (as a/b), Σ/∏/∫/√, relation symbols.
    • Complex constructs (matrices, multi-line aligned equations) can gracefully fall back to the raw source.
    • The conversion could happen at render time only, leaving the stored message untouched, so /export and /share still produce the original LaTeX.

    Current workarounds I'm using: an AGENTS.md rule asking the model to emit Unicode math instead of LaTeX, and /export to view in an editor with KaTeX. A built-in render-time conversion would be a much better default.

  6. neriousy commented on Oct 1, 2026

    @neriousy
    Member

    Closing as a duplicate of #40508. Same request: render LaTeX in the terminal UI. Tracking in the V2 TUI issue #40508.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions