Skip to content

foresight_math ​

A subset of LaTeX's inline math ($...$) laid out as LuaTeX lays it out with unicode-math and Latin Modern Math (issue #5 step 4.1): letters in math italic, Greek (\alpha, \Gamma), sub- and superscripts (^, _, primes), \frac, \sqrt, \mathrm, \mathbf, \mathit, operators and relations with TeX's spacing (\cdot, \times, \pm, \le, \ge, \partial, \nabla, ...), inline \sum, \prod and \int (their limits as scripts), accents (\hat, \bar, \vec, \tilde, \dot), \left( ... \right) sized to their content, operator names (\sin, \log, ...) and explicit spaces (\,, \;, \quad). No display style, matrices nor line breaking.

The formula is parsed into TeX's noads (Ord, Op, Bin, Rel, Open, Close, Punct, Inner, fractions, radicals, accents) and set by TeX's rules (The TeXbook, appendix G) with the constants of the font's MATH table: the styles (text, script, scriptscript, cramped), the spacing between atoms in mu (thin 3, medium 4, thick 5; none around binary and relation atoms in scripts), the script shifts and gaps, the fraction shifts and clearances, the radical's size variant and its rule, the delimiters' size variants. Script sizes are 70 % and 50 % (LaTeX's 7 and 5 pt at 10 pt), with the font's script alternates (ssty). \mathrm and \mathbf (and operator names) are the serif text faces, as unicode-math sets them in the main font.

Source: src/lib/foresight_math.F90

Dependencies

Contents ​

Variables ​

NameTypeAttributesDescription
MATH_FACEinteger(kind=I4P)parameterFace number of the math font (the text faces are 1-8).
ORDinteger(kind=I4P)parameter
OPinteger(kind=I4P)parameter
BINinteger(kind=I4P)parameter
RELinteger(kind=I4P)parameter
OPENinteger(kind=I4P)parameter
CLOSEinteger(kind=I4P)parameter
PUNCTinteger(kind=I4P)parameter
INNERinteger(kind=I4P)parameter
FRACinteger(kind=I4P)parameter
RADICALinteger(kind=I4P)parameter
ACCENTinteger(kind=I4P)parameter
SPACEinteger(kind=I4P)parameter
FENCEDinteger(kind=I4P)parameter
TEXT_STYLEinteger(kind=I4P)parameter
SCRIPT_STYLEinteger(kind=I4P)parameter
SCRIPTSCRIPT_STYLEinteger(kind=I4P)parameter
SPACINGinteger(kind=I4P)parameterSPACING(right, left).
MUreal(kind=R8P)parameterThin, medium, thick spaces [em].
NULL_DELIMITERreal(kind=R8P)parameterLaTeX's \nulldelimiterspace, 1.2 pt at 10 pt [em].
SCALEreal(kind=R8P)parameterSize of each style [base size].

Derived Types ​

math_item ​

A glyph or a rule of a formula, from its origin (the start of its baseline), y up.

Components

