Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fjebaker/zigtex
Embeddable LaTeX to SVG in Zig.
https://github.com/fjebaker/zigtex
latex latex-to-svg microtex renderer svg zig
Last synced: 3 months ago
JSON representation
Embeddable LaTeX to SVG in Zig.
- Host: GitHub
- URL: https://github.com/fjebaker/zigtex
- Owner: fjebaker
- License: gpl-3.0
- Created: 2024-08-05T13:38:13.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-08-05T20:38:40.000Z (6 months ago)
- Last Synced: 2024-09-30T03:20:59.055Z (4 months ago)
- Topics: latex, latex-to-svg, microtex, renderer, svg, zig
- Language: Zig
- Homepage:
- Size: 569 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ZigTeX
ZigTeX is a wrapper around [MicroTeX](https://github.com/NanoMichael/MicroTeX/tree/openmath) with a custom SVG renderer. ZigTeX principally gives you one function, which takes some LaTeX code and spits out an SVG:
```zig
const std = @import("std");
const ztex = @import("zigtex");pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();var render = try ztex.TexSvgRender.init(allocator, .{});
defer render.deinit();const tex =
\\\begin{equation}
\\ \hat{F}(\nu) = \int_{-\infty}^\infty e^{-i 2\pi t \nu} f(t) \text{d}t
\\\end{equation}
;const output = try render.parseRender(allocator, tex, .{});
defer allocator.free(output);var f = try std.fs.cwd().createFile("example.svg", .{});
defer f.close();
try f.writeAll(output);
}
```
This produces the title image on a transparent background.## Usage
To use in your Zig project, add this project as a dependency
```bash
zig fetch --save https://github.com/fjebaker/zigtex/archive/main.tar.gz
```Then modify your `build.zig` in the usual way:
```zig
const zigtex_dep = b.dependency(
"zigtex",
.{.optimize = optimize, .target = target},
);// ...
exe.root_module.addImport("zigtex", zigtex_dep.module("zigtex"));
```