tikra

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.

TikZ
SVG
Loading WebAssembly…

Why tikra

One small library, the same output everywhere: JavaScript, Python, Rust and the terminal.

No TeX install

No LaTeX, no system fonts, no external process. A single binary, a wheel, an npm package or a crate.

Real math in labels

Labels are typeset by mathra with the STIX Two Math font embedded, so they look the same on every machine.

Warnings, not errors

What tikra does not understand (\matrix, \pic, an unknown option) is listed as a warning, and the rest of the figure is drawn.

— ms

Fast and stable

Mean time to draw a corpus figure, measured in this page. The same input always writes the same bytes.

Use it

Pick your platform. All four packages run the same core, so a figure gives the same SVG, byte for byte, wherever it is converted.

JavaScript and TypeScript

on npm

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 } = render(code);
const bytes = png(svg, { dpi: 300 });

Python

on PyPI

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"]

Terminal

on crates.io

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

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)?)?;

What it reads

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.

What it draws

\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, patterns, the zigzag, snake and random steps decorations, and pgfplots basics. The full list is in spec/subset.md.

Limits

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.