Skip to main content

Module lines

Module lines 

Source
Expand description

Equation lines: the four commands an author writes inside a display-math environment’s body (\\, \label, \tag and \nonumber), and the reader that splits such a body into lines.

An equation line is one line of a display-math environment as its body reads between two \\: its mathematics, its labels, its tag and its no-number mark; each line is one reference point (equation lines). An align body such as a &= b \label{eq:first} \\ c &= d \nonumber holds two lines. The math feature declares one reference point per line and numbers it from what equation_lines reads here; the lowering rules of the feature that processes mathematics write each line’s tag or number, and, on the latex-recomposed backend, each line’s labels.

§The four commands

writtenfield namewhat the line records
\\, \\[1ex]LINEBREAK_COMMANDthe end of the line, and the optional spacing as written
\label{eq:name}LABEL_FIELDa label of the line
\tag{A}, \tag*{A}TAG_COMMANDthe tag’s content as inline nodes, and whether the star was written
\nonumberNONUMBER_COMMANDthe line is not numbered

The four commands are declared in the scoped package (ScopedPackageDef) PACKAGE (flm.math.lines): a set of element declarations that can be written only inside the environment bodies and arguments whose declarations refer to the package by name (scoped packages). The bodies of the six display-math environments refer to it, and the declarations are for math mode only, so this module’s declarations apply inside \begin{align}…\end{align} and the other five environments, and nowhere else. In inline mathematics \(…\) and in displayed mathematics \[…\], \\ and \tag are commands this module does not declare (under the math-passthrough feature, unknown commands kept as source); in text mode they mean what another feature declares there, if anything.

All four are fields: macros that a construct reads as data rather than as content (fields). Each node carries an element named FIELD and is read by the command’s name, and the environment’s reader, equation_lines, gives them their meaning. Where a command is written inside its line makes no difference to what the line records. The \label declared here is a separate declaration from the \label that a heading reads after its arguments, but it produces a field node of the same field name, so the references feature’s reader of a label, label_use, reads it unchanged.

The optional argument of \\ must follow the command immediately: in a \\ [b] the [b] is content of the next line, not spacing. This keeps a bracketed expression at the start of a line from being read as spacing.

\nonumber is the only way to write the no-number mark. \notag, which LaTeX’s amsmath package also accepts, is not declared: inside a body it is an unknown command, kept as source in the line.

The whitespace right after a command’s name belongs to the command’s node (see macros in the syntax guide), so the newline after \nonumber is not part of the line’s content. The name of \\ is a single character that is not a letter, which takes no such whitespace, so the newline after it begins the next line’s content.

§Reading a body as lines

equation_lines reads the direct children of an environment’s body once and returns one EquationLine per line, in order:

  • A \\ ends the line being read.
  • A \label, \tag or \nonumber is taken out of the content and recorded on the line it is written in. A \label written on a line of its own before the \\ belongs to the line that \\ ends; one written right after a \\ belongs to the next line. The whitespace around such a command stays in the content; where the command stood on a line of its own, the LaTeX writers keep a blank line from appearing through the math library’s newline rule (normalize_line_newlines).
  • Everything else (mathematics, whitespace, comments, and nested environments as a whole) is the line’s content, in order. The nodes of a nested environment are not examined, so a \\ inside a cases or matrix environment nested in an align does not split the outer lines.
  • A body with no \\ is one line.
  • A \\ followed only by whitespace, blank lines and comments ends the last line and begins no further one. It is not recorded (the last line’s linebreak is None), and the whitespace and comments after it are added to the last line’s content as written. A backend that writes the lines back therefore never writes a final \\, which would make LaTeX add the space of an empty line after the last equation. Anything else after the last \\ (mathematics, a \label, a \tag or a \nonumber) begins a further line.

A line’s linebreak is therefore Some exactly when another line follows it.

§The error, and empty lines

The body parser of the display-math environments (LinesBehavior) checks the lines when a body is parsed and reports one condition as an Error: LabelWithoutNumber (flm.math.label-without-number), a \label or a \tag written on a line that cannot be numbered, a line marked \nonumber or any line of equation*, align* or gather*. Each such command is reported once.

Whether a line must hold mathematics is a question for the feature that processes mathematics, not for this module: a line holding only whitespace, comments, a \label, a \tag or a \nonumber, a \\ at the start of a body, two \\ in a row and an empty body are read here without a report. A processing feature reports each such line from its check stage, as math-passthrough does.

The tree keeps the body as written, and equation_lines returns every line, an empty line as an EquationLine with no content, so that a backend can still write back what the author wrote.

§Lowering

None of the four commands is lowered on its own. Their nodes are only ever written inside an environment’s body, which the environment’s lowering rule reads as lines and writes from the lines’ data. A field node that reaches a backend on its own is an Error, reported by the only lowering rule of the field element (FieldRule).

§The lines and the numbers

The environment declares one reference point per line, whose index is the line’s index. A line that can be numbered carries the labels written on it, so \ref{eq:name} refers to the line it labels and shows the number the document gave that line; a line that cannot be numbered keeps no label, so nothing can refer to it. A line’s \tag replaces its number: the reference point states the tag’s content (Tag::content_ref), and the line counts in nothing. The math feature’s documentation describes the reference points in full.

§Map of the module

Structs§

EquationLine
One equation line of a display-math environment, as equation_lines reads it: its content, labels, tag, no-number mark and line break. The module documentation, Reading a body as lines, says how a body is split into lines.
LabelWithoutNumber
Condition flm.math.label-without-number (an Error): a \label or a \tag is written on an equation line that cannot be numbered, a line marked \nonumber or any line of a starred environment (equation*, align*, gather*).
LineBreak
A \\ node, as line_break reads it: the node and its spacing.
LinesBehavior
The body parser (FlmBodyParser) of the six display-math environments: techy’s ordinary parse of an environment body, up to and including \end{name}, followed by the check of the equation lines, which reports LabelWithoutNumber among the parse’s diagnostics. See the module documentation, The error, and empty lines.
Tag
A \tag node, as tag_of reads it: the node, its content and whether the star was written.

Enums§

LineCommand
The command that a LabelWithoutNumber condition reports: \label or \tag.

Constants§

LINEBREAK_COMMAND
The name of the line-break field, a single backslash: the author writes it after the escape character, so the command reads \\.
NONUMBER_COMMAND
The name of the no-number field, nonumber.
PACKAGE
The name of the scoped package that holds the four commands, flm.math.lines: the body declaration of each display-math environment refers to it, which makes the commands available inside the body.
SPACING_ARG
The name of the optional argument of \\, spacing: the vertical space added after the line, as in \\[1ex].
STAR_ARG
The name of the star argument of \tag, star: when it is written (\tag*), the tag is shown without parentheses.
TAG_COMMAND
The name of the tag field, tag.
TEXT_ARG
The name of the mandatory argument of \tag, text: the tag’s content, read in text mode.

Functions§

body_behavior
The LinesBehavior of a display-math environment, numbered saying whether the environment numbers its lines: the body parser that the environment’s body declaration carries (BodyDef::parser).
equation_lines
The equation lines of a display-math environment’s body: one EquationLine per line, in order. The module documentation, Reading a body as lines, says exactly how the body is split.
line_break
Reads a \\ node: Some with its spacing when node is the line-break field of this module, None for any other node.
package
The scoped package PACKAGE with the declarations of the four commands, owned by owner: what the math feature registers, and what the body of each display-math environment refers to.
tag_of
Reads a \tag node: Some with its content and its star when node is the tag field of this module, None for any other node. A tag whose text argument is absent (after a parse recovery) has no content.