# Help:Formula

Help index - Other languages: de, fi fr, Magyarul (Hungarian), ia, ja, sv, zh, ru

## 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 $...$. Line breaks within these tags are fine, and aren't rendered. They're a good idea to keep the raw markup clear (for instance, a line break after each term or row of a matrix).

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 $and$.

Discussion, bug reports and feature requests should go to the Wikitech-l mailing list.

## Special characters

Feature Syntax How it looks rendered
std. functions (good) \sin x + \ln y +\operatorname{sgn} z $\sin x + \ln y +\operatorname{sgn} z$
std. functions (wrong) sin x + ln y + sgn z $sin x + ln y + sgn z\,$
Modular arithm. s_k \equiv 0 \pmod{m} $s_k \equiv 0 \pmod{m}$
Derivatives \nabla \partial x dx \dot x \ddot y $\nabla \ \partial x \ dx \ \dot x\ \ddot y$
Sets \forall x \not\in \varnothing \subseteq A \cap B \cup \exists \{x,y\} \times C $\forall x \not\in \varnothing \subseteq A \cap B \cup \exists \{x,y\} \times C$
Logic p \land \bar{q} \to p\lor \lnot q $p \land \bar{q} \to p\lor \lnot q$
Root \sqrt{2}\approx 1.4 $\sqrt{2}\approx 1.4$
\sqrt[n]{x} $\sqrt[n]{x}$
Relations \sim \simeq \cong \le \ge \equiv \not\equiv \approx \ne $\sim \ \simeq \ \cong \ \le \ \ge \ \equiv \ \not\equiv \ \approx \ \ne$
Geometric \triangle \angle \perp \| 45^\circ $\triangle \ \angle \perp \| \ 45^\circ$
Arrows

\leftarrow \rightarrow \leftrightarrow
\longleftarrow \longrightarrow
\mapsto \longmapsto
\nearrow \searrow \swarrow \nwarrow
\uparrow \downarrow \updownarrow

$\leftarrow\ \rightarrow\ \leftrightarrow$ $\longleftarrow\ \longrightarrow$ $\mapsto\ \longmapsto$ $\nearrow\ \searrow\ \swarrow\ \nwarrow$ $\uparrow\ \downarrow\ \updownarrow$

\Leftarrow \Rightarrow \Leftrightarrow
\Longleftarrow \Longrightarrow \Longleftrightarrow
\Uparrow \Downarrow \Updownarrow

$\Leftarrow\ \Rightarrow\ \Leftrightarrow$ $\Longleftarrow\ \Longrightarrow\ \Longleftrightarrow$ $\Uparrow\ \Downarrow\ \Updownarrow$

Special \oplus \otimes \pm \mp \hbar \dagger \ddagger \star * \ldots \circ \cdot \times \bullet \infty \vdash \models $\oplus \otimes \pm \mp \hbar \dagger \ddagger \star * \ldots$ $\circ \cdot \times \bullet\ \infty \ \vdash \ \models$

## Subscripts, superscripts

Feature Syntax How it looks rendered
Superscript a^2 $a^2$ $a^2 \,\!$
Subscript a_2 $a_2$ $a_2 \,\!$
Grouping a^{2+2} $a^{2+2}$ $a^{2+2} \,\!$
a_{i,j} $a_{i,j}$ $a_{i,j} \,\!$
Combining sub & super x_2^3 $x_2^3$
Derivative (good) x' $x'$ $x' \,\!$
Derivative (wrong in HTML) x^\prime $x^\prime$ $x^\prime \,\!$
Derivative (wrong in PNG) x\prime $x\prime$ $x\prime \,\!$
Derivative dots \dot{x}, \ddot{x} $\dot{x}, \ddot{x}$
Underlines & overlines \hat a \bar b \vec c \widehat {d e f} \overline {g h i} \underline {j k l} $\hat a \ \bar b \ \vec c \ \widehat {d e f} \ \overline {g h i} \ \underline {j k l}$
Sum \sum_{k=1}^N k^2 $\sum_{k=1}^N k^2$
Product \prod_{i=1}^N x_i $\prod_{i=1}^N x_i$
Limit \lim_{n \to \infty}x_n $\lim_{n \to \infty}x_n$
Integral \int_{-N}^{N} e^x\, dx $\int_{-N}^{N} e^x\, dx$
Line Integral \oint_{C} x^3\, dx + 4y^2\, dy $\oint_{C} x^3\, dx + 4y^2\, dy$

## Fractions, matrices, multilines

Feature Syntax How it looks rendered
Fractions \frac{2}{4} or {2 \over 4} $\frac{2}{4}$
Binomial coefficients {n \choose k} ${n \choose k}$
Small Fractions \begin{matrix} \frac{2}{4} \end{matrix} $\begin{matrix} \frac{2}{4} \end{matrix}$
Matrices \begin{matrix} x & y \\ z & v \end{matrix} $\begin{matrix} x & y \\ z & v \end{matrix}$
\begin{vmatrix} x & y \\ z & v \end{vmatrix} $\begin{vmatrix} x & y \\ z & v \end{vmatrix}$
\begin{Vmatrix} x & y \\ z & v \end{Vmatrix} $\begin{Vmatrix} x & y \\ z & v \end{Vmatrix}$
\begin{bmatrix} 0 & \cdots & 0 \\ \vdots &

\ddots & \vdots \\ 0 & \cdots &

