tex

package
v0.0.0-...-5c1ce85 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: BSD-3-Clause Imports: 4 Imported by: 5

Documentation

Overview

Package tex provides a TeX-like box model.

The following is based directly on the document 'woven' from the TeX82 source code. This information is also available in printed form:

Knuth, Donald E.. 1986.  Computers and Typesetting, Volume B:
TeX: The Program.  Addison-Wesley Professional.

An electronic version is also available from:

http://brokestream.com/tex.pdf

The most relevant "chapters" are:

Data structures for boxes and their friends
Shipping pages out (Ship class)
Packaging (hpack and vpack)
Data structures for math mode
Subroutines for math mode
Typesetting math formulas

Many of the docstrings below refer to a numbered "node" in that book, e.g., node123

Note that (as TeX) y increases downward.

Index

Constants

This section is empty.

Variables

View Source
var DefaultFontConstants = FontConstants{
	ScriptSpace:   0.05,
	SubDrop:       0.4,
	Sup1:          0.7,
	Sub1:          0.3,
	Sub2:          0.5,
	Delta:         0.025,
	DeltaSlanted:  0.2,
	DeltaIntegral: 0.1,
}

Functions

This section is empty.

Types

type Accent

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

Accent is a character with an accent. Accents need to be dealt with separately as they are already offset from the baseline in TrueType fonts.

func NewAccent

func NewAccent(c string, state State, math bool) *Accent

func (*Accent) Depth

func (acc *Accent) Depth() float64

Depth returns the depth of this node.

func (*Accent) Grow

func (acc *Accent) Grow()

func (*Accent) Height

func (acc *Accent) Height() float64

Height returns the height of this node.

func (*Accent) Kerning

func (acc *Accent) Kerning(next Node) float64

func (*Accent) Render

func (acc *Accent) Render(x, y float64)

func (*Accent) Shrink

func (acc *Accent) Shrink()

func (*Accent) String

func (acc *Accent) String() string

func (*Accent) Width

func (acc *Accent) Width() float64

Width returns the width of this node.

type Box

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

Box is a node with a physical location

func HBox

func HBox(w float64) *Box

HBox is a box with a width but no height nor depth.

func VBox

func VBox(h, d float64) *Box

VBox is a box with a height but no width.

func (*Box) Depth

func (box *Box) Depth() float64

Depth returns the depth of this node.

func (*Box) Grow

func (box *Box) Grow()

func (*Box) Height

func (box *Box) Height() float64

Height returns the height of this node.

func (*Box) Kerning

func (*Box) Kerning(next Node) float64

func (*Box) Render

func (*Box) Render(x, y float64)

func (*Box) Shrink

func (box *Box) Shrink()

func (*Box) Width

func (box *Box) Width() float64

Width returns the width of this node.

type Char

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

Char is a single character.

Unlike TeX, the font information and metrics are stored with each `Char` to make it easier to lookup the font metrics when needed. Note that TeX boxes have a width, height, and depth, unlike Type1 and TrueType which use a full bounding box and an advance in the x-direction. The metrics must be converted to the TeX model, and the advance (if different from width) must be converted into a `Kern` node when the `Char` is added to its parent `HList`.

func NewChar

func NewChar(c string, state State, math bool) *Char

func (*Char) Depth

func (c *Char) Depth() float64

Depth returns the depth of this node.

func (*Char) Grow

func (box *Char) Grow()

func (*Char) Height

func (c *Char) Height() float64

Height returns the height of this node.

func (*Char) Kerning

func (c *Char) Kerning(next Node) float64

func (*Char) Render

func (c *Char) Render(x, y float64)

func (*Char) Shrink

func (box *Char) Shrink()

func (*Char) String

func (c *Char) String() string

func (*Char) Width

func (c *Char) Width() float64

Width returns the width of this node.

type FontConstants

type FontConstants struct {
	// Percentage of x-height of additional horiz. space after sub/superscripts
	ScriptSpace float64

	// Percentage of x-height that sub/superscripts drop below the baseline
	SubDrop float64

	// Percentage of x-height that superscripts are raised from the baseline
	Sup1 float64

	// Percentage of x-height that subscripts drop below the baseline
	Sub1 float64

	// Percentage of x-height that subscripts drop below the baseline when a
	// superscript is present
	Sub2 float64

	// Percentage of x-height that sub/supercripts are offset relative to the
	// nucleus edge for non-slanted nuclei
	Delta float64

	// Additional percentage of last character height above 2/3 of the
	// x-height that supercripts are offset relative to the subscript
	// for slanted nuclei
	DeltaSlanted float64

	// Percentage of x-height that supercripts and subscripts are offset for
	// integrals
	DeltaIntegral float64
}

FontConstants is a set of magical values that control how certain things, such as sub- and superscripts are laid out. These are all metrics that can't be reliably retrieved from the font metrics in the font itself.

type Glue

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

func NewGlue

func NewGlue(typ string) *Glue

func (*Glue) Depth

func (g *Glue) Depth() float64

Depth returns the depth of this node.

func (*Glue) Grow

func (g *Glue) Grow()

func (*Glue) Height

func (g *Glue) Height() float64

Height returns the height of this node.

func (*Glue) Kerning

func (g *Glue) Kerning(next Node) float64

func (*Glue) Render

func (g *Glue) Render(x, y float64)

func (*Glue) Shrink

func (g *Glue) Shrink()

func (*Glue) Width

func (g *Glue) Width() float64

Width returns the width of this node.

type HList

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

HList is a horizontal list of boxes.

func AutoHeightChar

func AutoHeightChar(c string, height, depth float64, state State, factor float64) *HList

AutoHeightChar creats a character as close to the given height and depth as possible.

func HCentered

func HCentered(elements []Node) *HList

HCentered creates an HList whose contents are centered within its enclosing box.

func HListOf

func HListOf(elements []Node, doKern bool) *HList

func (*HList) Depth

func (lst *HList) Depth() float64

Depth returns the depth of this node.

func (*HList) GlueOrder

func (lst *HList) GlueOrder() int

func (*HList) GlueSet

func (lst *HList) GlueSet() float64

func (*HList) GlueSign

func (lst *HList) GlueSign() int

func (*HList) Grow

func (lst *HList) Grow()

func (*HList) HPack

func (lst *HList) HPack(width float64, additional bool)

HPack computes the dimensions of the resulting boxes, and adjusts the glue if one of those dimensions is pre-specified.

The computed sizes normally enclose all of the material inside the new box; but some items may stick out if negative glue is used, if the box is overfull, or if a `\vbox` includes other boxes that have been shifted left.

If additional is false, HPack will produce a box whose width is exactly as wide as the given 'width'. Otherwise, HPack will produce a box with the natural width of the contents, plus the given 'width'.

func (*HList) Height

func (lst *HList) Height() float64

Height returns the height of this node.

func (*HList) Kerning

func (lst *HList) Kerning(next Node) float64

func (*HList) Nodes

func (lst *HList) Nodes() []Node

func (*HList) Render

func (lst *HList) Render(x, y float64)

func (*HList) Shift

func (lst *HList) Shift() float64

func (*HList) Shrink

func (lst *HList) Shrink()

func (*HList) Width

func (lst *HList) Width() float64

Width returns the width of this node.

type Kern

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

Kern is a node with a width to specify a (normally negative) amount of spacing.

This spacing correction appears in horizontal lists between letters like A and V, when the font designer decided it looks better to move them closer together or further apart. A Kern node can also appear in a vertical list, when its width denotes spacing in the vertical direction.

func NewKern

func NewKern(width float64) *Kern

func (*Kern) Depth

func (k *Kern) Depth() float64

Depth returns the depth of this node.

func (*Kern) Grow

func (k *Kern) Grow()

func (*Kern) Height

func (k *Kern) Height() float64

Height returns the height of this node.

func (*Kern) Kerning

func (k *Kern) Kerning(next Node) float64

func (*Kern) Render

func (k *Kern) Render(x, y float64)

func (*Kern) Shrink

func (k *Kern) Shrink()

func (*Kern) String

func (k *Kern) String() string

func (*Kern) Width

func (k *Kern) Width() float64

Width returns the width of this node.

type List

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

List is a list of vertical or horizontal nodes.

func ListOf

func ListOf(elements []Node) *List

func (*List) Depth

func (lst *List) Depth() float64

Depth returns the depth of this node.

func (*List) GlueOrder

func (lst *List) GlueOrder() int

func (*List) GlueSet

func (lst *List) GlueSet() float64

func (*List) GlueSign

func (lst *List) GlueSign() int

func (*List) Grow

func (lst *List) Grow()

func (*List) Height

func (lst *List) Height() float64

Height returns the height of this node.

func (*List) Kerning

