Subsection 4.9.8 Alignment in Display Mathematics
Displayed mathematics is implemented with the AMS-LaTeX
align
environment. Ampersands are used to control this, so use the \amp
macro for these. The first ampersand in a line or row is an alignment point, typically a symbol, like an equality. The next ampersand is a column separator, then the next is an alignment point, then a column separator, then… The moral of the story is you should have \(n\) alignment points, with \(n-1\) column separators, for a total of \(2n-1\) ampersands—always an odd number.For example,
<md> <mrow>A \amp = B \amp D \amp = E \amp \amp \text{Because}</mrow> <mrow> \amp = C \amp \amp = F \amp \amp <xref ref="txo" /></mrow> </md>
produces
\begin{align*}
A \amp = B \amp D \amp = E \amp \amp\text{Because}\\
\amp = C \amp \amp = F \amp \amp\knowl{./knowl/txo.html}{\text{Table 4.5.2.3}}\text{.}
\end{align*}
Sometimes you want several short equations on one line. Do not use
<me>
. Instead use a single <mrow>
inside an <md>
, and use alignment to spread them out evenly.For multi-line display mathematics with no ampersands present, each line will be centered. This is implemented with the AMS-LaTeX
gather
environment.You can fool the alignment behavior by hiding all your ampersands in macro definitions, so there is the optional
@alignment
attribute for the <md>
or <mdn>
element, in order to force the right kind of alignment. Allowable values are gather
, align
, and alignat
. The latter is similar to align
, but no space is automatically provided between columns. You can leave it that way, or explicitly add your own. For example, this allows you to precisely arrange individual terms of a system of linear equations, especially when terms with zero coefficients are omitted. When using the alignat
option PreTeXt tries to count ampersands to see how many columns you intend, since LaTeX needs this number (we are not sure why). This detection can be fooled too, especially if you have something like a matrix with lots of ampersands for other purposes. So set the @alignat-columns
attribute to the number of intended columns, if necessary.