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.

However, one can also use parser function #tag: {{#tag:math|...}}; this is more versatile: the wikitext at the dots is first expanded before interpreting the result as TeX code. Thus it can contain parameters, variables, parser functions and templates. Note however that with this syntax double braces in the TeX code must have a space in between, to avoid confusion with their use in template calls etc. Also, to produce the character "|" inside the TeX code, use {{!}}.

In TeX, as in HTML, extra spaces and newlines are ignored.

Rendering

By default, the PNG images are black on white (not transparent), but since bug 8 was fixed (see rev:59550) these colors can be customized for each formula. 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 (see bug 32694). 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 π{\displaystyle {\sqrt {\pi }}} whose alt text is "Square root of pi".

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 \text, \mbox, or \mathrm. You can also define new function names using \operatorname{...}. For example, <math>\text{abc}</math> gives abc{\displaystyle {\text{abc}}}. This does not work for special characters, they are ignored unless the whole <math> expression is rendered in HTML:

TeX and 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).

The project has settled on both HTML and TeX because each has advantages in some situations.

Pros of HTML

Formulas in HTML behave more like regular text. In-line HTML formulae always align properly with the rest of the HTML text and, to some degree, can be cut-and-pasted (this is not a problem if TeX is rendered using MathJax, and the alignment should not be a problem for PNG rendering once bug 32694 is fixed).

The formula’s background and font size match the rest of HTML contents (this can be fixed on TeX formulas by using the commands \pagecolor and \definecolor) and the appearance respects CSS and browser settings while the typeface is conveniently altered to help you identify formulae.

Pages using HTML code for formulae use less data to transmit, which is important to users with slow or capped Internet connections (e.g. those using dialup or mobile Internet connections which are either slow or have a data cap).

The display of a formula entered using mathematical templates can be conveniently altered by modifying the templates involved; this modification will affect all relevant formulae without any manual intervention.

The HTML code, if entered diligently, will contain all semantic information to transform the equation back to TeX or any other code as needed. It can even contain differences TeX does not normally catch, e.g. {{math|''i''}} for the imaginary unit and {{math|<var>i</var>}} for an arbitrary index variable.

Formulae using HTML code will render as sharp as possible no matter what device is used to render them.

Pros of TeX

On the other hand, if you encode the same formula as "{{math|<var>x</var>}}", you get the same visual result x and no information is lost. This requires diligence and more typing that could make the formula harder to understand as you type it. However, since there are far more readers than editors, this effort is worth considering if no other rendering options are available (such as MathJax, which was requested on bug 31406 for use on Wikimedia wikis and is being implemented on Extension:Math as a new rendering option).

One consequence of point 1 is that TeX code can be transformed into HTML, but not vice-versa.[1] 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 is true that the current situation is not ideal, but that is not a good reason to drop information/contents. It is more a reason to help improve the situation.

Another consequence of point 1 is that TeX can be converted to MathML (e.g. by MathJax) for browsers which support it, thus keeping its semantics and allowing the rendering to be better suited for the reader’s graphic device.

TeX is the preferred text formatting language of most professional mathematicians, scientists, and engineers. It is easier to persuade them to contribute if they can write in TeX.

TeX has been specifically designed for typesetting formulae, so input is easier and more natural if you are accustomed to it, and output is more aesthetically pleasing if you focus on a single formula rather than on the whole containing page.

Once a formula is done correctly in TeX, it will render reliably, whereas the success of HTML formulae is somewhat dependent on browsers or versions of browsers. Another aspect of this dependency is fonts: the serif font used for rendering formulae is browser-dependent and it may be missing some important glyphs. While the browser generally capable to substitute a matching glyph from a different font family, it need not be the case for combined glyphs (compare ‘ a̅ ’ and ‘ a̅ ’).

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 software. This does not hold for HTML formulae, which can easily end up being rendered wrongly or differently from the editor’s intentions on a different browser.[2]

TeX formulae, by default, render larger and are usually more readable than HTML formulae and are not dependent on client-side browser resources, such as fonts, and so the results are more reliably WYSIWYG.

While TeX does not assist you in finding HTML codes or Unicode values (which you can obtain by viewing the HTML source in your browser), cutting and pasting from a TeX PNG in Wikipedia into simple text will return the LaTeX source.

^ The entity support problem is not limited to mathematical formulae though; it can be easily solved by using the corresponding characters instead of entities, as the character repertoire links do, except for cases where the corresponding glyphs are visually indiscernible (e.g. &ndash; for ‘–’ and &minus; for ‘−’).

In some cases it may be the best choice to use neither TeX nor the html-substitutes, but instead the simple ASCII symbols of a standard keyboard (see below, for an example).

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.

Note that 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 en:Wikipedia:Manual of Style#Color coding.

Formatting issues

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

ab{\displaystyle a\qquad b}

quad space

a \quad b

ab{\displaystyle a\quad b}

text space

a\ b

ab{\displaystyle a\ b}

text space without PNG conversion

a \mbox{ } b

ab{\displaystyle a{\mbox{ }}b}

large space

a\;b

ab{\displaystyle a\;b}

medium space

a\>b

[not supported]

small space

a\,b

ab{\displaystyle a\,b}

no space

ab

ab{\displaystyle ab\,}

small negative space

a\!b

ab{\displaystyle a\!b}

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

Alignment with normal text flow

Due to the default css

img.tex { vertical-align: middle; }

an inline expression like ∫−NNexdx{\displaystyle \int _{-N}^{N}e^{x}\,dx} 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.

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.

pdflatex and the pdfcrop and pdf2svg utilities are needed for this procedure.

If you do not have these programs, you can also use the commands

latex file.tex
dvipdfm file.dvi

to get a PDF version of your diagram.

Programs

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.

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, transwiki it 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.

Include the source code in the image page, in a LaTeX source section, 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.

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.

Bug reports

Future

In the future, once the MathJax option which was added to the Math extension is stable enough, it may be enabled on Wikimedia wikis (per bug 31406) as a better alternative for the PNG rendering of TeX formulas. MathJax is a JavaScript library for inline rendering of mathematical formulae, and can be used to translate LaTeX into MathML for direct interpretation by the browser.