NameTypeAttributesDescription
faceinteger(kind=I4P)MATH_FACE (the math font) or a text face (1-8); 0 for a rule.
glyphinteger(kind=I4P)Glyph number in its face.
unicodeinteger(kind=I4P)Character shown.
xreal(kind=R8P)Origin abscissa (a rule's left).
yreal(kind=R8P)Baseline ordinate (a rule's bottom), up.
sizereal(kind=R8P)Font size (a rule's width).
heightreal(kind=R8P)A rule's height.

noad_tree ​

The parsed formula: noads in lists (linked by next), each with a nucleus and its scripts.

Components

NameTypeAttributesDescription
kindinteger(kind=I4P)allocatableNoad kind.
faceinteger(kind=I4P)allocatableFace of a character nucleus (MATH_FACE or a text face).
glyphinteger(kind=I4P)allocatableGlyph of a character nucleus (an accent's, a radical's), 0 if a list.
codeinteger(kind=I4P)allocatableIts character.
listinteger(kind=I4P)allocatableNucleus list (a fraction's numerator, a radical's or accent's body).
otherinteger(kind=I4P)allocatableA fraction's denominator.
leftinteger(kind=I4P)allocatableA fenced list's left delimiter glyph (0 none).
rightinteger(kind=I4P)allocatableIts right delimiter glyph (0 none).
supinteger(kind=I4P)allocatableSuperscript list, 0 none.
subinteger(kind=I4P)allocatableSubscript list, 0 none.
nextinteger(kind=I4P)allocatableNext noad of the list, 0 last.
spacereal(kind=R8P)allocatableAn explicit space [em] (SPACE noads).
ninteger(kind=I4P)Noads.

box_state ​

The items of the formula being set and the boxes' extents.

Components

NameTypeAttributesDescription
itemstype(math_item)allocatableItems.
ninteger(kind=I4P)Items in use.

Subroutines ​

math_layout ​

The items of the math source (without its $) set in text style at font size: glyphs and rules from the formula's origin (y up, in the units of size), its width, height and depth.

Attributes: pure

fortran
subroutine math_layout(source, size, items, width, height, depth)

Arguments

NameTypeIntentAttributesDescription
sourcecharacter(len=*)inLaTeX math.
sizereal(kind=R8P)inFont size.
itemstype(math_item)outallocatableGlyphs and rules.
widthreal(kind=R8P)outWidth.
heightreal(kind=R8P)outHeight above the baseline.
depthreal(kind=R8P)outDepth below it.

Call graph

next_math ​

The next math run of text from from, as pandoc reads TeX math in text: an unescaped $ followed by a non-blank opens it, the next unescaped $ preceded by a non-blank and followed by no letter, digit nor _ closes it (gnuplot's $data blocks and $f(x) function blocks, $5 and $10, are text); open and close the dollars' positions, 0 when there is none.

Attributes: pure

fortran
subroutine next_math(text, from, open, close)

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=*)inText.
frominteger(kind=I4P)inFirst position.
openinteger(kind=I4P)outOpening dollar, 0 none.
closeinteger(kind=I4P)outClosing dollar, 0 none.

Call graph

any_outline ​

Outline of a glyph of a text face or of the math font.

Attributes: pure

fortran
subroutine any_outline(face, glyph, ops, points)

Arguments

NameTypeIntentAttributesDescription
faceinteger(kind=I4P)inFace.
glyphinteger(kind=I4P)inGlyph.
opsinteger(kind=I4P)outallocatableOperations.
pointsinteger(kind=I4P)outallocatablePoints, x and y.

Call graph

parse_list ​

The noads from at to the end, to the } closing the group (closed) or to a \right: its first noad.

Attributes: pure, recursive

fortran
subroutine parse_list(tree, source, at, closed, head)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
sourcecharacter(len=*)inLaTeX math.
atinteger(kind=I4P)inoutPosition.
closedlogicalinA group: stop after its }.
headinteger(kind=I4P)outFirst noad, 0 for an empty list.

Call graph

parse_scripts ​

The ^, _ and primes after a noad: its superscript and subscript lists.

Attributes: pure, recursive

fortran
subroutine parse_scripts(tree, source, at, noad)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
sourcecharacter(len=*)inLaTeX math.
atinteger(kind=I4P)inoutPosition (at the first script sign).
noadinteger(kind=I4P)inThe noad.

Call graph

parse_argument ​

A macro's or a script's argument: a {...} group, else one atom.

Attributes: pure, recursive

fortran
subroutine parse_argument(tree, source, at, head)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
sourcecharacter(len=*)inLaTeX math.
atinteger(kind=I4P)inoutPosition.
headinteger(kind=I4P)outFirst noad.

Call graph

parse_atom ​

One atom at at: a character, a command, a group as an Ord; 0 for nothing (a font switch's empty group).

Attributes: pure, recursive

fortran
subroutine parse_atom(tree, source, at, noad)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
sourcecharacter(len=*)inLaTeX math.
atinteger(kind=I4P)inoutPosition.
noadinteger(kind=I4P)outNoad.

Call graph

text_argument ​

The {...} argument of \mathrm and its kin: its characters (blanks skipped, as math does; kept in \text) in a text face, as Ord noads.

Attributes: pure

fortran
subroutine text_argument(tree, source, at, face, head)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
sourcecharacter(len=*)inLaTeX math.
atinteger(kind=I4P)inoutPosition.
faceinteger(kind=I4P)inText face.
headinteger(kind=I4P)outFirst noad.

Call graph

text_list ​

Ord noads of the characters of text (UTF-8, braces and blanks out) in a text face.

Attributes: pure

fortran
subroutine text_list(tree, text, face, head)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
textcharacter(len=*)inText.
faceinteger(kind=I4P)inText face.
headinteger(kind=I4P)outFirst noad.

Call graph

delimiter ​

The delimiter after \left or \right: its math glyph, 0 for ..

Attributes: pure

fortran
subroutine delimiter(source, at, glyph)

Arguments

NameTypeIntentAttributesDescription
sourcecharacter(len=*)inLaTeX math.
atinteger(kind=I4P)inoutPosition.
glyphinteger(kind=I4P)outGlyph.

Call graph

math_char ​

The noad of a character typed in math: letters in math italic, digits and signs upright, each its atom kind.

Attributes: pure

fortran
subroutine math_char(tree, code, noad)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
codeinteger(kind=I4P)inCharacter.
noadinteger(kind=I4P)outNoad.

Call graph

command_code ​

The character and atom kind of a symbol command, 0 if name is not one.

Attributes: pure

fortran
subroutine command_code(name, kind, code)

Arguments

NameTypeIntentAttributesDescription
namecharacter(len=*)inCommand name.
kindinteger(kind=I4P)outAtom kind.
codeinteger(kind=I4P)outCharacter.

Call graph

new_noad ​

A fresh noad of kind.

Attributes: pure

fortran
subroutine new_noad(tree, kind, noad)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
kindinteger(kind=I4P)inKind.
noadinteger(kind=I4P)outNoad.

Call graph

new_char ​

A noad of kind whose nucleus is the math font's character code.

Attributes: pure

fortran
subroutine new_char(tree, kind, code, noad)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
kindinteger(kind=I4P)inKind.
codeinteger(kind=I4P)inCharacter.
noadinteger(kind=I4P)outNoad.

Call graph

set_list ​

Set the list from head in style (cramped or not) at base size base: its items appended from first, from the list's origin; its width, height and depth.

Attributes: pure, recursive

fortran
subroutine set_list(tree, state, head, style, cramped, base, width, height, depth, first)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
statetype(box_state)inoutItems.
headinteger(kind=I4P)inFirst noad.
styleinteger(kind=I4P)inStyle.
crampedlogicalinCramped.
basereal(kind=R8P)inBase font size.
widthreal(kind=R8P)outWidth.
heightreal(kind=R8P)outHeight.
depthreal(kind=R8P)outDepth.
firstinteger(kind=I4P)outFirst item.

Call graph

set_noad ​

Set one noad, its nucleus and scripts, from its origin; a character's italic correction added to its width unless it is the last of its list (as LuaTeX). First item of the list.

Attributes: pure, recursive

fortran
subroutine set_noad(tree, state, noad, style, cramped, base, width, height, depth, first, last)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
statetype(box_state)inoutItems.
noadinteger(kind=I4P)inNoad.
styleinteger(kind=I4P)inStyle.
crampedlogicalinCramped.
basereal(kind=R8P)inBase size.
widthreal(kind=R8P)outWidth.
heightreal(kind=R8P)outHeight.
depthreal(kind=R8P)outDepth.
firstinteger(kind=I4P)outFirst item.
lastlogicalinThe last noad of its list.

Call graph

set_char ​

A character in its face at size: in the math font its script alternate in script styles.

Attributes: pure

fortran
subroutine set_char(state, face, glyph, code, style, size, width, height, depth, italic)

Arguments

NameTypeIntentAttributesDescription
statetype(box_state)inoutItems.
faceinteger(kind=I4P)inFace.
glyphinteger(kind=I4P)inGlyph.
codeinteger(kind=I4P)inCharacter.
styleinteger(kind=I4P)inStyle.
sizereal(kind=R8P)inFont size.
widthreal(kind=R8P)outAdvance.
heightreal(kind=R8P)outHeight.
depthreal(kind=R8P)outDepth.
italicreal(kind=R8P)outItalic correction.

Call graph

set_scripts ​

The scripts of a set nucleus (its box width x height + depth, from its first item), TeX's rule 18 with the MATH constants of the nucleus' style; the box extended by them and the space after scripts.

Attributes: pure, recursive

fortran
subroutine set_scripts(tree, state, noad, style, cramped, base, char, italic, width, height, depth, operator)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
statetype(box_state)inoutItems.
noadinteger(kind=I4P)inNoad.
styleinteger(kind=I4P)inStyle of the nucleus.
crampedlogicalinCramped.
basereal(kind=R8P)inBase size.
charlogicalinThe nucleus a character.
italicreal(kind=R8P)inIts italic correction.
widthreal(kind=R8P)inoutBox width.
heightreal(kind=R8P)inoutHeight.
depthreal(kind=R8P)inoutDepth.
operatorlogicalinA big operator: the subscript back by the italic correction.

Call graph

set_fraction ​

\frac: numerator and denominator one style smaller (the denominator cramped), TeX's rule 15 with the MATH constants, the rule on the axis, both centered, a null delimiter space on each side.

Attributes: pure, recursive

fortran
subroutine set_fraction(tree, state, noad, style, cramped, base, width, height, depth)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
statetype(box_state)inoutItems.
noadinteger(kind=I4P)inNoad.
styleinteger(kind=I4P)inStyle.
crampedlogicalinCramped.
basereal(kind=R8P)inBase size.
widthreal(kind=R8P)outWidth.
heightreal(kind=R8P)outHeight.
depthreal(kind=R8P)outDepth.

Call graph

set_radical ​

\sqrt: the body cramped, the radical's smallest size variant covering it (with the gap and the rule), the rule on the radical's top over the body (TeX's rule 11 with the MATH constants).

Attributes: pure, recursive

fortran
subroutine set_radical(tree, state, noad, style, base, width, height, depth)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
statetype(box_state)inoutItems.
noadinteger(kind=I4P)inNoad.
styleinteger(kind=I4P)inStyle.
basereal(kind=R8P)inBase size.
widthreal(kind=R8P)outWidth.
heightreal(kind=R8P)outHeight.
depthreal(kind=R8P)outDepth.

Call graph

set_accent ​

An accent over its body: centered by the top accent attachments (the body's, else half its width; the accent's), raised by the body's height above the accent base height (TeX's rule 12).

Attributes: pure, recursive

fortran
subroutine set_accent(tree, state, noad, style, cramped, base, width, height, depth)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
statetype(box_state)inoutItems.
noadinteger(kind=I4P)inNoad.
styleinteger(kind=I4P)inStyle.
crampedlogicalinCramped.
basereal(kind=R8P)inBase size.
widthreal(kind=R8P)outWidth.
heightreal(kind=R8P)outHeight.
depthreal(kind=R8P)outDepth.

Call graph

set_fenced ​

\left ... \right: the body between delimiters of the smallest size variant covering it around the axis (TeX's \delimiterfactor 901 and \delimitershortfall 5 pt), centered on the axis; an Inner atom.

Attributes: pure, recursive

fortran
subroutine set_fenced(tree, state, noad, style, cramped, base, width, height, depth)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
statetype(box_state)inoutItems.
noadinteger(kind=I4P)inNoad.
styleinteger(kind=I4P)inStyle.
crampedlogicalinCramped.
basereal(kind=R8P)inBase size.
widthreal(kind=R8P)outWidth.
heightreal(kind=R8P)outHeight.
depthreal(kind=R8P)outDepth.

Call graph

binary_to_ordinary ​

TeX's rules 5 and 6: a Bin first, or after Bin, Op, Rel, Open or Punct, or before Rel, Close or Punct, is an Ord.

Attributes: pure

fortran
subroutine binary_to_ordinary(tree, head)

Arguments

NameTypeIntentAttributesDescription
treetype(noad_tree)inoutNoads.
headinteger(kind=I4P)inFirst noad.

Call graph

glyph_box ​

The advance, height, depth and italic correction of a glyph at size.

Attributes: pure

fortran
subroutine glyph_box(face, glyph, size, width, height, depth, italic)

Arguments

NameTypeIntentAttributesDescription
faceinteger(kind=I4P)inFace.
glyphinteger(kind=I4P)inGlyph.
sizereal(kind=R8P)inFont size.
widthreal(kind=R8P)outAdvance.
heightreal(kind=R8P)outHeight.
depthreal(kind=R8P)outDepth.
italicreal(kind=R8P)outItalic correction.

Call graph

add_glyph ​

Append a glyph.

Attributes: pure

fortran
subroutine add_glyph(state, face, glyph, code, x, y, size)

Arguments

NameTypeIntentAttributesDescription
statetype(box_state)inoutItems.
faceinteger(kind=I4P)inFace.
glyphinteger(kind=I4P)inGlyph.
codeinteger(kind=I4P)inCharacter.
xreal(kind=R8P)inAbscissa.
yreal(kind=R8P)inOrdinate, up.
sizereal(kind=R8P)inFont size.

Call graph

add_rule ​

Append a rule: its left, bottom, width and thickness.

Attributes: pure

fortran
subroutine add_rule(state, x, y, width, thickness)

Arguments

NameTypeIntentAttributesDescription
statetype(box_state)inoutItems.
xreal(kind=R8P)inLeft.
yreal(kind=R8P)inBottom, up.
widthreal(kind=R8P)inWidth.
thicknessreal(kind=R8P)inThickness.

Call graph

shift ​

Move the items from first to last.

Attributes: pure

fortran
subroutine shift(state, first, last, dx, dy)

Arguments

NameTypeIntentAttributesDescription
statetype(box_state)inoutItems.
firstinteger(kind=I4P)inFirst item.
lastinteger(kind=I4P)inLast item.
dxreal(kind=R8P)inAbscissa shift.
dyreal(kind=R8P)inOrdinate shift, up.

Call graph

skip_blanks ​

Past the blanks at at.

Attributes: pure

fortran
subroutine skip_blanks(source, at)

Arguments

NameTypeIntentAttributesDescription
sourcecharacter(len=*)inText.
atinteger(kind=I4P)inoutPosition.

Call graph

utf8_code ​

The code point of the UTF-8 character at at and its bytes.

Attributes: pure

fortran
subroutine utf8_code(text, at, code, n)

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=*)inText.
atinteger(kind=I4P)inPosition.
codeinteger(kind=I4P)outCode point.
ninteger(kind=I4P)outBytes.

Call graph

Functions ​

has_math ​

Whether text holds math (next_math).

Attributes: pure

Returns: logical

fortran
function has_math(text) result(yes)

Arguments

NameTypeIntentAttributesDescription
textcharacter(len=*)inText.

Call graph

any_upm ​

Units to the em of a text face (1-8) or of the math font (MATH_FACE).

Attributes: pure

Returns: integer(kind=I4P)

fortran
function any_upm(face) result(upm)

Arguments

NameTypeIntentAttributesDescription
faceinteger(kind=I4P)inFace.

Call graph

any_advance ​

Advance of a glyph of a text face or of the math font [font units].

Attributes: pure

Returns: integer(kind=I4P)

fortran
function any_advance(face, glyph) result(advance)

Arguments

NameTypeIntentAttributesDescription
faceinteger(kind=I4P)inFace.
glyphinteger(kind=I4P)inGlyph.

Call graph

atom_kind ​

The atom kind a noad spaces as: fractions, radicals and accents Ord (LaTeX's \frac a group), fenced lists Inner.

Attributes: elemental

Returns: integer(kind=I4P)

fortran
function atom_kind(kind) result(atom)

Arguments

NameTypeIntentAttributesDescription
kindinteger(kind=I4P)inNoad kind.

Call graph

em ​

Font units of the math font at size.

Attributes: pure

Returns: real(kind=R8P)

fortran
function em(units, size) result(length)

Arguments

NameTypeIntentAttributesDescription
unitsinteger(kind=I4P)inFont units.
sizereal(kind=R8P)inFont size.

Call graph

axis ​

The math axis at size.

Attributes: pure

Returns: real(kind=R8P)

fortran
function axis(size) result(height)

Arguments

NameTypeIntentAttributesDescription
sizereal(kind=R8P)inFont size.

Call graph

starts ​

source has word at at.

Attributes: pure

Returns: logical

fortran
function starts(source, at, word) result(yes)

Arguments

NameTypeIntentAttributesDescription
sourcecharacter(len=*)inText.
atinteger(kind=I4P)inPosition.
wordcharacter(len=*)inWord.

Call graph

is_letter ​

An ASCII letter.

Attributes: elemental

Returns: logical

fortran
function is_letter(ch) result(yes)

Arguments

NameTypeIntentAttributesDescription
chcharacter(len=1)inCharacter.

Call graph

word_number ​

The rank of word among the blank-separated words, 0 if absent.

Attributes: pure

Returns: integer(kind=I4P)

fortran
function word_number(words, word) result(k)

Arguments

NameTypeIntentAttributesDescription
wordscharacter(len=*)inWords.
wordcharacter(len=*)inWord.

Call graph

Released under the GPL v3, BSD 2-Clause, BSD 3-Clause or MIT License.