Extension:Math

The Math extension provides support for rendering mathematical formulas on-wiki via texvc and other backends. An overview of what can currently be done with this extension is found at the English Wikipedia's documentation.

Math output modes
The choice of the rendering mode heavily depends on the amount of math the wiki uses as well as the possibility to install required prerequisites and dependencies.

Client-side rendering, e.g. via JavaScript in the users web browser, is slow.

Server-side rendering can be done at on the wiki's host server or using a public rendering host, e.g. latexml.mathweb.org.

There are the following possible configuration options:


 * without command-line access to the server
 * no rendering (MW_MATH_SOURCE)
 * client-side rendering with [http://www.mathjax.org/ MathJax] (MW_MATH_MATHJAX)
 * server-side rendering with mathoid>Special:MyLanguage/Mathoid|Mathoid (MW_MATH_MATHML), which is the rendering mode used on Wikimedia projects in future.
 * server-side rendering with [http://math.nist.gov/~BMiller/LaTeXML/manual/intro/ LaTeXML] (MW_MATH_LATEXML)


 * with command-line access to the server
 * server-side rendering with LaTeX (MW_MATH_PNG)

If multiple modes are enabled, logged in users can set a personal preference in the appearance pane of their user preferences page.

A quick note about texvc
The TeX validator and converter texvc takes formulae and produces formatted output in HTML, MathML, and PNG images. Input data is parsed and scrutinized for safety.

On a shared host with no shell access
Use MathJax.

On a shared host with a limited shell access
On a shared host with limited command line access, (e.g. under jailshell) compiling with all the dependencies won't be possible. As a workaround compiling texvc>Special:MyLanguage/texvc|texvc will have to be done offline. Use  to to identify the OS of the shared host, and install the same offline. This can be done via a USB boot drive, live CD, virtual machine on a desktop PC or whichever you prefer. Then for example in Ubuntu, all dependencies can be installed using:

Get the Math extension and make texvc etc.:

Upload the  archive to the host and extract the required files  into the $IP/extensions/Math folder.

To test texvc is working (see texvc usage), e.g.:

On a host with full shell access
Compile texvc and texvccheck:

On a (virtual) private server
In some Linux distributions texvc and texvccheck come already built in the MediaWiki Math packages.

See compare>Special:MyLanguage/Comparison of extensions in distributions|Comparison of extensions in distributions.

For example in Debian or Ubuntu to install it and any other packages on which it depends: (MediaWiki, Math, texvc and texvccheck ) or (just texvc)

Client-side rendering with MathJax
From 1.19/1.20, the Math extension supports rendering via MathJax, a client-side JavaScript library for parsing latex or mathml code and producing in-browser representation using the browser's native support for HTML+CSS, or MathML, or SVG.

This can render math expressions more sharply (using subpixel antialiasing) and larger (scaling up for zoomed view, printing, or high-resolution screens).

Set $wgUseMathJax to enable MathJax rendering mode; it is still somewhat experimental. Users will have a check box on their preferences that will enable MathJax, or set MathJax to the default mode as shown below.


 * Settings (Math 1.1 // MW 1.19 - 1.22)


 * Settings (Math 1.2 // MW 1.23+)

See also ext-MathJaxMenu>Special:MyLanguage/Extension:Math/MathJaxMenu|How to modify the MathJax contextual menu.

To install MathJax on the same server as the wiki, download and unpack the latest distribution into $IP/extensions/MathJax. Add to LocalSittings.php the line $wgMathJaxUrl = '$IP/extensions/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML';

MathJax localization
MathJax is an upstream project, but its user interface is translated at translatewiki.net, the same website where MediaWiki and its extension are translated. Translations made there are exported to the MathJax source code, and they will be used in the MediaWiki extension, too. For more information about translating MathJax's menus see translatewiki:Translating:MathJax.

Server-side rendering with Mathoid
Beginning from Math 1.2 // MW 1.23+ you can use a Mathoid server that uses MathJax to convert texvc input on the server side to MathML+SVG rendering. Mathoid is the rendering mode that is going to be used on future Wikipedia. For that the following settings are recommended:

Check out mathoid>Special:MyLanguage/Mathoid|Mathoid to find instructions how to run your own Mathoid server. After enabling the MathML rendering mode you have to run the database update script again to create the required table.

Server-side rendering with LaTeXML
A convenient option to render LaTeX is to use the LaTeXML web service. This service converts LaTeX to high quality MathML.


 * Settings (MW 1.22) most or all of the 1.23+ settings also work


 * Settings (Math 1.2 // MW 1.23+)

A short guide to install LaTeXML on your own server can be found here: [http://www.formulasearchengine.com/node/3 Install LaTeXML]

After enabling the LaTeXML rendering mode you have to run the database update script again to create the required table.

Server-side rendering with LaTeX
To use your local webserver (default in Math 1.0, 1.1, is now deprecated) to convert the texvc input to PNG images via a local LaTeX installation and OCAML based translation from texvc to LaTeX you have to install texvc>Special:MyLanguage/texvc|texvc.

Installation of texvc

 * 1) If MediaWiki does not have write permissions to , see config items below  ,   and   you will have to grant them with e.g. *)
 * 2) Compile texvc
 * Install the required prerequisites and dependencies
 * Switch the directory
 * Compile texvc
 * Compile texvc
 * Compile texvc

To make the rendering of mathematical formulas possible with the Collection extension texvc must be installed in PATH (see the alternative installation methods just below)


 * Alternatively install the mediawiki math packages
 * 1) (MediaWiki, Math, texvc and texvccheck) or
 * 2) (just texvc)

List of all configuration settings
The following variables can be defined in LocalSettings.php after calling :

Purging pages that contain equations
Specifying the URL-parameter action=purge does not force the math equation to re-render the math tags. If a complete re-rendering of the math tags is desired the URL-parameter action=purge&mathpurge=true has to be passed. Be aware that this might cause side effects with other pages since the math extension uses the hash of the input TeX-input-string as the caching key. e.g. if you would force the re-rending with mathpurge option for a page containing the equation $E=mc^2$, the new rendering result would be used on all other pages containing $E=mc^2$ after the individual page caches are invalidated.

Error reporting
If something is wrong with the math extension you can report that at [https://bugzilla.wikimedia.org/enter_bug.cgi?format=guided&product=MediaWiki%20extensions&component=Math bugzilla]. In addition you should check how your problem relates to the automated unit tests that are generated from the page math-test>Special:MyLanguage/Extension:Math/CoverageTest|CoverageTest.

MathJax errors
MathJax has more bugs than latex. So please check if it's an MediaWiki Bug or a [https://github.com/mathjax/mathjax/issues</> MathJax problem]. If it's a MathJax problem that has been fixed you might consider to port the change to MediaWiki version of MathJax. Therefore a [<tvar|dev-env>http://formulasearchengine.com/review</> development environment] is required. Just cherrypick the change from MathJax and apply it to the modules/MathJax folder in the Math extension. Afterwards you can submit your change for review.

CSS for the MathML with SVG fallback mode
$$\sum_{i=0}^n x$$/* By default, MathML is exposed to accessibility tools and displayed in Gecko browsers. You can force visual rendering with the following style: */ .mwe-math-mathml-a11y { clip: auto; overflow: visible; position: static; width: auto; height: auto; opacity: 1; } .mwe-math-fallback-image-inline, .mwe-math-fallback-image-display { display: none !important; } /* To force the SVG fallback in Gecko browsers, use the following style: */ span.mwe-math-mathml-inline, div.mwe-math-mathml-display { display: none !important; } span.mwe-math-mathml-inline + .mwe-math-fallback-image-inline { display: inline !important; } div.mwe-math-mathml-display + .mwe-math-fallback-image-display { display: block !important; } /* When MathML is displayed, you can easily style it via CSS (font-family,     font-size, color etc). Below are some examples of math font families, with some suggested text fonts to go with. */ /* Asana Math (Palatino style) */ .mw-body, mtext { font-family: Palatino Linotype, URW Palladio L, Asana Math; } math { font-family: Asana Math; } /* Cambria (Microsoft Office style) */ .mw-body, mtext { font-family: Cambria; } math { font-family: Cambria Math; } /* Latin Modern (Computer Modern style) */ .mw-body, mtext { font-family: Latin Modern Roman; } math { font-family: Latin Modern Math; } /* STIX/XITS (Times New Roman style) */ .mw-body, mtext { font-family: XITS, STIX; } math { font-family: XITS Math, STIX Math; } /* TeX Gyre Bonum (Bookman style) */ .mw-body, mtext { font-family: TeX Gyre Bonum; } math { font-family: TeX Gyre Bonum Math; } /* TeX Gyre Pagella (Palatino style) */ .mw-body, mtext { font-family: TeX Gyre Pagella; } math { font-family: TeX Gyre Pagella Math; } /* TeX Gyre Schola (Century Schoolbook style) */ .mw-body, mtext { font-family: TeX Gyre Schola; } math { font-family: TeX Gyre Schola Math; } /* TeX Gyre Termes (Times New Roman style) */ .mw-body, mtext { font-family: TeX Gyre Termes; } math { font-family: TeX Gyre Termes Math; }

History
The Math extension was a part of the core MediaWiki software until MediaWiki 1.18. See the related bug #14202 on Bugzilla.

MW_MATH_MATHML/MW_MATH_LATEXML was implemented to perform MathML generation instead of texvc because texvc is very poor at creating MathML. See the historic option "MathML if possible (experimental)".

Wiki's rendering formulae with MathJax
This lists MediaWiki wiki's using the math extension's MathJax option, (but not those using other MathJax extensions).
 * [<tvar|spice>http://www.blue-spice.org/</> BlueSpice for MediaWiki], and demo wiki
 * [<tvar|sklogwiki>http://www.sklogwiki.org/SklogWiki/index.php/Main_Page</> SklogWiki], thermodynamics and statistical mechanics