Math in Labels

Any label — plot title, axis labels, TextPlot markdown bodies — may embed math inside $...$ using LaTeX-ish syntax. Math regions are lowered to inline Unicode text at render time: zero dependencies, no feature flag, always on, in every backend including the terminal.

#![allow(unused)]
fn main() {
Layout::new((0.0, 3.0), (0.0, 10.0))
    .with_x_label("$\\log_2$ fold change")
    .with_y_label("$-\\log_{10}(p)$")
    .with_title("Differential expression ($\\alpha = 0.05$)");
}

A literal dollar sign is written \$. A $ without a closing partner is left untouched as plain text.

Quick examples

InputOutput
$\sigma^2$σ²
$x_i$xᵢ
$\mu \pm \sigma$μ ± σ
$a \leq b \cdot c$a ≤ b · c
$\frac{a+b}{c}$(a+b)/c
$\sqrt{x^2+y^2}$√(x²+y²)
$\sum_{i=1}^{n} x_i$∑ᵢ₌₁ⁿ xᵢ
$-\log_{10}(p)$-log₁₀(p)
$\sin(\theta)$sin(θ)
$\exp(-t)$exp(-t)
$f \circ g$f ∘ g

Supported syntax

Greek letters

Both cases: \alpha\omega (lowercase) and \Gamma, \Delta, \Theta, \Lambda, \Xi, \Pi, \Sigma, \Phi, \Psi, \Omega (uppercase). Variants: \varepsilon → ε, \varphi → φ.

Operators, relations, arrows

\pm ±, \mp ∓, \times ×, \cdot ·, \div ÷, \circ ∘, \leq ≤, \geq ≥, \neq ≠, \approx ≈, \equiv ≡, \sim ∼, \propto ∝, \ll ≪, \gg ≫, \in ∈, \notin ∉, \subset ⊂, \cup ∪, \cap ∩, \infty ∞, \partial ∂, \nabla ∇, \degree °, \angle ∠, \forall ∀, \exists ∃, \ldots …, \cdots ⋯, \sum ∑, \prod ∏, \int ∫, \to/\rightarrow →, \leftarrow ←, \Rightarrow ⇒, \Leftarrow ⇐, \leftrightarrow ↔.

Operator names

Standard LaTeX function names pass through as plain text — their arguments and subscripts lower normally:

CommandOutputTypical use
\loglog$\log_{10} x$ → log₁₀ x
\lnln$\ln(n)$ → ln(n)
\expexp$\exp(-t)$ → exp(-t)
\sinsin$\sin(\theta)$ → sin(θ)
\coscos$\cos(\phi)$ → cos(φ)
\tantan$\tan(\alpha)$ → tan(α)
\arcsinarcsin$\arcsin(x)$ → arcsin(x)
\arccosarccos
\arctanarctan
\minmin$\min(a,b)$ → min(a,b)
\maxmax
\limlim$\lim_{x \to 0}$ → lim_(x → 0)
\limsuplim sup
\liminflim inf
\supsup
\infinf(infimum, not infinity — use \infty for ∞)
\argarg
\detdet
\dimdim
\kerker
\gcdgcd
\lcmlcm
\PrPr
\degdeg

Superscripts and subscripts

^ and _ take a single character or a {...} group. These are all-or-nothing: every character in the group must have a Unicode super/subscript form, otherwise the whole group falls back to a clean x^(…) or x_(…) — never a half-substituted mix.

x^2       → x²         (digit, maps cleanly)
x^{2n}    → x²ⁿ        (both have superscript forms)
x^{2q}    → x^(2q)     (q has no superscript — clean fallback)
x_i       → xᵢ
x_{i+1}   → xᵢ₊₁

Braceless command operands work too: x^\alpha → x^(α), x_\beta → x_(β).

Fractions and radicals

\frac{a}{b}a/b; multi-term parts are parenthesised: \frac{a+b}{c}(a+b)/c. Rendering is always inline — the output is plain text that flows anywhere a label can go, including rotated y-axis titles and terminal grids.

\sqrt{x}√x, \sqrt{x+y}√(x+y), \sqrt[3]{x}³√x.

Plot examples

Generated by cargo run --example math:

Scientific axes

$\log_2$ fold change / $-\log_{10}(p)$ — the standard RNA-seq and GWAS axis pair:

log2 fold change vs -log10(p) axes

Trigonometric labels

$\sin(\theta)$ in the title and y-axis label:

sin(theta) line plot

Exponential decay

$\exp(-t)$ on the y-axis:

exp(-t) decay curve

Greek letters and symbols

$\mu \pm \sigma$ on the x-axis:

Greek letters in an axis label

Superscripts

$x^2 + y^2 = r^2$ as the x-axis label:

Superscripts in an axis label

Fractions

$\frac{a+b}{c}$(a+b)/c:

Fraction in an axis label

Square root

$\sqrt{x^2+y^2}$√(x²+y²):

Square root in an axis label

Summation with limits

$\sum_{i=1}^{n} x_i$∑ᵢ₌₁ⁿ xᵢ:

Summation with limits

Quadratic formula

$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$x = (-b ± √(b² - 4ac))/(2a):

Quadratic formula in an axis label

Mixed text and math

Mixed text and math in labels

Rotated y-axis title

Energy $E = mc^2$ — math works in rotated labels too:

Math in a rotated y-axis title

CLI

Math works in any label flag — no extra flags needed:

kuva scatter data.tsv \
    --x log2fc --y neg_log10_pvalue \
    --x-label '$\log_2$ fold change' \
    --y-label '$-\log_{10}(p)$' \
    --title 'Differential expression ($\alpha = 0.05$)' \
    -o volcano.svg

The same labels render in the terminal backend with --terminal — the lowered Unicode lands directly on the character grid.

Shell quoting

$ and \ are special characters in most shells. Single quotes are the simplest way to pass math labels literally — the shell treats everything between '...' as plain text:

--x-label '$\log_2$ fold change'   # single quotes: $ and \ are literal

If you need to interpolate a shell variable into a label that also contains math, mix quote styles:

SAMPLE="$(basename "$file" .tsv)"
--title '$\sigma^2$ for '"$SAMPLE"
#        ^^^^^^^^^^^^^^^^ literal  ^^^^^^^^^ variable expands

Or use double quotes and escape both $ and \:

--title "\$\\sigma^2\$ for $SAMPLE"
#        \$ → $,  \\ → \,  $SAMPLE → expands

On Windows (cmd.exe / PowerShell), $ and \ have no special meaning in double-quoted strings, so no escaping is needed:

kuva scatter data.tsv --x-label "$\log_2$ fold change"