Expand description
LaTeX math labels: a Rust port of upstream D2’s d2latex package and the
mathjax-go TeX renderer it uses, producing the same measurements and SVG
as Go D2 without a JavaScript runtime or browser.
The oracle-fixtures feature compiles tests that read regenerated Go-oracle
artifacts.
Modules§
- gomath
- Pinned Go
mathfunctions shared by the renderers and color parsing. Pinned Go 1.27mathfunctions used by lib/geo, lib/shape and lib/svg: sin/cos (sin.go, trig_reduce.go), atan/atan2/asin/acos (atan.go, atan2.go, asin.go), log/log10 (log.go, log10.go), exp (exp_arm64.s), pow (pow.go), frexp/ldexp/modf. Go implements these in Go (or arm64 assembly for Exp), not via the platform libm, so results differ from Rust’sf64methods in the last bit. Fused operations follow the pinned arm64 build (FMADDD/FMSUBD), as in the d2-rs-elk translations these were taken from (go_trig.rs, go_math.rs, force_layout/logarithm.rs). - image_
svg - Shared imageasset SVG acquisition helpers. Shared native imageasset SVG envelope and compression admission. Exporter compatibility helpers retain their original behavior; bounded resolver admission uses caller limits and cancellation explicitly.
- png_
first_ frame - D2 internal/rasterimage/firstframe.go inspectPNG: the complete PNG/APNG container pass rasterimage.Config runs for imageasset’s raster probe. An animated PNG is admitted by its first frame; nothing is decoded.
- svg_
effects - Upstream 8558856dc d2svgimport/effects.go: SVG effect regions and masks.
- svg_
text - Upstream 8558856dc d2svgimport/text.go: positioned SVG text, bundled face selection, bounded shaping and shared glyph outlines.
- webp_
first_ frame - D2 internal/rasterimage/firstframe.go inspectWebP and extractWebPFrame: the WebP container pass behind imageasset’s raster Config and DecodeFirst. Animated WebP resources resolve to their first ANMF frame on the logical canvas; later frames are never decoded.
Enums§
- Math
Error - Math parsing or rendering failure.
Constants§
- MAX_
GROUP_ NESTING_ DEPTH - Maximum unescaped, uncommented brace-group nesting.
- MAX_
INPUT_ BYTES - Maximum UTF-8 byte length admitted by D2’s LaTeX renderer.
Functions§
- measure
- Measures the actual emitted SVG using original D2’s serialized intrinsic units.
- render
- Renders a deterministic semantic SVG for a TeX label.
- render_
exact - Renders TeX exactly as D2 v0.9.0’s
d2latex.Render(mathjax-go v0.1.0mathjax.Render) does, or refuses. - validate_
input - D2’s shared LaTeX admission policy. Rust strings already guarantee UTF-8.