Documentation
¶
Overview ¶
Package formula typesets math, written in TeX or Typst, with Untie (github.com/caelyreth/untie), and draws it 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. Text runs these fonts cannot cover use the platform's system fonts. The app is responsible for its fonts' licenses.
type HitEvent ¶
type HitEvent struct {
Source string
Dialect Dialect
Phase HitPhase
Hit untie.Hit
Found bool
Point untie.Point
Caret untie.CaretStop
HasCaret bool
Diagnostics []untie.Diagnostic
Position core.Point
Clicks int
Modifiers core.Modifiers
}
HitEvent carries the Untie source part and nearest caret under a formula's pointer. Diagnostics contains supplied diagnostics whose ranges cover that part, so an editor can route presses, caret placement and diagnostics without reproducing Untie's geometry.
type HitPhase ¶
type HitPhase uint8
HitPhase identifies the pointer interaction reported by HitEvent.
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. Missing text runs are measured and drawn by each View with its platform text engine. 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, wrapped to its block's padded viewport. TextView centers its lines and scrolls any unbreakable overflow. 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
// Streaming hides recoverable error and placeholder ink while Source is still arriving. SourceFunc continues to lay out each update. Set it false when the source is complete to show remaining errors; StreamingFunc follows what it reads.
Streaming bool
StreamingFunc func() 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
// Diagnostics are source ranges an editor wants associated with the formula; HitEvent reports the entries whose ranges cover the hit part. DiagnosticsFunc follows what it reads.
Diagnostics []untie.Diagnostic
DiagnosticsFunc func() []untie.Diagnostic
// OnHit receives hover, press and click events resolved through Untie's Box. It runs on the engine goroutine.
OnHit func(HitEvent)
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. Display formulas wrap at safe relations and operators when wider than the available width; an unbreakable part keeps its overflow. 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.