Render readable LaTeX in OpenCode v2 terminal conversations.
opencode-latex has two coordinated parts:
- The server plugin teaches agents to use compact Unicode for simple inline math and fenced
latexblocks for longer expressions. - The TUI plugin renders those blocks with
opentui-maththrough OpenTUI's image pipeline.
Graphical output uses Kitty graphics in terminals such as Ghostty and Kitty, or SIXEL in compatible xterm.js terminals such as obsidian-opencode. Other terminals and multiplexers receive a selectable Unicode-cell fallback.
Note
This is an initial 0.1.x release. Kitty output preserves real PNG transparency. SIXEL output is composited against the covered OpenTUI cell backgrounds because SIXEL cannot reproduce Kitty's alpha compositing exactly.
- OpenCode v2
- A terminal with Kitty graphics or SIXEL for graphical output
- No external TeX installation; MathJax performs the rendering
Install the package globally through OpenCode:
opencode plugin add opencode-latex@0.2.0Alternatively, add it to opencode.jsonc:
The package's ./tui companion is loaded automatically by the OpenCode v2 CLI. Restart OpenCode after installing or updating the package.
For local development, configure the repository path instead:
{
"$schema": "https://opencode.ai/config.json",
"plugins": ["/absolute/path/to/opencode-latex"]
}Ask OpenCode a math-heavy question normally. The plugin's server instruction tells the agent when to use Unicode inline math and when to emit a rendered block.
To test the renderer directly, send a fenced block:
```latex
\frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
```Long derivations should use compact rows:
```latex
\begin{aligned}
I^2 &= \int_0^{2\pi}\int_0^\infty e^{-r^2}r\,dr\,d\theta \\
&= 2\pi\left[-\frac12 e^{-r^2}\right]_0^\infty \\
&= \pi
\end{aligned}
```Use the latex fence exactly; this plugin registers that language without replacing other Markdown renderers.
Open the command palette with Ctrl+P and select LaTeX: Set default render mode, or run:
/latex-render-mode
Choose automatic graphics detection, forced Kitty graphics, or portable Unicode cells. The selection is saved across TUI restarts and applies whenever formulas are rendered. Choose Use configured default to return to the graphicsMode value from plugin configuration.
Options are optional:
{
"plugins": [
{
"package": "opencode-latex@0.2.0",
"options": {
"color": "#d4d4d4",
"graphicsMode": "auto",
"fontSize": 20,
"pixelRatio": 2
}
}
]
}colorsets the equation foreground. Its default follows OpenCode's light or dark theme.graphicsModeselects"auto", forced"kitty", or portable"cells"rendering. The default is"auto"; a saved command-palette selection overrides it until Use configured default is selected.fontSizesets the graphical MathJax font size. The default is20.pixelRatioincreases raster sharpness without changing the intended cell footprint. The default is2.
If startup reports Markdown code-block renderer already registered: latex, the plugin is loaded more than once. Remove the older local copy or duplicate config entry, then restart OpenCode. Check both the global ~/.config/opencode/plugins/ directory and project .opencode/plugins/ directories.
The fallback source renderer appears when a formula is invalid or graphical rendering fails. Each TeX command should use one backslash; only aligned or matrix row breaks use two.
Leave graphicsMode on "auto". OpenTUI will use Kitty, then SIXEL when current pixel geometry is available, then Unicode cells. tmux and terminals without a supported graphics protocol normally use the cell fallback.
bun install
bun run check
npm pack --dry-runThe narrow opentui-math transport fork is in src/opentui-math.ts. It keeps upstream MathJax rasterization and Unicode fallback while routing graphical placement, cleanup, terminal zoom, and SIXEL background compositing through the host OpenTUI runtime.
MIT
{ "$schema": "https://opencode.ai/config.json", "plugins": ["opencode-latex@0.2.0"] }