Documentation
¶
Overview ¶
Package math is a pure-Go TeX math-mode typesetter: it parses a broad subset of TeX math syntax and lays it out to a self-contained SVG using the OpenType MATH table (via go-opentype) for metrics and vector glyph outlines — no TeX engine, no server, no cgo. It compiles to GOOS=js/wasm for offline math preview.
Supported: math-italic variables and a large named-symbol table with proper atom-class spacing (Appendix G); superscripts/subscripts and big-operator limits; fractions; radicals (\sqrt, \sqrt[n]); stretchy delimiters (\left…\right); accents (\hat, \vec, \bar, …); \overline/\underline; math alphabets (\mathbb, \mathcal, \mathfrak, \mathrm, \mathbf, \mathsf, \mathtt, \mathit); \text; matrices (matrix/pmatrix/bmatrix/vmatrix/Vmatrix/cases), array (with an l/c/r + | column spec), aligned/split, gathered and smallmatrix; primes; spacing commands; \displaystyle/\textstyle; declarative in-math font switches (\rm \bf \it \sf \tt \cal \sl); named operators (\log, \sin, \lim, …) and \operatorname / \operatorname*; and the modular annotations \bmod, \pmod, \mod and \pod.
Index ¶
- func DefaultFont() []byte
- type Metrics
- type Renderer
- func (r *Renderer) RenderDisplaySVG(tex string, sizePx int) (string, error)
- func (r *Renderer) RenderDisplaySVGMetrics(tex string, sizePx int) (string, Metrics, error)
- func (r *Renderer) RenderSVG(tex string, sizePx int) (string, error)
- func (r *Renderer) RenderSVGMetrics(tex string, sizePx int) (string, Metrics, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultFont ¶
func DefaultFont() []byte
DefaultFont returns an embedded MATH font (STIX Two Math, OFL).
Types ¶
type Metrics ¶ added in v0.5.0
type Metrics struct {
Width, Height, Depth float64
}
Metrics describes a rendered math box in pixels. Width is the advance width; Height the extent above the baseline; Depth the extent below it. In the SVG returned alongside these metrics the baseline sits at y=Height, and the box spans [0,Width]×[0,Height+Depth] with no padding — so a caller can align the math baseline with its surrounding text baseline exactly (place the SVG's top edge Height above the baseline), which RenderSVG's padded, baseline-agnostic output does not permit.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer typesets TeX math with a single MATH-table font.
func (*Renderer) RenderDisplaySVG ¶ added in v0.2.0
RenderDisplaySVG is like RenderSVG but in display style (larger operators, limits set above/below).
func (*Renderer) RenderDisplaySVGMetrics ¶ added in v0.5.0
RenderDisplaySVGMetrics is RenderSVGMetrics in display style.
func (*Renderer) RenderSVG ¶
RenderSVG typesets tex at the given base pixel size (inline/text style) and returns a complete, self-contained <svg> document.
func (*Renderer) RenderSVGMetrics ¶ added in v0.5.0
RenderSVGMetrics typesets tex at inline/text style like RenderSVG, but returns a tightly-cropped SVG together with its exact box Metrics (advance width, height above the baseline, depth below). This is the baseline-aware form: the caller can place the box so the math baseline meets the text baseline instead of guessing from the overall height.