LaTeX syntax for mathematics
Abstract
Docutils supports mathematical content with a "math" directive and role. The input format is LaTeX math syntax[1] with support for literal Unicode symbols.
1 Inline formulas and displayed equations
The math role can be used for inline mathematical expressions: :math:`\psi(r) = \exp(-2r)` will produce . Inside the backtics you can write anything you would write between dollar signs in a LaTeX document. [1]
The math directive is used for displayed equations. It corresponds to an equation* or align* environment in a LaTeX document. If you write:
.. math:: \psi(r) = e^{-2r}
you will get:
A more complex example is the definition of the Fourier transform:
.. math:: :name: Fourier transform (\mathcal{F}f)(y) = \frac{1}{\sqrt{2\pi}^{\ n}} \int_{\mathbb{R}^n} f(x)\, e^{-\mathrm{i} y \cdot x} \,\mathrm{d} x.
which is rendered as:
The :name: option puts a label on the equation that can be linked to by hyperlink references.
Displayed equations can use \\ and & for line shifts and alignments:
.. math:: a &= (x + y)^2 & b &= (x - y)^2 \\ &= x^2 + 2xy + y^2 & &= x^2 - 2xy + y^2
LaTeX output will wrap it in an align* environment. The result is:
The aligned environment can be used as a component in a containing expression. E.g.,
.. math:: \left. \begin{aligned} B' & = -\partial\times E, \\ E' & = \partial\times B - 4\pi j, \end{aligned} \right\} \qquad \text{Maxwell’s equations}
results in
2 Mathematical symbols
The following tables are adapted from the first edition of "The LaTeX Companion" (Goossens, Mittelbach, Samarin) and the AMS Short Math Guide.
2.1 Accents and embellishments
The "narrow" accents are intended for a single-letter base.
\acute{x} |
\dot{t} |
\grave{x} |
\vec{x} |
||||
\bar{v} |
\ddot{t} |
\hat{x} |
|||||
\breve{x} |
\dddot{t} |
\mathring{x} |
|||||
\check{x} |
\ddddot{t} |
\tilde{n} |
When adding an accent to an i or j in math, dotless variants can be obtained with \imath and \jmath: , .
For embellishments that span multiple symbols, use:
\widetilde{gbi} |
\widehat{gbi} |
||
\overline{gbi} |
\underline{gbi} |
||
\overbrace{gbi} |
\underbrace{gbi} |
||
\overleftarrow{gbi} |
\underleftarrow{gbi} |
||
\overrightarrow{gbi} |
\underrightarrow{gbi} |
||
\overleftrightarrow{gbi} |
\underleftrightarrow{gbi} |
2.2 Binary operators
* |
\circledast |
\ominus |
|||
+ |
\circledcirc |
\oplus |
|||
- |
\circleddash |
\oslash |
|||
: |
\cup |
\otimes |
|||
\Cap |
\curlyvee |
\pm |
|||
\Cup |
\curlywedge |
\rightthreetimes |
|||
\amalg |
\dagger |
\rtimes |
|||
\ast |
\ddagger |
\setminus |
|||
\bigcirc |
\diamond |
\smallsetminus |
|||
\bigtriangledown |
\div |
\sqcap |
|||
\bigtriangleup |
\divideontimes |
\sqcup |
|||
\boxdot |
\dotplus |
\star |
|||
\boxminus |
\doublebarwedge |
\times |
|||
\boxplus |
\gtrdot |
\triangleleft |
|||
\boxtimes |
\intercal |
\triangleright |
|||
\bullet |
\leftthreetimes |
\uplus |
|||
\cap |
\lessdot |
\vee |
|||
\cdot |
\ltimes |
\veebar |
|||
\centerdot |
\mp |
\wedge |
|||
\circ |
\odot |
\wr |
2.3 Extensible delimiters
Unless you indicate otherwise, delimiters in math formulas remain at the standard size regardless of the height of the enclosed material. To get adaptable sizes, use \left and \right prefixes, for example or
Use . for "empty" delimiters:
See also the commands for fixed delimiter sizes below.
The following symbols extend when used with \left and \right:
2.3.1 Pairing delimiters
( ) |
\langle \rangle |
||
[ ] |
\lceil \rceil |
||
\{ \} |
\lfloor \rfloor |
||
\lvert \rvert |
\lgroup \rgroup |
||
\lVert \rVert |
\lmoustache \rmoustache |
2.3.2 Nonpairing delimiters
| |
\vert |
\arrowvert |
|||
\| |
\Vert |
\Arrowvert |
|||
/ |
\backslash |
\bracevert |
The use of | and \| for pairs of vertical bars may produce incorrect spacing, e.g., |k|=|-k| produces and |\sin(x)| produces . The pairing delimiters, e.g. and , prevent this problem.
2.4 Extensible vertical arrows
\uparrow |
\Uparrow |
\downarrow |
\Downarrow |
\updownarrow |
\Updownarrow |
2.5 Functions (named operators)
\arccos |
\gcd |
\Pr |
|||
\arcsin |
\hom |
\projlim |
|||
\arctan |
\inf |
\sec |
|||
\arg |
\injlim |
\sin |
|||
\cos |
\ker |
\sinh |
|||
\cosh |
\lg |
\sup |
|||
\cot |
\lim |
\tan |
|||
\coth |
\liminf |
\tanh |
|||
\csc |
\limsup |
\varlimsup |
|||
\deg |
\ln |
\varliminf |
|||
\det |
\log |
\varprojlim |
|||
\dim |
\max |
\varinjlim |
|||
\exp |
\min |
Named operators outside the above list can be typeset with \operatorname{name}, e.g.
The \DeclareMathOperator command can only be used in the LaTeX preamble.
2.6 Greek letters
Greek letters that have Latin look-alikes are rarely used in math formulas and not supported by LaTeX.
\Gamma |
\alpha |
\mu |
\omega |
||||
\Delta |
\beta |
\nu |
\digamma |
||||
\Lambda |
\gamma |
\xi |
\varepsilon |
||||
\Phi |
\delta |
\pi |
\varkappa |
||||
\Pi |
\epsilon |
\rho |
\varphi |
||||
\Psi |
\zeta |
\sigma |
\varpi |
||||
\Sigma |
\eta |
\tau |
\varrho |
||||
\Theta |
\theta |
\upsilon |
\varsigma |
||||
\Upsilon |
\iota |
\phi |
\vartheta |
||||
\Xi |
\kappa |
\chi |
|||||
\Omega |
\lambda |
\psi |
In LaTeX, the default font for capital Greek letters is upright/roman. Italic capital Greek letters can be obtained by loading a package providing the "ISO" math style. They are used by default in MathML.
Individual Greek italic capitals can also be achieved preceding the letter name with var like \varPhi:
2.7 Letterlike symbols
\forall |
\aleph |
\hbar |
\ell |
||||
\complement |
\beth |
\hslash |
\wp |
||||
\exists |
\gimel |
\Im |
\Re |
||||
\Finv |
\daleth |
\imath |
\circledR |
||||
\Game |
\partial |
\jmath |
\circledS |
||||
\mho |
\eth |
\Bbbk |
2.8 Math alphabets
The TeX math alphabet macros are intended for mathematical variables where style variations are important semantically. They style letters and numbers with a combination of font attributes (shape, weight, family) --- non-alphanumerical symbols, function names, and mathematical text are left unchanged.
MathML uses the mathvariant style attribute or pre-styled characters from the Mathematical Alphanumeric Symbols Unicode block.
command |
example |
result |
---|---|---|
\mathrm |
s_\mathrm{out} |
|
\mathbf |
\mathbf{r}^2=x^2+y^2 |
|
\mathit |
\mathit{\sin\Gamma} |
|
\mathcal |
\mathcal{F}f(x) |
|
\mathbb |
\mathbb{R \subset C} |
|
\mathfrak |
\mathfrak{a+b} |
|
\mathsf |
\mathsf x |
|
\mathtt |
\mathtt{0.12} |
The set of characters in a given "math alphabet" varies. LaTeX may produce garbage for unsupported characters. Additional math alphabets are defined in LaTeX packages, e.g.,
\mathbfit from isomath allows vector symbols in line with the International Standard [ISO-80000-2]. E.g., \mathbfit{r}^2=x^2+y^2 becomes .
Several packages, e.g. mathrsfs, define \mathscr that selects a differently shaped "script" alphabet.
The listing below shows the characters supported by Unicode and Docutils with math_output MathML. [2]
- default:
- mathrm:
- mathbf:
- mathit:
- mathbfit:
- mathcal:
- mathscr:
- mathbb:
- mathfrak:
- mathsf:
- mathsfit:
- mathsfbfit:
- mathtt:
Italic digits are not defined in Unicode but work in LaTeX.
In contrast to the math alphabet selectors, \boldsymbol only changes the font weight. It can be used to get a bold version of any mathematical symbol:
It is usually ill-advised to apply \boldsymbol to more than one symbol at a time.
2.9 Miscellaneous symbols
\# |
\clubsuit |
\neg |
|||
\& |
\diamondsuit |
\nexists |
|||
\angle |
\emptyset |
\prime |
|||
\backprime |
\exists |
\sharp |
|||
\bigstar |
\flat |
\spadesuit |
|||
\blacklozenge |
\forall |
\sphericalangle |
|||
\blacksquare |
\heartsuit |
\square |
|||
\blacktriangle |
\infty |
\surd |
|||
\blacktriangledown |
\lozenge |
\top |
|||
\bot |
\measuredangle |
\triangle |
|||
\diagdown |
\nabla |
\triangledown |
|||
\diagup |
\natural |
\varnothing |
2.10 Punctuation
. |
! |
\vdots |
|||
/ |
? |
\dotsb |
|||
| |
\colon [3] |
\dotsc |
|||
' |
\cdots |
\dotsi |
|||
; |
\ddots |
\dotsm |
|||
: |
\ldots |
\dotso |
Punctuation (not ratio): Compare spacing in to .
2.11 Relation symbols
2.11.1 Arrows
\circlearrowleft |
\circlearrowright |
||
\curvearrowleft |
\curvearrowright |
||
\hookleftarrow |
\hookrightarrow |
||
\leftarrow |
\rightarrow |
||
\Leftarrow |
\Rightarrow |
||
\leftarrowtail |
\rightarrowtail |
||
\leftharpoondown |
\rightharpoondown |
||
\leftharpoonup |
\rightharpoonup |
||
\leftleftarrows |
\rightrightarrows |
||
\leftrightarrow |
\Leftrightarrow |
||
\leftrightarrows |
\rightleftarrows |
||
\leftrightharpoons |
\rightleftharpoons |
||
\leftrightsquigarrow |
\rightsquigarrow |
||
\Lleftarrow |
\Rrightarrow |
||
\longleftarrow |
\longrightarrow |
||
\Longleftarrow |
\Longrightarrow |
||
\longleftrightarrow |
\Longleftrightarrow |
||
\looparrowleft |
\looparrowright |
||
\Lsh |
\Rsh |
||
\mapsto |
\longmapsto |
||
\multimap |
|||
\nleftarrow |
\nrightarrow |
||
\nLeftarrow |
\nRightarrow |
||
\nleftrightarrow |
\nLeftrightarrow |
||
\nwarrow |
\nearrow |
||
\swarrow |
\searrow |
||
\twoheadleftarrow |
\twoheadrightarrow |
||
\upharpoonleft |
\upharpoonright |
||
\downharpoonleft |
\downharpoonright |
||
\upuparrows |
\downdownarrows |
Synonyms: \gets, \to, \restriction.
2.11.2 Comparison
< |
\geq |
\ll |
\prec |
||||
= |
\geqq |
\lll |
\precapprox |
||||
> |
\geqslant |
\lnapprox |
\preccurlyeq |
||||
\approx |
\gg |
\lneq |
\preceq |
||||
\approxeq |
\ggg |
\lneqq |
\precnapprox |
||||
\asymp |
\gnapprox |
\lnsim |
\precneqq |
||||
\backsim |
\gneq |
\ncong |
\precnsim |
||||
\backsimeq |
\gneqq |
\neq |
\precsim |
||||
\bumpeq |
\gnsim |
\ngeq |
\risingdotseq |
||||
\Bumpeq |
\gtrapprox |
\ngeqq |
\sim |
||||
\circeq |
\gtreqless |
\ngeqslant |
\simeq |
||||
\cong |
\gtreqqless |
\ngtr |
\succ |
||||
\curlyeqprec |
\gtrless |
\nleq |
\succapprox |
||||
\curlyeqsucc |
\gtrsim |
\nleqq |
\succcurlyeq |
||||
\doteq |
\leq |
\nleqslant |
\succeq |
||||
\doteqdot |
\leqq |
\nless |
\succnapprox |
||||
\eqcirc |
\leqslant |
\nprec |
\succneqq |
||||
\eqsim |
\lessapprox |
\npreceq |
\succnsim |
||||
\eqslantgtr |
\lesseqgtr |
\nsim |
\succsim |
||||
\eqslantless |
\lesseqqgtr |
\nsucc |
\thickapprox |
||||
\equiv |
\lessgtr |
\nsucceq |
\thicksim |
||||
\fallingdotseq |
\lesssim |
\triangleq |
The commands \lvertneqq and \gvertneqq are not supported with MathML output, as there is no corresponding Unicode character.
Synonyms: \ne, \le, \ge, \Doteq, \llless, \gggtr.
Symbols can be negated prepending \not, e.g. \not=, \not\equiv, \not\gtrless, \not\lessgtr.
2.11.3 Miscellaneous relations
\backepsilon |
\ntrianglelefteq |
\subseteq |
|||
\because |
\ntriangleright |
\subseteqq |
|||
\between |
\ntrianglerighteq |
\subsetneq |
|||
\blacktriangleleft |
\nvdash |
\subsetneqq |
|||
\blacktriangleright |
\nVdash |
\supset |
|||
\bowtie |
\nvDash |
\Supset |
|||
\dashv |
\nVDash |
\supseteq |
|||
\frown |
\parallel |
\supseteqq |
|||
\in |
\perp |
\supsetneq |
|||
\mid |
\pitchfork |
\supsetneqq |
|||
\models |
\propto |
\therefore |
|||
\ni |
\shortmid |
\trianglelefteq |
|||
\nmid |
\shortparallel |
\trianglerighteq |
|||
\notin |
\smallfrown |
\varpropto |
|||
\nparallel |
\smallsmile |
\vartriangle |
|||
\nshortmid |
\smile |
\vartriangleleft |
|||
\nshortparallel |
\sqsubset |
\vartriangleright |
|||
\nsubseteq |
\sqsubseteq |
\vdash |
|||
\nsubseteqq |
\sqsupset |
\Vdash |
|||
\nsupseteq |
\sqsupseteq |
\vDash |
|||
\nsupseteqq |
\subset |
\Vvdash |
|||
\ntriangleleft |
\Subset |
Synonyms: \owns.
Symbols can be negated prepending \not, e.g. \not\in, \not\ni.
The commands \varsubsetneq, \varsubsetneqq, \varsupsetneq, and \varsupsetneqq are not supported with MathML output as there is no corresponding Unicode character.
2.12 Variable-sized operators
\sum |
\prod |
\bigcap |
\bigodot |
\int |
\coprod |
\bigcup |
\bigoplus |
\oint |
\bigwedge |
\biguplus |
\bigotimes |
\smallint |
\bigvee |
\bigsqcup |
Larger symbols are used in displayed formulas, sum-like symbols have indices above/below the symbol:
3 Notations
3.1 Top and bottom embellishments
3.2 Extensible arrows
xleftarrow and xrightarrow produce arrows that extend automatically to accommodate unusually wide subscripts or superscripts. These commands take one optional argument (the subscript) and one mandatory argument (the superscript, possibly empty):
A \xleftarrow{n+\mu-1} B \xrightarrow[T]{n\pm i-1} C
results in
3.3 Affixing symbols to other symbols
In addition to the standard accents and embellishments, other symbols can be placed above or below a base symbol with the \overset and \underset commands. The symbol is set in "scriptstyle" (smaller font size). For example, writing \overset{*}{X} becomes and \underset{+}{M} becomes .
3.4 Matrices
The matrix and cases environments can also contain \\ and &:
.. math:: \left ( \begin{matrix} a & b \\ c & d \end{matrix}\right)
Result:
The environments pmatrix, bmatrix, Bmatrix, vmatrix, and Vmatrix have (respectively) ( ), [ ], { }, | |, and delimiters built in, e.g.
To produce a small matrix suitable for use in text, there is a smallmatrix environment that comes closer to fitting within a single text line than a normal matrix.
For piecewise function definitions there is a cases environment:
3.5 Spacing commands
Horizontal spacing of elements can be controlled with the following commands:
3\qquad 4 |
= 2em |
||
3\quad 4 |
= 1em |
||
3~4 |
3\nobreakspace 4 |
||
3\ 4 |
escaped space |
||
3\;4 |
3\thickspace 4 |
||
3\:4 |
3\medspace 4 |
||
3\,4 |
3\thinspace 4 |
||
3 4 |
regular space [4] |
||
3\!4 |
3\negthinspace 4 |
negative space [5] |
|
3\negmedspace 4 |
|||
3\negthickspace 4 |
|||
3\hspace{1ex}4 |
custom length |
||
3\mspace{20mu}4 |
custom length [6] |
Whitespace characters are ignored in LaTeX math mode.
Negative spacing does not work with MathML (last tested in Firefox 115).
In LaTeX, the unit must be 'mu' (1 mu = 1/18em).
There are also three commands that leave a space equal to the height and width of its argument. For example \phantom{XXX} results in space as wide and high as three X’s:
The commands \hphantom and \vphantom insert space with the width or height of the argument. They are not supported with math_output MathML.
3.6 Modular arithmetic and modulo operation
The commands \bmod, \pmod, \mod, and \pod deal with the special spacing conventions of the “mod” notation. [7]
command |
example |
result |
---|---|---|
\bmod |
\gcd(n,m \bmod n) |
|
\pmod |
x\equiv y \pmod b |
|
\mod |
x\equiv y \mod c |
|
\pod |
x\equiv y \pod d |
|
\operatorname{mod}(m,n) |
Currently not supported by the "HTML" math_output option of the HTML writer.
3.7 Roots
command |
example |
result |
---|---|---|
\sqrt |
\sqrt{x^2-1} |
|
\sqrt[3n]{x^2-1} |
||
\sqrt\frac{1}{2} |
3.8 Boxed formulas
The command \boxed puts a box around its argument:
5 Delimiter sizes
Besides the automatic scaling of extensible delimiters with \left and \right, there are four commands to manually select delimiters of fixed size:
Sizing |
no |
\left |
\bigl |
\Bigl |
\biggl |
\Biggl |
command |
\right |
\bigr |
\Bigr |
\biggr |
\Biggr |
|
Result |
There are two or three situations where the delimiter size is commonly adjusted using these commands:
The first kind of adjustment is done for cumulative operators with limits, such as summation signs. With \left and \right the delimiters usually turn out larger than necessary, and using the Big or bigg sizes instead gives better results:
The second kind of situation is clustered pairs of delimiters, where left and right make them all the same size (because that is adequate to cover the encompassed material), but what you really want is to make some of the delimiters slightly larger to make the nesting easier to see.
The third kind of situation is a slightly oversize object in running text, such as where the delimiters produced by \left and \right cause too much line spreading. [8] In that case \bigl and \bigr can be used to produce delimiters that are larger than the base size but still able to fit within the normal line spacing: .
With MathML, an example would be parentheses around a smallmatrix environment vs. .
6 Text
The main use of the command \text is for words or phrases in a display. It is similar to \mbox in its effects but, unlike \mbox, automatically produces subscript-size text if used in a subscript, k_{\text{B}}T becomes .
Whitespace is kept inside the argument:
The text may contain math commands wrapped in $ signs, e.g.
7 Integrals and sums
The limits on integrals, sums, and similar symbols are placed either to the side of or above and below the base symbol, depending on convention and context. In inline formulas and fractions, the limits on sums, and similar symbols like
move to index positions: .
7.1 Altering the placement of limits
The commands \intop and \ointop produce integral signs with limits as in sums and similar: , and
The commands \limits and \nolimits override the default placement of the limits for any operator; \displaylimits forces standard positioning as for the sum command. They should follow immediately after the operator to which they apply.
Compare the same term with default positions, \limits, and \nolimits in inline and display mode: , , , vs.
8 Changing the size of elements in a formula
The declarations [9] \displaystyle, \textstyle, \scriptstyle, and \scriptscriptstyle, select a symbol size and spacing that would be applied in display math, inline math, first-order subscript, or second-order subscript, respectively even when the current context would normally yield some other size.
For example :math:`\displaystyle \sum_{n=0}^\infty \frac{1}{n}` is printed as rather than and
\frac{\scriptstyle\sum_{n > 0} z^n} {\displaystyle\prod_{1\leq k\leq n} (1-q^k)}
yields
"Declarations" are commands that affect processing of the current "group". In particular, notice where the braces fall that delimit the effect of the command: Right: {\displaystyle ...} Wrong: \displaystyle{...}.
With math_output MathML, the declaration must be the first element after the opening bracket.
Quantities and units – Part 2: Mathematical signs and symbols to be used in the natural sciences and technology: http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=31887.