Help:Formula MediaWiki and LaTeX

From WikiWaves
Jump to navigationJump to search

This page is taken from Wikimedia Help:Formula

MediaWiki and TeX

MediaWiki uses a subset of TeX markup, including some extensions from LaTeX and AMSLaTeX, 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. (See blahtex for information about current work on adding MathML support.)

More precisely, MediaWiki filters the markup through Texvc, which in turn passes the commands to TeX for the actual rendering. Thus, only a limited part of the full TeX language is supported; see below for details.

Syntax

Math markup goes inside <math> ... </math>. The edit toolbar has a button for this.

Similarly to HTML, in TeX extra spaces and newlines are ignored.

MediaWiki templates, variables and parameters cannot be used within math tags, see m:Template talk:Demo of attempt to use parameters within TeX.

Rendering

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. Vertical alignment with the surrounding text can also be a problem. The css selector of the images is img.tex.

It should be pointed out that most of these shortcomings have been addressed by Maynard Handley, but have not been released yet.

The alt attribute of the PNG images (the text that is displayed if your browser can't display images; Internet Explorer shows it up in the hover box) is the wikitext that produced them, excluding the <math> and </math>.

Apart from function and operator names, as is customary in mathematics for variables, letters are in italics; digits are not. For other text, (like variable labels) to avoid being rendered in italics like variables, use \mbox or \mathrm. For example, <math>\mbox{abc}</math> gives [math]\displaystyle{ \mbox{abc} }[/math].

TeX vs HTML

Before introducing TeX markup for producing special characters, it should be noted that, as this comparison table shows, sometimes similar results can be achieved in HTML (see Help:Special characters).

TeX Syntax (forcing PNG) TeX Rendering HTML Syntax HTML Rendering
<math>\alpha\,</math> [math]\displaystyle{ \alpha\, }[/math] &alpha; α
<math>\sqrt{2}</math> [math]\displaystyle{ \sqrt{2} }[/math] &radic;2 √2
<math>\sqrt{1-e^2}</math> [math]\displaystyle{ \sqrt{1-e^2} }[/math] &radic;(1&minus;''e''&sup2;) √(1−e²)

The use of HTML instead of TeX is still under discussion. The arguments either way can be summarised as follows.

Pros of HTML

  1. In-line HTML formulae always align properly with the rest of the HTML text.
  2. The formula's background, font size and face match the rest of HTML contents and the appearance respects CSS and browser settings.

Pros of TeX

  1. TeX is semantically superior to HTML. In TeX, "<math>x</math>" means "mathematical variable [math]\displaystyle{ x }[/math]", whereas in HTML "x" could mean anything. Information has been irrevocably lost.
  2. TeX has been specifically designed for typesetting formulae, so input is easier and more natural, and output is more aesthetically pleasing. Also anybody who has written mathematics at a professional level is already familiar with TeX.
  3. One consequence of point 1 is that TeX can be transformed in HTML, but not vice-versa. This means that on the server side we can always transform a formula, based on its complexity and location within the text, user preferences, type of browser, etc. Therefore, where possible, all the benefits of HTML can be retained, together with the benefits of TeX. It's true that the current situation is not ideal, but that's not a good reason to drop information/contents. It's more a reason to help improve the situation.
  4. When writing in TeX, editors need not worry about whether this or that version of this or that browser supports this or that HTML entity. The burden of these decisions is put on the server. This doesn't hold for HTML formulae, which can easily end up being rendered wrongly or differently from the editor's intentions on a different browser.

Functions, symbols, special characters

Feature Syntax How it looks rendered
Accents/Diacritics
\acute{a} \quad \grave{a} \quad \hat{a}
\tilde{a} \quad \breve{a} \quad \check{a} \quad \bar{a}
\ddot{a} \quad \dot{a}
[math]\displaystyle{ \acute{a} \quad \grave{a} \quad \hat{a} }[/math]

[math]\displaystyle{ \tilde{a} \quad \breve{a} \quad \check{a} \quad \bar{a} }[/math]
[math]\displaystyle{ \ddot{a} \quad \dot{a} }[/math]

Std. functions (good)
\sin a \ \cos b \ \tan c \ \cot d
\sec e \ \csc f
\arcsin k \ \arccos l \ \arctan m
\sinh g \ \cosh h \ \tanh i \ \coth j
\operatorname{sh}\,g \ \operatorname{argsh}\,k
\operatorname{ch}\,h \ \operatorname{argch}\,l
\operatorname{th}\,i \ \operatorname{argth}\,m
\lim n \ \limsup o \ \liminf p
\min q \ \max r \ \inf s \ \sup t
\exp u \ \ln v \ \lg w \ \log x \ \log_{10} y
\ker x \ \deg x \ \gcd x \ \Pr x
\det x \ \hom x \ \arg x \ \dim x
[math]\displaystyle{ \sin a \ \cos b \ \tan c \ \cot d }[/math]

[math]\displaystyle{ \sec e \ \csc f }[/math]
[math]\displaystyle{ \arcsin k \ \arccos l \ \arctan m }[/math]
[math]\displaystyle{ \sinh g \ \cosh h \ \tanh i \ \coth j }[/math]
[math]\displaystyle{ \operatorname{sh}\,g \ \operatorname{argsh}\,k }[/math]
[math]\displaystyle{ \operatorname{ch}\,h \ \operatorname{argch}\,l }[/math]
[math]\displaystyle{ \operatorname{th}\,i \ \operatorname{argth}\,m }[/math]
[math]\displaystyle{ \lim n \ \limsup o \ \liminf p }[/math]
[math]\displaystyle{ \min q \ \max r \ \inf s \ \sup t }[/math]
[math]\displaystyle{ \exp u \ \ln v \ \lg w \ \log x \ \log_{10} y }[/math]
[math]\displaystyle{ \ker x \ \deg x \ \gcd x \ \Pr x }[/math]
[math]\displaystyle{ \det x \ \hom x \ \arg x \ \dim x }[/math]

Std. functions (wrong)
sin x + ln y + sgn z
[math]\displaystyle{ sin x + ln y + sgn z\,\! }[/math]
Modular arithmetic
s_k \equiv 0 \pmod{m}
a \bmod b
[math]\displaystyle{ s_k \equiv 0 \pmod{m} }[/math]

[math]\displaystyle{ a \bmod b\,\! }[/math]

Derivatives
\nabla \; \partial x \; dx \; \dot x \; \ddot y
[math]\displaystyle{ \nabla \; \partial x \; dx \; \dot x \; \ddot y }[/math]
Sets

(Square symbols may not work for some wikis)

\forall \; \exists \; \empty \; \emptyset \; \varnothing
\in \ni \not\in \notin \subset \subseteq
\supset \supseteq \cap \bigcap \cup \bigcup \biguplus
[math]\displaystyle{ \forall \; \exists \; \empty \; \emptyset \; \varnothing }[/math]

[math]\displaystyle{ \in \ni \not\in \notin \subset \subseteq }[/math]
[math]\displaystyle{ \supset \supseteq \cap \bigcap \cup \bigcup \biguplus }[/math]

\sqsubset \sqsubseteq \sqsupset \sqsupseteq
\sqcap \sqcup \bigsqcup
[math]\displaystyle{ \sqsubset \sqsubseteq \sqsupset \sqsupseteq }[/math]

[math]\displaystyle{ \sqcap \sqcup \bigsqcup }[/math]

Logic
p \land \wedge \; \bigwedge \; \bar{q} \to p
\lor \; \vee \; \bigvee \; \lnot \; \neg q
\setminus \; \smallsetminus
[math]\displaystyle{ p \land \wedge \; \bigwedge \; \bar{q} \to p }[/math]

[math]\displaystyle{ \lor \; \vee \; \bigvee \; \lnot \; \neg q }[/math]
[math]\displaystyle{ \setminus \; \smallsetminus }[/math]

Root
\sqrt{2}\approx 1.4
[math]\displaystyle{ \sqrt{2}\approx 1.4 }[/math]
\sqrt[n]{x}
[math]\displaystyle{ \sqrt[n]{x} }[/math]
Relations
\sim \; \approx \; \simeq \; \cong \; \dot=
\le \; < \; \ll \; \gg \; \ge >
\equiv \; \not\equiv \; \ne \mbox{or} \neq \; \propto
\pm \; \mp
[math]\displaystyle{ \sim \; \approx \; \simeq \; \cong \; \dot= }[/math]

[math]\displaystyle{ \le \; \lt \; \ll \; \gg \; \ge \; \gt }[/math]
[math]\displaystyle{ \equiv \; \not\equiv \; \ne \mbox{or} \neq \; \propto }[/math]
[math]\displaystyle{ \pm \; \mp }[/math]

Geometric
\Diamond \; \Box \; \triangle \; \angle \; \perp
\; \mid \; \nmid \; \| \; 45^\circ
[math]\displaystyle{ \Diamond \; \Box \; \triangle \; \angle \; \perp \; \mid \; \nmid \; \| \; 45^\circ }[/math]
Arrows

(Harpoons may not work for some wikis)

\leftarrow \; \gets \; \rightarrow \; \to
\leftrightarrow \; \longleftarrow \; \longrightarrow
\mapsto \; \longmapsto
\hookrightarrow \; \hookleftarrow
\nearrow \; \searrow \; \swarrow \; \nwarrow
\uparrow \; \downarrow \; \updownarrow
[math]\displaystyle{ \leftarrow \; \gets \; \rightarrow \; \to }[/math]

[math]\displaystyle{ \leftrightarrow \; \longleftarrow \; \longrightarrow }[/math]
[math]\displaystyle{ \mapsto \; \longmapsto }[/math]
[math]\displaystyle{ \hookrightarrow \; \hookleftarrow }[/math]
[math]\displaystyle{ \nearrow \; \searrow \; \swarrow \; \nwarrow }[/math]
[math]\displaystyle{ \uparrow \; \downarrow \; \updownarrow }[/math]

\rightharpoonup \; \rightharpoondown 
\; \leftharpoonup \; \leftharpoondown 
\; \upharpoonleft \; \upharpoonright 
\; \downharpoonleft \; \downharpoonright
[math]\displaystyle{ \rightharpoonup \; \rightharpoondown \; \leftharpoonup \; \leftharpoondown \; \upharpoonleft \; \upharpoonright \; \downharpoonleft \; \downharpoonright }[/math]
\Leftarrow \; \Rightarrow \; \Leftrightarrow
\Longleftarrow \; \Longrightarrow
\Longleftrightarrow (or \iff)
\Uparrow \; \Downarrow \; \Updownarrow
[math]\displaystyle{ \Leftarrow \; \Rightarrow \; \Leftrightarrow }[/math]

[math]\displaystyle{ \Longleftarrow \; \Longrightarrow }[/math]
[math]\displaystyle{ \Longleftrightarrow (or \iff) }[/math]
[math]\displaystyle{ \Uparrow \; \Downarrow \; \Updownarrow }[/math]

Special
\eth \; \S \; \P \; \% \; \dagger \; \ddagger
\star \; * \; \ldots \smile \frown \wr
[math]\displaystyle{ \eth \; \S \; \P \; \% \; \dagger \; \ddagger }[/math]

[math]\displaystyle{ \star \; * \; \ldots \; \smile \frown \wr }[/math]

\oplus \bigoplus \otimes \bigotimes
\times \cdot \circ \bullet \bigodot
[math]\displaystyle{ \oplus \bigoplus \otimes \bigotimes }[/math]

[math]\displaystyle{ \times \cdot \circ \bullet \bigodot }[/math]

\triangleleft \triangleright \infty \bot \top
\vdash \vDash \Vdash \models \lVert \rVert
[math]\displaystyle{ \triangleleft \triangleright \infty \bot \top }[/math]

[math]\displaystyle{ \vdash \vDash \Vdash \models \lVert \rVert }[/math]

\imath \; \hbar \; \ell \; \mho \; \Finv
\Re \; \Im \; \wp \; \complement
[math]\displaystyle{ \imath \; \hbar \; \ell \; \mho \; \Finv }[/math]

[math]\displaystyle{ \Re \; \Im \; \wp \; \complement }[/math]

\diamondsuit \; \heartsuit \; \clubsuit \; \spadesuit
\Game \; \flat \; \natural \; \sharp
[math]\displaystyle{ \diamondsuit \; \heartsuit \; \clubsuit \; \spadesuit }[/math]

[math]\displaystyle{ \Game \; \flat \; \natural \; \sharp }[/math]

Lowercase \mathcal has some extras
\mathcal{5} \; \mathcal{abcde \; pqs}
[math]\displaystyle{ \mathcal{5} \; \mathcal{abcde \; pqs} }[/math]

Subscripts, superscripts, integrals

Feature Syntax How it looks rendered
HTML PNG
Superscript
a^2
[math]\displaystyle{ a^2 }[/math] [math]\displaystyle{ a^2 \,\! }[/math]
Subscript
a_2
[math]\displaystyle{ a_2 }[/math] [math]\displaystyle{ a_2 \,\! }[/math]
Grouping
a^{2+2}
[math]\displaystyle{ a^{2+2} }[/math] [math]\displaystyle{ a^{2+2}\,\! }[/math]
a_{i,j}
[math]\displaystyle{ a_{i,j} }[/math] [math]\displaystyle{ a_{i,j}\,\! }[/math]
Combining sub & super
x_2^3
[math]\displaystyle{ x_2^3 }[/math]
Preceding sub & super
{}_1^2\!X_3^4
[math]\displaystyle{ {}_1^2\!X_3^4 }[/math]
Derivative (forced PNG)
x', y'', f', f''\!
  [math]\displaystyle{ x', y'', f', f''\! }[/math]
Derivative (f in italics may overlap primes in HTML)
x', y'', f', f''
[math]\displaystyle{ x', y'', f', f'' }[/math] [math]\displaystyle{ x', y'', f', f''\! }[/math]
Derivative (wrong in HTML)
x^\prime, y^{\prime\prime}
[math]\displaystyle{ x^\prime, y^{\prime\prime} }[/math] [math]\displaystyle{ x^\prime, y^{\prime\prime}\,\! }[/math]
Derivative (wrong in PNG)
x\prime, y\prime\prime
[math]\displaystyle{ x\prime, y\prime\prime }[/math] [math]\displaystyle{ x\prime, y\prime\prime\,\! }[/math]
Derivative dots
\dot{x}, \ddot{x}
[math]\displaystyle{ \dot{x}, \ddot{x} }[/math]
Underlines, overlines, vectors
\hat a \ \bar b \ \vec c
[math]\displaystyle{ \hat a \ \bar b \ \vec c }[/math]
\overrightarrow{a b} \ \overleftarrow{c d} \ \widehat{d e f}
[math]\displaystyle{ \overrightarrow{a b} \ \overleftarrow{c d} \ \widehat{d e f} }[/math]
\overline{g h i} \ \underline{j k l}
[math]\displaystyle{ \overline{g h i} \ \underline{j k l} }[/math]
Overbraces
\begin{matrix} 5050 \ \overbrace{ 1+2+\cdots+100 } \end{matrix}
[math]\displaystyle{ \begin{matrix} 5050 \ \overbrace{ 1+2+\cdots+100 } \end{matrix} }[/math]
Underbraces
\begin{matrix} \underbrace{ a+b+\cdots+z } \ 26 \end{matrix}
[math]\displaystyle{ \begin{matrix} \underbrace{ a+b+\cdots+z } \ 26 \end{matrix} }[/math]
Sum
\sum_{k=1}^N k^2
[math]\displaystyle{ \sum_{k=1}^N k^2 }[/math]
Sum (force \textstyle)
\begin{matrix} \sum_{k=1}^N k^2 \end{matrix}
[math]\displaystyle{ \begin{matrix} \sum_{k=1}^N k^2 \end{matrix} }[/math]
Product
\prod_{i=1}^N x_i
[math]\displaystyle{ \prod_{i=1}^N x_i }[/math]
Product (force \textstyle)
\begin{matrix} \prod_{i=1}^N x_i \end{matrix}
[math]\displaystyle{ \begin{matrix} \prod_{i=1}^N x_i \end{matrix} }[/math]
Coproduct
\coprod_{i=1}^N x_i
[math]\displaystyle{ \coprod_{i=1}^N x_i }[/math]
Coproduct (force \textstyle)
\begin{matrix} \coprod_{i=1}^N x_i \end{matrix}
[math]\displaystyle{ \begin{matrix} \coprod_{i=1}^N x_i \end{matrix} }[/math]
Limit
\lim_{n \to \infty}x_n
[math]\displaystyle{ \lim_{n \to \infty}x_n }[/math]
Limit (force \textstyle)
\begin{matrix} \lim_{n \to \infty}x_n \end{matrix}
[math]\displaystyle{ \begin{matrix} \lim_{n \to \infty}x_n \end{matrix} }[/math]
Integral
\int_{-N}^{N} e^x\, dx
[math]\displaystyle{ \int_{-N}^{N} e^x\, dx }[/math]
Integral (force \textstyle)
\begin{matrix} \int_{-N}^{N} e^x\, dx \end{matrix}
[math]\displaystyle{ \begin{matrix} \int_{-N}^{N} e^x\, dx \end{matrix} }[/math]
Double integral
\iint_{D}^{W} \, dx\,dy
[math]\displaystyle{ \iint_{D}^{W} \, dx\,dy }[/math]
Triple integral
\iiint_{E}^{V} \, dx\,dy\,dz
[math]\displaystyle{ \iiint_{E}^{V} \, dx\,dy\,dz }[/math]
Quadruple integral
\iiiint_{F}^{U} \, dx\,dy\,dz\,dt
[math]\displaystyle{ \iiiint_{F}^{U} \, dx\,dy\,dz\,dt }[/math]
Path integral
\oint_{C} x^3\, dx + 4y^2\, dy
[math]\displaystyle{ \oint_{C} x^3\, dx + 4y^2\, dy }[/math]
Intersections
\bigcap_1^{n} p
[math]\displaystyle{ \bigcap_1^{n} p }[/math]
Unions
\bigcup_1^{k} p
[math]\displaystyle{ \bigcup_1^{k} p }[/math]


Fractions, matrices, multilines

Feature Syntax How it looks rendered
Fractions \frac{2}{4}=0.5 or {2 \over 4}=0.5 [math]\displaystyle{ \frac{2}{4}=0.5 }[/math]
Small Fractions (force \textstyle) \begin{matrix} \frac{2}{4} \end{matrix} = 0.5 [math]\displaystyle{ \begin{matrix} \frac{2}{4} \end{matrix} = 0.5 }[/math]
Binomial coefficients {n \choose k} [math]\displaystyle{ {n \choose k} }[/math]
Matrices \begin{matrix} x & y \\ z & v \end{matrix} [math]\displaystyle{ \begin{matrix} x & y \\ z & v \end{matrix} }[/math]
\begin{vmatrix} x & y \\ z & v \end{vmatrix} [math]\displaystyle{ \begin{vmatrix} x & y \\ z & v \end{vmatrix} }[/math]
\begin{Vmatrix} x & y \\ z & v \end{Vmatrix} [math]\displaystyle{ \begin{Vmatrix} x & y \\ z & v \end{Vmatrix} }[/math]
\begin{bmatrix} 0 & \cdots & 0 \\ \vdots &

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

0\end{bmatrix}
[math]\displaystyle{ \begin{bmatrix} 0 & \cdots & 0 \\ \vdots & \ddots & \vdots \\ 0 & \cdots & 0\end{bmatrix} }[/math]
\begin{Bmatrix} x & y \\ z & v \end{Bmatrix} [math]\displaystyle{ \begin{Bmatrix} x & y \\ z & v \end{Bmatrix} }[/math]
\begin{pmatrix} x & y \\ z & v \end{pmatrix} [math]\displaystyle{ \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]\displaystyle{ 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]\displaystyle{ \begin{matrix}f(n+1) & = & (n+1)^2 \\ \ & = & n^2 + 2n + 1 \end{matrix} }[/math]
Alternative multiline equations (using tables)

{| border="0" cellpadding="0" cellspacing="0"
|-
|<math>f(n+1)</math>
|<math>=(n+1)^2</math>
|-
|
|<math>=n^2 + 2n + 1</math>
|}

[math]\displaystyle{ f(n+1) \,\! }[/math] [math]\displaystyle{ =(n+1)^2 \,\! }[/math]
[math]\displaystyle{ =n^2 + 2n + 1 \,\! }[/math]
Simultaneous equations \begin{cases} 3 x + 5 y + z \\ 7 x - 2 y + 4 z \\ -6 x + 3 y + 2 z \end{cases} [math]\displaystyle{ \begin{cases} 3 x + 5 y + z \\ 7 x - 2 y + 4 z \\ -6 x + 3 y + 2 z \end{cases} }[/math]

Fonts

Feature Syntax How it looks rendered
Greek alphabet
(Note the lack of omicron; note also that several upper case Greek letters are rendered identically to the corresponding Roman ones)

\Alpha\ \Beta\ \Gamma\ \Delta\ \Epsilon\ \Zeta\ \Eta\ \Theta\ \Iota\ \Kappa\ \Lambda\ \Mu\ \Nu\ \Xi\ \Pi\ \Rho\ \Sigma\ \Tau\ \Upsilon\ \Phi\ \Chi\ \Psi\ \Omega

\alpha\ \beta\ \gamma\ \delta\ \epsilon\ \zeta\ \eta\ \theta\ \iota\ \kappa\ \lambda\ \mu\ \nu\ \xi\ \pi\ \rho\ \sigma\ \tau\ \upsilon\ \phi\ \chi\ \psi\ \omega

\varepsilon\ \digamma\ \vartheta\ \varkappa\ \varpi\ \varrho\ \varsigma\ \varphi

[math]\displaystyle{ \Alpha\ \Beta\ \Gamma\ \Delta\ \Epsilon\ \Zeta\ \Eta\ \Theta\ \Iota\ \Kappa\ \Lambda\ \Mu\ \Nu\ \Xi\ \Pi\ \Rho\ \Sigma\ \Tau\ \Upsilon\ \Phi\ \Chi\ \Psi\ \Omega }[/math]

[math]\displaystyle{ \alpha\ \beta\ \gamma\ \delta\ \epsilon\ \zeta\ \eta\ \theta\ \iota\ \kappa\ \lambda\ \mu\ \nu\ \xi\ \pi\ \rho\ \sigma\ \tau\ \upsilon\ \phi\ \chi\ \psi\ \omega }[/math]

[math]\displaystyle{ \varepsilon\ \digamma\ \vartheta\ \varkappa\ \varpi\ \varrho\ \varsigma\ \varphi }[/math]

blackboard bold \mathbb{N}\ \mathbb{Z}\ \mathbb{D}\ \mathbb{Q}\ \mathbb{R}\ \mathbb{C}\ \mathbb{H} [math]\displaystyle{ \mathbb{N}\ \mathbb{Z}\ \mathbb{D}\ \mathbb{Q}\ \mathbb{R}\ \mathbb{C}\ \mathbb{H} }[/math]
boldface (vectors) \mathbf{x}\cdot\mathbf{y} = 0 [math]\displaystyle{ \mathbf{x}\cdot\mathbf{y} = 0 }[/math]
boldface (greek) \boldsymbol{\alpha} + \boldsymbol{\beta} + \boldsymbol{\gamma} [math]\displaystyle{ \boldsymbol{\alpha} + \boldsymbol{\beta} + \boldsymbol{\gamma} }[/math]
italics \mathit{ABCDE abcde 1234} [math]\displaystyle{ \mathit{ABCDE abcde 1234}\,\! }[/math]
Roman typeface \mathrm{ABCDE abcde 1234} [math]\displaystyle{ \mathrm{ABCDE abcde 1234}\,\! }[/math]
Fraktur typeface \mathfrak{ABCDE abcde 1234} [math]\displaystyle{ \mathfrak{ABCDE abcde 1234} }[/math]
Calligraphy/Script \mathcal{ABCDE abcde 1234} [math]\displaystyle{ \mathcal{ABCDE abcde 1234} }[/math]
Hebrew \aleph \beth \gimel \daleth [math]\displaystyle{ \aleph\ \beth\ \gimel\ \daleth }[/math]
non-italicised characters \mbox{abc} [math]\displaystyle{ \mbox{abc} }[/math] [math]\displaystyle{ \mbox{abc} \,\! }[/math]
mixed italics (bad) \mbox{if} n \mbox{is even} [math]\displaystyle{ \mbox{if} n \mbox{is even} }[/math] [math]\displaystyle{ \mbox{if} n \mbox{is even} \,\! }[/math]
mixed italics (good) \mbox{if }n\mbox{ is even} [math]\displaystyle{ \mbox{if }n\mbox{ is even} }[/math] [math]\displaystyle{ \mbox{if }n\mbox{ is even} \,\! }[/math]

Parenthesizing big expressions, brackets, bars

Feature Syntax How it looks rendered
Bad ( \frac{1}{2} ) [math]\displaystyle{ ( \frac{1}{2} ) }[/math]
Good \left ( \frac{1}{2} \right ) [math]\displaystyle{ \left ( \frac{1}{2} \right ) }[/math]

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

Feature Syntax How it looks rendered
Parentheses \left ( \frac{a}{b} \right ) [math]\displaystyle{ \left ( \frac{a}{b} \right ) }[/math]
Brackets \left [ \frac{a}{b} \right ] \quad \left \lbrack \frac{a}{b} \right \rbrack [math]\displaystyle{ \left [ \frac{a}{b} \right ] \quad \left \lbrack \frac{a}{b} \right \rbrack }[/math]
Braces \left \{ \frac{a}{b} \right \} \quad \left \lbrace \frac{a}{b} \right \rbrace [math]\displaystyle{ \left \{ \frac{a}{b} \right \} \quad \left \lbrace \frac{a}{b} \right \rbrace }[/math]
Angle brackets \left \langle \frac{a}{b} \right \rangle [math]\displaystyle{ \left \langle \frac{a}{b} \right \rangle }[/math]
Bars and double bars \left | \frac{a}{b} \right \vert \left \Vert \frac{c}{d} \right \| [math]\displaystyle{ \left | \frac{a}{b} \right \vert \left \Vert \frac{c}{d} \right \| }[/math]
Floor and ceiling functions: \left \lfloor \frac{a}{b} \right \rfloor \left \lceil \frac{c}{d} \right \rceil [math]\displaystyle{ \left \lfloor \frac{a}{b} \right \rfloor \left \lceil \frac{c}{d} \right \rceil }[/math]
Slashes and backslashes \left / \frac{a}{b} \right \backslash [math]\displaystyle{ \left / \frac{a}{b} \right \backslash }[/math]
Up, down and up-down arrows \left \uparrow \frac{a}{b} \right \downarrow \quad \left \Uparrow \frac{a}{b} \right \Downarrow \quad \left \updownarrow \frac{a}{b} \right \Updownarrow [math]\displaystyle{ \left \uparrow \frac{a}{b} \right \downarrow \quad \left \Uparrow \frac{a}{b} \right \Downarrow \quad \left \updownarrow \frac{a}{b} \right \Updownarrow }[/math]

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

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

[math]\displaystyle{ \left [ 0,1 \right ) }[/math]
[math]\displaystyle{ \left \langle \psi \right | }[/math]

Use \left. and \right. if you don't
want a delimiter to appear:
\left . \frac{A}{B} \right \} \to X [math]\displaystyle{ \left . \frac{A}{B} \right \} \to X }[/math]
Size of the delimiters \big( \Big( \bigg( \Bigg( ... \Bigg] \bigg] \Big] \big]

