Documentation
¶
Overview ¶
Package formula typesets math, written in TeX or Typst, with Untie (github.com/caelyreth/untie), and draws it as shapes in the font size and the text color it inherits: inline, on its text's baseline, or as a display formula of its own. Its font is New Computer Modern Math Book, embedded and loaded off the engine's goroutine as a formula first shows, or the app's through NewRenderer. textview.TextView draws its formulas so with RenderMath: formula.RenderMath.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Fonts ¶
Fonts are a renderer's fonts, OpenType files: Math, with a MATH table, lays the formulas out; Text, else Math, sets \text and \operatorname; and Fallbacks are tried in order for characters the others lack, such as a CJK font's. The app is responsible for their licenses.
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer lays formulas out in one set of fonts and keeps the last layouts it made, as shapes ready to draw. It is safe for concurrent use, so the engines of a process share one.
func Default ¶
func Default() *Renderer
Default returns the renderer of the embedded New Computer Modern Math Book, whose font loads on first use: a View waits for it off the engine's goroutine.
func NewRenderer ¶
NewRenderer prepares a renderer for fonts, parsing and validating them, which takes a while for a large font: about 120 ms for New Computer Modern Math on an M-series Mac, and about 0.7 s in WebAssembly. It fails when Math has no usable MATH table.
func (*Renderer) RenderMath ¶
RenderMath shows a text view's formula with r, as textview.TextView.RenderMath takes it: an inline one, or a display one with Display's larger operators and limits, which TextView centers in its block's sideways scroll. A copy takes them as their TeX between $ and $$.
type View ¶
type View struct {
// Source is the formula without its delimiters ($…$); SourceFunc follows what it reads.
Source string
SourceFunc func() string
Dialect Dialect
Display bool
// Renderer lays it out; nil is Default().
Renderer *Renderer
// Label is what assistive technology reads in place of what the formula says.
Label string
Class string
Style core.Style
StyleFunc func() core.Style
// ErrorStyle's color marks what failed to parse; ErrorClass and ErrorStyle style the source a formula past Untie's limits, or whose fonts did not load, shows instead.
ErrorClass string
ErrorStyle core.Style
TestID string
}
View draws a formula. It sizes itself in ems of the font size it inherits, following the user's text size as text does, and paints in the text color it inherits, keeping the colors the formula names (\color{red}). As a core.Span's attachment it sits on the line's baseline. With Display it is a formula on a line of its own: larger operators, and limits above and below. What failed to parse is marked in ErrorStyle's color, the text color without one; a formula past Untie's limits shows its source as text in ErrorClass and ErrorStyle. It keeps its size in a container that stretches its children, standing at the start of the cross axis unless its style sets AlignSelf. Until its renderer's font has loaded, it is an empty em square. Assistive technology reads it as an image labelled with what the formula says, in the language the app shows.