Skip to main content

Crate d2_rs_math

Crate d2_rs_math 

Source
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 math functions shared by the renderers and color parsing. Pinned Go 1.27 math functions 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’s f64 methods 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§

MathError
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.0 mathjax.Render) does, or refuses.
validate_input
D2’s shared LaTeX admission policy. Rust strings already guarantee UTF-8.