Skip to content

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

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions