Help:Displaying a formula

Safer nicotine wiki Tobacco Harm Reduction
Jump to navigation Jump to search

Lua error: Internal error: The interpreter exited with status 127.Expression error: Unexpected < operator.

Lua error: Internal error: The interpreter exited with status 127. Lua error: Internal error: The interpreter exited with status 127.Lua error: Internal error: The interpreter exited with status 127.

This screenshot shows the formula E = mc2Lua error: Internal error: The interpreter exited with status 127. being edited using VisualEditor. The visual editor shows a button that allows to choose one of three offered modes to display a formula.

There are three methods for displaying formulas in Wikipedia: raw HTML, HTML with math templates (abbreviated here as {{math}}), and a subset of LaTeX implemented with the HTML markup <math></math> (referred to as LaTeX in this article). Each method has some advantages and some disadvantages, which have evolved over the time with improvements of MediaWiki. The manual of style has not always evolved accordingly. So the how-to recommendations that appear below may differ from those of the manual of style. In this case, they express a consensus resulting of the practice of most experienced members of WikiProject Mathematics and many discussions at Wikipedia talk:WikiProject Mathematics.

For example, the famous Einstein formula can be entered in raw HTML as {{nowrap|''E'' {{=}} ''mc''<sup>2</sup>}}, which is rendered as E = mc2 (the template {{nowrap}} is here only for avoiding a line break inside the formula). With {{math}}, it can be entered as {{math|''E'' {{=}} ''mc''{{sup|2}}}}, which is rendered as E = mc2Lua error: Internal error: The interpreter exited with status 127.. With LaTeX, it is entered as <math>E=mc^2</math>, and rendered as E=mc2.

Use of raw HTML

Variable names and many symbols look very different with raw HTML and the other display methods. This may be confusing in the common case where several methods are used in the same article. Moreover, mathematicians who are used to reading and writing texts written with LaTeX often find the raw HTML rendering awful.

So, raw HTML should normally not be used for new content. However, raw HTML is still present in many mathematical articles. It is generally a good practice to convert it to {{math}} format, but coherency must be respected; that is, such a conversion must be done in a whole article, or at least in a whole section. Moreover such a conversion must be identified as such in the edit summary, and it should be avoided making other changes in the same edit. This is for helping other users to identify changes that are possibly controversial (the "diff" of a conversion may be very large, and may hide other changes).

Converting raw HTML to {{math}} is rather simple: when the formula is enclosed with {{nowrap}}, it suffices to change "nowrap" into "math". However if the formula contains an equal sign, one has to add 1= just before the formula for avoiding confusion with the template syntax; for example, {{math|1=''E'' = ''mc''{{sup|2}}}}. Also, vertical bars, if any, must either be replaced with {{!}} or avoided by using {{abs}}.

LaTeX vs. {{math}}

These two ways of writing mathematical formulas each have their advantages and disadvantages. They are both accepted by the manual of style . The rendering of variable names is very similar. So having a variable name displayed in the same paragraph with {{math}} and <math> is generally not a problem.

The disadvantages of LaTeX are the following: On some browser configurations, LaTeX inline formulas appear with a slight vertical misalignment, or with a font size that is slightly different from that of the surrounding text. This not a problem with a block displayed formula. This is generally also not a real problem with inline formulas that exceed the normal line height (for example formulas with subscripts and superscripts). Also, the use of LaTeX in a piped link or in a section heading should appear in blue in the linked text or the table of content, but they do not. Moreover, links to sections headings containing LaTeX formulas do not work always as expected. Finally, too many LaTeX formulas may significantly increase the processing time of a page.

The disadvantages of {{math}} are the following: not all formulas can be displayed. While it is possible to render a complicated formula with {{math}}, it is often poorly rendered. Except for the most common ones, the rendering of non-alphanumeric Unicode symbols is often very poor and may depend on the browser configuration (misalignment, wrong size, ...). The spaces inside formulas are not managed automatically, and thus need some expertise for being rendered correctly. Except for short formulas, there are much more characters to type for entering a formula, and the source is more difficult to read.

Therefore, the common practice of most members of WikiProject mathematics is the following:

  • Use of {{mvar}} and {{math}} for isolated variables and very simple inline formulas
  • Use of LaTeX for displayed formulas and more complicated inline formulas
  • Use of LaTeX for formulas involving symbols that are not regularly rendered in Unicode (see )
  • Avoid formulas in section headings, and when this is a problem, use raw HTML (see Finite field for an example)

The choice between {{math}} and LaTeX depends on the editor. So converting from a format to another one must be done with stronger reasons than editor preference.

Display format of LaTeX

Lua error: Internal error: The interpreter exited with status 127. By default SVG images with non-visible MathML are generated. PNG images or text-only forms of the LaTeX can be set via user preferences at My Preferences - Appearance - Math.

The hidden MathML can be used by screen readers and other assistive technology. To display the MathML in Firefox:

In either case, you must have fonts that support MathML (see developer.mozilla.org) installed on your system. For copy-paste support in Firefox, you can also install MathML Copy.

Use of HTML templates

Lua error: Internal error: The interpreter exited with status 127. Lua error: Internal error: The interpreter exited with status 127. TeX markup is not the only way to render mathematical formulas. For simple inline formulas, the template {{math}} and its associated templates are often preferred. The following comparison table shows that similar results can be achieved with the two methods. See also Help:Special characters.

TeX syntax TeX rendering   HTML syntax HTML rendering
<math>\alpha</math> α {{math|''&alpha;''}}   or   {{mvar|&alpha;}} αLua error: Internal error: The interpreter exited with status 127.   or   α
<math>f(x) = x^2</math> f(x)=x2 {{math|''f''(''x'') {{=}} ''x''<sup>2</sup>}} f(x) = x2Lua error: Internal error: The interpreter exited with status 127.
<math>\{1,e,\pi\}</math> {1,e,π} {{math|{{mset|1, ''e'', ''&pi;''}}}} {1, e, π}Lua error: Internal error: The interpreter exited with status 127.
<math>|z + 1| \leq 2</math> |z+1|2 {{math|{{abs|''z'' + 1}} &le; 2}} z + 1| ≤ 2Lua error: Internal error: The interpreter exited with status 127.

Here is a summary of the mathematical templates:

Lua error: Internal error: The interpreter exited with status 127.

Care should be taken when writing sets within {{math}}, as braces, equal signs, and vertical bars can conflict with template syntax. The {{mset}} template is available for braces, as shown in the example above. Likewise, {{abs}} encloses its parameter inside vertical bars to help with the pipe character conflicting with template syntax. For a single vertical bar, use {{!}}, and for an equal sign, use {{}}.

HTML entities

Though Unicode characters are generally preferred, sometimes HTML entities are needed to avoid problems with wiki syntax or confusion with other characters:

Lua error: Internal error: The interpreter exited with status 127.

In the table below, the codes on the left produce the symbols on the right, but these symbols can also be entered directly in the wikitext either by typing them if they are available on the keyboard, by copy-pasting them, or by using menus below the edit windows. (When editing any Wikipedia page in a desktop web browser, use the "Insert" pulldown menu immediately below the article text, or the "Special characters" menu immediately above the article text.) Normally, lowercase Greek letters should be entered in italics, that is, enclosed between two single quotes ('').

HTML syntax Rendering
&alpha; &beta; &gamma; &delta; &epsilon; &zeta;
&eta; &theta; &iota; &kappa; &lambda; &mu; &nu;
&xi; &omicron; &pi; &rho; &sigma; &sigmaf;
&tau; &upsilon; &phi; &chi; &psi; &omega;

α β γ δ ε ζ
η θ ι κ λ μ ν
ξ ο π ρ σ ς
τ υ φ χ ψ ω

&Gamma; &Delta; &Theta; &Lambda; &Xi; &Pi;
&Sigma; &Phi; &Psi; &Omega;

Γ Δ Θ Λ Ξ Π
Σ Φ Ψ Ω

&int; &sum; &prod; &minus; &plusmn; &infin;
&asymp; &prop; = &equiv; &ne; &le; &ge;
&times; &middot; &sdot; &divide; &part; &prime; &Prime;
&nabla; &permil; &deg; &there4; &empty;

∫ ∑ ∏ − ± ∞
≈ ∝ = ≡ ≠ ≤ ≥
× · ⋅ ÷ ∂ ′ ″
∇ ‰ ° ∴ ∅

&isin; &notin; &cap; &cup; &sub; &sup; &sube; &supe;
&not; &and; &or; &exist; &forall;
&rArr; &hArr; &rarr; &harr; &uarr; &darr;
&alefsym; - &ndash; &mdash;

∈ ∉ ∩ ∪ ⊂ ⊃ ⊆ ⊇
¬ ∧ ∨ ∃ ∀
⇒ ⇔ → ↔ ↑ ↓
ℵ - – —

Superscripts and subscripts

Lua error: Internal error: The interpreter exited with status 127. Typically whitespace should be a regular space ( ) or none at all.

Spacing

To avoid line-wrapping in the middle of a formula, use {{math}}. If necessary, a non-breaking space ( ) can be inserted with "&nbsp;".

In rare circumstances, such as where one character overlaps another due to one being in italics, a thin space can be added with {{thin space}}.

More

For more on Wikipedia howtos and math style guidelines:

For more on special characters:

LaTeX basics

Math markup goes inside ‎<math>...‎</math>. Chemistry markup goes inside <math chem>...</math> or ‎<chem>...‎</chem>. All these tags use TeX.

The TeX code has to be put literally: MediaWiki templates, predefined templates, and parameters cannot be used within math tags: pairs of double braces are ignored and "#" gives an error message. However, math tags work in the then and else part of #if, etc. See m:Template:Demo of attempt to use parameters within TeX (backlinks edit) for more information.

The now deprecated tag <ce> was considered too ambiguous, and it has been replaced by <chem>.[1]

LaTeX commands

LaTeX commands are case-sensitive, and take one of the following two formats:

  • They start with a backslash \ and then have a name consisting of letters only. Command names are terminated by a space, a number or any other "non-letter".
  • They consist of a backslash \ and exactly one non-letter.

Some commands need an argument, which has to be given between curly braces {} after the command name. Some commands support optional parameters, which are added after the command name in square brackets []. The general syntax is:

\commandname[option1,option2,...]{argument1}{argument2}...

Special characters

The following symbols are reserved characters that either have a special meaning under LaTeX or are unavailable in all the fonts. If you enter them directly in your text, they will normally not render, but rather do things you did not intend.

# $ % ^ & _ { } ~ \

These characters can be entered by prefixing the escape character backslash \ or using special sequences:

\# \$ \% ^\wedge \& \_ \{ \} \sim \backslash

yielding

#$%&_{}.

The backslash character \ can not be entered by adding another backslash in front of it (\\); this sequence is used for line breaking. For introducing a backslash in math mode, you can use \backslash instead which gives .

The command \tilde produces a tilde which is placed over the next letter. For example, \tilde{a} gives a~. To produce just a tilde character ~, use \tilde{} which gives ~, placing a ~ over an empty box. Alternatively \sim produces , a large centred ~ which may be more appropriate in some situations.

The command \hat produces a hat over the next character, for example \hat{o} produces o^. For a stretchable version use \widehat{abc} giving abc^. The wedge \wedge is normally used as a mathematical operator the sequence ^\wedge produces the best equivalent to the ASCII caret ^ character.

Spaces

"Whitespace" characters, such as blank or tab, are treated uniformly as "space" by LaTeX. Several consecutive whitespace characters are treated as one "space". See below for commands that produces spaces of different size.

LaTeX environments

Environments in LaTeX have a role that is quite similar to commands, but they usually have effect on a wider part of formula. Their syntax is:

 \begin{environmentname}
   text to be influenced
 \end{environmentname}

Environments supported by Wikipedia include matrix, align, etc. See below.

Rendering

The 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; a work-around is described in the "Alignment with normal text flow" section below. The CSS selector of the images is img.tex.

An alt text of the PNG images, shown to visually impaired and others who cannot see the images, and is also used when the text is selected and copied, defaults to the wikitext that produced the image, excluding the <math> and </math>. In older versions of MediaWiki, You can override this by explicitly making an alt attribute for the math element. <math alt="Square root of pi">\sqrt{\pi}</math> generates an image π whose alt text is "Square root of pi". This should not be confused with the title attribute that produces pop-up text when the hovering over the PNG image, for example <math title="pi">\pi</math> generates an image π whose popup text is "pi". The override was removed in 2016.

Apart from function and operator names, as is customary in mathematics, variables and letters are in italics; digits are not. For other text, (like variable labels) to avoid being rendered in italics like variables, use \text or \mathrm (formerly \rm). You can also define new function names using \operatorname{...}. For example, \text{abc} gives abc. \operatorname{...} provides spacing before and after the operator name when appropriate, as when a\operatorname{sn}b is rendered as asnb (with space to the left and right of "sn") and a\operatorname{sn}(b+c) as asn(b+c) (with space to the left and not to the right). LaTeX's starred version, \operatorname* is not supported, but a workaround is to add \limits instead. For example, \operatorname{sn}_{b>c}(b+c) \qquad \operatorname{sn}\limits_{b>c}(b+c) renders as

snb>c(b+c)snb>c(b+c).

LaTeX does not have full support for Unicode characters, and not all characters render. Most Latin characters with accents render correctly. However some do not, in particular those that include multiple diacritics (e.g. with Latin letters used in Vietnamese) or that cannot be precomposed into a single character (such as the uppercase Latin letter W with ring), or that use other diacritics (like the ogonek or the double grave accent, used in Central European languages like Polish, or the horn attached above some vowels in Vietnamese), or other modified letter forms (used in IPA notations, or African languages, or in medieval texts), some digram ligatures (like IJ in Dutch), or Latin letters borrowed from Greek, or small capitals, as well as superscripts and subscript letters. For example, \text{ð} and \text{þ} (used in Icelandic) will give errors.

The normal way of entering quotation marks in text mode (two back ticks for the left and two apostrophes for the right), such as \text{a ``quoted'' word} will not work correctly. As a workaround, you can use the Unicode left and right quotation mark characters, which are available from the "Symbols" dropdown panel beneath the editor: \text{a “quoted” word}.

Force-rerendering of formulas

MediaWiki stores rendered formulas in a cache so that the images of those formulas do not need to be created each time the page is opened by a user. To force the rerendering of all formulas of a page, you must open it with the getter variables action=purge&mathpurge=true. Imagine for example there is a wrong rendered formula in the article Integral. To force the re-rendering of this formula you need to open the URL https://en.wikipedia.org/w/index.php?title=Integral&action=purge&mathpurge=true . Afterwards you need to bypass your browser cache so that the new created images of the formulas are actually downloaded.

Formatting using TeX

Functions, symbols, special characters

Accents and diacritics

\dot{a}, \ddot{a}, \acute{a}, \grave{a} a˙,a¨,a´,a`
\check{a}, \breve{a}, \tilde{a}, \bar{a} aˇ,a˘,a~,a¯
\hat{a}, \widehat{a}, \vec{a} a^,a^,a

Standard numerical functions

\exp_a b = a^b, \exp b = e^b, 10^m expab=ab,expb=eb,10m
\ln c, \lg d = \log e, \log_{10} f lnc,lgd=loge,log10f
\sin a, \cos b, \tan c, \cot d, \sec e, \csc f sina,cosb,tanc,cotd,sece,cscf
\arcsin h, \arccos i, \arctan j arcsinh,arccosi,arctanj
\sinh k, \cosh l, \tanh m, \coth n sinhk,coshl,tanhm,cothn
\operatorname{sh}k, \operatorname{ch}l, \operatorname{th}m, \operatorname{coth}n shk,chl,thm,cothn
\operatorname{argsh}o, \operatorname{argch}p, \operatorname{argth}q argsho,argchp,argthq
\sgn r, \left\vert s \right\vert sgnr,|s|
\min(x,y), \max(x,y) min(x,y),max(x,y)

Bounds

\min x, \max y, \inf s, \sup t minx,maxy,infs,supt
\lim u, \liminf v, \limsup w limu,lim infv,lim supw
\dim p, \deg q, \det m, \ker\phi dimp,degq,detm,kerϕ

Projections

\Pr j, \hom l, \lVert z \rVert, \arg z Prj,homl,z,argz

Differentials and derivatives

dt, \mathrm{d}t, \partial t, \nabla\psi dt,dt,t,ψ
dy/dx, \mathrm{d}y/\mathrm{d}x, \frac{dy}{dx}, \frac{\mathrm{d}y}{\mathrm{d}x}, \frac{\partial^2}{\partial x_1\partial x_2}y dy/dx,dy/dx,dydx,dydx,2x1x2y
\prime, \backprime, f^\prime, f', f'', f^{(3)}, \dot y, \ddot y ,,f,f,f,f(3),y˙,y¨

Letter-like symbols or constants

\infty, \aleph, \complement, \backepsilon, \eth, \Finv, \hbar ,,,,ð,,
\Im, \imath, \jmath, \Bbbk, \ell, \mho, \wp, \Re, \circledS, \S, \P, \AA ,ı,ȷ,k,,,,,,§,,Å

Modular arithmetic

s_k \equiv 0 \pmod{m} sk0(modm)
a \bmod b amodb
\gcd(m, n), \operatorname{lcm}(m, n) gcd(m,n),lcm(m,n)
\mid, \nmid, \shortmid, \nshortmid ,,,

Radicals

\surd, \sqrt{2}, \sqrt[n]{2}, \sqrt[3]{\frac{x^3+y^3}{2}} ,2,2n,x3+y323

Operators

+, -, \pm, \mp, \dotplus +,,±,,
\times, \div, \divideontimes, /, \backslash ×,÷,,/,
\cdot, * \ast, \star, \circ, \bullet ,*,,,
\boxplus, \boxminus, \boxtimes, \boxdot ,,,
\oplus, \ominus, \otimes, \oslash, \odot ,,,,
\circleddash, \circledcirc, \circledast ,,
\bigoplus, \bigotimes, \bigodot ,,

Sets

\{ \}, \O \empty \emptyset, \varnothing {},,
\in, \notin \not\in, \ni, \not\ni ,∉,,∌
\cap, \Cap, \sqcap, \bigcap ,,,
\cup, \Cup, \sqcup, \bigcup, \bigsqcup, \uplus, \biguplus ,,,,,,
\setminus, \smallsetminus, \times ,,×
\subset, \Subset, \sqsubset ,,
\supset, \Supset, \sqsupset ,,
\subseteq, \nsubseteq, \subsetneq, \varsubsetneq, \sqsubseteq ,,,,
\supseteq, \nsupseteq, \supsetneq, \varsupsetneq, \sqsupseteq ,,,,
\subseteqq, \nsubseteqq, \subsetneqq, \varsubsetneqq ,,,
\supseteqq, \nsupseteqq, \supsetneqq, \varsupsetneqq ,,,

Relations

=, \ne, \neq, \equiv, \not\equiv =,,,,≢
\doteq, \doteqdot, \overset{\underset{\mathrm{def}}{}}{=}, := ,,=def,:=
\sim, \nsim, \backsim, \thicksim, \simeq, \backsimeq, \eqsim, \cong, \ncong ,,,,,,,,
\approx, \thickapprox, \approxeq, \asymp, \propto, \varpropto ,,,,,
<, \nless, \ll, \not\ll, \lll, \not\lll, \lessdot <,,,≪̸,,⋘̸,
>, \ngtr, \gg, \not\gg, \ggg, \not\ggg, \gtrdot >,,,≫̸,,⋙̸,
\le, \leq, \lneq, \leqq, \nleq, \nleqq, \lneqq, \lvertneqq ,,,,,,,
\ge, \geq, \gneq, \geqq, \ngeq, \ngeqq, \gneqq, \gvertneqq ,,,,,,,
\lessgtr, \lesseqgtr, \lesseqqgtr, \gtrless, \gtreqless, \gtreqqless ,,,,,
\leqslant, \nleqslant, \eqslantless ,,
\geqslant, \ngeqslant, \eqslantgtr ,,
\lesssim, \lnsim, \lessapprox, \lnapprox ,,,
\gtrsim, \gnsim, \gtrapprox, \gnapprox ,,,
\prec, \nprec, \preceq, \npreceq, \precneqq ,,,,
\succ, \nsucc, \succeq, \nsucceq, \succneqq ,,,,
\preccurlyeq, \curlyeqprec ,
\succcurlyeq, \curlyeqsucc ,
\precsim, \precnsim, \precapprox, \precnapprox ,,,
\succsim, \succnsim, \succapprox, \succnapprox ,,,

Geometric

\parallel, \nparallel, \shortparallel, \nshortparallel ,,,
\perp, \angle, \sphericalangle, \measuredangle, 45^\circ ,,,,45
\Box, \square, \blacksquare, \diamond, \Diamond, \lozenge, \blacklozenge, \bigstar ,,,,,,,
\bigcirc, \triangle, \bigtriangleup, \bigtriangledown ,,,
\vartriangle, \triangledown ,
\blacktriangle, \blacktriangledown, \blacktriangleleft, \blacktriangleright ,,,

Logic

\forall, \exists, \nexists ,,
\therefore, \because, \And ,,&
\lor \vee, \curlyvee, \bigvee

don't use \or which is now deprecated

,,,
\land \wedge, \curlywedge, \bigwedge

don't use \and which is now deprecated

,,,
\bar{q}, \bar{abc}, \overline{q}, \overline{abc},

\lnot \neg, \not\operatorname{R}, \bot, \top

q¯,abc¯,q,abc,

¬¬,R,,

\vdash \dashv, \vDash, \Vdash, \models ,,,,
\Vvdash \nvdash \nVdash \nvDash \nVDash ,,,,
\ulcorner \urcorner \llcorner \lrcorner

Arrows

\Rrightarrow, \Lleftarrow ,
\Rightarrow, \nRightarrow, \Longrightarrow, \implies ,,,
\Leftarrow, \nLeftarrow, \Longleftarrow ,,
\Leftrightarrow, \nLeftrightarrow, \Longleftrightarrow, \iff ,,,
\Uparrow, \Downarrow, \Updownarrow ,,
\rightarrow \to, \nrightarrow, \longrightarrow ,,
\leftarrow \gets, \nleftarrow, \longleftarrow ,,
\leftrightarrow, \nleftrightarrow, \longleftrightarrow ,,
\uparrow, \downarrow, \updownarrow ,,
\nearrow, \swarrow, \nwarrow, \searrow ,,,
\mapsto, \longmapsto ,
\rightharpoonup \rightharpoondown \leftharpoonup \leftharpoondown \upharpoonleft \upharpoonright \downharpoonleft \downharpoonright \rightleftharpoons \leftrightharpoons ,,,,,,,,,
\curvearrowleft \circlearrowleft \Lsh \upuparrows \rightrightarrows \rightleftarrows \rightarrowtail \looparrowright ,,,,,,,
\curvearrowright \circlearrowright \Rsh \downdownarrows \leftleftarrows \leftrightarrows \leftarrowtail \looparrowleft ,,,,,,,
\hookrightarrow \hookleftarrow \multimap \leftrightsquigarrow \rightsquigarrow \twoheadrightarrow \twoheadleftarrow ,,,,,,

Special

\amalg \P \S \% \dagger \ddagger \ldots \cdots ⨿§%
\smile \frown \wr \triangleleft \triangleright
\diamondsuit, \heartsuit, \clubsuit, \spadesuit, \Game, \flat, \natural, \sharp ,,,,,,,

Unsorted (new stuff)

\diagup \diagdown \centerdot \ltimes \rtimes \leftthreetimes \rightthreetimes ,,,,,,
\eqcirc \circeq \triangleq \bumpeq \Bumpeq \doteqdot \risingdotseq \fallingdotseq ,,,,,,,
\intercal \barwedge \veebar \doublebarwedge \between \pitchfork ,,,,,
\vartriangleleft \ntriangleleft \vartriangleright \ntriangleright ,,,
\trianglelefteq \ntrianglelefteq \trianglerighteq \ntrianglerighteq ,,,

For a little more semantics on these symbols, see the brief TeX Cookbook.

Larger expressions

Subscripts, superscripts, integrals

Feature Syntax How it looks rendered
Superscript a^2, a^{x+3} a2,ax+3
Subscript a_2 a2
Grouping 10^{30} a^{2+2} 1030a2+2
a_{i,j} b_{f'} ai,jbf
Combining sub & super without and with horizontal separation x_2^3 x23
{x_2}^3 x23
Super super 10^{10^{8}} 10108
Preceding and/or additional sub & super \sideset{_1^2}{_3^4}\prod_a^b 3412ab
{}_1^2\!\Omega_3^4 12Ω34
Stacking \overset{\alpha}{\omega} ωα
\underset{\alpha}{\omega} ωα
\overset{\alpha}{\underset{\gamma}{\omega}} ωγα
\stackrel{\alpha}{\omega} ωα
Derivatives x', y'', f', f'' x,y,f,f
x^\prime, y^{\prime\prime} x,y
Derivative dots \dot{x}, \ddot{x} x˙,x¨
Underlines, overlines, vectors \hat a \ \bar b \ \vec c a^ b¯ c
\overrightarrow{a b} \ \overleftarrow{c d} \ \widehat{d e f} ab cd def^
\overline{g h i} \ \underline{j k l} ghi jkl_
Arc (workaround) \overset{\frown} {AB} AB
Arrows A \xleftarrow{n+\mu-1} B \xrightarrow[T]{n\pm i-1} C An+μ1BTn±i1C
Overbraces \overbrace{ 1+2+\cdots+100 }^{5050} 1+2++1005050
Underbraces \underbrace{ a+b+\cdots+z }_{26} a+b++z26
Sum \sum_{k=1}^N k^2 k=1Nk2
Sum (force \textstyle) \textstyle \sum_{k=1}^N k^2 k=1Nk2
Sum in a fraction (default \textstyle) \frac{\sum_{k=1}^N k^2}{a} k=1Nk2a
Sum in a fraction (force \displaystyle) \frac{\displaystyle \sum_{k=1}^N k^2}{a} k=1Nk2a
Sum in a fraction (alternative limits style) \frac{\sum\limits^{^N}_{k=1} k^2}{a} k=1Nk2a
Product \prod_{i=1}^N x_i i=1Nxi
Product (force \textstyle) \textstyle \prod_{i=1}^N x_i i=1Nxi
Coproduct \coprod_{i=1}^N x_i i=1Nxi
Coproduct (force \textstyle) \textstyle \coprod_{i=1}^N x_i i=1Nxi
Limit \lim_{n \to \infty}x_n limnxn
Limit (force \textstyle) \textstyle \lim_{n \to \infty}x_n limnxn
Integral \int\limits_{1}^{3}\frac{e^3/x}{x^2}\, dx 13e3/xx2dx
Integral (alternative limits style) \int_{1}^{3}\frac{e^3/x}{x^2}\, dx 13e3/xx2dx
Integral (force \textstyle) \textstyle \int\limits_{-N}^{N} e^x dx NNexdx
Integral (force \textstyle, alternative limits style) \textstyle \int_{-N}^{N} e^x dx NNexdx
Double integral \iint\limits_D dx\,dy Ddxdy
Triple integral \iiint\limits_E dx\,dy\,dz Edxdydz
Quadruple integral \iiiint\limits_F dx\,dy\,dz\,dt Fdxdydzdt
Line or path integral \int_{(x,y)\in C} x^3\, dx + 4y^2\, dy (x,y)Cx3dx+4y2dy
Closed line or path integral \oint_{(x,y)\in C} x^3\, dx + 4y^2\, dy (x,y)Cx3dx+4y2dy
Intersections \bigcap_{i=1}^n E_i i=1nEi
Unions \bigcup_{i=1}^n E_i i=1nEi

Display attribute

The ‎<math> tag can take a display attribute with possible values of inline and block.

Inline

If the value of the display attribute is inline, the contents will be rendered in inline mode: there will be no new paragraph for the equation and the operators will be rendered to consume only a small amount of vertical space.

The sum i=02i converges to 2.

The next line-width is not disturbed by large operators.

The code for the math example reads:

<math display="inline">\sum_{i=0}^\infty 2^{-i}</math>

The quotation marks around inline are optional and display=inline is also valid.[2]

Technical implementation

Technically the command \textstyle will be added to the user input before the TeX command is passed to the renderer. The result will be displayed without further formatting by outputting the image or MathMLelement to the page.

Block

In block-style the equation is rendered in its own paragraph and the operators are rendered consuming less horizontal space. The equation is indented.

The sum i=02i converges to 2.

It was entered as

<math display="block">\sum_{i=0}^\infty 2^{-i}</math>
Technical implementation

Technically the command \displaystyle will be added to the user input (if the user input does not already contain the string \displaystyle or \align) before the TeX command is passed to the renderer. The result will be displayed in a new paragraph. Therefore, the style of the MathImage is altered i.e. the style attribute "display:block;margin:auto" is added. For MathML it is ensured that display=inline is replaced by display block which produces a new paragraph

Not specified

If nothing is specified the equation is rendered in the same display style as "block", but without using a new paragraph. If the equation does appear on a line by itself, it is not automatically indented.

The sum i=02i converges to 2.

The next line-width is disturbed by large operators.

Or:

The sum

i=02i

converges to 2.

In both cases, the math is coded as:

<math>\sum_{i=0}^\infty 2^{-i}</math>

Fractions, matrices, multilines

Feature Syntax How it looks rendered
Fractions \frac{2}{4}=0.5 or {2 \over 4}=0.5 24=0.5
Small fractions (force \textstyle) \tfrac{2}{4} = 0.5 24=0.5
Large (normal) fractions (force \displaystyle) \dfrac{2}{4} = 0.5 \qquad \dfrac{2}{c + \dfrac{2}{d + \dfrac{2}{4}}} = a 24=0.52c+2d+24=a
Large (nested) fractions \cfrac{2}{c + \cfrac{2}{d + \cfrac{2}{4}}} = a 2c+2d+24=a
Cancellations in fractions \cfrac{x}{1 + \cfrac{\cancel{y}}{\cancel{y}}} = \cfrac{x}{2} x1+yy=x2
Binomial coefficients \binom{n}{k} (nk)
Small binomial coefficients (force \textstyle) \tbinom{n}{k} (nk)
Large (normal) binomial coefficients (force \displaystyle) \dbinom{n}{k} (nk)
Matrices
\begin{matrix}
x & y \\
z & v
\end{matrix}
xyzv
\begin{vmatrix}
x & y \\
z & v
\end{vmatrix}
|xyzv|
\begin{Vmatrix}
x & y \\
z & v
\end{Vmatrix}
xyzv
\begin{bmatrix}
0 & \cdots & 0 \\
\vdots & \ddots & \vdots \\
0 & \cdots & 0
\end{bmatrix}
[0000]
\begin{Bmatrix}
x & y \\
z & v
\end{Bmatrix}
{xyzv}
\begin{pmatrix}
x & y \\
z & v
\end{pmatrix}
(xyzv)
\bigl( \begin{smallmatrix}
a&b\\ c&d
\end{smallmatrix} \bigr)
(abcd)
Case distinctions
f(n) =
\begin{cases}
n/2, & \text{if }n\text{ is even} \\
3n+1, & \text{if }n\text{ is odd}
\end{cases}
f(n)={n/2,if n is even3n+1,if n is odd
Simultaneous equations
\begin{cases}
3x + 5y + z \\
7x - 2y + 4z \\
-6x + 3y + 2z
\end{cases}
{3x+5y+z7x2y+4z6x+3y+2z
Multiline equations
\begin{align}
f(x) & = (a+b)^2 \\
& = a^2+2ab+b^2 \\
\end{align}
f(x)=(a+b)2=a2+2ab+b2
\begin{alignat}{2}
f(x) & = (a-b)^2 \\
& = a^2-2ab+b^2 \\
\end{alignat}
f(x)=(ab)2=a22ab+b2
Multiline equations with multiple alignments per row
\begin{align}
f(a,b) & = (a+b)^2 && = (a+b)(a+b) \\
& = a^2+ab+ba+b^2  && = a^2+2ab+b^2 \\
\end{align}
f(a,b)=(a+b)2=(a+b)(a+b)=a2+ab+ba+b2=a2+2ab+b2
\begin{alignat}{3}
f(a,b) & = (a+b)^2 && = (a+b)(a+b) \\
& = a^2+ab+ba+b^2  && = a^2+2ab+b^2 \\
\end{alignat}
f(a,b)=(a+b)2=(a+b)(a+b)=a2+ab+ba+b2=a2+2ab+b2
Multiline equations (must define number of columns used ({lcl})) (should not be used unless needed)
\begin{array}{lcl}
z & = & a \\
f(x,y,z) & = & x + y + z
\end{array}
z=af(x,y,z)=x+y+z
Multiline equations (more)
\begin{array}{lcr}
z & = & a \\
f(x,y,z) & = & x + y + z
\end{array}
z=af(x,y,z)=x+y+z
Multiline alignment using & to left align (top example) versus && to right align (bottom example) the last column
\begin{alignat}{4}
F:\; && C(X) && \;\to\;     & C(X) \\
     && g    && \;\mapsto\; & g^2
\end{alignat}
\begin{alignat}{4}
F:\; && C(X) && \;\to\;     && C(X) \\
     && g    && \;\mapsto\; && g^2
\end{alignat}
F:C(X)C(X)gg2

F:C(X)C(X)gg2

Breaking up a long expression so that it wraps when necessary, at the expense of destroying correct spacing
<math>f(x) \,\!</math>
<math>= \sum_{n=0}^\infty a_n x^n </math>
<math>= a_0+a_1x+a_2x^2+\cdots</math>
f(x)=n=0anxn=a0+a1x+a2x2+
Arrays
\begin{array}{|c|c|c|} a & b & S \\
\hline
0 & 0 & 1 \\
0 & 1 & 1 \\
1 & 0 & 1 \\
1 & 1 & 0 \\
\end{array}
abS001011101110

Parenthesizing big expressions, brackets, bars

Feature Syntax How it looks rendered
☒NBad ( \frac{1}{2} )^n (12)n
GoodcheckY \left ( \frac{1}{2} \right )^n (12)n

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

Feature Syntax How it looks rendered
Parentheses \left ( \frac{a}{b} \right ) (ab)
Brackets \left [ \frac{a}{b} \right ] \quad
\left \lbrack \frac{a}{b} \right \rbrack
[ab][ab]
Braces \left \{ \frac{a}{b} \right \} \quad
\left \lbrace \frac{a}{b} \right \rbrace
{ab}{ab}
Angle brackets \left \langle \frac{a}{b} \right \rangle ab
Bars and double bars \left | \frac{a}{b} \right \vert \quad
\left \Vert \frac{c}{d} \right \|
|ab|cd
Floor and ceiling functions: \left \lfloor \frac{a}{b} \right \rfloor \quad
\left \lceil \frac{c}{d} \right \rceil
abcd
Slashes and backslashes \left / \frac{a}{b} \right \backslash /ab\
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
ababab
Delimiters can be mixed,
as long as \left and \right match
\left [ 0,1 \right )
\left \langle \psi \right |
[0,1)
ψ|
Use \left. and \right. if you
do not want a delimiter to appear
\left . \frac{A}{B} \right \} \to X AB}X
Size of the delimiters (add "l" or "r" to indicate the side for proper spacing) ( \bigl( \Bigl( \biggl( \Biggl( \dots \Biggr] \biggr] \Bigr] \bigr] ] (((((]]]]]
\{ \bigl\{ \Bigl\{ \biggl\{ \Biggl\{ \dots
\Biggr\rangle \biggr\rangle \Bigr\rangle \bigr\rangle \rangle
{{{{{
\| \big\| \Big\| \bigg\| \Bigg\| \dots \Bigg| \bigg| \Big| \big| | |||||
\lfloor \bigl\lfloor \Bigl\lfloor \biggl\lfloor \Biggl\lfloor \dots
\Biggr\rceil \biggr\rceil \Bigr\rceil \bigr\rceil \ceil
\uparrow \big\uparrow \Big\uparrow \bigg\uparrow \Bigg\uparrow \dots
\Bigg\Downarrow \bigg\Downarrow \Big\Downarrow \big\Downarrow \Downarrow
\updownarrow \big\updownarrow \Big\updownarrow \bigg\updownarrow \Bigg\updownarrow \dots
\Bigg\Updownarrow \bigg\Updownarrow \Big\Updownarrow \big\Updownarrow \Updownarrow
/ \big/ \Big/ \bigg/ \Bigg/ \dots
\Bigg\backslash \bigg\backslash \Big\backslash \big\backslash \backslash
/////\\\\

Equation numbering

The templates {{NumBlk}} and {{EquationRef}} can be used to number equations. The template {{EquationNote}} can be used to refer to a numbered equation from surrounding text. For example, the following syntax:

{{NumBlk|:|<math>x^2 + y^2 + z^2 = 1</math>|{{EquationRef|1}}}}

produces the following result (note the equation number in the right margin):

Lua error: Internal error: The interpreter exited with status 127.

x2+y2+z2=1

 

 

 

 

(1)

Lua error: Internal error: The interpreter exited with status 127.

Later on, the text can refer to this equation by its number using syntax like this:

As seen in equation ({{EquationNote|1}}), blah blah blah...

The result looks like this:

As seen in equation (1), blah blah blah...

The equation number produced by {{EquationNote}} is a link that the user can click to go immediately to the cited equation.

Alphabets and typefaces

Lua error: Internal error: The interpreter exited with status 127. Texvc cannot render arbitrary Unicode characters. Those it can handle can be entered by the expressions below. For others, such as Cyrillic, they can be entered as Unicode or HTML entities in running text, but cannot be used in displayed formulas.

Greek alphabet
\Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta \Theta ABΓΔEZHΘ
\Iota \Kappa \Lambda \Mu \Nu \Xi \Omicron \Pi IKΛMNΞOΠ
\Rho \Sigma \Tau \Upsilon \Phi \Chi \Psi \Omega PΣTΥΦXΨΩ
\alpha \beta \gamma \delta \epsilon \zeta \eta \theta αβγδϵζηθ
\iota \kappa \lambda \mu \nu \xi \omicron \pi ικλμνξoπ
\rho \sigma \tau \upsilon \phi \chi \psi \omega ρστυϕχψω
\varGamma \varDelta \varTheta \varLambda \varXi \varPi \varSigma \varPhi \varUpsilon \varOmega ΓΔΘΛΞΠΣΦΥΩ
\varepsilon \digamma \varkappa \varpi \varrho \varsigma \vartheta \varphi εϝϰϖϱςϑφ
Hebrew symbols
\aleph \beth \gimel \daleth
Blackboard bold/scripts
\mathbb{ABCDEFGHI} 𝔸𝔹𝔻𝔼𝔽𝔾𝕀
\mathbb{JKLMNOPQR} 𝕁𝕂𝕃𝕄𝕆
\mathbb{STUVWXYZ} 𝕊𝕋𝕌𝕍𝕎𝕏𝕐
Boldface
\mathbf{ABCDEFGHI} 𝐀𝐁𝐂𝐃𝐄𝐅𝐆𝐇𝐈
\mathbf{JKLMNOPQR} 𝐉𝐊𝐋𝐌𝐍𝐎𝐏𝐐𝐑
\mathbf{STUVWXYZ} 𝐒𝐓𝐔𝐕𝐖𝐗𝐘𝐙
\mathbf{abcdefghijklm} 𝐚𝐛𝐜𝐝𝐞𝐟𝐠𝐡𝐢𝐣𝐤𝐥𝐦
\mathbf{nopqrstuvwxyz} 𝐧𝐨𝐩𝐪𝐫𝐬𝐭𝐮𝐯𝐰𝐱𝐲𝐳
\mathbf{0123456789} 𝟎𝟏𝟐𝟑𝟒𝟓𝟔𝟕𝟖𝟗
Boldface (Greek)
\boldsymbol{\Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta \Theta} ABΓΔEZHΘ
\boldsymbol{\Iota \Kappa \Lambda \Mu \Nu \Xi \Omicron \Pi} IKΛMNΞOΠ
\boldsymbol{\Rho \Sigma \Tau \Upsilon \Phi \Chi \Psi \Omega} PΣTΥΦXΨΩ
\boldsymbol{\alpha \beta \gamma \delta \epsilon \zeta \eta \theta} αβγδϵζηθ
\boldsymbol{\iota \kappa \lambda \mu \nu \xi \omicron \pi} ικλμνξoπ
\boldsymbol{\rho \sigma \tau \upsilon \phi \chi \psi \omega} ρστυϕχψω
\boldsymbol{\varepsilon\digamma\varkappa\varpi} εϝϰϖ
\boldsymbol{\varrho\varsigma\vartheta\varphi} ϱςϑφ
Italics (default for Latin alphabet)
\mathit{0123456789} 0123456789
Greek italics (default for lowercase Greek)
\mathit{\Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta \Theta} ABΓΔEZHΘ
\mathit{\Iota \Kappa \Lambda \Mu \Nu \Xi \Omicron \Pi} IKΛMNΞOΠ
\mathit{\Rho \Sigma \Tau \Upsilon \Phi \Chi \Psi \Omega} ΣTΥΦXΨΩ
Greek uppercase boldface italics
\boldsymbol{\varGamma \varDelta \varTheta \varLambda} ΓΔΘΛ
\boldsymbol{\varXi \varPi \varSigma \varUpsilon \varOmega} ΞΠΣΥΩ
Roman typeface
\mathrm{ABCDEFGHI} ABCDEFGHI
\mathrm{JKLMNOPQR} JKLMNOPQR
\mathrm{STUVWXYZ} STUVWXYZ
\mathrm{abcdefghijklm} abcdefghijklm
\mathrm{nopqrstuvwxyz} nopqrstuvwxyz
\mathrm{0123456789} 0123456789
Sans serif
\mathsf{ABCDEFGHI} ABCDEFGHI
\mathsf{JKLMNOPQR} JKLMNOPQR
\mathsf{STUVWXYZ} STUVWXYZ
\mathsf{abcdefghijklm} abcdefghijklm
\mathsf{nopqrstuvwxyz} nopqrstuvwxyz
\mathsf{0123456789} 0123456789
Sans serif Greek (capital only)
\mathsf{\Alpha \Beta \Gamma \Delta \Epsilon \Zeta \Eta \Theta} ABΓΔEZHΘ
\mathsf{\Iota \Kappa \Lambda \Mu \Nu \Xi \Omicron \Pi} IKΛMNΞOΠ
\mathsf{\Rho \Sigma \Tau \Upsilon \Phi \Chi \Psi \Omega} ΣTΥΦXΨΩ
Calligraphy/script
\mathcal{ABCDEFGHI} 𝒜𝒞𝒟𝒢
\mathcal{JKLMNOPQR} 𝒥𝒦𝒩𝒪𝒫𝒬
\mathcal{STUVWXYZ} 𝒮𝒯𝒰𝒱𝒲𝒳𝒴𝒵
\mathcal{abcdefghi} 𝒶𝒷𝒸𝒹𝒻𝒽𝒾
\mathcal{jklmnopqr} 𝒿𝓀𝓁𝓂𝓃𝓅𝓆𝓇
\mathcal{stuvwxyz} 𝓈𝓉𝓊𝓋𝓌𝓍𝓎𝓏
Fraktur typeface
\mathfrak{ABCDEFGHI} 𝔄𝔅𝔇𝔈𝔉𝔊
\mathfrak{JKLMNOPQR} 𝔍𝔎𝔏𝔐𝔑𝔒𝔓𝔔
\mathfrak{STUVWXYZ} 𝔖𝔗𝔘𝔙𝔚𝔛𝔜
\mathfrak{abcdefghijklm} 𝔞𝔟𝔠𝔡𝔢𝔣𝔤𝔥𝔦𝔧𝔨𝔩𝔪
\mathfrak{nopqrstuvwxyz} 𝔫𝔬𝔭𝔮𝔯𝔰𝔱𝔲𝔳𝔴𝔵𝔶𝔷
\mathfrak{0123456789} 0123456789
Small scriptstyle text
{\scriptstyle\text{abcdefghijklm}} abcdefghijklm

Mixed text faces

Feature Syntax How it looks rendered
Italicised characters (spaces are ignored) x y z xyz
Non-italicised characters \text{x y z} x y z
Mixed italics (bad) \text{if} n \text{is even} ifnis even
Mixed italics (good) \text{if }n\text{ is even} if n is even
Mixed italics (alternative: ~ or "\ " forces a space) \text{if}~n\ \text{is even} ifn is even

Color

Equations can use color with the \color command. For example,

  • {\color{Blue}x^2}+{\color{Orange}2x}-{\color{LimeGreen}1}
    x2+2x1
  • x_{1,2}=\frac{{\color{Blue}-b}\pm\sqrt{\color{Red}b^2-4ac}}{\color{Green}2a }
    x1,2=b±b24ac2a

There are several alternate notations styles

  • {\color{Blue}x^2}+{\color{Orange}2x}-{\color{LimeGreen}1} works with both texvc and MathJax
    x2+2x1
  • \color{Blue}x^2\color{Black}+\color{Orange}2x\color{Black}-\color{LimeGreen}1 works with both texvc and MathJax
    x2+2x1
  • \color{Blue}{x^2}+\color{Orange}{2x}-\color{LimeGreen}{1} only works with MathJax
    x2+2x1

Some color names are predeclared according to the following table, you can use them directly for the rendering of formulas (or for declaring the intended color of the page background).

Colors supported
Apricot Aquamarine Bittersweet Black
Blue BlueGreen BlueViolet BrickRed
Brown BurntOrange CadetBlue CarnationPink
Cerulean CornflowerBlue Cyan Dandelion
DarkOrchid Emerald ForestGreen Fuchsia
Goldenrod Gray Green GreenYellow
JungleGreen Lavender LimeGreen Magenta
Mahogany Maroon Melon MidnightBlue
Mulberry NavyBlue OliveGreen Orange
OrangeRed Orchid Peach Periwinkle
PineGreen Plum ProcessBlue Purple
RawSienna Red RedOrange RedViolet
Rhodamine RoyalBlue RoyalPurple RubineRed
Salmon SeaGreen Sepia SkyBlue
SpringGreen Tan TealBlue Thistle
Turquoise Violet VioletRed White
WildStrawberry Yellow YellowGreen YellowOrange

Color should not be used as the only way to identify something, because it will become meaningless on black-and-white media or for color-blind people. See WP:Manual of Style (accessibility)#Color.

Latex does not have a command for setting the background color. The most effective way of setting a background color is by setting a CSS styling rule for a table cell:

{| class="wikitable" align="center"
| style="background-color: gray;"      | <math>x^2</math>
| style="background-color: Goldenrod;" | <math>y^3</math>
|}

Rendered as:

x2 y3

Custom colors can be defined using:

\definecolor{myorange}{rgb}{1,0.65,0.4}\color{myorange}e^{i \pi}\color{Black} + 1 = 0
eiπ+1=0

Formatting issues

Spacing

Lua error: Internal error: The interpreter exited with status 127.

TeX handles most spacing automatically, but you may sometimes want manual control.

Feature Syntax How it looks rendered
double quad space a \qquad b ab
quad space a \quad b ab
text space a\ b a b
text space in text mode a \text{ } b a b
large space a\;b ab
medium space a\<b Not supported
small space a\,b ab
tiny space (use for multiplication of factors) ab ab
tiny space (syntax space ignored) a b ab
no space (use for multi-letter variables) \mathit{ab} ab
small negative space a\!b ab
zero-width space a\hspace{0pt}b Not supported

Automatic spacing may be broken in very long expressions (because they produce an overfull hbox in TeX):

0+1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+\cdots
0+1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+

This can be remedied by putting a pair of braces { } around the whole expression:

{0+1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+\cdots}
0+1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+17+18+19+20+

When relational symbols such as are employed as ordinary symbols, for example in bra–ket notation, additional spacing may have to be avoided:

Feature Syntax How it looks rendered
without special formatting | \uparrow \rangle |
explicit opening and closing delimiter \left| \uparrow \right\rangle |
with additional braces | {\uparrow} \rangle |
arrow as ordinary symbol | \mathord\uparrow \rangle |

Alignment with normal text flow

Because of the default CSS

img.tex { vertical-align: middle; }

an inline expression like NNexdx should look good.

If you need to align it otherwise, use <math style="vertical-align:-100%;">...</math> 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.

If you rely on this workaround, if and when the rendering on the server gets fixed in a future release, this extra manual offset will suddenly make every affected formula align incorrectly. So use it sparingly, if at all.

Unimplemented elements and workarounds

The current Mathoid–MathJax backend has the following elements unimplemented (see also MathJax's own description of differences):

\oiint and \oiiint

Elements which are not yet implemented are \oiint, namely a two-fold integral \iint () with a circular curve through the centre of the two integrals, and similarly \oiiint, a circular curve through three integrals. In contrast, \oint () exists for the single dimension (integration over a curved line within a plane or any space with higher dimension).

These elements appear in many contexts: \oiint denotes a surface integral over the closed 2d boundary of a 3d region (which occurs in much of 3d vector calculus and physical applications – like Maxwell's equations), likewise \oiiint denotes integration over the closed 3d boundary (surface volume) of a 4d region, and they would be strong candidates for the next TeX version. As such there are a lot of workarounds in the present version.

However, since no standardisation exists as yet, any workaround like this (which uses many \! symbols for backspacing) should be avoided, if possible. See below for a possibility using PNG image enforcement.

Note that \iint (the double integral) and \iiint (the triple integral) are still not kerned as they should preferably be, and are currently rendered as if they were successive \int symbols; this is not a major problem for reading the formulas, even if the integral symbols before the last one do not have bounds, so it's best to avoid backspacing "hacks" as they may be inconsistent with a possible future better implementation of integrals symbols (with more precisely computed kerning positions).

\oiint and \oiiint as PNG images

These symbols are available as PNG images which are also integrated into two templates, {{oiint}} and {{oiiint}}, which take care of the formatting around the symbols.

The templates have three parameters:

preintegral
the text or formula immediately before the integral
intsubscpt
the subscript below the integral
integrand
the text or formula immediately after the integral
Examples
  • Stokes' theorem: {{oiint | intsubscpt=<math>\scriptstyle S</math> | integrand=<math>( \nabla \times \mathbf{F} ) \cdot {\mathrm d}\mathbf{S} = \oint_{\partial S} \mathbf{F} \cdot {\mathrm d}\boldsymbol{\ell}</math>}}
\oiintS (×𝐅)d𝐒=S𝐅d
  • Ampère's law + correction: {{oiint | preintegral=<math>\oint_C \mathbf{B} \cdot {\mathrm d} \boldsymbol{\ell} = \mu_0 </math> | intsubscpt = <math>{\scriptstyle S}</math> | integrand = <math>\left ( \mathbf{J} + \epsilon_0\frac{\partial \mathbf{E}}{\partial t} \right ) \cdot {\mathrm d}\mathbf{S}</math> }}
S𝐁d=μ0 \oiintS (𝐉+ϵ0𝐄t)d𝐒
  • Continuity of 4-momentum flux (in general relativity):[3]{{oiiint | preintegral=<math>\mathbf{P} = </math> | intsubscpt=<math>\scriptstyle \partial \Omega</math> | integrand=<math>\mathbf{T} \cdot {\mathrm d}^3\boldsymbol{\Sigma}</math> <math>=0</math>}}

𝐏= \oiiintΩ 𝐓d3Σ
=0

Oriented \oiint and \oiiint as PNG images

Some variants of \oiint and \oiiint have arrows on them to indicate the sense of integration, such as a line integral around a closed curve in the clockwise sense, and higher dimensional analogues. These are not implemented in TeX on Wikipedia either, although the template {{intorient}} is available - see link for details.

Arc notation \overarc

\overarc is not yet implemented to display the arc notation. However, there exists a workaround: use \overset{\frown}{AB}, which gives

AB

For longer arcs, use {{Overarc}}:

3.142857

Triple dot \dddot

\dddot is not implemented. For a workaround use \overset{...}{x}, which gives

x....

Starred operatorname \operatorname*

The starred version of \operatorname is not currently supported. A workaround for

\operatorname*{median}_{j\,\ne\,i} X_{i,j}

is

\operatorname{\underset{\mathit{j\,\ne\,i}}{median}} X_{i,j}

Strikethrough

Strikethrough like \sout or \st is not implemented, nor is overlapping like \rlap. This means struck characters like ƛ are difficult to type, except the hardcoded \hbar. A workaround suffix for a normal strikethrough is q \!\!\!\frac{}{\ }, and for elevated strikethrough is \lambda \!\!\!^{{}^\underline{\ \ }}, which give

q ,λ  _

Formatting in \text

Formatting in \text is not supported. In other words, you can't use:

\text{\textsf{textual description of a variable}}

but have to use:

\mathsf{textual\ description\ of\ a\ variable}

More specifically, in Mathoid's MathJax, no processing is done to the contents of \text at all. The texvcjs component blocks the use of macros, but another way this behavior leaks through is in the processing of quotation marks, where the Unicode version must be used instead of `:

\text{`failed ``ascii'' quotes'},\ \text{‘okay “unicode” quotes’}
`failed ``ascii'' quotes', ‘okay “unicode” quotes’

It is currently impossible to get straight (typewriter) quotes in MathJax.

Automatic line-breaking

The current image-based implementation precludes automatic line-breaking of inline formulae after binary operators and "=" as seen in TeX. The only workaround is to not write long formulae inline.

Readers wishing to enable automatic line-breaking can try to have the browser render the MathML itself or to use an alternate in-browser renderer.

Syntax to avoid

Unicode characters

Non-ASCII Unicode characters like π work in MathML, and MathJax but not in texvc so should currently be avoided. In the long term it may become possible to use these characters.

Unicode is currently possible in \text{} due to Wikipedia's switch to Mathoid (server-side MathJax in SVG/PNG mode). However, Unicode text in math mode is still unavailable due to texvcjs considering it invalid.

Deprecated syntax

The texvc processor accepted some non-standard syntax. These should be avoided as the MathJax based renderers do not support these syntax.

The following texvc commands are now deprecated and should be avoided. This is part of an effort to update the math engine see mw:Extension:Math/Roadmap for details. A bot User:Texvc2LaTeXBot will replace this syntax on the English Wikipedia.

Lua error: Internal error: The interpreter exited with status 127.

Chemistry

Lua error: Internal error: The interpreter exited with status 127. There are three ways to render chemical sum formulas as used in chemical equations:

  • <chem>...</chem> (<ce>...</ce> is a deprecated alias for it)
  • <math chem>...</math>
  • {{chem}} and {{chem2}}

<chem>X</chem> is short for <math chem>\ce{X}</math> (where X is a chemical sum formula)

Technically, <math chem> is a math tag with the extension mhchem enabled, according to the MathJax documentation.

Wikipedia:Manual of Style/Chemistry advises avoiding the <math>/<chem> markup method when possible.

Note, that the commands \cee and \cf are disabled, because they are marked as deprecated in the mhchem LaTeX package documentation.

If the formula reaches a certain "complexity", spaces might be ignored (<chem>A + B</chem> might be rendered as if it were <chem>A+B</chem> with a positive charge). In that case, write <chem>A{} + B</chem> (and not <chem>{A} + {B}</chem> as was previously suggested). This will allow auto-cleaning of formulas once the bug will be fixed and/or a newer mhchem version will be used.

Please note that there are still major issues with mhchem support in MediaWiki. Some issues can be solved by enabling the extension using <math chem> and formatting individual items with \ce. For example,

  • <math chem>\ce{pIC_{50}} = -\log_{10} \ce{(IC_{50})}</math>
    pICA50=log10(ICA50)

Molecular and condensed formula

mhchem {{chem}} {{chem2}} Equivalent HTML
Markup Renders asLua error: Internal error: The interpreter exited with status 127.

Bonds

mhchem Equivalent {{chem}} and HTML {{chem2}}
Markup Renders asLua error: Internal error: The interpreter exited with status 127.

Charges

mhchem {{chem}} {{chem2}} Equivalent HTML
Markup Renders asLua error: Internal error: The interpreter exited with status 127.

Addition compounds and stoichiometric numbers

mhchem {{chem}} {{chem2}}
Markup Renders asLua error: Internal error: The interpreter exited with status 127.

Wiki linking

{{chem}}
Markup
25 {{chem|link=oxygen|O|2}} + 2 {{chem|link=octane|C|8|H|18}} → 16 {{chem|link=Carbon dioxide|C|O|2}} + 18 {{chem|link=water|H|2|O}}
Renders as 25 OLua error: Internal error: The interpreter exited with status 127. + 2 CLua error: Internal error: The interpreter exited with status 127.HLua error: Internal error: The interpreter exited with status 127. → 16 COLua error: Internal error: The interpreter exited with status 127. + 18 HLua error: Internal error: The interpreter exited with status 127.O
{{chem2}}
Markup
{{chem2|25 [[oxygen|O2]] + 2 [[octane|C8H18]] -> 16 [[Carbon dioxide|CO2]] + 18 [[water|H2O]]}}
Renders as Lua error: Internal error: The interpreter exited with status 127.Lua error: Internal error: The interpreter exited with status 127.Lua error: Internal error: The interpreter exited with status 127.

(Italic) Math

mhchem
Markup
<chem>{C_\mathit{x}H_\mathit{y}} + \mathit{z}O2 -> {\mathit{x}CO2} + \frac{\mathit{y}}{2}H2O</chem>
Renders as Failed to parse (syntax error): {\displaystyle \ce{{C_\mathit{x}H_\mathit{y}} + \mathit{z}O2 -> {\mathit{x}CO2} + \frac{\mathit{y}}{2}H2O}}
{{chem}}
Markup
{{chem|C|''x''|H|''y''}} + ''z''{{chem|O|2}} → ''x''{{chem|C|O|2}} + {{frac|''y''|2}}{{chem|H|2|O}}
Renders as CLua error: Internal error: The interpreter exited with status 127.HLua error: Internal error: The interpreter exited with status 127. + zOLua error: Internal error: The interpreter exited with status 127.xCOLua error: Internal error: The interpreter exited with status 127. + y2HLua error: Internal error: The interpreter exited with status 127.O

Oxidation states

mhchem
Markup
<chem>Fe^{II}Fe^{III}2O4</chem>
Renders as FeAIIFeAIIIA2OA4
{{chem}} with ‎<sup>...‎</sup>
Markup
{{chem|Fe|<sup>II</sup>|Fe|<sup>III</sup>|2|O|4}}
Renders as FeIIFeIIILua error: Internal error: The interpreter exited with status 127.OLua error: Internal error: The interpreter exited with status 127.
{{chem2}}
Markup
{{chem2|Fe^{II}Fe^{III}2O4}}
Renders as Lua error: Internal error: The interpreter exited with status 127.Lua error: Internal error: The interpreter exited with status 127.Lua error: Internal error: The interpreter exited with status 127.

Greek characters

mhchem Equivalent {{chem}} and HTML {{chem2}}
Markup Renders asLua error: Internal error: The interpreter exited with status 127.

Isotopes

mhchem Equivalent {{chem}} and HTML
Markup Renders asLua error: Internal error: The interpreter exited with status 127.

States

States subscripting is not IUPAC recommendation.

mhchem {{chem}}
Markup Renders asLua error: Internal error: The interpreter exited with status 127.

Precipitate

mhchem
Markup
<chem>Ba^2+ + SO4^{2-} -> BaSO4(v)</chem>
Renders as BaA2++SOA4A2BaSOA4(v)
{{chem}}
Markup
{{chem|Ba|2+}} + {{chem|S|O|4|2-}} → {{chem|Ba|S|O|4}}↓
Renders as BaLua error: Internal error: The interpreter exited with status 127. + SOLua error: Internal error: The interpreter exited with status 127.BaSOLua error: Internal error: The interpreter exited with status 127.
{{chem2}}
Markup
{{chem2|Ba(2+) + SO4(2-) -> BaSO4↓}}
Renders as Lua error: Internal error: The interpreter exited with status 127.Lua error: Internal error: The interpreter exited with status 127.Lua error: Internal error: The interpreter exited with status 127.
Equivalent HTML
Markup
Ba<sup>2+</sup> + SO<sub>4</sub><sup>2&minus;</sup> &rarr; BaSO<sub>4</sub>&darr;
Renders as Ba2+ + SO42− → BaSO4

Reaction arrows

Markup Renders asLua error: Internal error: The interpreter exited with status 127.

Comparison of arrow symbols

Markup Renders asLua error: Internal error: The interpreter exited with status 127.

Further examples using ordinary LaTeX tags

<math chem>\begin{align}
\overbrace{\ce{2Fe3O4}}^{\text{magnetite}} + \ce{1/2 O2 ->}\ &{\color{Brown}\overbrace{\ce{3(\lambda{-}Fe2O3)}}^{\text{maghemite}}}\\
\underbrace{\ce{2Fe3O4}}_{\text{magnetite}} + \ce{1/2 O2 ->}\ &{\color{Red}\underbrace{\ce{3(\alpha{-}Fe2O3)}}_{\text{hematite}}}
\end{align}</math>
2FeA3OA4magnetite+12OA2 3(λ-FeA2OA3)maghemite2FeA3OA4magnetite+12OA2 3(α-FeA2OA3)hematite

To align the equations or color them, use <math chem> and \ce.

Commutative diagrams

A sample commutative diagram, created in the manner described

To make a commutative diagram, there are three steps:

  1. write the diagram in TeX
  2. convert to SVG
  3. upload the file to Wikimedia Commons

Diagrams in TeX

Xy-pic[lower-alpha 1] (online manual) is the most powerful and general-purpose diagram package in TeX. Diagrams created using it can be found at Commons: Category:Xy-pic diagrams.

Simpler packages include:

The following is a template for Xy-pic:

\documentclass[border=10pt]{standalone} % Crop to size, remove page numbers, leave margin
\usepackage[all]{xy} % Loading the XY-Pic package
\begin{document}
\SelectTips{eu}{} % Euler (shorter) arrowheads (tips)
$$
\xymatrix{
%%% Diagram goes here %%%
}
$$
\end{document}

Using postscript drivers may in some cases give smoother curves and will handle fonts differently:

\usepackage[all, ps, dvips]{xy}

Convert to SVG

Once you have produced your diagram in LaTeX (or TeX), you can convert it to an SVG file using the following sequence of commands:

pdflatex file.tex
pdf2svg file.pdf file.svg

The pdfcrop and pdf2svg utilities are needed for this procedure. You can alternatively use pdf2svg from PDFTron for the last step.

If you do not have pdfTeX (which is unlikely) you can use the following commands to replace the first step (TeX → PDF):

latex file.tex
dvipdfm file.dvi

In general, you will not be able to get anywhere with diagrams without TeX and Ghostscript, and the inkscape program is a useful tool for creating or modifying your diagrams by hand. There is also a utility pstoedit which supports direct conversion from Postscript files to many vector graphics formats, but it requires a non-free plugin to convert to SVG, and regardless of the format, this editor has not been successful in using it to convert diagrams with diagonal arrows from TeX-created files.

These programs are:

Upload the file

Lua error: Internal error: The interpreter exited with status 127. Lua error: Internal error: The interpreter exited with status 127.

As the diagram is your own work, upload it to Wikimedia Commons, so that all projects (notably, all languages) can use it without having to copy it to their language's Wiki. (If you've previously uploaded a file to somewhere other than Commons, to Commons.)

