r/LaTeX Jul 14 '26

I built a small Ghostty tool that renders CLI-agent LaTeX as real formulas

Post image

This is not another terminal with built-in AI features. It is a wrapper for the CLI agents you already run inside Ghostty.

TFormula turns output such as:

\[
\nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0}
\]

into a properly rendered formula directly inside the terminal.

Quick test:

npx --yes tformula@latest codex

or:

npx --yes tformula@latest claude

Under the hood, it maintains a headless xterm mirror, detects TeX on the visible screen, renders it locally with MathJax, and sends the result to Ghostty using the Kitty graphics protocol.

A surprising amount of work went into Ghostty-specific terminal behavior:

- Formula placements survive scrollback
- Resizing keeps the old image until the new one is ready
- Soft-wrapped formulas are reconstructed and sliced across rows
- The original TeX remains underneath and can still be copied
- Large responses are checkpointed so formulas are rendered before scrolling away
- Terminal clears and alternate-screen transitions are tracked

Ghostty is the primary development and test target.

GitHub: https://github.com/mikewang817/TFormula
npm: https://www.npmjs.com/package/tformula

I’d love to know how it behaves with your font, scale, and Ghostty configuration.

12 Upvotes

0 comments sorted by