ZigTeX is a wrapper around MicroTeX with a custom SVG renderer. ZigTeX principally gives you one function, which takes some LaTeX code and spits out an SVG:
conststd=@import("std");
constztex=@import("zigtex");
pubfnmain() !void {
vargpa=std.heap.GeneralPurposeAllocator(.{}){};
defer_=gpa.deinit();
constallocator=gpa.allocator();
varrender=tryztex.TexSvgRender.init(allocator, .{});
deferrender.deinit();
consttex=\\\begin{equation}\\ \hat{F}(\nu) = \int_{-\infty}^\infty e^{-i 2\pi t \nu} f(t) \text{d}t\\\end{equation}
;
constoutput=tryrender.parseRender(allocator, tex, .{});
deferallocator.free(output);
varf=trystd.fs.cwd().createFile("example.svg", .{});
deferf.close();
tryf.writeAll(output);
}This produces the title image on a transparent background.
To use in your Zig project, add this project as a dependency
zig fetch --save https://github.com/fjebaker/zigtex/archive/main.tar.gzThen modify your build.zig in the usual way:
constzigtex_dep=b.dependency(
"zigtex",
.{.optimize=optimize, .target=target},
);
// ...exe.root_module.addImport("zigtex", zigtex_dep.module("zigtex"));