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 ¶
- Variables
- type Accent
- type Box
- type Char
- type FontConstants
- type Glue
- type HList
- func (lst *HList) Depth() float64
- func (lst *HList) GlueOrder() int
- func (lst *HList) GlueSet() float64
- func (lst *HList) GlueSign() int
- func (lst *HList) Grow()
- func (lst *HList) HPack(width float64, additional bool)
- func (lst *HList) Height() float64
- func (lst *HList) Kerning(next Node) float64
- func (lst *HList) Nodes() []Node
- func (lst *HList) Render(x, y float64)
- func (lst *HList) Shift() float64
- func (lst *HList) Shrink()
- func (lst *HList) Width() float64
- type Kern
- type List
- func (lst *List) Depth() float64
- func (lst *List) GlueOrder() int
- func (lst *List) GlueSet() float64
- func (lst *List) GlueSign() int
- func (lst *List) Grow()
- func (lst *List) Height() float64
- func (lst *List) Kerning(next Node) float64
- func (lst *List) Nodes() []Node
- func (lst *List) Render(x, y float64)
- func (lst *List) Shrink()
- func (lst *List) Width() float64
- type Node
- type Rule
- type Ship
- type State
- type SubSuperCluster
- type Tree
- type VList
- func (lst *VList) Depth() float64
- func (lst *VList) GlueOrder() int
- func (lst *VList) GlueSet() float64
- func (lst *VList) GlueSign() int
- func (lst *VList) Grow()
- func (lst *VList) Height() float64
- func (lst *VList) Kerning(next Node) float64
- func (lst *VList) Nodes() []Node
- func (lst *VList) Render(x, y float64)
- func (lst *VList) SetShift(s float64)
- func (lst *VList) Shrink()
- func (lst *VList) VPack(height float64, additional bool, l float64)
- func (lst *VList) Width() float64
Constants ¶
This section is empty.
Variables ¶
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.
type Box ¶
type Box struct {
// contains filtered or unexported fields
}
Box is a node with a physical location
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`.
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 HList ¶
type HList struct {
// contains filtered or unexported fields
}
HList is a horizontal list of boxes.
func AutoHeightChar ¶
AutoHeightChar creats a character as close to the given height and depth as possible.
func (*HList) HPack ¶
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'.
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.
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a list of vertical or horizontal nodes.
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.
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.
type SubSuperCluster ¶
type SubSuperCluster struct {
*HList
}
type VList ¶
type VList struct {
// contains filtered or unexported fields
}
VList is a vertical list of boxes.
func (*VList) VPack ¶
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'.