Standalone TikZ to PNG with tectonic and pixi
For blog posts and slides I normally embed Graphviz DOT directly in orgmode and let the export handle rendering. That works well until a paper schematic needs inline math or a font family that does not cover enough Unicode glyphs 1. At that point, TikZ in a standalone document class is the path of least resistance: full LaTeX math rendering, arbitrary fonts through the TeX ecosystem, and tightly cropped output without manual trimming.
The build script loops over every .tex in a directory, compiles to PDF via tectonic, then rasterizes with pdftoppm (poppler):
1#!/usr/bin/env bash
2set -euo pipefail
3
4TIKZDIR="v1/pccp/imgs/tikz"
5OUTDIR="v1/pccp/imgs/tikz"
6DPI="${DPI:-300}"
7
8for texfile in "${TIKZDIR}"/*.tex; do
9 name="$(basename "${texfile}" .tex)"
10 echo "Building ${name}..."
11 tectonic "${texfile}" --outdir "${OUTDIR}"
12 pdftoppm -png -r "${DPI}" -singlefile \
13 "${OUTDIR}/${name}.pdf" "${OUTDIR}/${name}"
14 echo " -> ${OUTDIR}/${name}.png"
15done
Wiring this into pixi keeps the dependencies pinned and the invocation trivial:
1[tasks]
2tikz-figs = { cmd = "bash v1/pccp/imgs/tikz/build_tikz.sh" }
3
4[feature.texbuild.dependencies]
5tectonic = "*"
6poppler = "*"
7
8[environments]
9texbuild = {features = ["texbuild"]}
Then pixi run -e texbuild tikz-figs rebuilds everything. Override the resolution with DPI=600 pixi run -e texbuild tikz-figs for print quality. The same figures can live as #+begin_export latex blocks in the orgmode paper source for native export, with the standalone PNGs serving as quick-reference copies or targets for non-TeX workflows.
