Skip to content

V2 TUI: add native Mermaid and LaTeX rendering #40508

Open

Description

@opencode-agent

Summary

Add first-class Mermaid diagram and LaTeX math rendering to the OpenCode V2 TUI.

Mermaid should be the initial priority. LaTeX support should cover both display math and inline math embedded within surrounding prose.

Scope

  • Render fenced Mermaid blocks as diagrams in session content.
  • Render display LaTeX expressions.
  • Render inline LaTeX without forcing the surrounding text onto separate lines.
  • Define clear fallback behavior when rendering is unsupported or fails so the original source remains readable.
  • Preserve normal Markdown/code rendering and avoid interpreting ordinary text, such as currency values, as math.

Architecture

Prefer implementing these features as built-in/internal OpenCode plugins rather than adding them to OpenTUI core. This gives OpenCode first-class support without bloating the lower-level renderer and provides a concrete pressure test for the V2 plugin system.

The current plugin API does not appear to expose TUI session-content render slots/hooks. Track and add the minimum plugin API needed for internal plugins to recognize and render custom session content, with Mermaid and LaTeX as the proving use cases.

Acceptance criteria

  • Mermaid fences render visibly in the V2 TUI, with readable source fallback on failure.
  • Display and inline LaTeX render correctly in the V2 TUI.
  • Inline math composes with text before and after it on the same line where space allows.
  • Rendering works during streaming and after sessions are restored.
  • The implementation documents or demonstrates the internal plugin/content-rendering extension point.
  • Existing Markdown, code blocks, selection, scrolling, and copy behavior continue to work.

Activity

  1. dinoesau commented on Aug 5, 2026

    @dinoesau

    Upvoting this. I ask the agent to diagram code flows and processes all the time, and it reliably emits Mermaid syntax, but the GUI shows the raw fence as text instead of a rendered diagram. I have to copy the source into another tool to actually see it.

    For me the essentials are:

    • Completed mermaid fences render as diagrams in chat.
    • Raw source stays visible during streaming and on parse failure, never a broken or empty block.
    • The copy button still copies the Mermaid source.
    • Re-render on light/dark theme change.

    Worth noting: #3366 was closed as completed but no implementation ever merged (zero merged PRs), and PR #39818 has a draft for desktop/web chat via session-ui. Happy to test once a build is available.

  2. StarryJinda commented on Aug 13, 2026

    @StarryJinda

    This would be very helpful for our workflow. We keep mathematical research notes as Markdown files whose content is standard LaTeX, and assistant responses about those files currently render every formula as raw LaTeX source in the V2 TUI, which makes math-heavy derivations almost unreadable in the terminal.

    Beyond $...$ inline and $$...$$ display math, we would also like support for the common LaTeX display environments our documents use — \begin{equation} ... \end{equation}, align/aligned, gather, multline, and cases — ideally rendered with their expected alignment (e.g. multi-line align at the & points). If only a subset is feasible at first, fine, as long as unrecognized blocks fall back to the untouched source, since the raw LaTeX is still compilable and we copy it into documents. Thanks for tracking this!

  3. dinoesau commented on Aug 19, 2026

    @dinoesau

    You'll be glad to know that Mermaid support is now active in OpenCode v2. At least to some extent!

    It is still in beta, though.
    https://opencode.ai/v2/docs

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions