tui-math
Render LaTeX math beautifully in terminal UIs with ratatui.

Features
- LaTeX to Unicode terminal rendering
- MathML intermediate format support
- Native ratatui widget
- Unicode superscripts/subscripts when possible
- 2D rendering for fractions, roots, big operators
- Greek letters and mathematical symbols
Installation
[]
= "0.1"
Usage
Simple rendering
use render_latex;
let rendered = render_latex?;
println!;
As a ratatui widget
use MathWidget;
use Block;
let widget = new
.block;
frame.render_widget;
Stateful widget for caching
use ;
// Create state once
let mut state = new;
state.update;
// Render multiple times without re-parsing
let widget = new;
widget.render;
Examples
Run the interactive demo:
Or the simple CLI example:
Rendering Examples
| Formula | Screenshot |
|---|---|
Integral: \int_0^\infty e^{-x^2} dx = \frac{\sqrt{\pi}}{2} |
![]() |
Sum: \sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6} |
![]() |
Derivative: \frac{d}{dx} x^n = nx^{n-1} |
![]() |
Euler: e^{i\pi} + 1 = 0 |
![]() |
Fraction: \frac{a + b}{c + d} |
![]() |
Square Root: \sqrt{x^2 + y^2} |
![]() |
Supported LaTeX
- Basic math:
+,-,*,/,=, etc. - Superscripts:
x^2,e^{i\pi} - Subscripts:
a_1,x_{ij} - Fractions:
\frac{a}{b} - Square roots:
\sqrt{x},\sqrt[3]{x} - Greek letters:
\alpha,\beta,\Gamma, etc. - Big operators:
\sum,\prod,\int,\oint - Relations:
\leq,\geq,\neq,\equiv, etc. - Arrows:
\rightarrow,\Rightarrow,\leftrightarrow - Functions:
\sin,\cos,\log,\lim, etc. - Delimiters:
\langle,\rangle,\lceil,\rfloor
How it works
- LaTeX → MathML via
latex2mathml - MathML parsed with
roxmltree - Rendered to 2D character grid (MathBox)
- Unicode characters used where possible
- Integrated with ratatui's Widget trait
License
MIT





