TikZ and pgfplots to SVG and PNG.
No TeX install. JavaScript, Python, Rust or the terminal.
tikra reads the figure, draws paths, nodes and plots itself and typesets the math in labels with mathra. The banner above was drawn just now, in your browser, from docs/banner.tex.
What tikra does, from one command to pgfplots, diagrams and the figure in words. Every drawing and description in it is tikra's real output.
One small library, the same output everywhere: JavaScript, Python, Rust and the terminal.
No LaTeX, no system fonts, no external process. A single binary, a wheel, an npm package or a crate.
Labels are typeset by mathra in Latin Modern Math, TeX's own Computer Modern, embedded, so they look the same on every machine.
What tikra does not understand (an unknown command, environment or option) is listed as a warning, and the rest of the figure is drawn.
Mean time to draw a corpus figure, measured in this page. The same input always writes the same bytes.
Every example of the TikZ and pgfplots manuals, drawn by TeX and by tikra, and compared figure by figure. The full report.
Of the figures a converter can reproduce, the share tikra draws as TeX does.
Of every figure of the manuals, the share that matches TeX's drawing.
Figures no converter can reproduce: random numbers TeX draws anew on every run, an image file or external program, the day's date. The list, checked by eye.
A few figures of corpus/, drawn live on this page. Click one to open it in the playground, or see them all in the gallery.
Pick your platform. All four packages run the same core, so a figure gives the same SVG, byte for byte, wherever it is converted.
Node, bundlers (Vite, webpack, esbuild) and browsers. Types included.
npm install @mathlabs/tikra
import { init, tikzToSvg, render, png } from "@mathlabs/tikra";
await init(); // browsers and bundlers; Node needs nothing
const svg = tikzToSvg(String.raw`\tikz \draw (0,0) circle (1);`);
const { warnings, alt, description } = render(code); // and the figure in words
const bytes = png(svg, { dpi: 300 });
Python 3.9 and later, wheels for Linux, macOS and Windows. Types included.
pip install tikra
import tikra
svg = tikra.tikz_to_svg(r"\tikz \draw (0,0) circle (1);")
open("figure.png", "wb").write(tikra.png(svg, dpi=300))
tikra.render(code)["warnings"]
tikra.render(code)["description"] # the figure in words
One binary: a .tex file or stdin to SVG or PNG.
cargo install tikra-cli
tikra figure.tex -o figure.svg tikra figure.tex -o figure.png --dpi 300 tikra figure.tex -o figure.png --transparent cat figure.tex | tikra --warnings tikra figure.tex --describe
The core itself, for servers and native apps. API docs on docs.rs.
cargo add tikra
let out = tikra::convert(code)?;
std::fs::write("figure.svg", &out.svg)?;
std::fs::write("figure.png", tikra::png(&out.svg, 300.0, true)?)?;
A full standalone document, a bare tikzpicture, an inline \tikz, a lone axis environment, or loose TikZ statements. The preamble is read for \definecolor, \colorlet, \tikzset and \usetikzlibrary; TikZ escaped twice or for Markdown is repaired, with a warning.
\draw, \fill, \filldraw, \path, \node, \coordinate, \clip, \foreach, scopes with transformations, \def, \pgfmathsetmacro, styles, xcolor mixes, positioning and calc, every path operation (--, |-, to[out=,in=], bend, .. controls .., rectangle, circle, ellipse, arc, grid, plot), node shapes and anchors, arrow tips, dashes, opacity, and the libraries: decorations, matrices, pics, trees, graphs, chains, mind maps, circuits, shadings, fadings, patterns, spy, data visualization, and pgfplots (2D and 3D axes, legends, colorbars, colormaps, polar, ternary, Smith charts, fill between). The full list is in spec/subset.md.
100,000 statements per figure, 64 levels of nesting, 2,000 samples per plot, coordinates within ±100,000 cm, PNG up to 100 megapixels. Past a limit you get a clear error or a warning, never a hang.