MediaWiki renders mathematical equations using a combination of html markup and a variant of LaTeX.
The version of LaTeX used is a subset of AMS-LaTeX markup, a superset of LaTeX markup which is in turn a superset of TeX markup, for mathematical formulae. Only a limited part of the full TeX language is supported; see below for details.
By default SVG images with non-visible MathML are generated. The older PNG images can be set via user preferences. On some browsers like Firefox, it is possible to use MathML for display via extensions; see the main extension page at mw:Extension:Math for details. Client side MathJax is no longer supported.
Video Help:Displaying a formula
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>
. A script will be used to replace all <ce>
with <chem>
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 adding a prefix 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 . 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 . For a stretchable version use \widehat{abc}
giving . 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:
Environments supported by Wikipedia include matrix, align, etc. See below.
Rendering
By default, the PNG images are rendered black on white, with a transparent background. On darker backgrounds, the characters may show white edges. To remove these, match the PNG background color with the background color of the page using \pagecolor
. However, black text on a dark background is hard to read and should be avoided altogether where possible.
The 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; a work-around is described in the "Alignment with normal text flow" section below. The css selector of the images is img.tex
.
The alt text of the PNG images, which is displayed to visually impaired and other readers 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>
. You can override this by explicitly specifying an alt
attribute for the math
element. For example, <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 popup text when the hovering over the PNG image, for example <math title="pi">\pi</math>
generates an image whose popup text is "pi".
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
. You can also define new function names using \operatorname{...}
. For example, \text{abc}
gives . \operatorname{...}
provides spacing before and after the operator name when appropriate, as when a\operatorname{sn}b
is rendered as (with space to the left and right of "sn") and a\operatorname{sn}(b+c)
as (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
- .
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. See also mw:Extension:Math#Purging pages that contain equations for more details.
Maps Help:Displaying a formula
TeX vs HTML
TeX markup is not the only way to produce special characters. As this comparison table shows, sometimes similar results can be achieved in HTML using Template:Math. See also Help:Special characters.
The codes on the left produce the symbols on the right, but the latter can also be put directly in the wikitext, except for '='.
The project has not reached a consensus on HTML and TeX because each has advantages in some situations.
Native MathML
The default MathML/SVG renderer option, selectable through My Preferences - Appearance - Math, generates hidden MathML code. This code can be used by screen readers and other assistive technology. To actually display the MathML in Firefox you can install the Native MathML extension, or simply copy its CSS rules to your Wikipedia user stylesheet. In either case, you must have fonts that support MathML installed on your system. For copy-paste support also install MathML Copy. Details on using MathML in other systems can be found at mw:Extension:Math.
Formatting using TeX
Functions, symbols, special characters
For a little more semantics on these symbols, see the brief TeX Cookbook.
Larger expressions
Subscripts, superscripts, integrals
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; i.e., there will be no new paragraph for the equation and the operators will be rendered to consume only a small amount of vertical space.
Example
The sum 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>
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.
Example
The equation
It was entered as
<math display="block">\text{geometric series:}\quad \sum_{i=0}^\infty 2^{-i}=2 </math>
Technical implementation
Technically it will add the command \displaystyle will be added to the user input, if the user input does not 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 current behavior is preserved. That means all equations are rendered in display style but not using a new paragraph.
Example
The sum converges to 2.
The next line-width is disturbed by large operators.
The code for the math example reads:
<math>\sum_{i=0}^\infty 2^{-i}</math>
The equation
It was entered as
<math>\text{geometric series:}\quad \sum_{i=0}^\infty 2^{-i}=2 </math>
Fractions, matrices, multilines
Parenthesizing big expressions, brackets, bars
You can use various delimiters with \left and \right:
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):
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
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.
Mixed text faces
Color
Equations can use color with the \color
command. For example,
{\color{Blue}x^2}+{\color{Orange}2x}-{\color{LimeGreen}1}
x_{1,2}=\frac{{\color{Blue}-b}\pm\sqrt{\color{Red}b^2-4ac}}{\color{Green}2a }
There are several alternate notations styles
{\color{Blue}x^2}+{\color{Orange}2x}-{\color{LimeGreen}1}
works with both texvc and MathJax\color{Blue}x^2\color{Black}+\color{Orange}2x\color{Black}-\color{LimeGreen}1
works with both texvc and MathJax\color{Blue}{x^2}+\color{Orange}{2x}-\color{LimeGreen}{1}
only works with MathJax
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).
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 of setting a background color is by setting a CSS styling rules for a table cell
{| class="wikitable" align="center" | style="background: gray;" | <math>\pagecolor{Gray}x^2</math> | style="background: Goldenrod;" | <math>\pagecolor{Goldenrod}y^3</math> |}
Rendered as
The \pagecolor{Goldenrod}
command is necessary for the Texvc renderer to use the correct anti-aliasing around the edges of the semi-transparent images. Without the command a default (white) background color is used -- below are shown the results displayed on non-white background.
{| class="wikitable" align="center" | style="background: gray;" | <math>x^2</math> | style="background: Goldenrod;" | <math>y^3</math> |}
Custom colours can be defined using
Formatting issues
Spacing
TeX handles most spacing automatically, but you may sometimes want manual control.
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
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}
Alignment with normal text flow
Because of the default CSS
an inline expression like 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
\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:
<math>\oiint_{\scriptstyle S}( \nabla \times \mathbf{F} ) \cdot {\rm d}\mathbf{S} = \oint_{\partial S} \mathbf{F} \cdot {\rm d}\boldsymbol{\ell} </math>
- Ampère's law + correction:
{{oiint | preintegral=<math>\oint_C \mathbf{B} \cdot {\rm 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 {\rm d}\mathbf{S}</math> }}
- Continuity of 4-momentum flux (in general relativity):
<math display=block> \mathbf{P} = \oiiint_{\scriptstyle \partial \Omega} \mathbf{T} \cdot {\rm d}^3\boldsymbol{\Sigma} = 0 </math>
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
Triple dot \dddot
\dddot
is not implemented. For a workaround use \overset{...}{x}
, which gives .
Starred operatorname \operatorname*
The starred version of \operatorname
is not currently supported. A workaround for
is
Syntax to avoid
The texvc processor accepts some non-standard syntax. These should be avoided as the MathJax based renderers do not support these syntax.
Percentages
Texvc accepts %
for representing percentages. This causes an error with MathJax and should be replaced with \%
in all renderers.
\textrm
In texvc spaces need to be represented inside the \textrm environment using \,
\
and normal spaces are ignored i.e. \textrm{A\,B C}
would render as A BC. In mathjax \textrm is an alias for \text which is renders its argument as normal text, hence \textrm{A\,B C}
renders as A\,B C. To ensure compatibility between versions alway use the \text environment: \text{A B C}
.
Unicode characters
Non-ASCII Unicode characters like ? work in MathML, and MathJax but not in texvc so should be avoided.
Chemistry
There are three ways to render chemical sum formulae as used in chemical equations:
<chem>...</chem>
(more recommended for chemical equation than the alias<ce>...</ce>
)<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.
Note, that the commands \cee
and \cf
are disabled, because they are marked as deprecated in the mhchem LaTeX package documentation.
Please note that there are still major issues with mhchem support in MediaWiki. Some issue 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>
Molecular and condensed formula
Bonds
Charges
Addition compounds and stoichiometric numbers
Wiki linking
(Italic) Math
Oxidation States
Greek characters
Isotopes
States
States Subscripting is not IUPAC recommendation.
Precipitate
Reaction arrows
Comparison of arrow symbols
To align the equations or color them, use <math chem>
and \ce
.
Commutative diagrams
To make a commutative diagram, there are three steps:
- write the diagram in TeX
- convert to SVG
- upload the file to Wikimedia Commons
Diagrams in TeX
Xy-pic (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:
- AMS's amscd
- Paul Taylor's diagrams
- François Borceux Diagrams
The following is a template for Xy-pic:
Using postscript drivers may in some cases give smoother curves and will handle fonts differently:
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:
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):
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:
- a working TeX distribution, such as TeX Live
- Ghostscript
- pstoedit
- Inkscape
Upload the file
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 todvips
. - 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:
- 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}}
/{{cob}}
templates. - (Don't include it in the Summary section, which is just supposed to be a summary.)
- Include the source code in the image page, in the Source section of the
- License
- The most common license for commutative diagrams is
PD-self
; some usePD-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.
Examples of implemented TeX formulas
Quadratic polynomial
Quadratic formula
Tall parentheses and fractions
Integrals
Matrices and determinants
Summation
Differential equation
Complex numbers
Limits
Integral equation
Example
Continuation and cases
Prefixed subscript
Fraction and small fraction
Area of a quadrilateral
Volume of a sphere-stand
Multiple equations
See also
- Typesetting of mathematical formulae
- Help:Score (a tag for tablatures, "sheet music") and Help:Musical symbols
- Table of mathematical symbols
- WP:Rendering math
- mw:Extension:Blahtex, or blahtex: a LaTeX to MathML converter for Wikipedia
- commons:Category:Images which should use TeX
References
Footnotes
Citations
External links
- A LaTeX tutorial
- LaTex online editor
- Doob, Michael, A Gentle Introduction to TeX: A Manual for Self-study (PDF) . A paper introducing TeX -- see page 39 onwards for a good introduction to the maths side of things.
- Oetiker, Tobias; Partl, Hubert; Hyna, Irene; Schlegl, Elisabeth (December 13, 2009), The Not So Short Introduction to LaTeX 2? (PDF) (4.27 ed.) . A paper introducing LaTeX -- skip to page 49 for the math section. See page 63 for a complete reference list of symbols included in LaTeX and AMS-LaTeX.
- The Comprehensive LaTeX Symbol List--symbols not found here may be documented there.
- Long list of many symbols
- short list of common symbols
- The esint package for closed double integrals
- The esint package for closed double integrals
- cancel package homepage and PDF documentation
- AMS-LaTeX guide.
- A set of public domain fixed-size math symbol bitmaps.
- List of mathematical symbols with their Unicode characters and their LaTeX commands
- MathML: A product of the W3C Math working group, is a low-level specification for describing mathematics as a basis for machine-to-machine communication
Source of article : Wikipedia