LaTeX Labels¶
cplots handles LaTeX in axis labels, titles, and legend entries across all
backends through the latex_labels flag.
The problem¶
Backends differ in their LaTeX support:
| Backend | LaTeX support |
|---|---|
| matplotlib | Native — renders via TeX or mathtext |
| plotly (HTML) | Via MathJax — requires raw LaTeX strings |
| altair | None — Vega-Lite does not support LaTeX |
A label like r"$k\ [h\,\mathrm{Mpc}^{-1}]$" renders correctly in
matplotlib and plotly (with MathJax) but appears as raw markup in altair.
The solution¶
Set latex_labels=True to pass strings through unchanged:
When latex_labels=False (the default), cplots strips LaTeX to plain
Unicode before passing it to the backend. The stripping logic handles:
- Greek letters (
\alpha→α) - Super/subscripts (
^{-1}→⁻¹,_{m}→ₘ) - Math mode delimiters (
$...$removed) \frac{a}{b}→a/b
strip_latex directly¶
Multi-panel figures¶
Pass latex_labels=True on the Figure to propagate to all panels:
For plotly, pass backend="plotly" to get MathJax rendering in the browser: