formula

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package formula lays out the equations of the formats with the layout of math of okage, the package texmath (okage D78), and draws them on the display list. A format builds a tree of texmath from its equation, such as an equation of Office Math with OMML. A Typesetter lays out the tree, and the result is an Object that the layout of HTML and CSS places as an object of a Source, as it places a chart (D62).

The equations take STIX Two Math, the math font that okage holds. The glyphs are drawn as runs of glyphs with their text, so that a writer of PDF keeps the text of an equation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Atoms

func Atoms(l texmath.List, s string, v texmath.Variant) texmath.List

Atoms appends the atoms of the characters of s to l, as Office Math and MathML set the characters of a run. Each letter is an atom of its own, in the math alphabet v. A run of digits, with a decimal point between them, is one atom. Each other character is an atom of its class in TeX, such as a binary operator for +, so that texmath gives it the space of TeX. A hyphen-minus is the minus sign, and white space is left out, as the equations of Word and MathML do.

func MathML

func MathML(e *Element) (texmath.List, bool)

MathML returns the tree of a formula of Presentation MathML, the math element e or an element in it, and whether its attribute display is block. The elements of Content MathML and the annotations draw nothing.

func OMML

func OMML(n roxmltree.Node, maxDepth int) (texmath.List, bool)

OMML returns the tree of an equation of Office Math, the markup of ECMA-376 Part 1, section 22.1: an m:oMath element or an element in it. The elements are read by their local names. An element that nests deeper than maxDepth is left out, and OMML then returns false.

Types

type Element

type Element struct {
	Name     string
	Attrs    map[string]string
	Text     string
	Children []*Element
}

Element is an element of MathML, as a format reads it: its local name, its attributes, its text and its child elements. The text of a token element, such as mi or mo, is its characters.

func (*Element) Attr

func (e *Element) Attr(name string) string

Attr returns the attribute name of e, or "".

type Object

type Object struct {
	// contains filtered or unexported fields
}

Object is an equation laid out. It is a picture that a format draws itself, which satisfies the interface Object of the package layout. Its methods are safe for concurrent use.

func (*Object) Depth

func (o *Object) Depth() float64

Depth returns the depth of the equation below its baseline, in points. A format moves the object down by its depth, so that the baseline of the equation sits on the baseline of the line.

func (*Object) Draw

func (o *Object) Draw(ctx context.Context, dev display.Device, rect okage.Rect) error

Draw draws the equation onto dev, scaled to fill rect.

func (*Object) Size

func (o *Object) Size() (width, height float64)

Size returns the width of the equation, and its height above the baseline with its depth below it, in points.

type Typesetter

type Typesetter struct {
	// contains filtered or unexported fields
}

Typesetter lays out equations with STIX Two Math. It is not safe for concurrent use, because the face of okage that it reads is not. The Objects that it returns are safe for concurrent use.

func New

func New() (*Typesetter, error)

New returns a Typesetter. It returns an error that wraps ivy.ErrFormat if the math font cannot be read.

func (*Typesetter) Layout

func (t *Typesetter) Layout(n texmath.Node, size float64, style texmath.Style, color okage.Color) (*Object, error)

Layout lays out the tree n at the size, in points, in the style, such as texmath.Display for an equation on a line of its own. color is the color of the items that the tree does not color. It returns an error that wraps ivy.ErrLimit when the tree goes past a limit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL