Skip to main content

Module tex

Module tex 

Source
Expand description

The TeX of a formula, with holes: what a renderer of mathematics converts, written from the formula’s nodes.

A processing feature that hands its formulas to a typesetter of TeX notation (MathJax, a converter to Unicode text) needs each formula’s TeX as a string, except where the formula holds document text: the argument of a text command (\text{…}, \textbf{…}, \mbox{…}, the commands of text) is content the feature lowers itself, so that a reference in it is a link and its style is FLM’s. This module writes the TeX as a list of parts, each a piece of TeX text or a hole standing for one text command.

§What it reads

  • group_tex: a math group (\(…\), \[…\], a node of the element flm.math), whose TeX is its content, without the delimiters.
  • line_tex: one equation line of a display-math environment, an EquationLine as equation_lines reads it, whose TeX is its content written under the newline rule (below). A line’s \\, \tag, \nonumber and labels are not part of its content and are never written: they are data of the line, which its frame holds. The environment as a whole is not assembled here: a caller that writes it writes \begin{name}, then per line its content, what its frame shows, its line break and its trailing run (below), then \end{name}, passing each line’s LineTex::ends_line to line_tex for the next line.

§How the nodes are written

The nodes are those of any processor’s commands of math mode, each written by its source:

  • a command of the processor (a macro, an environment) and a run of characters, as their source as written;
  • a group, as its delimiters around its content;
  • \ensuremath{…} (ensuremath), as its argument’s content alone, the command left out, since inside a formula it stands for its argument;
  • a text command, as a hole, at any depth (inside a group or a command’s argument);
  • a comment, as one space: the comment takes in its line end, so that dropping it would run the tokens on either side together (\alpha%%c then b on the next line is \alpha b, not \alphab).

A command that holds a text command, a comment or \ensuremath{…} is written as its call as written (an environment as \begin{name} and \end{name} around its arguments and body), then each argument by the same rules; any other node is written as its source, unchanged.

Where the TeX written so far ends with a control word (a backslash and letters, \rangle) and the next text begins with a letter, one space stands between them, which TeX skips after a control word: the two come from places the source did not write side by side (the end of a user definition’s expansion and the letter after its use; \alpha and the argument of \ensuremath{b}), and the letter would otherwise continue the control word (\rangleA, \alphab).

§The newline rule on a line

A line’s content is written under the math library’s newline rule (normalize_line_newlines; the module documentation of latex, The newline rule), so that a \label, \tag or \nonumber taken off a line of its own leaves no blank line, which LaTeX refuses inside mathematics. Each TeX part of the content is normalized; the run of whitespace that ends the content is taken off and returned as the line’s trailing run, for the caller to write after the line’s tag and its line break; when it is not empty, the run that begins the next line’s content is dropped. A hole is not a line’s end, and a comment, written as a space, does not end a line either.

§The shape of the result

The result holds strings and node handles only, so that an extension can receive it across a binding as data: a part is {tex} or {hole: {command, node}}, and a line adds its trailing run.

The functions recompose the source of the nodes they write as source (recompose_source), so call them on a worker thread, as every stage and lowering rule of a run already executes.

Structs§

LineTex
The TeX of one equation line’s content (see the module documentation, The newline rule on a line): what line_tex returns.
TextHole
A text command inside a formula (\text{…}, \textbf{…}, \mbox{…}; see is_math_text_command), which the TeX leaves as a hole: the caller lowers its argument itself and decides how the hole is written.

Enums§

TexPart
One part of a formula’s TeX, in order: TeX text, or a hole for a text command (see the module documentation).

Functions§

group_tex
The TeX of the math group node (a node of flm.math): its content, without its delimiters, written by the rules of the module documentation. A formula that holds no text command gives one TeX part, an empty formula none.
line_tex
The TeX of the equation line line’s content, written by the rules of the module documentation, each TeX part under the newline rule, and the run of whitespace that ended the content.