Skip to content

MakieTeX

Plotting vector images in Makie

MakieTeX.jl

MakieTeX is a package that allows users to plot vector images - PDF, SVG, and TeX (which compiles to PDF) directly in Makie. It exposes two approaches: the teximg recipe which plots any LaTeX-like object, and the CachedDocument API which allows users to plot documents directly as scatter markers.

To see a list of all exported functions, types, and macros, see the API page.

julia
using MakieTeX, CairoMakie

teximg(raw"""
\begin{align*}
\frac{1}{2} \times \frac{1}{2} = \frac{1}{4}
\end{align*}
""")

Principle of operation

Rendering

Rendering can occur either to a bitmap (for GL backends) or to a Cairo surface (for CairoMakie). Both of these have APIs (rasterize and draw_to_cairo_surface).

Each rendering format has its own complexities, so the rendering pipelines are usually separate. SVG uses librsvg while PDF and EPS use Poppler directly. TeX uses the available local TeX renderer (if not, tectonic is bundled with MakieTeX) and Typst uses Typst_jll.jl to render to a PDF, which then each follow the Poppler pipeline.

Makie

When rendering to Makie, MakieTeX rasterizes the document to a bitmap by default via the Makie attribute conversion pipeline (specifically Makie.to_spritemarker), and then Makie treats it like a general image scatter marker.

HOWEVER, when rendering with CairoMakie, there is a function hook to get the correct marker for Cairo specifically, ignoring the default Makie conversion pipeline. This is CairoMakie.cairo_scatter_marker, and we overload it in MakieTeX.MakieTeXCairoMakieExt to get the correct marker. This also allows us to apply styling to SVG elements, but again ONLY IN CAIROMAKIE! This is a bit of an incompatibility and a breaking of the implicit promise from Makie that rendering should be the same across backends, but the tradeoff is (to me, at least) worth it.