Help:Formula
MozillaWiki Handbook
Software help for MozillaWiki — see page histories for older versions.
Handbook Contents | Other help
Contents
TeX
MediaWiki uses TeX markup for mathematical formulae. It generates either PNG images or simple HTML markup, depending on user preferences and the complexity of the expression. In the future, as more browsers are smarter, it will be able to generate enhanced HTML or even MathML in many cases.
Math markup goes inside <math> ... </math>. The edit toolbar has a button for this.
The PNG images are black on white (not transparent). These colors, as well as font sizes and types, are independent of browser settings or css. Font sizes and types will often deviate from what HTML renders. The css selector of the images is img.tex.
In the case of a non-white page background, the white background of the formula effectively highlights it, which can be an advantage or a disadvantage.
One may want to avoid using TeX markup as part of a line of regular text, as the formulae don't align properly and the font size, as said, usually does not match.
The alt attribute of the TeX images (the text that shows up in the hover box) is the wikitext that produced them, excluding the <math> and </math>.
Discussion, bug reports and feature requests should go to the Wikitech-l mailing list. These can also be filed on Mediazilla under MediaWiki extensions.
General
Spaces and newlines are ignored. Apart from function and operator names, as is customary in mathematics for variables, letters are in italics; digits are not. For other text, to avoid being rendered in italics like variables, use \mbox
: <math>\mbox{abc}</math>
gives <math>\mbox{abc}</math>
Line breaks help keep the wikitext clear, for instance, a line break after each term or matrix row.
Functions, symbols, special characters
For producing special characters without math tags, see Help:Special characters.
Comparison:
- α gives α, <math>\alpha</math> gives <math>\alpha</math> ("&" and ";" vs. "\", in this case the same code word "alpha"
- √2 gives √2, <math>\sqrt{2}</math> gives <math>\sqrt{2}</math> (the same difference as above, but also another code word, "radic" vs. "sqrt"; in TeX braces)
- √(1-e²) gives √(1-e²), <math>\sqrt{1-e^2}</math> gives <math>\sqrt{1-e^2}</math> (parentheses vs. braces, "''e''" vs. "e", "²" vs. "^2")
Feature | Syntax | How it looks rendered |
---|---|---|
std. functions (good) | \sin x + \ln y +\operatorname{sgn} z | <math>\sin x + \ln y +\operatorname{sgn} z</math> |
std. functions (wrong) | sin x + ln y + sgn z | <math>sin x + ln y + sgn z\,</math> |
Modular arithm. | s_k \equiv 0 \pmod{m} | <math>s_k \equiv 0 \pmod{m}</math> |
Derivatives | \nabla \partial x dx \dot x \ddot y | <math>\nabla \ \partial x \ dx \ \dot x\ \ddot y</math> |
Sets | \forall x \not\in \empty \varnothing \subseteq A \cap \bigcap B \cup \bigcup \exists \{x,y\} \times C | <math>\forall x \not\in \empty \varnothing \subseteq A \cap \bigcap B \cup \bigcup \exists \{x,y\} \times C</math> |
Logic | p \land \bar{q} \to p\lor \lnot q | <math>p \land \bar{q} \to p\lor \lnot q</math> |
Root | \sqrt{2}\approx 1.4 | <math>\sqrt{2}\approx 1.4</math> |
\sqrt[n]{x} | <math>\sqrt[n]{x}</math> | |
Relations | \sim \simeq \cong \le \ge \equiv \not\equiv \approx \ne \propto | <math> \sim \ \simeq \ \cong \ \le \ \ge \ \equiv \ \not\equiv \ \approx \ \ne \ \propto</math> |
Geometric | \triangle \angle \perp \| 45^\circ | <math>\triangle \ \angle \perp \| \ 45^\circ</math> |
Arrows |
\leftarrow \rightarrow \leftrightarrow |
<math>\leftarrow\ \rightarrow\ \leftrightarrow</math> <math>\longleftarrow\ \longrightarrow</math> <math>\mapsto\ \longmapsto</math> <math>\nearrow\ \searrow\ \swarrow\ \nwarrow</math> <math>\uparrow\ \downarrow\ \updownarrow</math> |
\Leftarrow \Rightarrow \Leftrightarrow |
<math>\Leftarrow\ \Rightarrow\ \Leftrightarrow</math> <math>\Longleftarrow\ \Longrightarrow\ \Longleftrightarrow</math> <math>\Uparrow\ \Downarrow\ \Updownarrow</math> |
|
Special | \oplus \otimes \pm \mp \hbar \wr \dagger \ddagger \star * \ldots \circ \cdot \times \bullet \infty \vdash \models | <math>\oplus \otimes \pm \mp \hbar \wr \dagger \ddagger \star * \ldots</math> <math>\circ \cdot \times \bullet\ \infty \ \vdash \ \models</math> |
Lowercase \mathcal has some extras | \mathcal {45abcdenpqstuvwx} | <math>\mathcal {45abcdenpqstuvwx}</math> |
Subscripts, superscripts, integrals
Feature | Syntax | How it looks rendered | |
---|---|---|---|
Superscript | a^2 | <math>a^2</math> | <math>a^2 \,\!</math> |
Subscript | a_2 | <math>a_2</math> | <math>a_2 \,\!</math> |
Grouping | a^{2+2} | <math>a^{2+2}</math> | <math>a^{2+2} \,\!</math> |
a_{i,j} | <math>a_{i,j}</math> | <math>a_{i,j} \,\!</math> | |
Combining sub & super | x_2^3 | <math>x_2^3</math> | |
Preceding sub & super | {}_1^2\!X_3^4 | <math>{}_1^2\!X_3^4</math> | |
Derivative (good) | x' | <math>x'</math> | <math>x' \,\!</math> |
Derivative (wrong in HTML) | x^\prime | <math>x^\prime</math> | <math>x^\prime \,\!</math> |
Derivative (wrong in PNG) | x\prime | <math>x\prime</math> | <math>x\prime \,\!</math> |
Derivative dots | \dot{x}, \ddot{x} | <math>\dot{x}, \ddot{x}</math> | |
Underlines & overlines | \hat a \bar b \vec c \widehat {d e f} \overline {g h i} \underline {j k l} | <math>\hat a \ \bar b \ \vec c \ \widehat {d e f} \ \overline {g h i} \ \underline {j k l}</math> | |
Sum | \sum_{k=1}^N k^2 | <math>\sum_{k=1}^N k^2</math> | |
Product | \prod_{i=1}^N x_i | <math>\prod_{i=1}^N x_i</math> | |
Limit | \lim_{n \to \infty}x_n | <math>\lim_{n \to \infty}x_n</math> | |
Integral | \int_{-N}^{N} e^x\, dx | <math>\int_{-N}^{N} e^x\, dx</math> | |
Path Integral | \oint_{C} x^3\, dx + 4y^2\, dy | <math>\oint_{C} x^3\, dx + 4y^2\, dy</math> |
Fractions, matrices, multilines
Feature | Syntax | How it looks rendered | ||||
---|---|---|---|---|---|---|
Fractions | \frac{2}{4} or {2 \over 4} | <math>\frac{2}{4}</math> | ||||
Binomial coefficients | {n \choose k} | <math>{n \choose k}</math> | ||||
Small Fractions | \begin{matrix} \frac{2}{4} \end{matrix} | <math>\begin{matrix} \frac{2}{4} \end{matrix}</math> | ||||
Matrices | \begin{matrix} x & y \\ z & v \end{matrix} | <math>\begin{matrix} x & y \\ z & v \end{matrix}</math> | ||||
\begin{vmatrix} x & y \\ z & v \end{vmatrix} | <math>\begin{vmatrix} x & y \\ z & v \end{vmatrix}</math> | |||||
\begin{Vmatrix} x & y \\ z & v \end{Vmatrix} | <math>\begin{Vmatrix} x & y \\ z & v \end{Vmatrix}</math> | |||||
\begin{bmatrix} 0 & \cdots & 0 \\ \vdots &
\ddots & \vdots \\ 0 & \cdots & 0\end{bmatrix} |
<math>\begin{bmatrix} 0 & \cdots & 0 \\ \vdots
& \ddots & \vdots \\ 0 & \cdots & 0\end{bmatrix} </math> |
|||||
\begin{Bmatrix} x & y \\ z & v \end{Bmatrix} | <math>\begin{Bmatrix} x & y \\ z & v \end{Bmatrix}</math> | |||||
\begin{pmatrix} x & y \\ z & v \end{pmatrix} | <math>\begin{pmatrix} x & y \\ z & v \end{pmatrix}</math> | |||||
Case distinctions | f(n) = \begin{cases} n/2, & \mbox{if }n\mbox{ is even} \\ 3n+1, & \mbox{if }n\mbox{ is odd} \end{cases} | <math>f(n) = \begin{cases} n/2, & \mbox{if }n\mbox{ is even} \\ 3n+1, & \mbox{if }n\mbox{ is odd} \end{cases} </math> | ||||
Multiline equations | \begin{matrix}f(n+1) & = & (n+1)^2 \\ \ & = & n^2 + 2n + 1 \end{matrix} | <math>\begin{matrix}f(n+1) & = & (n+1)^2 \\ \ & = & n^2 + 2n + 1 \end{matrix}</math> | ||||
Alternative multiline equations (using tables) | {| |- |<math>f(n+1)</math> |<math>=(n+1)^2</math> |- | |<math>=n^2 + 2n + 1</math> |} |
|
Fonts
Feature | Syntax | How it looks rendered | |
---|---|---|---|
Greek letters | \alpha \beta \gamma \Gamma \phi \Phi \Psi\ \tau \Omega | <math>\alpha\ \beta\ \gamma\ \Gamma\ \phi\ \Phi\ \Psi\ \tau\ \Omega</math> | |
Blackboard bold | x\in\mathbb{R}\sub\mathbb{C} | <math>x\in\mathbb{R}\subset\mathbb{C}</math> | |
boldface (vectors) | \mathbf{x}\cdot\mathbf{y} = 0 | <math>\mathbf{x}\cdot\mathbf{y} = 0</math> | |
boldface (greek) | \boldsymbol{\alpha} + \boldsymbol{\beta} + \boldsymbol{\gamma} | <math>\boldsymbol{\alpha} + \boldsymbol{\beta} + \boldsymbol{\gamma}</math> | |
Fraktur typeface | \mathfrak{a} \mathfrak{B} | <math>\mathfrak{a} \mathfrak{B}</math> | |
Script | \mathcal{ABC} | <math>\mathcal{ABC}</math> | |
Hebrew | \aleph \beth \gimel \daleth | <math>\aleph\ \beth\ \gimel\ \daleth</math> | |
non-italicised characters | \mbox{abc} | <math>\mbox{abc}</math> | <math>\mbox{abc} \,\!</math> |
mixed italics (bad) | \mbox{if} n \mbox{is even} | <math>\mbox{if} n \mbox{is even}</math> | <math>\mbox{if} n \mbox{is even} \,\!</math> |
mixed italics (good) | \mbox{if }n\mbox{ is even} | <math>\mbox{if }n\mbox{ is even}</math> | <math>\mbox{if }n\mbox{ is even} \,\!</math> |
Parenthesizing big expressions, brackets, bars
Feature | Syntax | How it looks rendered |
---|---|---|
Not good | ( \frac{1}{2} ) | <math>( \frac{1}{2} )</math> |
Better | \left ( \frac{1}{2} \right ) | <math>\left ( \frac{1}{2} \right )</math> |
You can use various delimiters with \left and \right:
Feature | Syntax | How it looks rendered |
---|---|---|
Parentheses | \left ( A \right ) | <math>\left ( A \right )</math> |
Brackets | \left [ A \right ] | <math>\left [ A \right ]</math> |
Braces | \left \{ A \right \} | <math>\left \{ A \right \}</math> |
Angle brackets | \left \langle A \right \rangle | <math>\left \langle A \right \rangle</math> |
Bars and double bars | \left | A \right | and \left \| B \right \| | <math>\left | A \right | and \left \| B \right \|</math> |
Delimiters can be mixed, |
\left [ 0,1 \right ) |
<math>\left [ 0,1 \right )</math> |
Use \left. and \right. if you don't want a delimiter to appear: |
\left . \frac{A}{B} \right \} \to X | <math>\left . \frac{A}{B} \right \} \to X</math> |
Floor and ceiling functions: | \lfloor x \rfloor = \lceil y \rceil | <math>\lfloor x \rfloor = \lceil y \rceil</math> |
Spacing
Note that TeX handles most spacing automatically, but you may sometimes want manual control.
Feature | Syntax | How it looks rendered |
---|---|---|
double quad space | a \qquad b | <math>a \qquad b</math> |
quad space | a \quad b | <math>a \quad b</math> |
text space | a\ b | <math>a\ b</math> |
text space without PNG conversion | a \mbox{ } b | <math>a \mbox{ } b</math> |
large space | a\;b | <math>a\;b</math> |
medium space | a\>b | [not supported] |
small space | a\,b | <math>a\,b</math> |
no space | ab | <math>ab\,</math> |
negative space | a\!b | <math>a\!b</math> |
Align with normal text flow
Due to the default css
img.tex { vertical-align: middle; }
an inline expression like <math>\int_{-N}^{N} e^x\, dx</math> should look good.
Forced PNG rendering
To force the formula to render as PNG, add \, (small space) at the end of the formula (where it is not rendered). This will force PNG if the user is in "HTML if simple" mode, but not for "HTML if possible" mode (math rendering settings in preferences).
You can also use \,\! (small space and negative space, which cancel out) anywhere inside the math tags. This does force PNG even in "HTML if possible" mode, unlike \,.
This could be useful to keep the rendering of formulae in a proof consistent, for example, or to fix formulae that render incorrectly in HTML (at one time, a^{2+2} rendered with an extra underscore), or to demonstrate how something is rendered when it would normally show up as HTML (as in the examples above).
For instance:
Syntax | How it looks rendered |
---|---|
a^{c+2} | <math>a^{c+2}</math> |
a^{c+2} \, | <math>a^{c+2} \,</math> |
a^{\,\!c+2} | <math>a^{\,\!c+2}</math> |
a^{b^{c+2}} | <math>a^{b^{c+2}}</math> (WRONG with option "HTML if possible or else PNG"!) |
a^{b^{c+2}} \, | <math>a^{b^{c+2}} \,</math> (WRONG with option "HTML if possible or else PNG"!) |
a^{b^{c+2}}\approx 5 | <math>a^{b^{c+2}}\approx 5</math> (due to "<math>\approx</math>" correctly displayed, no code "\,\!" needed) |
a^{b^{\,\!c+2}} | <math>a^{b^{\,\!c+2}}</math> |
\int_{-N}^{N} e^x\, dx | <math>\int_{-N}^{N} e^x\, dx</math> |
\int_{-N}^{N} e^x\, dx \, | <math>\int_{-N}^{N} e^x\, dx \,</math> |
\int_{-N}^{N} e^x\, dx \,\! | <math>\int_{-N}^{N} e^x\, dx \,\!</math> |
This has been tested with most of the formulae on this page, and seems to work perfectly.
You might want to include a comment in the HTML so people don't "correct" the formula by removing it:
- <!-- The \,\! is to keep the formula rendered as PNG instead of HTML. Please don't remove it.-->
Examples
<math>\frac{2}{3-x} = \frac{3}{2-x}</math>
<math>\left(3-x\right) \times \left( \frac{2}{3-x} \right) = \left(3-x\right) \times \left( \frac{3}{2-x} \right)</math>
<math>2 = \left(3-x\right) \times \left( \frac{3}{2-x} \right)</math>
<math>2 = \left( \frac{\left(3-x\right) \times 3}{2-x} \right)</math>
<math>2 = \left( \frac{9-3x}{2-x} \right)</math>
<math>2 \times \left(2-x\right) = \left(2-x\right) \times \left( \frac{9-3x}{2-x} \right)</math>
<math>2 \times \left(2-x\right) = \frac{\left(2-x\right) \times \left(9-3x\right)}{2-x}</math>
<math>2 \times \left(2-x\right) = 9-3x \!</math>
<math>4-2x = 9-3x \!</math>
<math>-2x+3x = 9-4 \!</math>
<math>x = 5 \!</math>
See also
- Proposed GNU LilyPond support
External Links
- A LaTeX tutorial. http://www.maths.tcd.ie/~dwilkins/LaTeXPrimer/
- A PDF document introducing TeX -- see page 39 onwards for a good introduction to the maths side of things: http://www.ctan.org/tex-archive/info/gentle/gentle.pdf
- A PDF document introducing LaTeX -- skip to page 59 for the math section. See page 72 for a complete reference list of symbols included in LaTeX and AMS-LaTeX. http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf
- TeX reference card: http://www.csit.fsu.edu/~mimi/tex/tex-refcard-letter.pdf
- Can't remember but I put it here so it must be ok ;-) http://www.ams.org/tex/amslatex.html
- A set of public domain fixed-size math symbol bitmaps: http://us.metamath.org/symbols/symbols.html
Help contents Reading:
Go |
Search |
URL |
Namespace |
Page name |
Section |
Link |
Backlinks |
Piped link |
Interwiki link |
Redirect |
Variable |
Category
|