Check size
Before uploading, check that the default size of the image is neither too large nor too small by opening in an SVG application and viewing at default size (100% scaling), otherwise adjust the -y option to dvips.
Name
Make sure the file has a meaningful name.
Upload
Login to Wikimedia Commons, then upload the file; for the Summary, give a brief description.

Now go to the image page and add a description, including the source code, using this template:

{{Information
 |description =
     {{en|1= '''Description [[:en:Link to WP page|topic]]'''}}
 |source = {{own}}, created as per:
  [[:en:Help:Displaying a formula#Commutative diagrams]];
  source code below.
 |date = '''The Creation Date, like 1999-12-31'''
 |author = '''[[User:YourUserName|Your Real Name]]'''
 |permission = {{self|PD-self '''(or [[commons:Licensing#Well-known licenses|other license]])'''
     |author = '''[[User:YourUserName|Your Real Name]]'''}}
}}

==TeX source==

<syntaxhighlight lang="latex">
 % TeX source here
</syntaxhighlight>
 
[[Category:Commutative diagrams]]
[[Category:Xy-pic diagrams]]
[[Category:Images with LaTeX source code]]
Source code
  • Include the source code in the image page, in the Source section of the {{Information}} template, so that the diagram can be edited in future.
  • Include the complete .tex file, not just the fragment, so future editors do not need to reconstruct a compilable file.
  • You may optionally make the source code section collapsible, using the {{cot}} or {{cob}} templates.
  • (Don't include it in the Summary section, which is just supposed to be a summary.)
License
The most common license for commutative diagrams is PD-self; some use PD-ineligible, especially for simple diagrams, or other licenses. Please do not use the GFDL, as it requires the entire text of the GFDL to be attached to any document that uses the diagram.
Description
If possible, link to a Wikipedia page relevant to the diagram. (The 1= is necessary if you use nest templates within the description, and harmless otherwise.)
Category
Include [[Category:Commutative diagrams]], so that it appears in commons:Category:Commutative diagrams. There are also subcategories, which you may choose to use.
Include image
Now include the image on the original page via [[File:Diagram.svg]]

Examples

A sample conforming diagram is commons:File:PSU-PU.svg.

Semantics and links

While links from formulas using LaTeX macros such as \href or \url or are currently not supported, one can link individual math expressions to wikidata items to explain the meaning of individual terms of mathematical expressions. For example,

Markup
<math qid=Q35875>E=mc^2</math>
Renders as E=mc2

links to a special page that displays additional information on that formulas. To change the information shown on the specialpage navigate to the wikidata item linked at the bottom of the special page. Use the has part property to link parts of the equation to other wikidata items with their respective Wikipedia Articles. This is not limited to individual identifiers, but can also be used to link more complex terms.

A condensed version of that specialpage, might be shown in the future as popup phab:T239357.

Examples of implemented TeX formulas

Quadratic polynomial

Markup
<math>ax^2 + bx + c = 0</math>
Renders as ax2+bx+c=0

Quadratic formula

Markup
<math>x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}</math>
Renders as x=b±b24ac2a

Tall parentheses and fractions

Markup
<math>2 = \left( \frac{\left(3-x\right) \times 2}{3-x} \right)</math>
Renders as 2=((3x)×23x)
Markup
<math>S_{\text{new}} = S_{\text{old}} - \frac{ \left( 5-T \right) ^2} {2}</math>
Renders as Snew=Sold(5T)22

Integrals

Markup
<math>\int_a^x \int_a^s f(y)\,dy\,ds = \int_a^x f(y)(x-y)\,dy</math>
Renders as axasf(y)dyds=axf(y)(xy)dy
Markup
<math>\int_e^{\infty}\frac {1}{t(\ln t)^2}dt = \left. \frac{-1}{\ln t} \right\vert_e^\infty = 1</math>
Renders as e1t(lnt)2dt=1lnt|e=1

Matrices and determinants

Markup
<math>\det(\mathsf{A}-\lambda\mathsf{I}) = 0</math>
Renders as det(AλI)=0

Summation

Markup
<math>\sum_{i=0}^{n-1} i</math>
Renders as i=0n1i
Markup
<math>\sum_{m=1}^\infty\sum_{n=1}^\infty\frac{m^2 n}{3^m\left(m 3^n + n 3^m\right)}</math>
Renders as m=1n=1m2n3m(m3n+n3m)

Differential equation

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

Complex numbers

Markup
<math>|\bar{z}| = |z|,
|(\bar{z})^n| = |z|^n,
\arg(z^n) = n \arg(z)</math>
Renders as |z¯|=|z|,|(z¯)n|=|z|n,arg(zn)=narg(z)

Limits

Markup
<math>\lim_{z\to z_0} f(z)=f(z_0)</math>
Renders as limzz0f(z)=f(z0)

Integral equation

Markup
<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>
Renders as ϕn(κ)=14π2κ20sin(κR)κRR[R2Dn(R)R]dR

Example

Markup
<math>\phi_n(\kappa) =
0.033C_n^2\kappa^{-11/3},\quad
\frac{1}{L_0}\ll\kappa\ll\frac{1}{l_0}</math>
Renders as ϕn(κ)=0.033Cn2κ11/3,1L0κ1l0

Continuation and cases

Markup
<math>f(x) =
  \begin{cases}
    1 & -1 \le x < 0 \\
    \frac{1}{2} & x = 0 \\
    1 - x^2 & \text{otherwise}
  \end{cases}</math>
Renders as f(x)={11x<012x=01x2otherwise

Prefixed subscript

Markup
 <math>{}_pF_q(a_1,\dots,a_p;c_1,\dots,c_q;z)
= \sum_{n=0}^\infty
\frac{(a_1)_n\cdots(a_p)_n}{(c_1)_n\cdots(c_q)_n}
\frac{z^n}{n!}</math>
Renders as pFq(a1,,ap;c1,,cq;z)=n=0(a1)n(ap)n(c1)n(cq)nznn!

Fraction and small fraction

Markup
<math>\frac{a}{b}\ \tfrac{a}{b}</math>
Renders as ab ab

Area of a quadrilateral

Markup
<math>S=dD\sin\alpha</math>
Renders as S=dDsinα

Volume of a sphere-stand

Markup
<math> V = \frac{1}{6} \pi h \left [ 3 \left ( r_1^2 + r_2^2 \right ) + h^2 \right ] </math>
Renders as V=16πh[3(r12+r22)+h2]

Multiple equations

The altered newline code \\[0.6ex] below adds a vertical space between the two lines of length equal to 0.6 times the height of a single 'x' character.

Markup
<math>\begin{align}
u & = \tfrac{1}{\sqrt{2}}(x+y) \qquad & x &= \tfrac{1}{\sqrt{2}}(u+v) \\[0.6ex]
v & = \tfrac{1}{\sqrt{2}}(x-y) \qquad & y &= \tfrac{1}{\sqrt{2}}(u-v)
\end{align}</math>
Renders as u=12(x+y)x=12(u+v)v=12(xy)y=12(uv)

See also

References

Footnotes

  1. ^ Use the barr option for commutative diagrams, e.g., \usepackage[cmtip,all,barr]{xy}.

Lua error: Internal error: The interpreter exited with status 127.Lua error: Internal error: The interpreter exited with status 127.

Citations

  1. ^ Lua error: Internal error: The interpreter exited with status 127.
  2. ^ Lua error: Internal error: The interpreter exited with status 127.
  3. ^ Lua error: Internal error: The interpreter exited with status 127.

Lua error: Internal error: The interpreter exited with status 127.

External links

Lua error: Internal error: The interpreter exited with status 127.

Lua error: Internal error: The interpreter exited with status 127. Lua error: Internal error: The interpreter exited with status 127. Lua error: Internal error: The interpreter exited with status 127.