term-maths
Character-grid mathematical notation renderer for terminals, implemented in Rust.
Accepts LaTeX math input and renders it as 2D Unicode character art in a terminal. Targets JuliaMono as the recommended font for full Unicode math symbol coverage.
Available as both a Rust crate and a Python package (via PyO3 + Maturin).
Rust Usage
Add to your Cargo.toml:
[]
= "0.1"
Render a LaTeX expression:
let block = render;
println!;
Output:
a
───
b
Python Usage
Requires a Rust toolchain and maturin:
=
# a
# ───
# b
# Compose blocks side-by-side (baseline-aligned)
=
=
=
# Unicode math fonts
# ℕℤℚℝℂ
# LaTeX round-trip
See python/examples/ for more: render_demo.py, dsp_equations.py,
block_composition.py, and math_fonts.py.
Rendering Examples
All output below is produced directly by the library.
Fractions and Arithmetic
a
───
b
1
─────────
1
1 + ───
x
────────
-b ± √b² - 4ac
────────────────
2a
Superscripts, Subscripts, and Inline Unicode
x^2 → x²
a_n → aₙ
x_i^2 → x²ᵢ
a + b = c → a + b = c
x^2 + y^2 → x² + y² = z²
Big Operators with Limits
N - 1
∑
n = 0
1
⌠
⎮
⌡
0
n
∏
i = 1
DSP Reference Equations
2π
-j ──── kn
N - 1 N
X[k] = ∑ x[n] ·e
n = 0
∞
⌠
(f · g)(t) = ⎮ f(τ) g(t - τ) dτ
⌡
-∞
b₀ + b₁ z⁻¹ + b₂ z⁻²
H(z) = ──────────────────────
1 + a₁ z⁻¹ + a₂ z⁻²
⎛ ⎛ 2πn ⎞⎞
w(n) = 0.5 ⎜1 - cos⎜───────⎟⎟
⎝ ⎝ N - 1 ⎠⎠
Matrices
⎛a b⎞ ⎡1 0⎤ │a b│
⎝c d⎠ ⎣0 1⎦ │c d│
⎡1 2 3⎤
⎢4 5 6⎥
⎣7 8 9⎦
⎛ 1 ⎞
⎜─── 0 ⎟
⎜ 2 ⎟
⎜ 3 ⎟
⎜ 0 ───⎟
⎝ 4 ⎠
Delimiters, Sqrt, and Accents
⎛ a ⎞
⎜───⎟
⎝ b ⎠
───
│ a
│───
√ b
‾‾‾‾‾
x + y
Math Fonts (Unicode Mathematical Alphanumeric Symbols)
\mathbb{R} → ℝ
\mathbb{Z} → ℤ
\mathcal{L} → ℒ
\mathbf{x} → 𝐱
\mathfrak{g} → 𝔤
\mathbb{R}^n → ℝⁿ
Output Backends
Core (always available):
- Plain text via
render()andDisplay - LaTeX round-trip via
to_latex()
Optional (feature-gated):
[]
= { = "0.1", = ["crossterm", "ratatui"] }
| Feature | Backend | Description |
|---|---|---|
crossterm |
CrosstermRenderer |
Direct terminal output with cursor positioning |
ratatui |
MathWidget |
TUI widget implementing ratatui::Widget |
python |
PyO3 extension | Python bindings (maturin build --features python) |
Crossterm
use ;
let block = render;
print_at?;
Ratatui
use ;
let block = render;
let widget = new;
widget.render;
LaTeX Round-Trip
let latex = to_latex;
// "x^{2} \;+\; y^{2}"
Font Recommendation
For best results, use JuliaMono. It provides complete coverage of:
- Mathematical Alphanumeric Symbols (U+1D400-U+1D7FF) for bold, italic, script, fraktur, double-struck, sans-serif variants
- Box-drawing and bracket piece characters for delimiters and integrals
- Full Greek alphabet and mathematical operators
- Superscript/subscript digits and letters
Other monospace fonts will work but may show fallback glyphs for some mathematical symbols.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.