LaTeX output style
The rules that fix the LaTeX mathconv writes for each MathML construct, with an example of every rule.
The output reads like LaTeX that a careful author writes by hand. A form people commonly write is preferred over one that is merely more uniform, as long as each input still has exactly one output. This principle settles apparent conflicts between rules; where rules overlap, the rule states which one applies.
The LaTeX writer follows the rules below. Each rule settles one
question, together they make the output canonical, and every rule has
an example. Inputs are MathML without the surrounding <math>
element, except where the display mode matters, and outputs are shown
without delimiters unless the rule concerns them.
| Code | Section | Covers |
|---|---|---|
| C | Characters | the command for each character |
| S | Spacing | spaces in the LaTeX source, and spacing commands |
| G | Groups and scripts | braces, and the order of scripts |
| L | Letters and names | letter styles, identifiers and function names |
| F | Fractions and roots | \frac, \binom, \genfrac, \sqrt |
| U | Under and over | limits, accents, braces and arrows set below or above |
| B | Brackets | fences, \left and \right, vertical bars, intervals |
| T | Text | \text and its contents |
| M | Matrices and tables | environments, cells and rows |
| E | Enclosures | boxes, strikes and lines around content |
| P | Phantoms and other content | phantoms, unknown content |
| K | Content markup | products, parentheses, functions, calculus, constructors and numbers of content markup |
| D | Delimiters | delimiters around the body |
Characters#
C1. Each character has one command, the one authors type most#
A character that LaTeX writes as a command is always written with the
same command. Where LaTeX has several equivalent spellings for one
symbol, the canonical one is the spelling that authors use most,
measured on a large sample of formulas that people typed. The measured
choice is recorded in xtask/tables/command-choices.txt with the
number of formulas that use each spelling, and every chosen command is
accepted by both KaTeX and MathJax. An alias that authors type less
often never appears.
| Input | Output |
|---|---|
<mo>≤</mo> | \leq |
<mo>≥</mo> | \geq |
<mo>≠</mo> | \neq |
<mo>→</mo> | \to |
<mo>…</mo> | \dots |
<mo>⋯</mo> | \cdots |
<mo>∧</mo> | \wedge |
<mi>ℏ</mi> | \hbar |
<mi>∅</mi> | \emptyset |
<mi>φ</mi> | \varphi |
<mi>ϕ</mi> | \phi |
<mi>ε</mi> | \varepsilon |
<mi>ϵ</mi> | \epsilon |
Each command renders as the character it stands for: LaTeX renders
\varphi as φ and \phi as ϕ, \varepsilon as ε and \epsilon as ϵ. Letter
variants such as θ and ϑ, ρ and ϱ, σ and ς, π and ϖ, κ and ϰ likewise
have one command each.
Two commands are aliases only when they draw the same character. These pairs are, and the output uses the command in the second column:
| Aliases | Output |
|---|---|
\to, \rightarrow | \to |
\gets, \leftarrow | \leftarrow |
\le, \leq | \leq |
\ge, \geq | \geq |
\ne, \neq | \neq |
\dots, \ldots | \dots |
\land, \wedge | \wedge |
\lor, \vee | \vee |
\lnot, \neg | \neg |
\hbar, \hslash | \hbar |
\emptyset, \varnothing | \emptyset |
\vDash, \models | \models |
|, \Vert | | |
Where the commands draw different characters, each character keeps its
own command: \cdots is U+22EF and \dots is U+2026, and U+2300, which
some generators write for \varnothing, is \varnothing. The role of a
token can also decide: \perp is the relation and \bot the identifier
for U+22A5, and an identifier holding the divides sign (U+2223) is the
bar |, where the operator is \mid between two items and the bar |
where a delimiter stands (rules B4 and B6).
| Input | Output |
|---|---|
<mi>a</mi><mo>⊥</mo><mi>b</mi> | a \perp b |
<mi>⊥</mi> | \bot |
<mi>a</mi><mi>∣</mi><mi>b</mi> | `a |
<mi>a</mi><mo>∣</mo><mi>b</mi> | a \mid b |
<mo>∣</mo><mi>k</mi><mo>⟩</mo> | ` |
C2. Characters that need no command are written as themselves#
Latin letters, digits and the ASCII symbols that LaTeX treats as ordinary are written directly.
| Input | Output |
|---|---|
<mi>x</mi><mo>+</mo><mn>1</mn> | x + 1 |
<mo>(</mo><mi>a</mi><mo>)</mo> | (a) |
C3. Reserved characters are escaped or replaced#
#, $, %, &, _, { and } are written with a backslash
before them. The backslash is \backslash, ^ is \hat{} and ~ is
\sim. <, > and | are written as themselves, subject to rules C5
and B4. " and the backtick have no math-mode symbol and are written
in text mode: \text{"} and \text{\`{}}.
| Input | Output |
|---|---|
<mo>%</mo> | \% |
<mo>\</mo> | \backslash |
<mo>~</mo> | \sim |
<mo>"</mo> | \text{"} |
C4. A character with no command is written as itself, as a negation, or as text#
For a character with no LaTeX command, the writer takes the first of these that applies:
- A Latin letter that Unicode composes from a base letter and up to
three accents inside a token of several characters is the accent
command over the letter, as it is in a token of its own:
<mi>rêt</mi>is\mathrm{r\hat{e}t}. - A symbol or punctuation mark that both KaTeX and MathJax accept in math mode is written as the character itself.
- A relation followed by the combining long solidus (U+0338) is
\notbefore the relation, and the solidus alone is\not{}. - Any other character is written inside
\text{}, and the fallbackunmapped-characteris recorded. - A character that no renderer can show is left out, and the fallback
unmapped-characterrecords its code point. These are the private-use characters, the line separator and the paragraph separator.
Invisible characters, such as the zero width space and joiner, the
directional marks and the variation selectors, never reach the writer:
the reader leaves them out of every token and text, as the
architecture describes, so they take no
rule of their own: <mi>a</mi><mo>​</mo><mi>b</mi> is ab.
Inside \text{}, a symbol that only math mode draws, such as ‼, goes
between $ marks. A combining mark, a code point that Unicode draws
over or under the character before it, is kept where both renderers
read it. KaTeX reads a mark of the Combining Diacritical Marks block
(U+0300 to U+036F) as an accent on the character before it, and knows
only the twelve marks of the LaTeX text accents, such as U+0301 of \'
and U+0327 of \c. Any other mark of that block, and a mark of it after
a space, a brace or an escaped character such as \%, is left out and
recorded with unmapped-character, and the character before it stays.
No strike-through command works in text mode in both renderers (KaTeX
has \sout, MathJax does not), so a letter struck through with U+0335
or U+0336 loses its stroke. KaTeX shows the marks of the other
combining blocks, such as U+20D7, as characters of their own, and they
are kept. The rule is the same for a mark in text and for one in a
token that goes into \text{}.
| Input | Output |
|---|---|
<mi>字</mi> | \text{字} |
<mo>⫿</mo> | ⫿ |
<mi mathvariant="normal">rêt</mi> | \mathrm{r\hat{e}t} |
<mi>a</mi><mo>≪̸</mo><mi>b</mi> | a \not\ll b |
<mo≯</mo> | \not{} |
<mtext>a‼b</mtext> | \text{a$‼$b} |
<mtext>ǵ</mtext> | \text{ǵ} |
<mtext>g̶</mtext> | \text{g} |
<mi>字̶</mi> | \text{字} |
C5. < never starts a raw tag#
When < would be directly followed by a letter, /, ! or ?, a
space is written between them. This rule applies after the spacing
rules, so it also separates < inside a script, where operators get no
spaces.
| Input | Output |
|---|---|
<msub><mi>x</mi><mrow><mi>a</mi><mo><</mo><mi>b</mi></mrow></msub> | x_{a< b} |
C6. Primes are apostrophes#
A prime (′, ″, ‴), the apostrophe ' and the right single quotation
mark in a token are written as apostrophes, one per prime, whether the
markup holds one prime character per element or several in one. TeX
reads an apostrophe as a superscript, so a prime is written as one only
where it can be the first superscript of the item before it. A
superscript made only of primes has no ^, and follows the subscript. A
superscript with other content keeps its braces.
- After an item that already has a superscript, the prime follows an empty group, which carries it and keeps it from joining the superscript before it, as a second pair of scripts does (rule G8). Several primes follow one group.
- After an item that has no superscript, such as a subscript, a fence or a command, the prime follows it directly.
- A prime that has scripts of its own is their base and is braced, like any base that is not a single plain token (rule G4). So is any base that ends in a prime.
- A prime at the start of a row is the superscript of an empty base, and so is one at the start of a script.
- A fence delimiter that holds an apostrophe or a prime is a quotation
mark, not a prime, and is written as text with its other characters,
as in
\text{\%′}.
| Input | Output |
|---|---|
<msup><mi>f</mi><mo>″</mo></msup> | f'' |
<mi>f</mi><mo>′</mo> | f' |
<msup><mi>T</mi><mo>′′</mo></msup> | T'' |
<msubsup><mi>f</mi><mi>n</mi><mo>′</mo></msubsup> | f_n' |
<msup><mi>x</mi><mo>'</mo></msup> | x' |
<msup><mi>s</mi><mn>2</mn></msup><mo>′</mo> | s^2{}' |
<msup><mi>s</mi><mn>2</mn></msup><mo>′</mo><mo>′</mo> | s^2{}'' |
<msub><mi>f</mi><mn>2</mn></msub><mo>′</mo> | f_2' |
<mfenced><mi>x</mi></mfenced><mo>′</mo> | (x)' |
<msup><mfenced><mi>x</mi></mfenced><mn>2</mn></msup><mo>′</mo> | (x)^2{}' |
<msup><mrow><mi>f</mi><mo>′</mo></mrow><mn>2</mn></msup><mo>′</mo> | {f'}^2{}' |
<msup><mi>x</mi><mrow><msup><mi>a</mi><mn>2</mn></msup><mo>′</mo></mrow></msup> | x^{a^2{}'} |
<mi>W</mi><msubsup><mo>′</mo><mi>i</mi><mi>μ</mi></msubsup> | W{'}_i^{\mu} |
<mi>f</mi><msup><mo>′</mo><mn>2</mn></msup> | f{'}^2 |
<mo>′</mo><mi>x</mi> | 'x |
<msup><mfenced open="'" close="'"><mi>s</mi></mfenced><mn>2</mn></msup> | \text{'}s\text{'}^2 |
C7. Digit group separators#
A comma inside a number is written {,}, which keeps LaTeX from adding
space after it. A comma that an mtext sets between two numbers is the
same separator; one in an mo is a comma of a list, as the markup cannot
tell it from a decimal comma. A space inside a number is written \,, whatever its
width: the space, the no-break space and every space separator of
Unicode (U+2000 to U+200A, U+202F, U+205F, U+3000) group digits alike.
| Input | Output |
|---|---|
<mn>1,000</mn> | 1{,}000 |
<mn>1 000</mn> | 1\,000 |
<mn>50</mn><mtext>,</mtext><mn>000</mn> | 50{,}000 |
<mn>1 000</mn> | 1\,000 |
C8. Common scientific symbols have a fixed spelling#
Some characters are written the way authors usually type them:
- the micro sign is
\mu; - the degree sign is the ring operator as a superscript on an empty base, which rule G7 attaches to the preceding item, and a token whose text begins with the degree sign is split: the degree sign is written as above and the rest of the text as a token of its own, in the letter style the whole text would have had;
- the minus sign, and the en dash, figure dash and non-breaking hyphen
of a token, are
-; the dash of a text stays a dash; - the code points that the mathematical alphanumeric blocks leave
unassigned, because the styled letter is encoded elsewhere, are the
letter in its style: U+1D455 is
h, U+1D49D is\mathcal{B}; - the black-letter R and I, U+211C and U+2111, are the real and the
imaginary part,
\Reand\Im; the letters R and I in the fraktur style are\mathfrak{R}and\mathfrak{I}; - the asterisk operator is
*and the division slash is/; - Å is a ring over A, and a medium black circle, used as a radical dot,
is
\bullet; - characters that producers write for another spelling are that spelling:
the increment sign U+2206 is
\Delta, U+2254 and U+2255 are:=and=:, the Greek question mark U+037E is the semicolon (with its spacing), the fraction slash U+2044 is/, the low asterisk U+204E is*, and U+2262 is\not\equiv. A right single quotation mark in a token is a prime (rule C6), and space characters at the ends of a token that holds more are left out:<mo> = </mo>is=; - a letter that Unicode composes from a Latin letter and accents, in an
identifier of one letter, is the accent command over the letter, in
the letter's style:
Ĥis\hat{H}; a letter with a mark that has no accent command, such asç, is text (rule C4). The dotless j is\jmath; a Greek capital with the shape of a Latin capital is that letter in upright style,Αis\mathrm{A}, because MathJax has no\Alpha, and the small omicron iso. Cyrillic letters are text, as the markup does not say whether one stands for a Latin letter; - angle brackets from every Unicode block are
\langleand\rangle; - a macron or overline character alone, such as
¯or‾, and a combining accent alone, such as U+0303, are written as their accent on an empty group.
| Input | Output |
|---|---|
<mi>µ</mi><mi>m</mi> | \mu m |
<mn>30</mn><mi>°</mi><mi mathvariant="normal">C</mi> | 30^{\circ}\mathrm{C} |
<mi>°C</mi> | {}^{\circ}\mathrm{C} |
<mi>a</mi><mo>−</mo><mi>b</mi> | a - b |
<msup><mi>a</mi><mo>∗</mo></msup> | a^{*} |
<mi>m</mi><mo>∕</mo><mi>s</mi> | m / s |
<mi>x</mi><mo>–</mo><mn>1</mn> | x - 1 |
<mn>5</mn><mi>Å</mi> | 5\mathring{A} |
<mo>〈</mo><mi>a</mi><mo>〉</mo> | \langle a\rangle |
<mi>̃</mi> | \tilde{} |
<mi>∆</mi><mi>T</mi> | \Delta T |
<mi>Ĥ</mi> | \hat{H} |
<mi>Α</mi> | \mathrm{A} |
<mi>ℜ</mi><mo>(</mo><mi>z</mi><mo>)</mo> | \Re(z) |
<mi>a</mi><mo>≔</mo><mi>b</mi> | a := b |
Spacing#
S1. A space separates a control word from a following letter or digit#
A control word or \operatorname{…} directly followed by a letter or
a digit is followed by one space. Elsewhere, neither gets a space.
| Input | Output |
|---|---|
<mi>α</mi><mi>x</mi> | \alpha x |
<msup><mi>α</mi><mn>2</mn></msup> | \alpha^2 |
<mi>sgn</mi><mo>⁡</mo><mi>x</mi> | \operatorname{sgn} x |
S2. Operators are spaced as the operator dictionary spaces them#
An operator gets one space on each side where the operator dictionary gives it space in its form:
- relations and binary operators in infix form get a space on both
sides:
a = b,a + b; - punctuation, the marks that separate or end (
,;:.!?), gets no space before it, even after an operator that asks for one:a, \dots, b. A comma, a semicolon and a colon get a space after them:f(x, y); a full stop, an exclamation mark and a question mark none, sox = 1.ends with the full stop and3.14keeps the decimal point of a number that a producer split into tokens; - prefix and postfix operators get none:
-x,n!; - a sign (
+,-,±,∓) directly after an operator that cannot end an operand, such as a relation, a binary operator, a comma or an opening bracket, is a prefix operator, so it gets none either:a = -b,x \to -\infty,(a, -b). After an item that ends an operand, such as an identifier, a closing bracket or!, it is a binary operator:(a) - b,n! - 1; - a prefix sign is tight against whatever follows, including a large
operator, which would otherwise take the space its dictionary entry
gives before it:
-\sum y,a = -\oint y,y = -\partial x, buta - \sum ywhere the sign is binary; the hyphen and the en dash that producers write for a minus are signs there too:a = -1; - a colon directly followed by an equals sign, or an equals sign by a
colon, is one relation,
:=or=:, with space around the pair; - brackets get none:
(a), and an opening bracket that has no partner is tight against a large operator after it:(\sum_i a_i; - inside a script, a limit or a root index, operators written as one
character get no spaces, and operators written as commands keep
them:
x^{n+1},\lim_{x \to 0}.
| Input | Output |
|---|---|
<mi>a</mi><mo>+</mo><mi>b</mi><mo>=</mo><mi>c</mi> | a + b = c |
<mi>f</mi><mo>(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo>)</mo> | f(x, y) |
<mi>a</mi><mo>,</mo><mo>…</mo><mo>,</mo><mi>b</mi> | a, \dots, b |
<mi>x</mi><mo>=</mo><mn>1</mn><mo>.</mo> | x = 1. |
<mn>3</mn><mo>.</mo><mn>14</mn> | 3.14 |
<mi>a</mi><mo>:</mo><mo>=</mo><mi>b</mi> | a := b |
<mi>a</mi><mo>=</mo><mo>-</mo><mi>b</mi> | a = -b |
<mi>a</mi><mo>=</mo><mo>-</mo><mo>∮</mo><mi>y</mi> | a = -\oint y |
<mi>a</mi><mo>=</mo><mo>-</mo><mo>Δ</mo><mi>V</mi> | a = -\Delta V |
<mo>(</mo><mo>∑</mo><mi>n</mi> | (\sum n |
<mo>(</mo><mi>a</mi><mo>)</mo><mo>-</mo><mi>b</mi> | (a) - b |
<msup><mi>x</mi><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow></msup> | x^{n+1} |
S3. No space at the edge of a group#
A space is written only between two items: never after {, before
}, at the start or at the end of the output. Outside text there is
never more than one space in a row. The control space \ is a space
already, so the space between items does not follow it: a\ = \ b.
| Input | Output |
|---|---|
<msup><mi>x</mi><mrow><mo>-</mo><mn>1</mn></mrow></msup> | x^{-1} |
S4. Space uses the nearest named command#
A Space is written as the spacing command whose width is closest to
it. A space narrower than one eighteenth of an em is not written. A
space wider than \qquad is \qquad followed by the rest, by the same
rule. A negative space is \! as many times as comes closest to its
width, and at least once.
| Command | \! | \, | \ | \; | \ | \quad | \qquad |
|---|---|---|---|---|---|---|---|
| Width in eighteenths of an em | −3 | 3 | 4 | 5 | 6 | 18 | 36 |
The commands are the ones authors type: of a sample of 20,000 formulas,
\, is in 2,312, \ in 926, \; in 765, \! in 474, \quad in 371
and \qquad in 157, and none has \:. The medium space of 4
eighteenths is therefore written \ , and so are the interword space
of 6 eighteenths and a no-break space (U+00A0) that is the whole
content of a token. ~, which is in 167
formulas, is written the same way, because the markup does not tell it
from a control space.
The markup that the commands become depends on the generator. KaTeX
writes \, as U+2009, \; as U+2005 U+200A and \! as U+2009
followed by the invisible separator U+2063, and the others write
mspace elements of 0.167, 0.278 and −0.167 em. A control space and ~
are a no-break space in every generator but pandoc, which writes
mspace of 0.222 em for them. Each of these gives back the command the
author typed.
| Input | Output |
|---|---|
<mspace width="1em"/> | \quad |
<mo> </mo> | \, |
<mspace width="thinmathspace"/> | \, |
<mspace width="0.222em"/> | \ |
<mtext> </mtext> | \ |
<mtext> ⁣</mtext> | \! |
Groups and scripts#
G1. A script of one letter or one digit has no braces#
A subscript or superscript that is exactly one Latin letter or one digit is written without braces. Every other script is braced, including a single command and a number of several digits.
| Input | Output |
|---|---|
<msub><mi>a</mi><mi>i</mi></msub> | a_i |
<msup><mi>x</mi><mn>10</mn></msup> | x^{10} |
<msup><mi>x</mi><mi>α</mi></msup> | x^{\alpha} |
G2. Command arguments are always braced#
| Input | Output |
|---|---|
<mfrac><mn>1</mn><mn>2</mn></mfrac> | \frac{1}{2} |
G3. The subscript comes before the superscript#
| Input | Output |
|---|---|
<msubsup><mi>x</mi><mn>1</mn><mn>2</mn></msubsup> | x_1^2 |
G4. A base is braced unless it is a single token, text, fence or accent#
An accent or a brace command with its argument, such as \overline{AB},
counts as one unit. Any other base, such as a row, a fraction, another
script, a base with limits, or an item set with \overset, \underset
or \xrightarrow, is braced. Both renderers read a script that follows
the last three as a script of a limit, and MathJax rejects the second
subscript or superscript that results. A unit whose written form ends in
a script is braced too, so that the script after it is not a second
one: a token that ends in a prime (rule C6) or a degree sign, and a
fence without a closing delimiter whose content ends in a script.
| Input | Output |
|---|---|
<msup><mrow><mo>(</mo><mi>a</mi><mo>)</mo></mrow><mn>2</mn></msup> | (a)^2 |
<msup><mfrac><mi>a</mi><mi>b</mi></mfrac><mn>2</mn></msup> | {\frac{a}{b}}^2 |
<msup><msub><mi>x</mi><mi>i</mi></msub><mn>2</mn></msup> | {x_i}^2 |
<msub><mtext>max</mtext><mi>x</mi></msub> | \text{max}_x |
<msub><munder><mi>x</mi><mi>y</mi></munder><mi>c</mi></msub> | {\underset{y}{x}}_c |
<msup><mi mathvariant="italic">f′</mi><mn>2</mn></msup> | {f'}^2 |
<msup><mover accent="true"><mrow><mi>A</mi><mi>B</mi></mrow><mo>¯</mo></mover><mn>2</mn></msup> | \overline{AB}^2 |
G5. An empty script is left out#
A script position holding nothing is not written. An empty command
argument is written {}.
| Input | Output |
|---|---|
<msubsup><mi>x</mi><mrow/><mn>2</mn></msubsup> | x^2 |
<mfrac><mi>a</mi><mrow/></mfrac> | \frac{a}{} |
G6. Scripts on the left use an empty base#
Each pair of left scripts follows an empty group, and the base follows the scripts.
| Input | Output |
|---|---|
<mmultiscripts><mi>C</mi><mprescripts/><mn>6</mn><mn>14</mn></mmultiscripts> | {}_6^{14}C |
G7. An empty base attaches to the preceding item#
Marks such as the degree sign are written as scripts on an empty base. Such a script, without left scripts, attaches to the preceding item in the row, and the empty base is not written, when that item is a token other than an operator, a text, a fence, or a script with one pair, and the scripts do not clash with the scripts that the written item ends with: it holds no script of the same kind, and no subscript would follow its superscript. Primes count as a superscript (rule C6), and so does a degree sign inside token text, so consecutive degree signs are each a ring on its own empty group. What the item ends with is whatever was written last, such as a prime at the end of a token or the subscript of the last item inside a fence without a closing delimiter. An operator that carries scripts of its own is such a token too: a large operator, which takes limits, and a relation or an arrow, which has thick space on both sides in the operator dictionary. Otherwise, including at the start of a row, after any other operator, such as a sign, and after an item that holds a script of the same kind, the script follows an empty group so that it does not attach to the preceding item.
| Input | Output |
|---|---|
<mn>90</mn><msup><mi/><mo>∘</mo></msup> | 90^{\circ} |
<mn>90</mn><mo>°</mo> | 90^{\circ} |
<mn>90</mn><mo>°</mo><mo>°</mo> | 90^{\circ}{}^{\circ} |
<mi>a°</mi><msup><mi/><mn>2</mn></msup> | \mathrm{a}{}^{\circ}{}^2 |
<msub><mi>x</mi><mn>1</mn></msub><msup><mi/><mo>∘</mo></msup> | x_1^{\circ} |
<msup><mi>x</mi><mn>2</mn></msup><msup><mi/><mo>∘</mo></msup> | x^2{}^{\circ} |
<msup><mi>x</mi><mn>2</mn></msup><msub><mi/><mn>1</mn></msub> | x^2{}_1 |
<mfenced open="(" close=""><msub><mi>x</mi><mn>1</mn></msub></mfenced><msub><mi/><mn>2</mn></msub> | (x_1{}_2 |
<mo>+</mo><msup><mi/><mn>2</mn></msup> | +{}^2 |
<mo>∑</mo><msubsup><mrow/><mi>i</mi><mi>n</mi></msubsup> | \sum_i^n |
<mi>a</mi><mo>=</mo><msup><mrow/><mi>f</mi></msup><mi>b</mi> | a =^f b |
G8. Several pairs of scripts on one side#
Right pairs are written in order, and each pair after the first follows an empty group. Left pairs are each written after an empty group. A pair whose scripts are both empty is left out.
| Input | Output |
|---|---|
<mmultiscripts><mi>T</mi><mi>a</mi><mi>b</mi><mi>c</mi><mi>d</mi></mmultiscripts> | T_a^b{}_c^d |
<mmultiscripts><mi>x</mi><none/><mi>a</mi><mi>b</mi><none/></mmultiscripts> | x^a{}_b |
<mmultiscripts><mi>X</mi><mi>a</mi><mi>b</mi><mprescripts/><mi>c</mi><mi>d</mi></mmultiscripts> | {}_c^dX_a^b |
G9. A bare script is braced before a letter or digit#
A script written without braces by rule G1, directly followed by an item
that starts with a Latin letter or a digit, is written in braces, so
that x^{2}3 is not read as x^{23}. A space between the two, as after
a large operator, or any other following item leaves the script bare.
| Input | Output |
|---|---|
<msup><mi>x</mi><mn>2</mn></msup><mn>3</mn> | x^{2}3 |
<msup><mi>x</mi><mn>2</mn></msup><mi>α</mi> | x^2\alpha |
<msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>y</mi> | x^2 + y |
Letters and names#
L1. Variants map to fixed commands#
| Variant | Command | Example |
|---|---|---|
| italic | none | x, ab |
| normal | \mathrm | \mathrm{d} |
| bold | \mathbf | \mathbf{x} |
| bold-italic | \boldsymbol | \boldsymbol{x} |
| double-struck | \mathbb | \mathbb{R} |
| script, bold-script | \mathcal | \mathcal{L} |
| fraktur, bold-fraktur | \mathfrak | \mathfrak{g} |
| sans-serif, all kinds | \mathsf | \mathsf{A} |
| monospace | \mathtt | \mathtt{x} |
The italic variant is the style of the letters of math mode, so several
letters in it are written plain, as authors type them; \mathit draws
the text italic font, which differs in shape and spacing.
A style command covers letters and digits only, from the first to the
last letter or digit of the token, because a bracket, a sign or a comma
looks the same in every style and a style command around one is at best
noise (\left\mathbf{(} is not a delimiter at all). A token without a
letter or digit takes no command, so a bold ( is ( and a bold ∞ is
\infty, and characters at the ends of a token stay outside the command:
a bold (x is (\mathbf{x}. Primes after the last letter stay inside it,
and a decimal point between digits stays too, as in \mathbf{3.5}. The
script, bold-script and fraktur styles have no digit forms, so only
their letters take the command: \mathcal{x}1.
A bold Greek letter is \boldsymbol{\alpha}. \mathsf and \mathtt
change only Latin letters and digits, so a sans-serif ξ is \xi. \mathrm changes only
Latin letters, so a token in the normal variant without a Latin letter
gets no command: a digit, a symbol or a Greek letter is written alone,
and a normal-variant α is \alpha, which both renderers show
italic. A Greek letter in a token that also holds Latin letters, in
the normal, sans-serif and monospace variants, stands outside the
command that covers the Latin letters around it: \delta\mathrm{t},
\mu\mathrm{A}.
L2. Consecutive letters in one style share a command#
Identifier and number tokens of one character that are written with the
same style command, and have nothing between them, are written inside
one command, as an author types \mathrm{dx}. The commands are
\mathrm, \mathbf, \mathsf, \mathtt, \mathcal, \mathbb and
\mathfrak. An operator, a space or any other node ends the run. A
letter that carries a script is the last of its run, and the script
follows the command: \mathrm{KCl}_2. MathJax draws that within 0.1 em
of the separate commands for every one of these styles (the largest
difference is 0.09 em, for \mathfrak{gl}_2). A token of several
characters, a function name and \boldsymbol keep their own commands;
KaTeX builds an mi that holds other elements for \boldsymbol{ab},
which it does not for \boldsymbol{a}\boldsymbol{b}.
| Input | Output |
|---|---|
<mi mathvariant="bold">A</mi><mi mathvariant="bold">B</mi> | \mathbf{AB} |
<mi mathvariant="bold">x</mi><mn mathvariant="bold">1</mn> | \mathbf{x1} |
<mi mathvariant="bold">A</mi><mi mathvariant="normal">B</mi> | \mathbf{A}\mathrm{B} |
<mi mathvariant="normal">a</mi><msup><mi mathvariant="normal">b</mi><mn>2</mn></msup> | \mathrm{ab}^2 |
<mi mathvariant="normal">C</mi><msub><mi mathvariant="normal">O</mi><mn>2</mn></msub><mi mathvariant="normal">x</mi> | \mathrm{CO}_2\mathrm{x} |
<mi mathvariant="normal">ab</mi><mi mathvariant="normal">c</mi> | \mathrm{ab}\mathrm{c} |
L3. Function names use their command, or \operatorname#
A known function name is written as its control word. Any other
function name is written \operatorname{…}. Rule S1 puts a space between
a function name and a following letter or digit.
Which tokens are function names is decided by the
rewrite stage: an upright
identifier that spells a known function name is one, with or without
function application after it, and so is any other upright identifier of
ASCII letters that function application follows, even a single letter,
as in \operatorname{E}(X). A run of
one-letter identifiers is one when function application follows it, and
a run of upright ones also when an opening bracket or fence follows it
or its last letter carries a script, as for any other name. An italic or
bold identifier is not one.
An identifier of words of letters that a space character separates, such
as arg max, is the known name that the words spell together, so
arc sin is \arcsin and lim sup is \limsup; any other is a
function name when function application follows it or it is the base
of an under and over construct, and \operatorname keeps its space as
the spacing command of rule S4: \operatorname{arg\,max}. In an
identifier that is not a function name a space character is written
the same way.
A known name that is also a unit, as listed under
Function names that are also units,
is a function name only when the markup shows its use: function
application follows it, it is the base of a script or of an under and
over construct, a script on an empty base follows it, arg precedes
it, or an opening bracket or fence follows it. Otherwise it
is an ordinary upright identifier of several letters, by rule L4.
| Input | Output |
|---|---|
<mi>sin</mi><mo>⁡</mo><mi>x</mi> | \sin x |
<mi>sin</mi><mi>x</mi> | \sin x |
<mi>log⁡</mi><mi>x</mi> | \log x |
<mi>l</mi><mi>o</mi><mi>g</mi><mo>⁡</mo><mi>x</mi> | \log x |
<mi>arg max</mi><mo>⁡</mo><mi>f</mi> | \operatorname{arg\,max} f |
<mi>lim sup</mi><mo>⁡</mo><mi>a</mi> | \limsup a |
<mi mathvariant="normal">m</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">x</mi><mo>(</mo>… | \max(… |
<mi mathvariant="normal">l</mi><mi mathvariant="normal">o</mi><msub><mi mathvariant="normal">g</mi><mn>2</mn></msub> | \log_2 |
<mi>arg</mi><mi>min</mi><msub><mrow/><mi>x</mi></msub> | \arg\min_x |
<mi>sgn</mi><mo>⁡</mo><mi>x</mi> | \operatorname{sgn} x |
<mi mathvariant="normal">E</mi><mo>⁡</mo><mi>X</mi> | \operatorname{E} X |
<mi>s</mi><mi>i</mi><mi>n</mi><mi>x</mi> | sinx |
<mi mathvariant="italic">sin</mi><mi>x</mi> | sinx |
<mn>5</mn><mi>min</mi> | 5\mathrm{min} |
<msub><mi>min</mi><mi>x</mi></msub> | \min_x |
<mi>min</mi><mo>(</mo><mi>a</mi><mo>)</mo> | \min(a) |
L4. Other upright identifiers of several letters use \mathrm#
An upright identifier of several letters that is not a function name
is written \mathrm{…}.
| Input | Output |
|---|---|
<mi>area</mi> | \mathrm{area} |
Fractions and roots#
F1. A fraction with a line is \frac#
Its numerator and denominator are written by the ordinary rules, with
the ordinary spaces; an empty one is {} (G5).
| Input | Output |
|---|---|
<mfrac><mn>1</mn><mn>2</mn></mfrac> | \frac{1}{2} |
<mfrac><mrow><mi>a</mi><mo>+</mo><mi>b</mi></mrow><mn>2</mn></mfrac> | \frac{a + b}{2} |
<mfrac><mfrac><mi>a</mi><mi>b</mi></mfrac><mi>c</mi></mfrac> | \frac{\frac{a}{b}}{c} |
F2. A fraction without a line is \binom or \genfrac#
A fraction without a line that is alone inside round parentheses that
stretch is written \binom. The parentheses belong to \binom, so rule
B1 does not apply to them. Any other fraction without a line is written
\genfrac.
| Input | Output |
|---|---|
<mo>(</mo><mfrac linethickness="0"><mi>n</mi><mi>k</mi></mfrac><mo>)</mo> | \binom{n}{k} |
<mfrac linethickness="0"><mi>n</mi><mi>k</mi></mfrac> | \genfrac{}{}{0pt}{}{n}{k} |
F3. Roots use \sqrt#
A root with an index writes the index in square brackets. Operators
written as one character get no spaces in the index (S2). An empty
index is not written. An index that contains ], or that starts with a
group, is put in braces: the ] would end the optional argument, and a
group followed by a script is not read as one argument.
| Input | Output |
|---|---|
<msqrt><mi>x</mi></msqrt> | \sqrt{x} |
<msqrt><mi>a</mi><mo>+</mo><mi>b</mi></msqrt> | \sqrt{a + b} |
<mroot><mi>x</mi><mn>3</mn></mroot> | \sqrt[3]{x} |
<mroot><mi>x</mi><mrow><mi>n</mi><mo>+</mo><mn>1</mn></mrow></mroot> | \sqrt[n+1]{x} |
<mroot><mi>x</mi><mo>]</mo></mroot> | \sqrt[{]}]{x} |
<mroot><mi>x</mi><msup><mspace width="1em"/><mn>2</mn></msup></mroot> | \sqrt[{{\quad}^2}]{x} |
Under and over#
U1. Limits are scripts#
Source markup writes limits as under and over items or as scripts, and
a formula should read as a person types it. The items below and above
an operator that LaTeX sets with limits in display style, such as \sum
or \bigcup, and above a function name that takes limits (the names
listed in Concepts),
are written as its subscript and superscript, whatever the markup says
about movable limits, and \limits is never written for them. An
integral is set with its limits beside it, so under and over items of
an operator such as \int or \oint keep \limits, and subscripts
and superscripts do not. Any other base takes its items by rule U4.
| Input | Output |
|---|---|
<munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover> | \sum_{i=1}^n |
<munder><mo movablelimits="false">∑</mo><mi>i</mi></munder> | \sum_i |
<munder><mo>∫</mo><mi>Ω</mi></munder> | \int\limits_{\Omega} |
<msub><mo>∫</mo><mi>Ω</mi></msub> | \int_{\Omega} |
<munder><mi>lim</mi><mrow><mi>x</mi><mo>→</mo><mn>0</mn></mrow></munder> | \lim_{x \to 0} |
<munder><mo movablelimits="false">lim</mo><mi>x</mi></munder> | \lim_x |
<munder><mi>sin</mi><mi>x</mi></munder> | \underset{x}{\sin} |
U2. Accents use the narrow or the wide command#
An accent over a token of one character, or over an accent that is
itself over such a token, uses the narrow command for its character,
such as \hat, \tilde, \bar, \vec, \dot or \ddot. Over anything
wider, ^, ~, ¯ and → use \widehat, \widetilde, \overline
and \overrightarrow, and every other accent keeps its narrow command.
The line is the exception: the macron ˉ and a macron or overline
character that the markup sets not to stretch (stretchy="false") keep
\bar over one character, and a horizontal bar, or a macron or overline
character that stretches, is \overline over any base. Generators
write \bar and \overline with these characters and attributes, so
each of them gives back the command the author typed.
Over nothing, an accent is on an empty group. A line below, _ or ¯,
is \underline, and an arrow below is \underrightarrow,
\underleftarrow or \underleftrightarrow; any other accent below
follows rule U4. An item is written as an accent only when it is
flagged as one (see the reader) and is one
character that LaTeX has an accent for. A mark that draws an accent is
one whichever element holds it, so <mtext>→</mtext> over a base is
\vec, and accent="false" does not turn a bar, a hat or a tilde into
a label: authors who write it on these marks mean the accent, and the
attribute only moves the mark in a browser. With an accent above and one
below, the one below is outside.
| Input | Output |
|---|---|
<mover accent="true"><mi>x</mi><mo>^</mo></mover> | \hat{x} |
<mover accent="true"><mrow><mi>a</mi><mi>b</mi></mrow><mo>^</mo></mover> | \widehat{ab} |
<mover accent="true"><mi>v</mi><mo>→</mo></mover> | \vec{v} |
<mover><mi>x</mi><mo stretchy="false">¯</mo></mover> | \bar{x} |
<mover><mi>x</mi><mo>¯</mo></mover> | \overline{x} |
<mover accent="true"><mover accent="true"><mi>a</mi><mo>^</mo></mover><mo>^</mo></mover> | \hat{\hat{a}} |
<mover accent="true"><msub><mi>x</mi><mn>1</mn></msub><mo>˙</mo></mover> | \dot{x_1} |
<munder accentunder="true"><mi>x</mi><mo>_</mo></munder> | \underline{x} |
<mover accent="false"><mi>x</mi><mo>^</mo></mover> | \hat{x} |
<mover accent="false"><mrow><mi>a</mi><mi>b</mi></mrow><mo>¯</mo></mover> | \overline{ab} |
<mover><mi>r</mi><mtext>→</mtext></mover> | \vec{r} |
<mover><mi>x</mi><mtext>ab</mtext></mover> | \overset{\text{ab}}{x} |
U3. Horizontal braces and labelled arrows have their own commands#
A horizontal brace below or above a base is \underbrace or
\overbrace, accent or not, and a label set beyond the brace is
written as its script. An arrow with an item above it is \xrightarrow,
\xleftarrow or \xmapsto with that item as the argument; an item
below goes in square brackets before it. These are the arrows that
both renderers draw this way; others follow rule U4. A space set as an
item only widens the label and is not written. A base that takes limits,
such as a sum, carries the brace as a limit (rule U1), so a label beyond
it follows rule U4.
So an arrow is \to as a symbol (C1), \vec or
\overrightarrow as an accent (U2), and \xrightarrow when it carries
a label.
| Input | Output |
|---|---|
<munder><munder><mrow><mi>a</mi><mi>b</mi></mrow><mo>⏟</mo></munder><mi>n</mi></munder> | \underbrace{ab}_n |
<mover><mo>→</mo><mi>f</mi></mover> | \xrightarrow{f} |
<munderover><mo>→</mo><mi>a</mi><mi>b</mi></munderover> | \xrightarrow[a]{b} |
<mover><mo>⇒</mo><mi>f</mi></mover> | \overset{f}{\Rightarrow} |
<mover><mrow><mover><mo>∑</mo><mo>⏞</mo></mover></mrow><mn>2</mn></mover> | \overset{2}{\sum^{⏞}} |
U4. Anything else set below or above uses \underset and \overset#
With both, \underset is outside. A relation keeps its spacing under
\overset, as \overset{\text{def}}{=}. The items are set in script
style, so operators written as one character get no spaces.
| Input | Output |
|---|---|
<mover><mi>x</mi><mo>*</mo></mover> | \overset{*}{x} |
<munderover><mi>X</mi><mi>a</mi><mi>b</mi></munderover> | \underset{a}{\overset{b}{X}} |
Brackets#
B1. \left and \right only around tall content#
A stretchy fence is written with \left and \right when its content
contains a fraction, a root, a table, an under or over construct other
than an accent, or a large operator. Any other fence is written plainly, and so is a fence
with a delimiter that one of the renderers does not accept after
\left or \right. Both accept (, ), [, ], {, }, |,
‖, ⟨, ⟩, ⌈, ⌉, ⌊ and ⌋. A fence with no delimiter at all
is its content alone. A fence that belongs to \binom (F2) or to a
matrix environment (M1) is part of that command.
| Input | Output |
|---|---|
<mo>(</mo><mi>a</mi><mo>+</mo><mi>b</mi><mo>)</mo> | (a + b) |
<mo>(</mo><mo>-</mo><mi>x</mi><mo>)</mo> | (-x) |
<mo>(</mo><mfrac><mi>a</mi><mi>b</mi></mfrac><mo>)</mo> | \left(\frac{a}{b}\right) |
B2. A missing side is a dot#
With \left and \right, a side without a delimiter is written
\left. or \right.. Without them, it is not written. An mfenced
that gives only one of open and close has no delimiter on the other
side, as one that gives it empty has, so no bracket that the author did
not write appears; with neither, the delimiters are parentheses, as
the reader describes.
| Input | Output |
|---|---|
<mfenced open="{" close=""><mfrac><mi>a</mi><mi>b</mi></mfrac></mfenced> | \left\{\frac{a}{b}\right. |
<mfenced open="{"><mi>x</mi></mfenced> | \{x |
<mfenced><mi>t</mi><mo>,</mo><mi>a</mi></mfenced> | (t, a) |
B3. Delimiters are written by the character rules#
Each delimiter is written by rules C1 to C3; the double bar ‖ is
\|.
| Input | Output |
|---|---|
<mo>{</mo><mi>a</mi><mo>}</mo> | \{a\} |
<mo>⟨</mo><mi>a</mi><mo>⟩</mo> | \langle a\rangle |
B4. A lone bar is a plain bar, in a set it is \mid#
A vertical bar that the rewrite stage left without a partner is written
|. Between two items inside braces it is \mid, as the bar of a set
is.
input: <mo>{</mo><mi>x</mi><mo>|</mo><mi>x</mi><mo>></mo><mn>0</mn><mo>}</mo>
output: \{x \mid x > 0\}
input: <mi>P</mi><mo>(</mo><mi>A</mi><mo>|</mo><mi>B</mi><mo>)</mo>
output: P(A|B)
The divides sign ∣ (U+2223) is the relation \mid between two items, as
in P(A \mid B), and a bar like | where a delimiter stands: at the
start of a row or the end of one, and as the partner of another bar or
of a bracket, as rule B6 describes.
input: <mo>∣</mo><mi>k</mi><mo>⟩</mo>
output: |k\rangle
B5. Mismatched brackets are written as they are#
A fence may have different brackets on its two sides, as a half-open interval has. Unpaired brackets are written as ordinary characters, except beside a table: an opening bracket without a partner directly before a table, and a closing bracket without a partner directly after one, make a fence around that table alone, with the other side empty, so that the bracket is as tall as the table. A table between an opening and a closing bracket that do not pair is the content of one fence.
| Input | Output |
|---|---|
<mo>[</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo>)</mo> | [a, b) |
<mo>]</mo><mi>a</mi><mo>,</mo><mi>b</mi><mo>[</mo> | ]a, b[ |
input: <mo>{</mo>
<mtable>
<mtr><mtd><mn>1</mn></mtd><mtd><mn>2</mn></mtd><mtd><mn>3</mn></mtd></mtr>
<mtr><mtd><mn>4</mn></mtd><mtd><mn>5</mn></mtd><mtd><mn>6</mn></mtd></mtr>
</mtable>
output: \left\{\begin{matrix}1 & 2 & 3 \\ 4 & 5 & 6\end{matrix}\right.
B6. Bars pair by counting#
The bars of one kind in a row pair in order, the first with the second, the third with the fourth, when there is an even number of them and each pair has content that is not empty and neither starts nor ends with an infix operator. An opening bar may then follow an item, as in a product with an absolute value. Bars that do not pair that way follow their place: a bar after an item closes the bar before it, if there is one.
input: <mi>a</mi><mo>|</mo><mi>x</mi><mo>|</mo><mo>+</mo><mo>|</mo><mi>y</mi><mo>|</mo>
output: a|x| + |y|
The divides sign counts as a vertical bar here, so ∣x∣ is |x|, a
tall one is \left|…\right|, and a bar of either character pairs with a
bar of the other. The parallel sign ∥ (U+2225) is the same for the double
bar ‖: around content it is \|x\|, a tall one is \left\|…\right\|,
and between two items it is the relation \parallel, as in
D(p \parallel q).
B7. A script on a closing delimiter applies to the fence#
A closing bracket or bar that carries a script, as in |x|_F, still
closes its fence, and the script applies to the whole fence. The bar
counts as one of the bars of its row for rule B6, so a norm with a
subscript beside a set bar keeps both roles, and a tall content gets
sized delimiters.
input: <mo>{</mo><mi>W</mi><mo>∣</mo><mo>|</mo><mo>|</mo><mi>W</mi><mo>|</mo><msub><mo>|</mo><mi>F</mi></msub><mo>≤</mo><mn>1</mn><mo>}</mo>
output: \{W \mid ||W||_F \leq 1\}
input: <mo>(</mo><mfrac><mi>a</mi><mi>b</mi></mfrac><msup><mo>)</mo><mn>2</mn></msup>
output: \left(\frac{a}{b}\right)^2
Text#
T1. Text uses \text#
Text is written in \text{}. Bold, italic, sans-serif and monospace
text use \textbf, \textit, \textsf and \texttt. Text in any
other variant has no text command and is written as math, with the
variant's command of rule L1.
| Input | Output |
|---|---|
<mtext>if</mtext> | \text{if} |
<mtext mathvariant="bold">Note</mtext> | \textbf{Note} |
<mtext>𝔸</mtext> | \mathbb{A} |
Text that holds one character with a spelling in math is not text but
that character, as authors type it. A punctuation mark (. , ; :
! ?) is written by the punctuation rules of S2, a Greek letter is
the letter, and a symbol with a command of its own, such as →, is that
command. A symbol that math mode writes as an ASCII character (/, =,
the minus sign, the dash) stays text, and so does text that sets a
letter style. Inside longer text, a Greek letter is written as math
between $ marks.
| Input | Output |
|---|---|
<mn>5</mn><mtext>.</mtext> | 5. |
<mtext>π</mtext> | \pi |
<mi>x</mi><mtext>→</mtext><mi>y</mi> | x \to y |
<mi>m</mi><mtext>/</mtext><mi>s</mi> | m\text{/}s |
<mtext>for λ real</mtext> | \text{for $\lambda$ real} |
T2. Text keeps one space at each end#
Runs of whitespace inside text become one space. A space at the start
or the end of text is kept, once, inside the braces, where it separates
the text from the item beside it: \text{for all }x. A no-break space
(U+00A0) counts as a space and is written as an ordinary one. Adjacent
text is one \text, and the spaces where two texts meet are one space.
Text that holds only whitespace is not text but a space of a third of
an em, 6 eighteenths, written by rule S4; each no-break space in it
adds a third of an em.
| Input | Output |
|---|---|
<mtext> for all </mtext> | \text{ for all } |
<mtext>for all </mtext><mi>x</mi> | \text{for all }x |
<mi>a</mi><mtext> b</mtext> | a\text{ b} |
<mtext> if </mtext> | \text{ if } |
<mtext>a </mtext><mtext> b</mtext> | \text{a b} |
<mi>a</mi><mtext> </mtext><mi>b</mi> | a\ b |
T3. Special characters in text#
Inside text, #, $, %, &, _, { and } get a backslash. \,
~, ^, < and > have no text command that both KaTeX and MathJax
accept, so they are written as in math, between $ marks: $\backslash$,
$\sim$, $\hat{}$, $<$ and $>$.
| Input | Output |
|---|---|
<mtext>50% off</mtext> | \text{50\% off} |
<mtext><b></mtext> | \text{$<$b$>$} |
T4. String literals keep their quotes#
An ms is written as text with its quotes, which are " unless the
lquote and rquote attributes say otherwise.
| Input | Output |
|---|---|
<ms>abc</ms> | \text{"abc"} |
T5. An accented letter of text is one character#
An accent set over text of one letter, where Unicode composes the
letter and the accent into one character, is that character. It joins
the text next to it, so a word whose accented letter is a node of its
own is written as one \text. Where Unicode has no composed character,
the accent keeps rule U2.
| Input | Output |
|---|---|
<mtext>m</mtext><mover accent="true"><mtext>e</mtext><mo>ˊ</mo></mover><mtext>dia</mtext> | \text{média} |
<mtext>a</mtext><mover accent="true"><mtext>q</mtext><mo>ˊ</mo></mover><mtext>b</mtext> | \text{a}\acute{\text{q}}\text{b} |
Matrices and tables#
M1. The environment follows from role, fences and alignment#
The first matching entry applies:
cases: a table of at most two columns and no lines, directly after a{that has no closing partner, which is the opening side of a fence whose closing side is empty. The{belongs tocasesand is not written. Any other table after such a{is written inside\left\{…\right..aligned: a table of equations without lines whose columns alternate right and left, or that has one column, aligned right. A single column aligned left is written with an empty left-hand side,&before each line.pmatrix,bmatrix,Bmatrix,vmatrixorVmatrix: a table with every column centred and no lines, whether a matrix or a table of equations, alone inside a fence that stretches, with the delimiters(),[],{},||or‖‖. The fence belongs to the environment and is not written. A row of equations that is alone inside such a fence is a row of the matrix, not a line of an equation.gathered: a table of equations without lines with one centred column.matrix: a matrix with every column centred and no lines.array: any other table, such as one of equations with several centred columns, or any table with lines. A fence around it, and a fence with other content or other delimiters around any table, is written by the bracket rules.
Labelled lines that make up a whole display formula are written in
align* and gather* instead of aligned and gathered, so that
each line can carry its label (rule M4).
input: <mo>(</mo>
<mtable>
<mtr><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd></mtr>
<mtr><mtd><mn>0</mn></mtd><mtd><mn>1</mn></mtd></mtr>
</mtable>
<mo>)</mo>
output: \begin{pmatrix}1 & 0 \\ 0 & 1\end{pmatrix}
input: <mo>{</mo>
<mtable columnalign="left left">
<mtr><mtd><mi>x</mi></mtd><mtd><mi>x</mi><mo>≥</mo><mn>0</mn></mtd></mtr>
<mtr><mtd><mo>-</mo><mi>x</mi></mtd><mtd><mi>x</mi><mo><</mo><mn>0</mn></mtd></mtr>
</mtable>
output: \begin{cases}x & x \geq 0 \\ -x & x < 0\end{cases}
input: <mtable columnalign="right left">
<mtr><mtd><mi>a</mi></mtd><mtd><mo>=</mo><mi>b</mi></mtd></mtr>
<mtr><mtd><mi>c</mi></mtd><mtd><mo>=</mo><mi>d</mi></mtd></mtr>
</mtable>
output: \begin{aligned}a & = b \\ c & = d\end{aligned}
The alignment of a column and the role of a table follow from the
markup as Architecture describes: from the
alignment of the table, the row and the cell, and from the classes that
name an alignment, so that the same lines come out alike however the
markup states their alignment. A table is one of equations when its
columns alternate right and left, when it is set in display style, and
when its rows are lines of equations: with one column, every line but
the first has a relation, and with an even number of columns, the
cells of each even-numbered column start with a relation. A column that
holds one relation in each of its cells, between two other columns, is
part of the cell after it, so lines set as three columns, a, =, b,
are the lines a & = b.
input: <mtable>
<mtr><mtd><mi>a</mi></mtd><mtd><mo>=</mo></mtd><mtd><mi>b</mi></mtd></mtr>
<mtr><mtd><mi>c</mi></mtd><mtd><mo>=</mo></mtd><mtd><mi>d</mi></mtd></mtr>
</mtable>
output: \begin{aligned}a & = b \\ c & = d\end{aligned}
input: <mtable>
<mtr><mtd columnalign="right"><mi>a</mi></mtd>
<mtd columnalign="left"><mo>=</mo><mi>b</mi></mtd></mtr>
<mtr><mtd columnalign="right"><mi>c</mi></mtd>
<mtd columnalign="left"><mo>=</mo><mi>d</mi></mtd></mtr>
</mtable>
output: \begin{aligned}a & = b \\ c & = d\end{aligned}
input: <mtable>
<mtr><mtd><mi>a</mi><mo>=</mo><mi>b</mi></mtd></mtr>
<mtr><mtd><mi>c</mi><mo>=</mo><mi>d</mi></mtd></mtr>
</mtable>
output: \begin{gathered}a = b \\ c = d\end{gathered}
A column of left-aligned lines is written with an empty left-hand side,
except inside a fence that it fills, where it is an array of one
left-aligned column: \left[\begin{array}{l}a = 1 \\ b = 2\end{array}\right].
The first line need not hold a relation, since it may be the start of
an equation that the next lines continue.
input: <mtable columnalign="left">
<mtr><mtd><mi>a</mi><mo>+</mo><mi>b</mi></mtd></mtr>
<mtr><mtd><mo>=</mo><mi>c</mi></mtd></mtr>
</mtable>
output: \begin{aligned} & a + b \\ & = c\end{aligned}
M2. Cells and rows are separated by & and \\#
Cells are separated by a space, & and a space; rows by a space, \\
and a space. There is no \\ after the last row and no space next to
\begin{…} or \end{…}. An empty cell is written as nothing, and the
spaces around it become one.
A column of a table of equations that is empty in every row is padding
and is dropped, wherever it stands: at an edge, or between the pairs of
columns of lines with several relations. The exception is the empty
left-hand side of the lines, the empty column before a column of lines
that all start with a relation, or before the only column that shows
anything when it is left-aligned; it is written as an empty first cell,
& = b. So is an empty right-hand side before the next left-hand side,
as in \text{C:} & & s_1 & = s_3. A matrix keeps an empty column,
which may be deliberate.
input: <mtable>
<mtr><mtd><mi>a</mi></mtd><mtd/></mtr>
<mtr><mtd><mi>c</mi></mtd><mtd><mi>d</mi></mtd></mtr>
</mtable>
output: \begin{matrix}a & \\ c & d\end{matrix}
input: <mtable columnalign="right left right left">
<mtr><mtd/><mtd><mi>x</mi></mtd><mtd><mo>=</mo><mn>1</mn></mtd><mtd/>
<mtd><mi>y</mi></mtd><mtd><mo>=</mo><mn>2</mn></mtd><mtd/></mtr>
<mtr><mtd/><mtd><mi>u</mi></mtd><mtd><mo>=</mo><mn>3</mn></mtd><mtd/>
<mtd><mi>v</mi></mtd><mtd><mo>=</mo><mn>4</mn></mtd><mtd/></mtr>
</mtable>
output: \begin{aligned}x & = 1 & y & = 2 \\ u & = 3 & v & = 4\end{aligned}
LaTeX reads a [ directly after \\ or after \begin{…} as the start of an
optional argument, a row skip or a vertical alignment, so a cell that
starts with a bracket is written with the bracket in a group, {[}.
Other cells need no group.
input: <mtable columnalign="right left">
<mtr><mtd><mo>[</mo><mi>a</mi><mo>]</mo></mtd><mtd><mo>=</mo><mn>0</mn></mtd></mtr>
<mtr><mtd><mo>[</mo><mi>b</mi><mo>]</mo></mtd><mtd><mo>=</mo><mn>1</mn></mtd></mtr>
</mtable>
output: \begin{aligned}{[}a] & = 0 \\ {[}b] & = 1\end{aligned}
M3. array states alignment and lines#
An array has a column specification of l, c and r, with |
between columns that have a solid line between them and : where the
line is dashed. A solid line between rows is \hline after the row
separator and a dashed one is \hdashline. A line around the table
is not written.
input: <mo>[</mo>
<mtable columnlines="solid">
<mtr><mtd><mn>1</mn></mtd><mtd><mn>0</mn></mtd></mtr>
<mtr><mtd><mn>0</mn></mtd><mtd><mn>1</mn></mtd></mtr>
</mtable>
<mo>]</mo>
output: \left[\begin{array}{c|c}1 & 0 \\ 0 & 1\end{array}\right]
M4. A row label is a tag, or text at the end of its line#
A row label, such as an equation number, is written at the end of its
row. When the table is the whole of a display formula, each label is a
\tag* on its line: lines that would be aligned are align*, lines
that would be gathered are gather* (rule M1), and a table of one
line is the line followed by its tag. \tag* shows its argument as it
stands, so labels such as (2a) and [A1] keep their brackets, and a
line without a label gets nothing. The starred environments number no
line of their own, also in a renderer set up to number equations.
Anywhere else the label follows its line after a \qquad, written like
any other content: in an inline formula, in a table that stands inside
other material, and in a table written as array, cases or a matrix,
which have no display environment that numbers lines. KaTeX accepts
\tag* in display mode only, MathJax rejects it inside aligned, and
both reject align* and gather* inside other material.
The argument of \tag* is text. A label of text, numbers and the
brackets and punctuation ( ) [ ] . , : ; / is written there as text,
with the escapes of rule T3 and text in another style in its text
command, as in \tag*{\textbf{(1)}}. A label that holds other math,
such as a Greek identifier, is math between $ signs, as in
\tag*{$(\alpha)$}. An empty label adds nothing. The side attribute,
which places labels on the left, is not followed: the side of a tag is
a setting of the renderer. The option
drop_labels leaves labels out.
input: <math display="block"><mtable><mlabeledtr><mtd><mtext>(1)</mtext></mtd><mtd><mi>E</mi><mo>=</mo><mi>m</mi><msup><mi>c</mi><mn>2</mn></msup></mtd></mlabeledtr></mtable></math>
output: E = mc^2 \tag*{(1)}
input: <math display="block"><mtable>
<mlabeledtr><mtd><mtext>(2)</mtext></mtd><mtd><mi>a</mi></mtd><mtd><mo>=</mo><mi>b</mi></mtd></mlabeledtr>
<mtr><mtd><mi>c</mi></mtd><mtd><mo>=</mo><mi>d</mi></mtd></mtr>
</mtable></math>
output: \begin{align*}a & = b \tag*{(2)} \\ c & = d\end{align*}
input: <mtable>
<mlabeledtr><mtd><mtext>(2)</mtext></mtd><mtd><mi>a</mi></mtd><mtd><mo>=</mo><mi>b</mi></mtd></mlabeledtr>
<mlabeledtr><mtd><mtext>(3)</mtext></mtd><mtd><mi>c</mi></mtd><mtd><mo>=</mo><mi>d</mi></mtd></mlabeledtr>
</mtable>
output: \begin{aligned}a & = b \qquad \text{(2)} \\ c & = d \qquad \text{(3)}\end{aligned}
A row label of an mlabeledtr is the first child when another child
follows it; a row of one child shows that child. In a table of
equations without such rows, a last column whose cells that show
something are each a number in parentheses, as (1) and (2.3), holds
the numbers of the lines, and each of its cells is the label of its
row. A table with labelled rows is a table of equations.
M5. A table of one line is not an environment#
A table of one cell is written as its content, and a table of equations with one row as its cells one after another. Such tables only wrap an equation or split it at its relation, and a careful author writes the equation directly. A labelled table of one row is likewise its line, followed by its label (rule M4). A matrix of one row or one column keeps its environment, and so does a row of equations that is alone inside a fence, which is a row of a matrix there (rule M1).
| Input | Output |
|---|---|
<mtable><mtr><mtd><mi>x</mi><mo>=</mo><mn>1</mn></mtd></mtr></mtable> | x = 1 |
<mtable columnalign="right left"><mtr><mtd><mi>a</mi></mtd><mtd><mo>=</mo><mi>b</mi></mtd></mtr></mtable> | a = b |
<mtable columnalign="right left"><mtr><mtd><mi>a</mi><mo>=</mo><mi>b</mi></mtd><mtd><mo>+</mo><mi>c</mi></mtd></mtr></mtable> | a = b + c |
Enclosures#
E1. Notations map to fixed commands#
box and roundedbox are \boxed; updiagonalstrike,
downdiagonalstrike and both together are \cancel, \bcancel and
\xcancel; top and bottom are \overline and \underline; and
radical is \sqrt. Several notations nest in this order, the first
outermost. Any other notation, including the default longdiv of an menclose
without a notation, is not written: the content is written alone, and
the fallback unsupported-notation is recorded with the notation's
name as its detail.
| Input | Output |
|---|---|
<menclose notation="box"><mi>x</mi></menclose> | \boxed{x} |
<menclose notation="box updiagonalstrike"><mi>x</mi></menclose> | \boxed{\cancel{x}} |
<menclose notation="circle"><mi>x</mi></menclose> | x |
Phantoms and other content#
P1. A phantom is \phantom#
Hidden content that keeps all its dimensions, as mphantom gives, is
\phantom{…}. Of the combinations that no current reader produces,
hidden content keeping only its width is \hphantom, hidden content
keeping only its height and depth is \vphantom, shown content without
height and depth is \smash, and any other combination takes the
nearest of these.
| Input | Output |
|---|---|
<mphantom><mi>x</mi></mphantom> | \phantom{x} |
A phantom with no content takes no space and is not written, so the line that continues a split equation starts with its relation, or with an empty first cell in an aligned table.
| Input | Output |
|---|---|
<mrow><mphantom/><mo>=</mo><mi>b</mi></mrow> | = b |
<msub><mi>N</mi><mrow><mphantom/><mo>≥</mo><mn>2</mn></mrow></msub> | N_{\geq 2} |
P2. Unknown content is written like a row#
Text directly inside the element of an Unknown node was lowered to
one token per character, so it follows the rules for tokens.
| Input | Output |
|---|---|
<foo>a+b</foo> | a + b |
A Verbatim node, which no current reader produces, is written as its
head followed by its arguments in their recorded brackets.
Content markup#
Content markup lowers to the same nodes as presentation markup, so every
rule above applies to it. The rules in this section decide the notation
that lowering chooses for content markup, as described in
Architecture. Inputs are shown
without the surrounding <math> element.
K1. A product is written side by side, or with \cdot throughout#
The factors of a product stand side by side, as in 2x and ab, when
no two neighbours would run together. Neighbours run together when
either is a name of several characters, when the second starts with a
number, and when a fraction follows a number, which would read as a
mixed number. A product with any such pair separates all its factors
with \cdot, so that names of species and parameters stay apart. A
product inside a product is one product.
| Input | Output |
|---|---|
<apply><times/><cn>2</cn><ci>x</ci></apply> | 2x |
<apply><times/><ci>k</ci><ci>A</ci><ci>B</ci></apply> | kAB |
<apply><times/><ci>kf</ci><ci>A</ci><ci>B</ci></apply> | \mathrm{kf} \cdot A \cdot B |
<apply><times/><ci>x</ci><cn>2</cn></apply> | x \cdot 2 |
K2. Parentheses stand only where the binding requires them#
An argument is put in parentheses when it binds more loosely than its place requires, following the usual order: relations bind more loosely than sums, sums than products, products than powers. A sum in a product, a difference on the right of a difference, a sign after the first term, a power base that is not a single token or fence, and a relation inside a relation get parentheses; a product in a sum, a sum in a fraction or an exponent, and a sign that starts a product or follows a relation get none. A negation takes parentheses around a relation, and a large operator that more factors follow takes them around itself.
| Input | Output |
|---|---|
<apply><times/><ci>a</ci><apply><plus/><ci>b</ci><ci>c</ci></apply></apply> | a(b + c) |
<apply><plus/><apply><times/><ci>a</ci><ci>b</ci></apply><ci>c</ci></apply> | ab + c |
<apply><minus/><ci>a</ci><apply><minus/><ci>b</ci><ci>c</ci></apply></apply> | a - (b - c) |
<apply><plus/><ci>a</ci><apply><minus/><ci>b</ci></apply></apply> | a + (-b) |
<apply><power/><apply><plus/><ci>a</ci><ci>b</ci></apply><cn>2</cn></apply> | (a + b)^2 |
<apply><divide/><apply><plus/><ci>a</ci><ci>b</ci></apply><ci>c</ci></apply> | \frac{a + b}{c} |
<apply><not/><apply><eq/><ci>a</ci><ci>b</ci></apply></apply> | \neg(a = b) |
K3. A function takes a single token without parentheses#
A function name before a single token, such as an identifier or a
number, is followed by it directly, as in \sin x; any other argument,
and several arguments, are in parentheses. When further factors of a
product follow, other than one that starts with a function name, the
argument is in parentheses, so that \sin(x)y is not read as the sine
of xy. An identifier of several letters applied as a function is a
function name; an identifier of one letter is followed by its
arguments in parentheses. exp is a power of e, and log with a
logbase has the base as its subscript.
| Input | Output |
|---|---|
<apply><sin/><ci>x</ci></apply> | \sin x |
<apply><sin/><apply><plus/><ci>x</ci><cn>1</cn></apply></apply> | \sin(x + 1) |
<apply><times/><apply><sin/><ci>x</ci></apply><apply><cos/><ci>x</ci></apply></apply> | \sin x\cos x |
<apply><times/><apply><sin/><ci>x</ci></apply><ci>y</ci></apply> | \sin(x)y |
<apply><ci>f</ci><ci>x</ci><ci>y</ci></apply> | f(x, y) |
<apply><ci>sgn</ci><ci>x</ci></apply> | \operatorname{sgn}(x) |
<apply><exp/><apply><minus/><ci>x</ci></apply></apply> | e^{-x} |
<apply><log/><logbase><cn>2</cn></logbase><ci>x</ci></apply> | \log_{2}x |
K4. Bound variables become limits, differentials and derivatives#
A sum or a product writes its bound variable and lower limit as
i = 1 below and its upper limit above; a condition or a
domainofapplication stands below instead. An integral writes its
limits alone and ends with \,dx for each bound variable. A limit
writes x \to a. A derivative of a token is a fraction with the
token in the numerator, and of any other expression the operator
\frac{d}{dx} before it; without a bound variable it is a prime. Partial
derivatives write the total degree on \partial.
| Input | Output |
|---|---|
<apply><sum/><bvar><ci>i</ci></bvar><lowlimit><cn>1</cn></lowlimit><uplimit><ci>n</ci></uplimit><ci>i</ci></apply> | \sum_{i=1}^n i |
<apply><int/><bvar><ci>x</ci></bvar><lowlimit><cn>0</cn></lowlimit><uplimit><cn>1</cn></uplimit><ci>f</ci></apply> | \int_0^1 f\,dx |
<apply><limit/><bvar><ci>x</ci></bvar><lowlimit><cn>0</cn></lowlimit><ci>f</ci></apply> | \lim_{x \to 0}f |
<apply><diff/><bvar><ci>x</ci></bvar><ci>y</ci></apply> | \frac{dy}{dx} |
<apply><diff/><bvar><ci>x</ci></bvar><apply><sin/><ci>x</ci></apply></apply> | \frac{d}{dx}\sin x |
<apply><diff/><ci>f</ci></apply> | f' |
<apply><partialdiff/><bvar><ci>x</ci></bvar><bvar><ci>y</ci></bvar><ci>f</ci></apply> | \frac{\partial^{2}f}{\partial x\partial y} |
K5. A piecewise definition is cases#
Each piece is a row of its value and "if" with its condition, and
otherwise a row of its value and "otherwise".
input: <piecewise>
<piece><apply><minus/><ci>x</ci></apply><apply><lt/><ci>x</ci><cn>0</cn></apply></piece>
<otherwise><ci>x</ci></otherwise>
</piecewise>
output: \begin{cases}-x & \text{if }x < 0 \\ x & \text{otherwise}\end{cases}
K6. Intervals, sets, lists, vectors and matrices have their delimiters#
An interval is closed by default; its closure chooses round or square
brackets on each side. A set is in braces, with a condition after
\mid; a list is in parentheses. A vector is a column and a matrix a
grid, both in parentheses. A lambda maps its bound variables to its
expression.
| Input | Output |
|---|---|
<interval closure="open-closed"><cn>0</cn><cn>1</cn></interval> | (0, 1] |
<set><bvar><ci>x</ci></bvar><condition><apply><lt/><ci>x</ci><cn>5</cn></apply></condition></set> | \{x \mid x < 5\} |
<vector><ci>a</ci><ci>b</ci></vector> | \begin{pmatrix}a \\ b\end{pmatrix} |
<lambda><bvar><ci>x</ci></bvar><bvar><ci>y</ci></bvar><apply><plus/><ci>x</ci><ci>y</ci></apply></lambda> | (x, y) \mapsto x + y |
K7. Numbers, identifiers and symbols#
A cn is written as an mn and a ci as an mi, so a name of
several letters is upright (L4). A number in e-notation is written in
scientific notation, a rational number as a fraction, and a number in
another base with the base as its subscript. A csymbol that names a
known symbol is written as that symbol: the time of a model is t
whatever its text. Any other csymbol is written as its text.
| Input | Output |
|---|---|
<cn type="e-notation">1.5<sep/>-3</cn> | 1.5 \times 10^{-3} |
<cn type="rational">22<sep/>7</cn> | \frac{22}{7} |
<ci>kcat</ci> | \mathrm{kcat} |
<csymbol definitionURL="http://www.sbml.org/sbml/symbols/time">time</csymbol> | t |
<apply><in/><ci>n</ci><naturalnumbers/></apply> | n \in \mathbb{N} |
Delimiters#
D1. Delimiters touch the body, and an empty formula stays empty#
The delimiters option selects the
delimiters. No space separates a
delimiter from the body. A formula with an empty body has empty
output, whatever the option, so no empty $$ appears.
| Input | dollar | paren |
|---|---|---|
<math><mi>x</mi></math> | $x$ | \(x\) |
<math display="block"><mi>x</mi></math> | $$x$$ | \[x\] |
<math></math> | (empty) | (empty) |