go-term-latex
go-term-latex renders LaTeX math equations directly in the terminal — no
browser, no GUI, no intermediate files the caller has to manage.
termlatex.Display(os.Stdout, `\int_0^\infty e^{-x^2}\,dx = \frac{\sqrt{\pi}}{2}`, termlatex.Options{})
That one call compiles the equation, converts the result to a tight-cropped PNG, and sends it to the terminal using the best available protocol: Kitty graphics, Sixel, or Unicode half-block characters as a fallback.
How it works
- The equation is wrapped in a minimal
standaloneLaTeX document (amsmath,amssymb,amsfontsincluded). - A TeX backend turns the document into a PDF or DVI:
pdflatex,tectonic, orlatex+dvipng— whichever is installed. - The raster stage converts to PNG:
pdftoppm(from poppler) for PDF backends,dvipngfor the DVI backend. - The PNG is passed to
floatpane/termimagewhich handles protocol selection and escape-sequence encoding.
What this is not
- Not a full TeX runtime. This is a thin Go wrapper around TeX tools you provide. Go has no pure-Go LaTeX math renderer capable of production-quality output; shelling out is the right call for quality.
- Not safe for untrusted input. Even without
-shell-escape, TeX documents can read local files. See Security. - Not a streaming renderer. Each call opens a temp dir, compiles, converts, and cleans up. For a REPL or notebook-style interface, cache the PNG yourself and re-display rather than recompiling on every redraw.
Sister projects
| Project | Role |
|---|---|
| floatpane/termimage | Terminal image display layer (Kitty/Sixel/HalfBlock). |
| floatpane/matcha | Mail client — potential consumer for message previews with embedded math. |