<section label="section-mathematics">
<title>Mathematics</title>
<introduction>
<p>
To be able to create both <latex/> and HTML output
(plus variations),
we rely on MathJax,
which in turn supports an extensive subset of the mathematical symbols normally available.
The AMSMath symbol set is a good approximation.
The <pretext/> Guide has a link to the complete list of macros supported by MathJax.
We load the <c>AMSsymbols</c> library.
</p>
</introduction>
<subsection>
<title>Basic Mathematics</title>
<p>
The following is from the MathJax
<url href="http://www.mathjax.org/demos/tex-samples/" visual="www.mathjax.org/demos/tex-samples/">demonstration page</url>,
an identity due to Ramanujan:
<me>
\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\ldots} } } }
</me>
</p>
<p>
And again, from the MathJax demonstration page, Maxwell's equations:
<idx>Maxwell's equations</idx>
<md>
<mrow>\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}}</mrow>
<mrow>\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho</mrow>
<mrow>\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}}</mrow>
<mrow>\nabla \cdot \vec{\mathbf{B}} & = 0</mrow>
</md>
<notation>
<usage><m>\nabla</m></usage>
<description>gradient operator</description>
</notation>
</p>
<p>
Historically,
we provided internal support for the <latex/> package <c>extpfeil</c>.
As of 2023-10-19 this has become an author election
(see the <tag>docinfo</tag> section in the source of this document).
We preeserve a small test that this extensible arrows library is being included properly:
<me>
A\xmapsto[\text{bijection}]{\Phi+\Psi+\Theta}B
</me>
</p>
<p>
Look back at the top of the source file of this document to see how to include your <tex/> macros just once.
For best results keep your macros simple and semantic.
</p>
<p>
<pretext/> once provided modest built-in support for
<q>slanted</q>, or
<q>beveled</q>, or
<q>nice</q>
fractions.
To wit, we mean fractions such as: <m>\sfrac{3}{8}</m>.
Use the pre-defined <c>\sfrac{}{}</c> macro in your mathematics to achieve this presentation.
The presentation in HTML is subpar,
but could improve as MathJax provides support.
It is now an author's responsibility to add support for superior typesetting for <init>PDF</init> output by loading the <c>xfrac</c> <latex/> package with the following in <tag>docinfo</tag>:
<cd>
<cline><math-package latex-name="xfrac" mathjax-name=""/></cline>
</cd>
which is what we have done here as a test.
See the Guide for more details.
</p>
<p>
We consider a system of equations.
We number the first and last equation
(there are just two)
and include an <c>xml:id</c> on each.
We reference the whole system later as the range of equations from the first to the last.
<mdn>
<mrow xml:id="equation-system-begin">\frac{dx}{dt} \amp = x^2 - 4x - y + 4</mrow>
<mrow xml:id="equation-system-end">\frac{dy}{dt} \amp = x^3 - y</mrow>
</mdn>.
</p>
</subsection>
<subsection>
<title>Displayed Mathematics</title>
<p>
Multi-line displays of mathematics are achieved with the <c>md</c> tag (
<q>math display</q>),
and the variant that produces numbers on each line,
<c>mdn</c> (
<q>math display numbered</q>),
used within a paragraph
(<c>p</c>).
As a good example of how XML syntax is superior,
you author <m>n</m> lines of equations by enclosing each line inside of a <c>mrow</c> tag,
rather than using <m>n-1</m> separators
(such as <c>\\</c>).
</p>
<p>
If you use no ampersands to express alignment
(read ahead),
then each equation is centered independently on the width of the text.
This is implemented according to the AMSmath <latex/> package's <c>gather</c> environment.
Example:
<md>
<mrow>\frac{dx}{dt} = x^2 - 4x - y + 4</mrow>
<mrow>\frac{dy}{dt} = x^3 - y</mrow>
</md>.
</p>
<p>
An ampersand is used, in two ways,
to describe positioning several equations per line, organized in columns.
We have created the pre-defined <latex/> macro <c>\amp</c> as one way specify these,
but the escape sequence <c>&amp;</c> may be used also.
The second, fourth, sixth, <ellipsis/> ampersands separate columns,
and the spacing between columns will be provided automatically.
The first, third, fifth,
<ellipsis/> ampersands are alignment points for the equations in each column.
Typically this is placed just prior to a binary operator,
such as an equal sign (<c>\amp = </c>), or for a column of explanations or commentary,
just prior to the <c>\text{}</c> macro.
Note that this scenario suggests always having an odd number of ampersands in each <c>mrow</c>.
In the example below,
alignment is on the equals sign in the first two columns,
and provides left-justification to the explanations in the third column.
N.B.: the use below of the <c>\text{}</c> macro does not include mathematics within its argument.
Doing so may yield unpredictable results depending on your choice of delimiters for the mathematics
(and using an <c>m</c> tag will be ineffective).
<md>
<mrow>\frac{dx}{dt} \amp = x^2 - 4x - y + 4 \amp \frac{dy}{dt} \amp = x^3 - y \amp\amp x, y\text{ version}</mrow>
<mrow>\frac{dw}{dt} \amp = z^3 - w \amp \frac{dz}{dt} \amp = z^2 - 4z - w + 4 \amp\amp z, w\text{ version}</mrow>
</md>
</p>
<p>
<pretext/> will automatically detect the presence or absence of ampersands,
but by defining macros for entire aligned equations,
you can effectively hide the ampersands.
So the <c>@alignment</c> attribute can override automatic detection.
We use a simple <latex/> macro to demonstrate setting <c>alignment='align'</c> to override the use of a <c>gather</c> environment and use a <c>align</c> environment instead.
Example:
<md alignment="align">
<mrow>\myequation{\frac{dx}{dt}}{x^2 - 4x - y + 4}</mrow>
<mrow>\myequation{\frac{dy}{dt}}{x^3 - y}</mrow>
</md>.
</p>
<p>
The AMSmath <latex/> package's <c>alignat</c> environment is a third variant of alignment.
It never happens automatically,
you need to ask for it with <c>alignment="alignat"</c>.
It is very similar to <c>align</c> but adds no space between the equation columns.
So you can leave it that way, or you can add your own
<q>extra</q>
space to suit.
Here is a previous example with no inter-column space:
<md alignment="alignat">
<mrow>\frac{dx}{dt} \amp = x^2 - 4x - y + 4 \amp \frac{dy}{dt} \amp = x^3 - y \amp\amp x, y\text{ version}</mrow>
<mrow>\frac{dw}{dt} \amp = z^3 - w \amp \frac{dz}{dt} \amp = z^2 - 4z - w + 4 \amp\amp z, w\text{ version}</mrow>
</md>.
This modified example has a middle row with three columns,
while the other rows have just one column,
as a test of our routines for determining the <c>mrow</c> with the greatest number of ampersands (and how many there are),
<md alignment="alignat">
<mrow>\frac{dw}{dt} &= z^3 - w</mrow>
<mrow>\frac{dx}{dt} &= x^2 - 4x - y + 4 & \frac{dy}{dt} &= x^3 - y&& x, y\text{ third column}</mrow>
<mrow>\frac{dw}{dt} & = z^3 - w</mrow>
</md>.
Final example demonstrates that ampersands in other objects
(matrices here)
can wreak havoc with computing the number of columns.
So we provide yet another attribute to override automatic detection,
<c>alignat-columns</c>.
This is the number of <em>columns</em>
not the number of <em>ampersands</em>.
Generally, for <m>c</m> columns,
there will be <m>2c-1</m> ampersands.
<md alignment="alignat" alignat-columns="2">
<mrow>A &= \begin{bmatrix}1 & 2 \\ 3 & 4\end{bmatrix} & I &= \begin{bmatrix}1 & 0 \\ 0 & 1\end{bmatrix}</mrow>
</md>.
One caveat: if your number of ampersands is even
(see advice above about using an odd number)
behavior should still be correct, as in next example.
</p>
<p>
If you want super-precise control over alignment of the terms of a system of equations
(linear or not)
you can use the <c>alignat</c> option to advantage by not including any extra space.
This example is modified slightly from a post by Alex Jordan:
<md alignment="alignat">
<mrow>2x \amp {}+{} \amp y \amp {}+{} \amp 3z \amp {}={} \amp 10</mrow>
<mrow>x \amp \amp \amp {}+{} \amp z \amp {}={} \amp 6</mrow>
<mrow>x \amp {}+{} \amp 3y \amp {}+{} \amp 2z \amp {}={} \amp 13</mrow>
</md>.
Beautiful.
</p>
<aside>
<title>Overlap Test</title>
<p>
This is simply to test what happens when an aside bumps into something like the content below that may extend past the normal right content boundary.
It likely only is of interest with the theme <c>default-modern</c>.
</p>
</aside>
<p>
A long equation, to check layout on various screen sizes.
This is Weil's
<q>explicit formula</q>
for the Riemann <m>\zeta</m>-function:
<men>
\sum_\gamma S_-(\gamma) = \frac{\log Q}{\pi} \hat S_-(0) + \frac{1}{2\pi} \sum_{j=1}^d \Re\left\{ \int_{-\infty}^\infty \frac{\Gamma'}{\Gamma}\left(\frac{1}{4} + \frac{it}{2} + \mu_j\right)S_-(t) dt\right\} - \frac{d}{2\pi}\hat S_-(0)\log \pi
</men>.
</p>
<example>
<title>Excessive Display Mathematics</title>
<p>
In print versions,
a long run of displayed equations often needs to be broken across pages.
If you are reading some other version of this,
then there is nothing to see here.
But for <latex/> output it could be interesting.
First, with no extra effort,
this page-long display should break naturally,
no matter how the preceding material changes.
<md number="yes">
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
</md>.
</p>
<p>
In this version we have turned off page breaking for the entire display,
but then allowed a break at every fourth equation,
so you should see a reasonably attractive page break right after one of the <m>m^2+n^2=p^2</m> equations.
<mdn break="no">
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
</mdn>.
</p>
<p>
So.
Do not take any extra steps and let <latex/> figure out the breaks.
If you do not like a break,
modify the <c>md</c> or <c>mdn</c> to go back to the AMSmath default behavior and not break at all.
Ever.
Or rather, go further and modify an individual <c>mrow</c> to suggest that it is a good place for a break.
</p>
</example>
<p>
This is a poorly-authored paragaph to test the conversion to <init>HTML</init>.
There are two displayed equations,
separated by a period ending the first one's sentence,
which should migrate into the display,
and not leave behind an empty paragraph:
<me>
z+y = z
</me>.
<me>
a + b = c
</me>.
This final sentence should remain,
inside another <init>HTML</init> paragraph,
without the second equation's period.
</p>
</subsection>
<subsection>
<title><latex/> Packages and MathJax Extensions</title>
<p>
If you would like to enhance your mathematics by using a macro from a <latex/> package <em>and</em>
there is a MathJax extension <em>which implements the same macro</em>,
then you may use this with your mathematics as we demonstrate here.
</p>
<p>
This example is from Jason Underdown.
<idx><h>Underdown, Jason</h></idx>
The package is named <c>cancel</c> and is included in the TeXLive distribution,
so is fairly standard.
The particular macro being demonstrated is <c>\cancelto{}{}</c>.
<me>
\lim_{b \rightarrow \infty}\left[\cancelto{0}{-\frac{1}{s}e^{-sb}} + \frac{1}{s}\right]
</me>.
Look at the source of this article to see the package name being supplied in a <tag>math-package</tag> element within the <tag>docinfo</tag> section.
That is the only setup required to make the macro usable in <latex/> and <init>HTML</init> output.
<idx><h>canceling a term</h></idx>
<idx sortby="cancelto macro"><c>cancelto</c> macro</idx>
</p>
<p>
See the
<pubtitle><pretext/> Guide</pubtitle>
subsection about
<q>MathJax Extensions</q>
for more detail.
</p>
</subsection>
<subsection>
<title>Advanced Mathematics</title>
<p>
MathJax is extremely capable in rendering a subset of <latex/> in web browsers,
and improving all the time.
You can get fairly fancy with some of its supported commands.
In particular,
if you need to mix in a few words with your mathematics,
the <c>\text{}</c> macro is supported.
For example, you might use an
<q>if</q>
or an
<q>otherwise</q>
in the definition of a piecewise function.
</p>
<p>
Consider that the first line below is text sandwiched in-between two Greek letters,
wrapped in a <c>\text{}</c> macro.
In HTML output we have taken care that the font for text material within display mathematics should match the font of the surrounding paragraph,
as also happens with <latex/> output.
The second line is nearly identical in the source,
but is just naked text being rendered like a slew of variables.
<md>
<mrow>\alpha\text{ is not equal to }\beta</mrow>
<mrow>\alpha is not equal to \beta</mrow>
<mrow>\alpha\neq\beta</mrow>
</md>.
We are not suggesting here that using words in place of symbols,
as in the first line, is a good practice.
(It is not.)
</p>
<p>
The following example is a good stress-test of using the <c>\text{}</c> macro to achieve certain effects.
Note the Unicode left and right smart quotes.
This a contribution from Alex Jordan as part of his work on
<pubtitle>APEX Calculus</pubtitle>.
<md>
<mrow>y \rightarrow \frac{\sin(0) }{0} \rightarrow {{\text{β}}\atop{}}\frac{0}{0}{{\text{β}}\atop{}}\text{.}</mrow>
</md>
And another one from Alex.
Note the use of the <c>\mathord{}</c> and <c>\mathrel{}</c> macros to control spacing around the mathematical symbols.
Examine the source to see how the quotation marks have been authored with <init>XML</init> syntax for Unicode characters,
since we do not allow most markup inside mathematics.
<md>
<mrow>\zeta(1)=\sum_{n=1}^{\infty}\frac{1}{n}\mathrel{\text{ β}\mathord{=}{\text{β }}}\prod_{p}\left(\frac{1}{1-1/p}\right)=\prod_{p}\left(\frac{1}{1-p^{-1}}\right)</mrow>
</md>
</p>
<p>
Generally, you cannot use any <init>XML</init> elements inside of the mathematics elements.
An exception is the <c>xref</c> element which you might want to use to provide justifications for the steps of a derivation.
Here is a visual example that is mathematically meaningless,
<md>
<mrow>A&=B+C&&<xref ref="corollary-FTC-derivative" text="type-global"/></mrow>
<mrow>&=D+E&&<xref ref="theorem-FTC" text="title"/></mrow>
<mrow>&=F+G&&<xref ref="theorem-number-01" text="custom">A nice result</xref></mrow>
</md>.
</p>
<p>
Scott Beaver likes to write short chains of equalities all in one line,
with the cross-references sitting on each equals sign.
Here we test the <latex/> <c>\overset</c> and <c>\underset</c> macros wrapping a <pretext/> <tag>xref</tag>,
with and without content, inside an <tag>me</tag> element.
Note that <c>\stackrel</c> is obsolete,
and <c>\overunderset</c> is not yet supported by MathJax
(but see
<url href="https://github.com/mathjax/MathJax/issues/2704" visual="github.com/mathjax/MathJax/issues/2704">GitHub #2704</url>).
The mathematics is Scott's, the reasons are totally unrelated to the math.
<me>
AC-AD \overset{<xref ref="theorem-FTC" text="global"/>}{=} A(C-D) \underset{<xref ref="definition-indefinite-integral" text="global"/>}{=} A0_{n\times p} \overset{<xref ref="theorem-FTC" text="global">Thm.</xref>}{=} 0_{m\times p}
</me>
We suggest using cross-references that only display numbers (<tag>xref</tag> with <attr>text</attr> set to <c>global</c>) since if you stick to elements like <tag>theorem</tag>,
<tag>lemma</tag>, <tag>definition</tag>, or <tag>axiom</tag>,
then the numbers will be unambiguous and the target of the cross-reference will contain full information.
But note that if you mix in divisions, or perhaps figures,
as reasons then there is a possibility that numbers will need to be qualified by their type.
We have provided an abbreviation for one cross-reference to <xref ref="theorem-FTC" text="type-global"/>
(which will not benefit from automatic translation to other languages).
</p>
</subsection>
<subsection>
<title>Local Tags on Equations</title>
<p>
If you are not writing a research monograph,
maybe (a) you will not use many numbered equations,
or do not like the looks of them,
or feel they scare your readers,
and (b) maybe your cross-references are always local-ish,
like strictly within an <c>example</c> or a <c>proof</c>.
For this situation you can create, and employ, a
<q>local</q>
tag on a displayed equation.
Nothing enforces the idea of what constitutes local,
and there is nothing to stop you from using the same symbols more than once.
With freedom comes responsibility.
</p>
<p>
Use the <c>@tag</c> attribute on an <c>mrow</c>, only.
(Remember, you can have just one <c>mrow</c>.)
The behavior is identical within an <c>md</c> or <c>mdn</c>.
The value of the <c>@tag</c> attribute is a symbol name.
The prefix <c>d</c> means
<q>double</q>, and the prefix <c>t</c> means
<q>triple</q>. So allowed values are
<cd>
<cline>star, dstar, tstar</cline>
<cline>dagger, ddagger, tdagger</cline>
<cline>daggerdbl, ddaggerdbl, tdaggerdbl</cline>
<cline>hash, dhash, thash</cline>
<cline>maltese, dmaltese, tmaltese</cline>
</cd>
Cross-references to these tagged equations happens in the usual way and should behave as expected.
We test the double versions to make sure the symbols render properly in various output formats.
<mdn>
<mrow xml:id="equation-local-star" tag="dstar">c^2 \amp = a^2+b^2</mrow>
<mrow xml:id="equation-local-dagger" tag="ddagger">c^2 \amp = a^2+b^2</mrow>
<mrow xml:id="equation-local-daggerdbl" tag="ddaggerdbl">c^2 \amp = a^2+b^2</mrow>
<mrow xml:id="equation-local-hash" tag="dhash">c^2 \amp = a^2+b^2</mrow>
<mrow xml:id="equation-local-maltese" tag="dmaltese">c^2 \amp = a^2+b^2</mrow>
<mrow>z^2 \amp = x^2+y^2</mrow>
</mdn>
Here are the local cross-references:
<xref ref="equation-local-star"/>,
<xref ref="equation-local-dagger"/>, <xref ref="equation-local-daggerdbl"/>,
<xref ref="equation-local-hash"/>, <xref ref="equation-local-maltese"/>.
We test another farther away in <xref ref="section-cross-referencing" text="type-global"/>, contrary to our advice above.
</p>
</subsection>
<subsection xml:id="commutative-diagrams">
<title>Commutative Diagrams</title>
<p>
This diagram is authored by Tom Judson using the syntax of the <init>AMS</init> <latex/>
<q>CD</q>
package.
Inside of a <tag>me</tag> element start with <c>\begin{CD}</c>.
Remember to escape the less-than character.
<me>
\begin{CD} E[x]/\langle p(x) \rangle @>\psi>> F[x]/\langle q(x) \rangle\\ @VV{\sigma}V @VV{\tau}V\\ E(\alpha) @>\overline{\phi}>> F(\beta)\\ @VVV @VVV\\ E @>\phi>> F \end{CD}
</me>
While this package is not as flexible as some generic drawing packages,
it has the advantage of full support by MathJax,
and thus the <init>HTML</init> version will be more accessible.
</p>
</subsection>
<subsection xml:id="line-breaking-math">
<title>Line-Breaking after Mathematics</title>
<p>
As of 2021-05-14, in <init>HTML</init> output the next sentence should just fill a full line across the page.
We take active measures to bind the concluding period to the final bit of mathematics,
the variable <m>x</m>.
The prevents a bad line break which could see the period <em>begin</em>
a new line, all by itself.
In the event that the line-breaking siutation improves,
we could relax these measures.
This testing is only relevant to <init>HTML</init> output,
not <latex/> output.
</p>
<p>
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx <m>x</m>.
</p>
</subsection>
<subsection xml:id="font-math">
<title>Fonts and Mathematics</title>
<p>
This section is about testing types and sizes of fonts,
not so much about using different typefaces.
First, one long displayed equation,
which is designed to be full-width for <latex/> output when using defaults as of 2020-01-29
(commit <c>defd4bffd462e7ea</c>).
</p>
<p>
Start paragraph.
<me>
a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2
</me>
End paragraph.
</p>
<p>
The next paragraph has five ways to write the sine of <m>x</m>,
bracketed by plain text versions.
This tests font size and the fonts employed.
The raw source of this paragraph is (spread over two lines)
<cd>
<cline>sin x | <m>\sin x</m> | <m>\text{sin}\ x</m> | <m>\mathrm{sin}\ x</m> |</cline>
<cline><m>\text{sin}x</m> | <m>sin x</m> | sin x</cline>
</cd>
The five ways, from good to bad,
<ol>
<li>
The best way, using <c>\sin</c>.
Note the distance to the <m>x</m>.
</li>
<li>With a <c>\text{}</c> macro.</li>
<li>
With a <c>\mathrm{}</c> macro.
Not recommended for <pretext/>.
</li>
<li>
Without a space.
Note that the previous two require explicit spacing.
</li>
<li>
No extra effort,
so <latex/> renders as a product of four variables.
</li>
</ol>
</p>
<p>
sin x | <m>\sin x</m> | <m>\text{sin}\ x</m> | <m>\mathrm{sin}\ x</m> |
<m>\text{sin}x</m> | <m>sin x</m> | sin x
</p>
<p>
Finally a simple paragraph that places a text
<q>x</q>
next to a variable
<q>x</q>.
</p>
<p>
wordxx<m>x+x</m>xxword
</p>
</subsection>
<subsection xml:id="miscellaneous-math">
<title>Miscellaneous</title>
<p>
In <init>HTML</init> output,
a MathJax workaround for a Safari rendering bug was inserting extra spaces after textual subscripts and superscripts (
<url href="https://groups.google.com/g/mathjax-users/c/ANjLK9KtcWA/m/vlHaPja-AwAJ" visual="groups.google.com/g/mathjax-users/c/ANjLK9KtcWA/m/vlHaPja-AwAJ">MathJax thread</url>).
<pretext/> CSS now applies a correction.
The following tests if the CSS fix is sufficient,
and could be used to test the necessity of our fix in the future.
Following is the original report,
though <c>NOT</c> has been moved to a superscript:
<md>
<mrow>T_\text{clk}-t_\text{su} \gt t_\text{clk-Q} + \max\left( t_\text{XOR}, t^\text{NOT} \right)</mrow>
</md>.
There should not be anything to see in <latex/>/<init>PDF</init> output. (2021-10-21)
</p>
</subsection>
<subsection xml:id="testing-math" label="testing-math">
<title>Testing Mathematics</title>
<p>
This subsection is strictly about testing the five different elements used for mathematics (i.e. designed to hold <latex/> syntax).
It only varies the elements employed and the options for numbering displayed equations.
And not local tags or page breaks,
or other less-critical features.
There will not be much here for the interested reader to learn from.
</p>
<p>
First a bit of token inline mathematics,
via the <tag>m</tag> element,
where numbering is not an option.
Consider <m>x+y</m> as an expression.
</p>
<p>
Now single-line displayed equations.
First, the <tag>me</tag> element.
Which will not be numbered,
<me>
x^{1} + y^{1} = z^{1}
</me>.
Second, the <tag>men</tag> element.
Which will always be numbered,
<men>
x^{2} + y^{2} = z^{2}
</men>.
</p>
<p>
The remainder has three displayed equations each.
The first <tag>mrow</tag> has no <attr>number</attr> attribute,
the second sets the attribute to <c>no</c> and the third sets the attribute to <c>yes</c>.
The numbering of the first case is determined by the variant of the element,
the latter two provide explicit control.
</p>
<p>
The <tag>md</tag> element.
<md>
<mrow>x^{3} + y^{3} = z^{3}</mrow>.
<mrow number="no">x^{4} + y^{4} = z^{4}</mrow>.
<mrow number="yes">x^{5} + y^{5} = z^{5}</mrow>.
</md>
</p>
<p>
The <tag>mdn</tag> element.
<mdn>
<mrow>x^{6} + y^{6} = z^{6}</mrow>.
<mrow number="no">x^{7} + y^{7} = z^{7}</mrow>.
<mrow number="yes">x^{8} + y^{8} = z^{8}</mrow>.
</mdn>
</p>
</subsection>
</section>
Section 7 Mathematics
View Source for section
To be able to create both LaTeX and HTML output (plus variations), we rely on MathJax, which in turn supports an extensive subset of the mathematical symbols normally available. The AMSMath symbol set is a good approximation. The PreTeXt Guide has a link to the complete list of macros supported by MathJax. We load the
AMSsymbols library.
Subsection 7.1 Basic Mathematics
View Source for subsection
<subsection>
<title>Basic Mathematics</title>
<p>
The following is from the MathJax
<url href="http://www.mathjax.org/demos/tex-samples/" visual="www.mathjax.org/demos/tex-samples/">demonstration page</url>,
an identity due to Ramanujan:
<me>
\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\ldots} } } }
</me>
</p>
<p>
And again, from the MathJax demonstration page, Maxwell's equations:
<idx>Maxwell's equations</idx>
<md>
<mrow>\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}}</mrow>
<mrow>\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho</mrow>
<mrow>\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}}</mrow>
<mrow>\nabla \cdot \vec{\mathbf{B}} & = 0</mrow>
</md>
<notation>
<usage><m>\nabla</m></usage>
<description>gradient operator</description>
</notation>
</p>
<p>
Historically,
we provided internal support for the <latex/> package <c>extpfeil</c>.
As of 2023-10-19 this has become an author election
(see the <tag>docinfo</tag> section in the source of this document).
We preeserve a small test that this extensible arrows library is being included properly:
<me>
A\xmapsto[\text{bijection}]{\Phi+\Psi+\Theta}B
</me>
</p>
<p>
Look back at the top of the source file of this document to see how to include your <tex/> macros just once.
For best results keep your macros simple and semantic.
</p>
<p>
<pretext/> once provided modest built-in support for
<q>slanted</q>, or
<q>beveled</q>, or
<q>nice</q>
fractions.
To wit, we mean fractions such as: <m>\sfrac{3}{8}</m>.
Use the pre-defined <c>\sfrac{}{}</c> macro in your mathematics to achieve this presentation.
The presentation in HTML is subpar,
but could improve as MathJax provides support.
It is now an author's responsibility to add support for superior typesetting for <init>PDF</init> output by loading the <c>xfrac</c> <latex/> package with the following in <tag>docinfo</tag>:
<cd>
<cline><math-package latex-name="xfrac" mathjax-name=""/></cline>
</cd>
which is what we have done here as a test.
See the Guide for more details.
</p>
<p>
We consider a system of equations.
We number the first and last equation
(there are just two)
and include an <c>xml:id</c> on each.
We reference the whole system later as the range of equations from the first to the last.
<mdn>
<mrow xml:id="equation-system-begin">\frac{dx}{dt} \amp = x^2 - 4x - y + 4</mrow>
<mrow xml:id="equation-system-end">\frac{dy}{dt} \amp = x^3 - y</mrow>
</mdn>.
</p>
</subsection>
The following is from the MathJax demonstration page, an identity due to Ramanujan:
\begin{equation*}
\frac{1}{\Bigl(\sqrt{\phi \sqrt{5}}-\phi\Bigr) e^{\frac25 \pi}} = 1+\frac{e^{-2\pi}} {1+\frac{e^{-4\pi}} {1+\frac{e^{-6\pi}} {1+\frac{e^{-8\pi}} {1+\ldots} } } }
\end{equation*}
And again, from the MathJax demonstration page, Maxwellβs equations:
\begin{align*}
\nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}}\\
\nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho\\
\nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}}\\
\nabla \cdot \vec{\mathbf{B}} & = 0
\end{align*}
Historically, we provided internal support for the LaTeX package
extpfeil. As of 2023-10-19 this has become an author election (see the <docinfo> section in the source of this document). We preeserve a small test that this extensible arrows library is being included properly:
\begin{equation*}
A\xmapsto[\text{bijection}]{\Phi+\Psi+\Theta}B
\end{equation*}
Look back at the top of the source file of this document to see how to include your TeX macros just once. For best results keep your macros simple and semantic.
PreTeXt once provided modest built-in support for βslantedβ, or βbeveledβ, or βniceβ fractions. To wit, we mean fractions such as: \(\sfrac{3}{8}\text{.}\) Use the pre-defined
\sfrac{}{} macro in your mathematics to achieve this presentation. The presentation in HTML is subpar, but could improve as MathJax provides support. It is now an authorβs responsibility to add support for superior typesetting for PDF output by loading the xfrac LaTeX package with the following in <docinfo>:<math-package latex-name="xfrac" mathjax-name=""/>
which is what we have done here as a test. See the Guide for more details.
We consider a system of equations. We number the first and last equation (there are just two) and include an
xml:id on each. We reference the whole system later as the range of equations from the first to the last.
\begin{align}
\frac{dx}{dt} \amp = x^2 - 4x - y + 4\tag{7.1}\\
\frac{dy}{dt} \amp = x^3 - y\text{.}\tag{7.2}
\end{align}
Subsection 7.2 Displayed Mathematics
View Source for subsection
<subsection>
<title>Displayed Mathematics</title>
<p>
Multi-line displays of mathematics are achieved with the <c>md</c> tag (
<q>math display</q>),
and the variant that produces numbers on each line,
<c>mdn</c> (
<q>math display numbered</q>),
used within a paragraph
(<c>p</c>).
As a good example of how XML syntax is superior,
you author <m>n</m> lines of equations by enclosing each line inside of a <c>mrow</c> tag,
rather than using <m>n-1</m> separators
(such as <c>\\</c>).
</p>
<p>
If you use no ampersands to express alignment
(read ahead),
then each equation is centered independently on the width of the text.
This is implemented according to the AMSmath <latex/> package's <c>gather</c> environment.
Example:
<md>
<mrow>\frac{dx}{dt} = x^2 - 4x - y + 4</mrow>
<mrow>\frac{dy}{dt} = x^3 - y</mrow>
</md>.
</p>
<p>
An ampersand is used, in two ways,
to describe positioning several equations per line, organized in columns.
We have created the pre-defined <latex/> macro <c>\amp</c> as one way specify these,
but the escape sequence <c>&amp;</c> may be used also.
The second, fourth, sixth, <ellipsis/> ampersands separate columns,
and the spacing between columns will be provided automatically.
The first, third, fifth,
<ellipsis/> ampersands are alignment points for the equations in each column.
Typically this is placed just prior to a binary operator,
such as an equal sign (<c>\amp = </c>), or for a column of explanations or commentary,
just prior to the <c>\text{}</c> macro.
Note that this scenario suggests always having an odd number of ampersands in each <c>mrow</c>.
In the example below,
alignment is on the equals sign in the first two columns,
and provides left-justification to the explanations in the third column.
N.B.: the use below of the <c>\text{}</c> macro does not include mathematics within its argument.
Doing so may yield unpredictable results depending on your choice of delimiters for the mathematics
(and using an <c>m</c> tag will be ineffective).
<md>
<mrow>\frac{dx}{dt} \amp = x^2 - 4x - y + 4 \amp \frac{dy}{dt} \amp = x^3 - y \amp\amp x, y\text{ version}</mrow>
<mrow>\frac{dw}{dt} \amp = z^3 - w \amp \frac{dz}{dt} \amp = z^2 - 4z - w + 4 \amp\amp z, w\text{ version}</mrow>
</md>
</p>
<p>
<pretext/> will automatically detect the presence or absence of ampersands,
but by defining macros for entire aligned equations,
you can effectively hide the ampersands.
So the <c>@alignment</c> attribute can override automatic detection.
We use a simple <latex/> macro to demonstrate setting <c>alignment='align'</c> to override the use of a <c>gather</c> environment and use a <c>align</c> environment instead.
Example:
<md alignment="align">
<mrow>\myequation{\frac{dx}{dt}}{x^2 - 4x - y + 4}</mrow>
<mrow>\myequation{\frac{dy}{dt}}{x^3 - y}</mrow>
</md>.
</p>
<p>
The AMSmath <latex/> package's <c>alignat</c> environment is a third variant of alignment.
It never happens automatically,
you need to ask for it with <c>alignment="alignat"</c>.
It is very similar to <c>align</c> but adds no space between the equation columns.
So you can leave it that way, or you can add your own
<q>extra</q>
space to suit.
Here is a previous example with no inter-column space:
<md alignment="alignat">
<mrow>\frac{dx}{dt} \amp = x^2 - 4x - y + 4 \amp \frac{dy}{dt} \amp = x^3 - y \amp\amp x, y\text{ version}</mrow>
<mrow>\frac{dw}{dt} \amp = z^3 - w \amp \frac{dz}{dt} \amp = z^2 - 4z - w + 4 \amp\amp z, w\text{ version}</mrow>
</md>.
This modified example has a middle row with three columns,
while the other rows have just one column,
as a test of our routines for determining the <c>mrow</c> with the greatest number of ampersands (and how many there are),
<md alignment="alignat">
<mrow>\frac{dw}{dt} &= z^3 - w</mrow>
<mrow>\frac{dx}{dt} &= x^2 - 4x - y + 4 & \frac{dy}{dt} &= x^3 - y&& x, y\text{ third column}</mrow>
<mrow>\frac{dw}{dt} & = z^3 - w</mrow>
</md>.
Final example demonstrates that ampersands in other objects
(matrices here)
can wreak havoc with computing the number of columns.
So we provide yet another attribute to override automatic detection,
<c>alignat-columns</c>.
This is the number of <em>columns</em>
not the number of <em>ampersands</em>.
Generally, for <m>c</m> columns,
there will be <m>2c-1</m> ampersands.
<md alignment="alignat" alignat-columns="2">
<mrow>A &= \begin{bmatrix}1 & 2 \\ 3 & 4\end{bmatrix} & I &= \begin{bmatrix}1 & 0 \\ 0 & 1\end{bmatrix}</mrow>
</md>.
One caveat: if your number of ampersands is even
(see advice above about using an odd number)
behavior should still be correct, as in next example.
</p>
<p>
If you want super-precise control over alignment of the terms of a system of equations
(linear or not)
you can use the <c>alignat</c> option to advantage by not including any extra space.
This example is modified slightly from a post by Alex Jordan:
<md alignment="alignat">
<mrow>2x \amp {}+{} \amp y \amp {}+{} \amp 3z \amp {}={} \amp 10</mrow>
<mrow>x \amp \amp \amp {}+{} \amp z \amp {}={} \amp 6</mrow>
<mrow>x \amp {}+{} \amp 3y \amp {}+{} \amp 2z \amp {}={} \amp 13</mrow>
</md>.
Beautiful.
</p>
<aside>
<title>Overlap Test</title>
<p>
This is simply to test what happens when an aside bumps into something like the content below that may extend past the normal right content boundary.
It likely only is of interest with the theme <c>default-modern</c>.
</p>
</aside>
<p>
A long equation, to check layout on various screen sizes.
This is Weil's
<q>explicit formula</q>
for the Riemann <m>\zeta</m>-function:
<men>
\sum_\gamma S_-(\gamma) = \frac{\log Q}{\pi} \hat S_-(0) + \frac{1}{2\pi} \sum_{j=1}^d \Re\left\{ \int_{-\infty}^\infty \frac{\Gamma'}{\Gamma}\left(\frac{1}{4} + \frac{it}{2} + \mu_j\right)S_-(t) dt\right\} - \frac{d}{2\pi}\hat S_-(0)\log \pi
</men>.
</p>
<example>
<title>Excessive Display Mathematics</title>
<p>
In print versions,
a long run of displayed equations often needs to be broken across pages.
If you are reading some other version of this,
then there is nothing to see here.
But for <latex/> output it could be interesting.
First, with no extra effort,
this page-long display should break naturally,
no matter how the preceding material changes.
<md number="yes">
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
</md>.
</p>
<p>
In this version we have turned off page breaking for the entire display,
but then allowed a break at every fourth equation,
so you should see a reasonably attractive page break right after one of the <m>m^2+n^2=p^2</m> equations.
<mdn break="no">
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
</mdn>.
</p>
<p>
So.
Do not take any extra steps and let <latex/> figure out the breaks.
If you do not like a break,
modify the <c>md</c> or <c>mdn</c> to go back to the AMSmath default behavior and not break at all.
Ever.
Or rather, go further and modify an individual <c>mrow</c> to suggest that it is a good place for a break.
</p>
</example>
<p>
This is a poorly-authored paragaph to test the conversion to <init>HTML</init>.
There are two displayed equations,
separated by a period ending the first one's sentence,
which should migrate into the display,
and not leave behind an empty paragraph:
<me>
z+y = z
</me>.
<me>
a + b = c
</me>.
This final sentence should remain,
inside another <init>HTML</init> paragraph,
without the second equation's period.
</p>
</subsection>
Multi-line displays of mathematics are achieved with the
md tag ( βmath displayβ), and the variant that produces numbers on each line, mdn ( βmath display numberedβ), used within a paragraph (p). As a good example of how XML syntax is superior, you author \(n\) lines of equations by enclosing each line inside of a mrow tag, rather than using \(n-1\) separators (such as \\).
If you use no ampersands to express alignment (read ahead), then each equation is centered independently on the width of the text. This is implemented according to the AMSmath LaTeX packageβs
gather environment. Example:
\begin{gather*}
\frac{dx}{dt} = x^2 - 4x - y + 4\\
\frac{dy}{dt} = x^3 - y\text{.}
\end{gather*}
An ampersand is used, in two ways, to describe positioning several equations per line, organized in columns. We have created the pre-defined LaTeX macro
\amp as one way specify these, but the escape sequence & may be used also. The second, fourth, sixth, β¦ ampersands separate columns, and the spacing between columns will be provided automatically. The first, third, fifth, β¦ ampersands are alignment points for the equations in each column. Typically this is placed just prior to a binary operator, such as an equal sign (\amp = ), or for a column of explanations or commentary, just prior to the \text{} macro. Note that this scenario suggests always having an odd number of ampersands in each mrow. In the example below, alignment is on the equals sign in the first two columns, and provides left-justification to the explanations in the third column. N.B.: the use below of the \text{} macro does not include mathematics within its argument. Doing so may yield unpredictable results depending on your choice of delimiters for the mathematics (and using an m tag will be ineffective).
\begin{align*}
\frac{dx}{dt} \amp = x^2 - 4x - y + 4 \amp \frac{dy}{dt} \amp = x^3 - y \amp\amp x, y\text{ version}\\
\frac{dw}{dt} \amp = z^3 - w \amp \frac{dz}{dt} \amp = z^2 - 4z - w + 4 \amp\amp z, w\text{ version}
\end{align*}
PreTeXt will automatically detect the presence or absence of ampersands, but by defining macros for entire aligned equations, you can effectively hide the ampersands. So the
@alignment attribute can override automatic detection. We use a simple LaTeX macro to demonstrate setting alignment='align' to override the use of a gather environment and use a align environment instead. Example:
\begin{align*}
\myequation{\frac{dx}{dt}}{x^2 - 4x - y + 4}\\
\myequation{\frac{dy}{dt}}{x^3 - y}\text{.}
\end{align*}
The AMSmath LaTeX packageβs
alignat environment is a third variant of alignment. It never happens automatically, you need to ask for it with alignment="alignat". It is very similar to align but adds no space between the equation columns. So you can leave it that way, or you can add your own βextraβ space to suit. Here is a previous example with no inter-column space:
\begin{alignat*}{3}
\frac{dx}{dt} \amp = x^2 - 4x - y + 4 \amp \frac{dy}{dt} \amp = x^3 - y \amp\amp x, y\text{ version}\\
\frac{dw}{dt} \amp = z^3 - w \amp \frac{dz}{dt} \amp = z^2 - 4z - w + 4 \amp\amp z, w\text{ version}\text{.}
\end{alignat*}
This modified example has a middle row with three columns, while the other rows have just one column, as a test of our routines for determining the
mrow with the greatest number of ampersands (and how many there are),
\begin{alignat*}{3}
\frac{dw}{dt} &= z^3 - w\\
\frac{dx}{dt} &= x^2 - 4x - y + 4 & \frac{dy}{dt} &= x^3 - y&& x, y\text{ third column}\\
\frac{dw}{dt} & = z^3 - w\text{.}
\end{alignat*}
Final example demonstrates that ampersands in other objects (matrices here) can wreak havoc with computing the number of columns. So we provide yet another attribute to override automatic detection,
alignat-columns. This is the number of columns not the number of ampersands. Generally, for \(c\) columns, there will be \(2c-1\) ampersands.
\begin{alignat*}{2}
A &= \begin{bmatrix}1 & 2 \\ 3 & 4\end{bmatrix} & I &= \begin{bmatrix}1 & 0 \\ 0 & 1\end{bmatrix}\text{.}
\end{alignat*}
One caveat: if your number of ampersands is even (see advice above about using an odd number) behavior should still be correct, as in next example.
If you want super-precise control over alignment of the terms of a system of equations (linear or not) you can use the
alignat option to advantage by not including any extra space. This example is modified slightly from a post by Alex Jordan:
\begin{alignat*}{4}
2x \amp {}+{} \amp y \amp {}+{} \amp 3z \amp {}={} \amp 10\\
x \amp \amp \amp {}+{} \amp z \amp {}={} \amp 6\\
x \amp {}+{} \amp 3y \amp {}+{} \amp 2z \amp {}={} \amp 13\text{.}
\end{alignat*}
Beautiful.
Aside: Overlap Test.
A long equation, to check layout on various screen sizes. This is Weilβs βexplicit formulaβ for the Riemann \(\zeta\)-function:
\begin{equation}
\sum_\gamma S_-(\gamma) = \frac{\log Q}{\pi} \hat S_-(0) + \frac{1}{2\pi} \sum_{j=1}^d \Re\left\{ \int_{-\infty}^\infty \frac{\Gamma'}{\Gamma}\left(\frac{1}{4} + \frac{it}{2} + \mu_j\right)S_-(t) dt\right\} - \frac{d}{2\pi}\hat S_-(0)\log \pi\text{.}\tag{7.3}
\end{equation}
Example 7.1. Excessive Display Mathematics.
View Source for example
<example>
<title>Excessive Display Mathematics</title>
<p>
In print versions,
a long run of displayed equations often needs to be broken across pages.
If you are reading some other version of this,
then there is nothing to see here.
But for <latex/> output it could be interesting.
First, with no extra effort,
this page-long display should break naturally,
no matter how the preceding material changes.
<md number="yes">
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow>m^2+n^2=p^2</mrow>
<!-- -->
</md>.
</p>
<p>
In this version we have turned off page breaking for the entire display,
but then allowed a break at every fourth equation,
so you should see a reasonably attractive page break right after one of the <m>m^2+n^2=p^2</m> equations.
<mdn break="no">
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
<mrow>x^2+y^2=z^2</mrow>
<mrow>a^2+b^2=c^2</mrow>
<mrow>\alpha^2+\beta^2=\gamma^2</mrow>
<mrow break="yes">m^2+n^2=p^2</mrow>
<!-- -->
</mdn>.
</p>
<p>
So.
Do not take any extra steps and let <latex/> figure out the breaks.
If you do not like a break,
modify the <c>md</c> or <c>mdn</c> to go back to the AMSmath default behavior and not break at all.
Ever.
Or rather, go further and modify an individual <c>mrow</c> to suggest that it is a good place for a break.
</p>
</example>
In print versions, a long run of displayed equations often needs to be broken across pages. If you are reading some other version of this, then there is nothing to see here. But for LaTeX output it could be interesting. First, with no extra effort, this page-long display should break naturally, no matter how the preceding material changes.
\begin{gather*}
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\\
x^2+y^2=z^2\\
a^2+b^2=c^2\\
\alpha^2+\beta^2=\gamma^2\\
m^2+n^2=p^2\text{.}
\end{gather*}
In this version we have turned off page breaking for the entire display, but then allowed a break at every fourth equation, so you should see a reasonably attractive page break right after one of the \(m^2+n^2=p^2\) equations.
\begin{gather}
x^2+y^2=z^2\tag{7.4}\\
a^2+b^2=c^2\tag{7.5}\\
\alpha^2+\beta^2=\gamma^2\tag{7.6}\\
m^2+n^2=p^2\tag{7.7}\\
x^2+y^2=z^2\tag{7.8}\\
a^2+b^2=c^2\tag{7.9}\\
\alpha^2+\beta^2=\gamma^2\tag{7.10}\\
m^2+n^2=p^2\tag{7.11}\\
x^2+y^2=z^2\tag{7.12}\\
a^2+b^2=c^2\tag{7.13}\\
\alpha^2+\beta^2=\gamma^2\tag{7.14}\\
m^2+n^2=p^2\tag{7.15}\\
x^2+y^2=z^2\tag{7.16}\\
a^2+b^2=c^2\tag{7.17}\\
\alpha^2+\beta^2=\gamma^2\tag{7.18}\\
m^2+n^2=p^2\tag{7.19}\\
x^2+y^2=z^2\tag{7.20}\\
a^2+b^2=c^2\tag{7.21}\\
\alpha^2+\beta^2=\gamma^2\tag{7.22}\\
m^2+n^2=p^2\tag{7.23}\\
x^2+y^2=z^2\tag{7.24}\\
a^2+b^2=c^2\tag{7.25}\\
\alpha^2+\beta^2=\gamma^2\tag{7.26}\\
m^2+n^2=p^2\tag{7.27}\\
x^2+y^2=z^2\tag{7.28}\\
a^2+b^2=c^2\tag{7.29}\\
\alpha^2+\beta^2=\gamma^2\tag{7.30}\\
m^2+n^2=p^2\tag{7.31}\\
x^2+y^2=z^2\tag{7.32}\\
a^2+b^2=c^2\tag{7.33}\\
\alpha^2+\beta^2=\gamma^2\tag{7.34}\\
m^2+n^2=p^2\tag{7.35}\\
x^2+y^2=z^2\tag{7.36}\\
a^2+b^2=c^2\tag{7.37}\\
\alpha^2+\beta^2=\gamma^2\tag{7.38}\\
m^2+n^2=p^2\tag{7.39}\\
x^2+y^2=z^2\tag{7.40}\\
a^2+b^2=c^2\tag{7.41}\\
\alpha^2+\beta^2=\gamma^2\tag{7.42}\\
m^2+n^2=p^2\tag{7.43}\\
x^2+y^2=z^2\tag{7.44}\\
a^2+b^2=c^2\tag{7.45}\\
\alpha^2+\beta^2=\gamma^2\tag{7.46}\\
m^2+n^2=p^2\tag{7.47}\\
x^2+y^2=z^2\tag{7.48}\\
a^2+b^2=c^2\tag{7.49}\\
\alpha^2+\beta^2=\gamma^2\tag{7.50}\\
m^2+n^2=p^2\text{.}\tag{7.51}
\end{gather}
So. Do not take any extra steps and let LaTeX figure out the breaks. If you do not like a break, modify the
md or mdn to go back to the AMSmath default behavior and not break at all. Ever. Or rather, go further and modify an individual mrow to suggest that it is a good place for a break.
This is a poorly-authored paragaph to test the conversion to HTML. There are two displayed equations, separated by a period ending the first oneβs sentence, which should migrate into the display, and not leave behind an empty paragraph:
\begin{equation*}
z+y = z\text{.}
\end{equation*}
\begin{equation*}
a + b = c\text{.}
\end{equation*}
This final sentence should remain, inside another HTML paragraph, without the second equationβs period.
Subsection 7.3 LaTeX Packages and MathJax Extensions
View Source for subsection
<subsection>
<title><latex/> Packages and MathJax Extensions</title>
<p>
If you would like to enhance your mathematics by using a macro from a <latex/> package <em>and</em>
there is a MathJax extension <em>which implements the same macro</em>,
then you may use this with your mathematics as we demonstrate here.
</p>
<p>
This example is from Jason Underdown.
<idx><h>Underdown, Jason</h></idx>
The package is named <c>cancel</c> and is included in the TeXLive distribution,
so is fairly standard.
The particular macro being demonstrated is <c>\cancelto{}{}</c>.
<me>
\lim_{b \rightarrow \infty}\left[\cancelto{0}{-\frac{1}{s}e^{-sb}} + \frac{1}{s}\right]
</me>.
Look at the source of this article to see the package name being supplied in a <tag>math-package</tag> element within the <tag>docinfo</tag> section.
That is the only setup required to make the macro usable in <latex/> and <init>HTML</init> output.
<idx><h>canceling a term</h></idx>
<idx sortby="cancelto macro"><c>cancelto</c> macro</idx>
</p>
<p>
See the
<pubtitle><pretext/> Guide</pubtitle>
subsection about
<q>MathJax Extensions</q>
for more detail.
</p>
</subsection>
If you would like to enhance your mathematics by using a macro from a LaTeX package and there is a MathJax extension which implements the same macro, then you may use this with your mathematics as we demonstrate here.
This example is from Jason Underdown. The package is named
cancel and is included in the TeXLive distribution, so is fairly standard. The particular macro being demonstrated is \cancelto{}{}.
\begin{equation*}
\lim_{b \rightarrow \infty}\left[\cancelto{0}{-\frac{1}{s}e^{-sb}} + \frac{1}{s}\right]\text{.}
\end{equation*}
Look at the source of this article to see the package name being supplied in a
<math-package> element within the <docinfo> section. That is the only setup required to make the macro usable in LaTeX and HTML output. See the PreTeXt Guide subsection about βMathJax Extensionsβ for more detail.
Subsection 7.4 Advanced Mathematics
View Source for subsection
<subsection>
<title>Advanced Mathematics</title>
<p>
MathJax is extremely capable in rendering a subset of <latex/> in web browsers,
and improving all the time.
You can get fairly fancy with some of its supported commands.
In particular,
if you need to mix in a few words with your mathematics,
the <c>\text{}</c> macro is supported.
For example, you might use an
<q>if</q>
or an
<q>otherwise</q>
in the definition of a piecewise function.
</p>
<p>
Consider that the first line below is text sandwiched in-between two Greek letters,
wrapped in a <c>\text{}</c> macro.
In HTML output we have taken care that the font for text material within display mathematics should match the font of the surrounding paragraph,
as also happens with <latex/> output.
The second line is nearly identical in the source,
but is just naked text being rendered like a slew of variables.
<md>
<mrow>\alpha\text{ is not equal to }\beta</mrow>
<mrow>\alpha is not equal to \beta</mrow>
<mrow>\alpha\neq\beta</mrow>
</md>.
We are not suggesting here that using words in place of symbols,
as in the first line, is a good practice.
(It is not.)
</p>
<p>
The following example is a good stress-test of using the <c>\text{}</c> macro to achieve certain effects.
Note the Unicode left and right smart quotes.
This a contribution from Alex Jordan as part of his work on
<pubtitle>APEX Calculus</pubtitle>.
<md>
<mrow>y \rightarrow \frac{\sin(0) }{0} \rightarrow {{\text{β}}\atop{}}\frac{0}{0}{{\text{β}}\atop{}}\text{.}</mrow>
</md>
And another one from Alex.
Note the use of the <c>\mathord{}</c> and <c>\mathrel{}</c> macros to control spacing around the mathematical symbols.
Examine the source to see how the quotation marks have been authored with <init>XML</init> syntax for Unicode characters,
since we do not allow most markup inside mathematics.
<md>
<mrow>\zeta(1)=\sum_{n=1}^{\infty}\frac{1}{n}\mathrel{\text{ β}\mathord{=}{\text{β }}}\prod_{p}\left(\frac{1}{1-1/p}\right)=\prod_{p}\left(\frac{1}{1-p^{-1}}\right)</mrow>
</md>
</p>
<p>
Generally, you cannot use any <init>XML</init> elements inside of the mathematics elements.
An exception is the <c>xref</c> element which you might want to use to provide justifications for the steps of a derivation.
Here is a visual example that is mathematically meaningless,
<md>
<mrow>A&=B+C&&<xref ref="corollary-FTC-derivative" text="type-global"/></mrow>
<mrow>&=D+E&&<xref ref="theorem-FTC" text="title"/></mrow>
<mrow>&=F+G&&<xref ref="theorem-number-01" text="custom">A nice result</xref></mrow>
</md>.
</p>
<p>
Scott Beaver likes to write short chains of equalities all in one line,
with the cross-references sitting on each equals sign.
Here we test the <latex/> <c>\overset</c> and <c>\underset</c> macros wrapping a <pretext/> <tag>xref</tag>,
with and without content, inside an <tag>me</tag> element.
Note that <c>\stackrel</c> is obsolete,
and <c>\overunderset</c> is not yet supported by MathJax
(but see
<url href="https://github.com/mathjax/MathJax/issues/2704" visual="github.com/mathjax/MathJax/issues/2704">GitHub #2704</url>).
The mathematics is Scott's, the reasons are totally unrelated to the math.
<me>
AC-AD \overset{<xref ref="theorem-FTC" text="global"/>}{=} A(C-D) \underset{<xref ref="definition-indefinite-integral" text="global"/>}{=} A0_{n\times p} \overset{<xref ref="theorem-FTC" text="global">Thm.</xref>}{=} 0_{m\times p}
</me>
We suggest using cross-references that only display numbers (<tag>xref</tag> with <attr>text</attr> set to <c>global</c>) since if you stick to elements like <tag>theorem</tag>,
<tag>lemma</tag>, <tag>definition</tag>, or <tag>axiom</tag>,
then the numbers will be unambiguous and the target of the cross-reference will contain full information.
But note that if you mix in divisions, or perhaps figures,
as reasons then there is a possibility that numbers will need to be qualified by their type.
We have provided an abbreviation for one cross-reference to <xref ref="theorem-FTC" text="type-global"/>
(which will not benefit from automatic translation to other languages).
</p>
</subsection>
MathJax is extremely capable in rendering a subset of LaTeX in web browsers, and improving all the time. You can get fairly fancy with some of its supported commands. In particular, if you need to mix in a few words with your mathematics, the
\text{} macro is supported. For example, you might use an βifβ or an βotherwiseβ in the definition of a piecewise function.
Consider that the first line below is text sandwiched in-between two Greek letters, wrapped in a
\text{} macro. In HTML output we have taken care that the font for text material within display mathematics should match the font of the surrounding paragraph, as also happens with LaTeX output. The second line is nearly identical in the source, but is just naked text being rendered like a slew of variables.
\begin{gather*}
\alpha\text{ is not equal to }\beta\\
\alpha is not equal to \beta\\
\alpha\neq\beta\text{.}
\end{gather*}
We are not suggesting here that using words in place of symbols, as in the first line, is a good practice. (It is not.)
The following example is a good stress-test of using the
\text{} macro to achieve certain effects. Note the Unicode left and right smart quotes. This a contribution from Alex Jordan as part of his work on APEX Calculus.
\begin{gather*}
y \rightarrow \frac{\sin(0) }{0} \rightarrow {{\text{β}}\atop{}}\frac{0}{0}{{\text{β}}\atop{}}\text{.}
\end{gather*}
And another one from Alex. Note the use of the
\mathord{} and \mathrel{} macros to control spacing around the mathematical symbols. Examine the source to see how the quotation marks have been authored with XML syntax for Unicode characters, since we do not allow most markup inside mathematics.
\begin{gather*}
\zeta(1)=\sum_{n=1}^{\infty}\frac{1}{n}\mathrel{\text{ β}\mathord{=}{\text{β }}}\prod_{p}\left(\frac{1}{1-1/p}\right)=\prod_{p}\left(\frac{1}{1-p^{-1}}\right)
\end{gather*}
Generally, you cannot use any XML elements inside of the mathematics elements. An exception is the
xref element which you might want to use to provide justifications for the steps of a derivation. Here is a visual example that is mathematically meaningless,
\begin{align*}
A&=B+C&&\knowl{./knowl/xref/corollary-FTC-derivative.html}{\text{Corollary 4.1}}\\
&=D+E&&\knowl{./knowl/xref/theorem-FTC.html}{\text{The Fundamental Theorem of Calculus}}\\
&=F+G&&\knowl{./knowl/xref/theorem-number-01.html}{\text{A nice result}}\text{.}
\end{align*}
Scott Beaver likes to write short chains of equalities all in one line, with the cross-references sitting on each equals sign. Here we test the LaTeX
\overset and \underset macros wrapping a PreTeXt <xref>, with and without content, inside an <me> element. Note that \stackrel is obsolete, and \overunderset is not yet supported by MathJax (but see GitHub #2704). The mathematics is Scottβs, the reasons are totally unrelated to the math.
\begin{equation*}
AC-AD \overset{\knowl{./knowl/xref/theorem-FTC.html}{2.1}}{=} A(C-D) \underset{\knowl{./knowl/xref/definition-indefinite-integral.html}{2.2}}{=} A0_{n\times p} \overset{\knowl{./knowl/xref/theorem-FTC.html}{Thm.Β 2.1}}{=} 0_{m\times p}
\end{equation*}
We suggest using cross-references that only display numbers (
<xref> with @text set to global) since if you stick to elements like <theorem>, <lemma>, <definition>, or <axiom>, then the numbers will be unambiguous and the target of the cross-reference will contain full information. But note that if you mix in divisions, or perhaps figures, as reasons then there is a possibility that numbers will need to be qualified by their type. We have provided an abbreviation for one cross-reference to TheoremΒ 2.1 (which will not benefit from automatic translation to other languages).Subsection 7.5 Local Tags on Equations
View Source for subsection
<subsection>
<title>Local Tags on Equations</title>
<p>
If you are not writing a research monograph,
maybe (a) you will not use many numbered equations,
or do not like the looks of them,
or feel they scare your readers,
and (b) maybe your cross-references are always local-ish,
like strictly within an <c>example</c> or a <c>proof</c>.
For this situation you can create, and employ, a
<q>local</q>
tag on a displayed equation.
Nothing enforces the idea of what constitutes local,
and there is nothing to stop you from using the same symbols more than once.
With freedom comes responsibility.
</p>
<p>
Use the <c>@tag</c> attribute on an <c>mrow</c>, only.
(Remember, you can have just one <c>mrow</c>.)
The behavior is identical within an <c>md</c> or <c>mdn</c>.
The value of the <c>@tag</c> attribute is a symbol name.
The prefix <c>d</c> means
<q>double</q>, and the prefix <c>t</c> means
<q>triple</q>. So allowed values are
<cd>
<cline>star, dstar, tstar</cline>
<cline>dagger, ddagger, tdagger</cline>
<cline>daggerdbl, ddaggerdbl, tdaggerdbl</cline>
<cline>hash, dhash, thash</cline>
<cline>maltese, dmaltese, tmaltese</cline>
</cd>
Cross-references to these tagged equations happens in the usual way and should behave as expected.
We test the double versions to make sure the symbols render properly in various output formats.
<mdn>
<mrow xml:id="equation-local-star" tag="dstar">c^2 \amp = a^2+b^2</mrow>
<mrow xml:id="equation-local-dagger" tag="ddagger">c^2 \amp = a^2+b^2</mrow>
<mrow xml:id="equation-local-daggerdbl" tag="ddaggerdbl">c^2 \amp = a^2+b^2</mrow>
<mrow xml:id="equation-local-hash" tag="dhash">c^2 \amp = a^2+b^2</mrow>
<mrow xml:id="equation-local-maltese" tag="dmaltese">c^2 \amp = a^2+b^2</mrow>
<mrow>z^2 \amp = x^2+y^2</mrow>
</mdn>
Here are the local cross-references:
<xref ref="equation-local-star"/>,
<xref ref="equation-local-dagger"/>, <xref ref="equation-local-daggerdbl"/>,
<xref ref="equation-local-hash"/>, <xref ref="equation-local-maltese"/>.
We test another farther away in <xref ref="section-cross-referencing" text="type-global"/>, contrary to our advice above.
</p>
</subsection>
If you are not writing a research monograph, maybe (a) you will not use many numbered equations, or do not like the looks of them, or feel they scare your readers, and (b) maybe your cross-references are always local-ish, like strictly within an
example or a proof. For this situation you can create, and employ, a βlocalβ tag on a displayed equation. Nothing enforces the idea of what constitutes local, and there is nothing to stop you from using the same symbols more than once. With freedom comes responsibility.
Use the
@tag attribute on an mrow, only. (Remember, you can have just one mrow.) The behavior is identical within an md or mdn. The value of the @tag attribute is a symbol name. The prefix d means βdoubleβ, and the prefix t means βtripleβ. So allowed values arestar, dstar, tstar dagger, ddagger, tdagger daggerdbl, ddaggerdbl, tdaggerdbl hash, dhash, thash maltese, dmaltese, tmaltese
Cross-references to these tagged equations happens in the usual way and should behave as expected. We test the double versions to make sure the symbols render properly in various output formats.
\begin{align}
c^2 \amp = a^2+b^2\tag{βΆβΆ}\\
c^2 \amp = a^2+b^2\tag{β β }\\
c^2 \amp = a^2+b^2\tag{β‘β‘}\\
c^2 \amp = a^2+b^2\tag{##}\\
c^2 \amp = a^2+b^2\tag{β β }\\
z^2 \amp = x^2+y^2\tag{7.52}
\end{align}
Subsection 7.6 Commutative Diagrams
View Source for subsection
<subsection xml:id="commutative-diagrams">
<title>Commutative Diagrams</title>
<p>
This diagram is authored by Tom Judson using the syntax of the <init>AMS</init> <latex/>
<q>CD</q>
package.
Inside of a <tag>me</tag> element start with <c>\begin{CD}</c>.
Remember to escape the less-than character.
<me>
\begin{CD} E[x]/\langle p(x) \rangle @>\psi>> F[x]/\langle q(x) \rangle\\ @VV{\sigma}V @VV{\tau}V\\ E(\alpha) @>\overline{\phi}>> F(\beta)\\ @VVV @VVV\\ E @>\phi>> F \end{CD}
</me>
While this package is not as flexible as some generic drawing packages,
it has the advantage of full support by MathJax,
and thus the <init>HTML</init> version will be more accessible.
</p>
</subsection>
This diagram is authored by Tom Judson using the syntax of the AMS LaTeX βCDβ package. Inside of a
<me> element start with \begin{CD}. Remember to escape the less-than character.
\begin{equation*}
\begin{CD} E[x]/\langle p(x) \rangle @>\psi>> F[x]/\langle q(x) \rangle\\ @VV{\sigma}V @VV{\tau}V\\ E(\alpha) @>\overline{\phi}>> F(\beta)\\ @VVV @VVV\\ E @>\phi>> F \end{CD}
\end{equation*}
While this package is not as flexible as some generic drawing packages, it has the advantage of full support by MathJax, and thus the HTML version will be more accessible.
Subsection 7.7 Line-Breaking after Mathematics
View Source for subsection
<subsection xml:id="line-breaking-math">
<title>Line-Breaking after Mathematics</title>
<p>
As of 2021-05-14, in <init>HTML</init> output the next sentence should just fill a full line across the page.
We take active measures to bind the concluding period to the final bit of mathematics,
the variable <m>x</m>.
The prevents a bad line break which could see the period <em>begin</em>
a new line, all by itself.
In the event that the line-breaking siutation improves,
we could relax these measures.
This testing is only relevant to <init>HTML</init> output,
not <latex/> output.
</p>
<p>
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx <m>x</m>.
</p>
</subsection>
As of 2021-05-14, in HTML output the next sentence should just fill a full line across the page. We take active measures to bind the concluding period to the final bit of mathematics, the variable \(x\text{.}\) The prevents a bad line break which could see the period begin a new line, all by itself. In the event that the line-breaking siutation improves, we could relax these measures. This testing is only relevant to HTML output, not LaTeX output.
xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx xxx \(x\text{.}\)
Subsection 7.8 Fonts and Mathematics
View Source for subsection
<subsection xml:id="font-math">
<title>Fonts and Mathematics</title>
<p>
This section is about testing types and sizes of fonts,
not so much about using different typefaces.
First, one long displayed equation,
which is designed to be full-width for <latex/> output when using defaults as of 2020-01-29
(commit <c>defd4bffd462e7ea</c>).
</p>
<p>
Start paragraph.
<me>
a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2
</me>
End paragraph.
</p>
<p>
The next paragraph has five ways to write the sine of <m>x</m>,
bracketed by plain text versions.
This tests font size and the fonts employed.
The raw source of this paragraph is (spread over two lines)
<cd>
<cline>sin x | <m>\sin x</m> | <m>\text{sin}\ x</m> | <m>\mathrm{sin}\ x</m> |</cline>
<cline><m>\text{sin}x</m> | <m>sin x</m> | sin x</cline>
</cd>
The five ways, from good to bad,
<ol>
<li>
The best way, using <c>\sin</c>.
Note the distance to the <m>x</m>.
</li>
<li>With a <c>\text{}</c> macro.</li>
<li>
With a <c>\mathrm{}</c> macro.
Not recommended for <pretext/>.
</li>
<li>
Without a space.
Note that the previous two require explicit spacing.
</li>
<li>
No extra effort,
so <latex/> renders as a product of four variables.
</li>
</ol>
</p>
<p>
sin x | <m>\sin x</m> | <m>\text{sin}\ x</m> | <m>\mathrm{sin}\ x</m> |
<m>\text{sin}x</m> | <m>sin x</m> | sin x
</p>
<p>
Finally a simple paragraph that places a text
<q>x</q>
next to a variable
<q>x</q>.
</p>
<p>
wordxx<m>x+x</m>xxword
</p>
</subsection>
This section is about testing types and sizes of fonts, not so much about using different typefaces. First, one long displayed equation, which is designed to be full-width for LaTeX output when using defaults as of 2020-01-29 (commit
defd4bffd462e7ea).
Start paragraph.
\begin{equation*}
a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2 + a^2 + b^2
\end{equation*}
End paragraph.
The next paragraph has five ways to write the sine of \(x\text{,}\) bracketed by plain text versions. This tests font size and the fonts employed. The raw source of this paragraph is (spread over two lines)
sin x | <m>\sin x</m> | <m>\text{sin}\ x</m> | <m>\mathrm{sin}\ x</m> |
<m>\text{sin}x</m> | <m>sin x</m> | sin x
The five ways, from good to bad,
-
The best way, using
\sin. Note the distance to the \(x\text{.}\) -
With a
\text{}macro. -
With a
\mathrm{}macro. Not recommended for PreTeXt. -
Without a space. Note that the previous two require explicit spacing.
-
No extra effort, so LaTeX renders as a product of four variables.
sin x | \(\sin x\) | \(\text{sin}\ x\) | \(\mathrm{sin}\ x\) | \(\text{sin}x\) | \(sin x\) | sin x
Finally a simple paragraph that places a text βxβ next to a variable βxβ.
wordxx\(x+x\)xxword
Subsection 7.9 Miscellaneous
View Source for subsection
<subsection xml:id="miscellaneous-math">
<title>Miscellaneous</title>
<p>
In <init>HTML</init> output,
a MathJax workaround for a Safari rendering bug was inserting extra spaces after textual subscripts and superscripts (
<url href="https://groups.google.com/g/mathjax-users/c/ANjLK9KtcWA/m/vlHaPja-AwAJ" visual="groups.google.com/g/mathjax-users/c/ANjLK9KtcWA/m/vlHaPja-AwAJ">MathJax thread</url>).
<pretext/> CSS now applies a correction.
The following tests if the CSS fix is sufficient,
and could be used to test the necessity of our fix in the future.
Following is the original report,
though <c>NOT</c> has been moved to a superscript:
<md>
<mrow>T_\text{clk}-t_\text{su} \gt t_\text{clk-Q} + \max\left( t_\text{XOR}, t^\text{NOT} \right)</mrow>
</md>.
There should not be anything to see in <latex/>/<init>PDF</init> output. (2021-10-21)
</p>
</subsection>
In HTML output, a MathJax workaround for a Safari rendering bug was inserting extra spaces after textual subscripts and superscripts ( MathJax thread). PreTeXt CSS now applies a correction. The following tests if the CSS fix is sufficient, and could be used to test the necessity of our fix in the future. Following is the original report, though
NOT has been moved to a superscript:
\begin{gather*}
T_\text{clk}-t_\text{su} \gt t_\text{clk-Q} + \max\left( t_\text{XOR}, t^\text{NOT} \right)\text{.}
\end{gather*}
There should not be anything to see in LaTeX/PDF output. (2021-10-21)
Subsection 7.10 Testing Mathematics
View Source for subsection
<subsection xml:id="testing-math" label="testing-math">
<title>Testing Mathematics</title>
<p>
This subsection is strictly about testing the five different elements used for mathematics (i.e. designed to hold <latex/> syntax).
It only varies the elements employed and the options for numbering displayed equations.
And not local tags or page breaks,
or other less-critical features.
There will not be much here for the interested reader to learn from.
</p>
<p>
First a bit of token inline mathematics,
via the <tag>m</tag> element,
where numbering is not an option.
Consider <m>x+y</m> as an expression.
</p>
<p>
Now single-line displayed equations.
First, the <tag>me</tag> element.
Which will not be numbered,
<me>
x^{1} + y^{1} = z^{1}
</me>.
Second, the <tag>men</tag> element.
Which will always be numbered,
<men>
x^{2} + y^{2} = z^{2}
</men>.
</p>
<p>
The remainder has three displayed equations each.
The first <tag>mrow</tag> has no <attr>number</attr> attribute,
the second sets the attribute to <c>no</c> and the third sets the attribute to <c>yes</c>.
The numbering of the first case is determined by the variant of the element,
the latter two provide explicit control.
</p>
<p>
The <tag>md</tag> element.
<md>
<mrow>x^{3} + y^{3} = z^{3}</mrow>.
<mrow number="no">x^{4} + y^{4} = z^{4}</mrow>.
<mrow number="yes">x^{5} + y^{5} = z^{5}</mrow>.
</md>
</p>
<p>
The <tag>mdn</tag> element.
<mdn>
<mrow>x^{6} + y^{6} = z^{6}</mrow>.
<mrow number="no">x^{7} + y^{7} = z^{7}</mrow>.
<mrow number="yes">x^{8} + y^{8} = z^{8}</mrow>.
</mdn>
</p>
</subsection>
This subsection is strictly about testing the five different elements used for mathematics (i.e. designed to hold LaTeX syntax). It only varies the elements employed and the options for numbering displayed equations. And not local tags or page breaks, or other less-critical features. There will not be much here for the interested reader to learn from.
First a bit of token inline mathematics, via the
<m> element, where numbering is not an option. Consider \(x+y\) as an expression.
Now single-line displayed equations. First, the
<me> element. Which will not be numbered,
\begin{equation*}
x^{1} + y^{1} = z^{1}\text{.}
\end{equation*}
Second, the
<men> element. Which will always be numbered,
\begin{equation}
x^{2} + y^{2} = z^{2}\text{.}\tag{7.53}
\end{equation}
The remainder has three displayed equations each. The first
<mrow> has no @number attribute, the second sets the attribute to no and the third sets the attribute to yes. The numbering of the first case is determined by the variant of the element, the latter two provide explicit control.
The
<md> element.
\begin{gather}
x^{3} + y^{3} = z^{3}\notag\\
x^{4} + y^{4} = z^{4}\notag\\
x^{5} + y^{5} = z^{5}\tag{7.54}
\end{gather}
The
<mdn> element.
\begin{gather}
x^{6} + y^{6} = z^{6}\tag{7.55}\\
x^{7} + y^{7} = z^{7}\notag\\
x^{8} + y^{8} = z^{8}\tag{7.56}
\end{gather}