func (lst *List) Kerning(next Node) float64

func (*List) Nodes

func (lst *List) Nodes() []Node

func (*List) Render

func (lst *List) Render(x, y float64)

func (*List) Shrink

func (lst *List) Shrink()

func (*List) Width

func (lst *List) Width() float64

Width returns the width of this node.

type Node

type Node interface {
	// Kerning returns the amount of kerning between this and the next node.
	Kerning(next Node) float64

	// Shrinks one level smaller.
	// There are only three levels of sizes, after which things
	// will no longer get smaller.
	Shrink()

	// Grows one level larger.
	// There is no limit to how big something can get.
	Grow()

	// Render renders the node at (x,y) on the canvas.
	Render(x, y float64)

	// Width returns the width of this node.
	Width() float64

	// Height returns the height of this node.
	Height() float64

	// Depth returns the depth of this node.
	Depth() float64
}

Node represents a node in the TeX box model.

type Rule

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

Rule is a solid black rectangle.

Like a HList, Rule has a width, a depth and a height. However, if any of these dimensions is ∞, the actual value will be determined by running the rule up to the boundary of the innermost enclosing box. This is called a "running dimension". The width is never running in an HList; the height and depth are never running in a VList.

func HRule

func HRule(state State, thickness float64) *Rule

HRule is a horizontal rule.

func NewRule

func NewRule(w, h, d float64, state State) *Rule

func VRule

func VRule(state State) *Rule

VRule is a vertical rule.

func (*Rule) Depth

func (rule *Rule) Depth() float64

Depth returns the depth of this node.

func (*Rule) Grow

func (rule *Rule) Grow()

func (*Rule) Height

func (rule *Rule) Height() float64

Height returns the height of this node.

func (*Rule) Kerning

func (rule *Rule) Kerning(next Node) float64

func (*Rule) Render

func (rule *Rule) Render(x, y float64)

func (*Rule) Shrink

func (rule *Rule) Shrink()

func (*Rule) String

func (rule *Rule) String() string

func (*Rule) Width

func (rule *Rule) Width() float64

Width returns the width of this node.

type Ship

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

Ship boxes to output once boxes have been set up.

Since boxes can be inside of boxes inside of boxes... the main work of Ship is done by two mutually recursive routines, hlistOut and vlistOut, which traverse the HList and VList nodes inside of horizontal and vertical boxes.

func (*Ship) Call

func (ship *Ship) Call(ox, oy float64, box Tree)

type State

type State struct {
	Font font.Font
	DPI  float64
	// contains filtered or unexported fields
}

func NewState

func NewState(be font.Backend, font font.Font, dpi float64) State

func (State) Backend

func (state State) Backend() font.Backend

type SubSuperCluster

type SubSuperCluster struct {
	*HList
}

type Tree

type Tree interface {
	Node

	Nodes() []Node
	GlueOrder() int
	GlueSign() int
	GlueSet() float64
}

type VList

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

VList is a vertical list of boxes.

func VCentered

func VCentered(elements []Node) *VList

VCentered creates a VList whose contents are centered within its enclosing box.

func VListOf

func VListOf(elements []Node) *VList

func (*VList) Depth

func (lst *VList) Depth() float64

Depth returns the depth of this node.

func (*VList) GlueOrder

func (lst *VList) GlueOrder() int

func (*VList) GlueSet

func (lst *VList) GlueSet() float64

func (*VList) GlueSign

func (lst *VList) GlueSign() int

func (*VList) Grow

func (lst *VList) Grow()

func (*VList) Height

func (lst *VList) Height() float64

Height returns the height of this node.

func (*VList) Kerning

func (lst *VList) Kerning(next Node) float64

func (*VList) Nodes

func (lst *VList) Nodes() []Node

func (*VList) Render

func (lst *VList) Render(x, y float64)

func (*VList) SetShift

func (lst *VList) SetShift(s float64)

func (*VList) Shrink

func (lst *VList) Shrink()

func (*VList) VPack

func (lst *VList) VPack(height float64, additional bool, l float64)

VPack computes the dimensions of the resulting boxes, and adjusts the glue if one of those dimensions is pre-specified.

If additional is false, VPack will produce a box whose height is exactly as tall as the given 'height'. Otherwise, VPack will produce a box with the natural height of the contents, plus the given 'height'.

func (*VList) Width

func (lst *VList) Width() float64

Width returns the width of this node.

Jump to

Keyboard shortcuts

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