0\end{bmatrix}
$\begin{bmatrix} 0 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ 0 & \cdots & 0\end{bmatrix}$
\begin{Bmatrix} x & y \\ z & v \end{Bmatrix} $\begin{Bmatrix} x & y \\ z & v \end{Bmatrix}$
\begin{pmatrix} x & y \\ z & v \end{pmatrix} $\begin{pmatrix} x & y \\ z & v \end{pmatrix}$
Case distinctions f(n) = \begin{cases} n/2, & \mbox{if }n\mbox{ is even} \\ 3n+1, & \mbox{if }n\mbox{ is odd} \end{cases} $f(n) = \begin{cases} n/2, & \mbox{if }n\mbox{ is even} \\ 3n+1, & \mbox{if }n\mbox{ is odd} \end{cases}$
Multiline equations \begin{matrix}f(n+1) & = & (n+1)^2 \\ \ & = & n^2 + 2n + 1 \end{matrix} $\begin{matrix}f(n+1) & = & (n+1)^2 \\ \ & = & n^2 + 2n + 1 \end{matrix}$
Alternative multiline equations (using tables)

{|
|-
|$f(n+1)$
|$=(n+1)^2$
|-
|
|$=n^2 + 2n + 1$
|}


 $f(n+1) \,\!$ $=(n+1)^2 \,\!$ $=n^2 + 2n + 1 \,\!$

## Fonts

Feature Syntax How it looks rendered
Greek letters \alpha \beta \gamma \Gamma \phi \Phi \Psi\ \tau \Omega $\alpha\ \beta\ \gamma\ \Gamma\ \phi\ \Phi\ \Psi\ \tau\ \Omega$
Blackboard bold x\in\mathbb{R}\sub\mathbb{C} $x\in\mathbb{R}\subset\mathbb{C}$
boldface (vectors) \mathbf{x}\cdot\mathbf{y} = 0 $\mathbf{x}\cdot\mathbf{y} = 0$
boldface (greek) \boldsymbol{\alpha} + \boldsymbol{\beta} + \boldsymbol{\gamma} $\boldsymbol{\alpha} + \boldsymbol{\beta} + \boldsymbol{\gamma}$
Fraktur typeface \mathfrak{a} \mathfrak{B} $\mathfrak{a} \mathfrak{B}$
Script \mathcal{ABC} $\mathcal{ABC}$
Hebrew \aleph \beth \gimel \daleth $\aleph\ \beth\ \gimel\ \daleth$
non-italicised characters \mbox{abc} $\mbox{abc}$ $\mbox{abc} \,\!$
mixed italics (bad) \mbox{if} n \mbox{is even} $\mbox{if} n \mbox{is even}$ $\mbox{if} n \mbox{is even} \,\!$
mixed italics (good) \mbox{if }n\mbox{ is even} $\mbox{if }n\mbox{ is even}$ $\mbox{if }n\mbox{ is even} \,\!$

## Parenthesizing big expressions

Feature Syntax How it looks rendered
Not good ( \frac{1}{2} ) $( \frac{1}{2} )$
Better \left ( \frac{1}{2} \right ) $\left ( \frac{1}{2} \right )$

You can use various delimiters with \left and \right:

Feature Syntax How it looks rendered
Parentheses \left ( A \right ) $\left ( A \right )$
Brackets \left [ A \right ] $\left [ A \right ]$
Braces \left \{ A \right \} $\left \{ A \right \}$
Angle brackets \left \langle A \right \rangle $\left \langle A \right \rangle$
Bars and double bars \left | A \right | and \left \| B \right \| $\left | A \right | and \left \| B \right \|$

Delimiters can be mixed,
as long as \left and \right match

\left [ 0,1 \right )
\left \langle \psi \right |

$\left [ 0,1 \right )$
$\left \langle \psi \right |$

Use \left. and \right. if you don't
want a delimiter to appear:
\left . \frac{A}{B} \right \} \to X $\left . \frac{A}{B} \right \} \to X$

## 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 $a \qquad b$
quad space a \quad b $a \quad b$
text space a\ b $a\ b$
text space without PNG conversion a \mbox{ } b $a \mbox{ } b$
large space a\;b $a\;b$
medium space a\>b [not supported]
small space a\,b $a\,b$
no space ab $ab\,$
negative space a\!b $a\!b$

## Align with normal text flow

If you desperately need to insert an equation like
$\int_{-N}^{N} e^x\, dx$
in the normal text flow, you can use a HTML <div> tag for vertical alignment:
<div style="vertical-align:-100%;display:inline;">$...$</div>

## Forced PNG rendering

If you must, it is possible to force the formula to render as PNG, without affecting the display of the formula, by adding \, (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 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^{2+2} $a^{2+2}$
a^{2+2} \, $a^{2+2} \,$
a^{\,\!2+2} $a^{\,\!2+2}$
\int_{-N}^{N} e^x\, dx $\int_{-N}^{N} e^x\, dx$
\int_{-N}^{N} e^x\, dx \, $\int_{-N}^{N} e^x\, dx \,$
\int_{-N}^{N} e^x\, dx \,\! $\int_{-N}^{N} e^x\, dx \,\!$

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

$\frac{2}{3-x} = \frac{3}{2-x}$

$\left(3-x\right) \times \left( \frac{2}{3-x} \right) = \left(3-x\right) \times \left( \frac{3}{2-x} \right)$

$2 = \left(3-x\right) \times \left( \frac{3}{2-x} \right)$

$2 = \left( \frac{\left(3-x\right) \times 3}{2-x} \right)$

$2 = \left( \frac{9-3x}{2-x} \right)$

$2 \times \left(2-x\right) = \left(2-x\right) \times \left( \frac{9-3x}{2-x} \right)$

$2 \times \left(2-x\right) = \frac{\left(2-x\right) \times \left(9-3x\right)}{2-x}$

$2 \times \left(2-x\right) = 9-3x \!$

$4-2x = 9-3x \!$

$-2x+3x = 9-4 \!$

$x = 5 \!$