[math]\displaystyle{ \big( \Big( \bigg( \Bigg( ... \Bigg] \bigg] \Big] \big] }[/math]

\big\{ \Big\{ \bigg\{ \Bigg\{ ... \Bigg\rangle \bigg\rangle \Big\rangle \big\rangle

[math]\displaystyle{ \big\{ \Big\{ \bigg\{ \Bigg\{ ... \Bigg\rangle \bigg\rangle \Big\rangle \big\rangle }[/math]

\big\| \Big\| \bigg\| \Bigg\| ... \Bigg| \bigg| \Big| \big| [math]\displaystyle{ \big\| \Big\| \bigg\| \Bigg\| ... \Bigg| \bigg| \Big| \big| }[/math]
\big\lfloor \Big\lfloor \bigg\lfloor \Bigg\lfloor ... \Bigg\rceil \bigg\rceil \Big\rceil \big\rceil

[math]\displaystyle{ \big\lfloor \Big\lfloor \bigg\lfloor \Bigg\lfloor ... \Bigg\rceil \bigg\rceil \Big\rceil \big\rceil }[/math]

\big\uparrow \Big\uparrow \bigg\uparrow \Bigg\uparrow ... \Bigg\Downarrow \bigg\Downarrow \Big\Downarrow \big\Downarrow

[math]\displaystyle{ \big\uparrow \Big\uparrow \bigg\uparrow \Bigg\uparrow ... \Bigg\Downarrow \bigg\Downarrow \Big\Downarrow \big\Downarrow }[/math]

\big\updownarrow \Big\updownarrow \bigg\updownarrow \Bigg\updownarrow ... \Bigg\Updownarrow \bigg\Updownarrow \Big\Updownarrow \big\Updownarrow

[math]\displaystyle{ \big\updownarrow \Big\updownarrow \bigg\updownarrow \Bigg\updownarrow ... \Bigg\Updownarrow \bigg\Updownarrow \Big\Updownarrow \big\Updownarrow }[/math]

\big / \Big / \bigg / \Bigg / ... \Bigg\backslash \bigg\backslash \Big\backslash \big\backslash

[math]\displaystyle{ \big / \Big / \bigg / \Bigg / ... \Bigg\backslash \bigg\backslash \Big\backslash \big\backslash }[/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]\displaystyle{ a \qquad b }[/math]
quad space a \quad b [math]\displaystyle{ a \quad b }[/math]
text space a\ b [math]\displaystyle{ a\ b }[/math]
text space without PNG conversion a \mbox{ } b [math]\displaystyle{ a \mbox{ } b }[/math]
large space a\;b [math]\displaystyle{ a\;b }[/math]
medium space a\>b [not supported]
small space a\,b [math]\displaystyle{ a\,b }[/math]
no space ab [math]\displaystyle{ ab\, }[/math]
small negative space a\!b [math]\displaystyle{ a\!b }[/math]

Align with normal text flow

Due to the default css

img.tex { vertical-align: middle; }

an inline expression like [math]\displaystyle{ \int_{-N}^{N} e^x\, dx }[/math] should look good.

If you need to align it otherwise, use <font style="vertical-align:-100%;"><math>...</math></font> and play with the vertical-align argument until you get it right; however, how it looks may depend on the browser and the browser settings.

Also note that if you rely on this workaround, if/when the rendering on the server gets fixed in future releases, as a result of this extra manual offset your formulae will suddenly be aligned incorrectly. So use it sparingly, if at all.

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]\displaystyle{ a^{c+2} }[/math]
a^{c+2} \, [math]\displaystyle{ a^{c+2} \, }[/math]
a^{\,\!c+2} [math]\displaystyle{ a^{\,\!c+2} }[/math]
a^{b^{c+2}} [math]\displaystyle{ a^{b^{c+2}} }[/math] (WRONG with option "HTML if possible or else PNG"!)
a^{b^{c+2}} \, [math]\displaystyle{ a^{b^{c+2}} \, }[/math] (WRONG with option "HTML if possible or else PNG"!)
a^{b^{c+2}}\approx 5 [math]\displaystyle{ a^{b^{c+2}}\approx 5 }[/math] (due to "[math]\displaystyle{ \approx }[/math]" correctly displayed, no code "\,\!" needed)
a^{b^{\,\!c+2}} [math]\displaystyle{ a^{b^{\,\!c+2}} }[/math]
\int_{-N}^{N} e^x\, dx [math]\displaystyle{ \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.-->

Color

Equations can use color:

  • {\color{Blue}x^2}+{\color{Brown}2x}-{\color{OliveGreen}1}
    [math]\displaystyle{ {\color{Blue}x^2}+{\color{Brown}2x}-{\color{OliveGreen}1} }[/math]
  • x_{1,2}=\frac{-b\pm\sqrt{\color{Red}b^2-4ac}}{2a}
    [math]\displaystyle{ x_{1,2}=\frac{-b\pm\sqrt{\color{Red}b^2-4ac}}{2a} }[/math]

Note that this should be avoided in the same circumstances as color coding of text. See en:Wikipedia:Manual of Style#Formatting issues

Examples

Quadratic Polynomial

[math]\displaystyle{ ax^2 + bx + c = 0 }[/math]

<math>ax^2 + bx + c = 0</math>

Quadratic Polynomial (Force PNG Rendering)

[math]\displaystyle{ ax^2 + bx + c = 0\, }[/math]

<math>ax^2 + bx + c = 0\,</math>

Quadratic Formula

[math]\displaystyle{ x_{1,2}=\frac{-b\pm\sqrt{b^2-4ac}}{2a} }[/math]

<math>x_{1,2}=\frac{-b\pm\sqrt{b^2-4ac}}{2a}</math>

Tall Parentheses and Fractions

[math]\displaystyle{ 2 = \left( \frac{\left(3-x\right) \times 2}{3-x} \right) }[/math]

<math>2 = \left( \frac{\left(3-x\right) \times 2}{3-x} \right)</math>

Integrals

[math]\displaystyle{ \int_a^x \int_a^s f(y)\,dy\,ds = \int_a^x f(y)(x-y)\,dy }[/math]

<math>\int_a^x \int_a^s f(y)\,dy\,ds = \int_a^x f(y)(x-y)\,dy</math>

Summation

[math]\displaystyle{ \sum_{m=1}^\infty\sum_{n=1}^\infty\frac{m^2\,n}{3^m\left(m\,3^n+n\,3^m\right)} }[/math]

<math>\sum_{m=1}^\infty\sum_{n=1}^\infty\frac{m^2\,n}
{3^m\left(m\,3^n+n\,3^m\right)}</math>

Differential Equation

[math]\displaystyle{ u'' + p(x)u' + q(x)u=f(x),\quad x\gt a }[/math]

<math>u'' + p(x)u' + q(x)u=f(x),\quad x>a</math>

Complex numbers

[math]\displaystyle{ |\bar{z}| = |z|, |(\bar{z})^n| = |z|^n, \arg(z^n) = n \arg(z)\, }[/math]

<math>|\bar{z}| = |z|, |(\bar{z})^n| = |z|^n, \arg(z^n) = n \arg(z)\,</math>

Limits

[math]\displaystyle{ \lim_{z\rightarrow z_0} f(z)=f(z_0)\, }[/math]

<math>\lim_{z\rightarrow z_0} f(z)=f(z_0)\,</math>

Integral Equation

[math]\displaystyle{ \phi_n(\kappa) = \frac{1}{4\pi^2\kappa^2} \int_0^\infty \frac{\sin(\kappa R)}{\kappa R} \frac{\partial}{\partial R}\left[R^2\frac{\partial D_n(R)}{\partial R}\right]\,dR }[/math]

<math>\phi_n(\kappa) = \frac{1}{4\pi^2\kappa^2} \int_0^\infty
\frac{\sin(\kappa R)}{\kappa R} \frac{\partial}{\partial R}\left[R^2\frac{\partial
D_n(R)}{\partial R}\right]\,dR</math>

Example

[math]\displaystyle{ \phi_n(\kappa) = 0.033C_n^2\kappa^{-11/3},\quad \frac{1}{L_0}\ll\kappa\ll\frac{1}{l_0}\, }[/math]

<math>\phi_n(\kappa) = 
0.033C_n^2\kappa^{-11/3},\quad \frac{1}{L_0}\ll\kappa\ll\frac{1}{l_0}\,</math>

Continuation and cases

[math]\displaystyle{ f(x) = \begin{cases}1 & -1 \le x \lt  0 \\
 \frac{1}{2} & x = 0 \\ 1 - x^2 & 0 \lt  x \le 1\end{cases} }[/math]

<math>f(x) = \begin{cases}1 & -1 \le x < 0 \\
\frac{1}{2} & x = 0 \\ 1 - x^2 & 0 < x\le 1\end{cases}</math>

Prefixed subscript

[math]\displaystyle{ {}_pF_q(a_1,...,a_p;c_1,...,c_q;z) = \sum_{n=0}^\infty \frac{(a_1)_n\cdot\cdot\cdot(a_p)_n}{(c_1)_n\cdot\cdot\cdot(c_q)_n}\frac{z^n}{n!}\, }[/math]

 <math>{}_pF_q(a_1,...,a_p;c_1,...,c_q;z) = \sum_{n=0}^\infty
\frac{(a_1)_n\cdot\cdot\cdot(a_p)_n}{(c_1)_n\cdot\cdot\cdot(c_q)_n}\frac{z^n}{n!}\,</math>