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!;
// Output:
// x²+1
// ────
// y
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:
Output Examples
LaTeX: x^2 + y^2 = z^2
Rendered: x²+y²=z²
LaTeX: \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
Rendered:
-b±√b²-4ac
x=──────────
2a
LaTeX: \sum_{i=1}^n i^2
Rendered:
n
∑ i²
i=1
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