Extension:Math

The Math extension provides support for rendering mathematical formulas on-wiki via texvc and other backends. It was a part of the core MediaWiki software until MediaWiki 1.18, r85706. See also the related bug #14202 on Bugzilla.

Installation
{{ExtensionInstall // Select the rendering modes you want to offer for your visitors e.g. $wgMathValidModes = array(MW_MATH_PNG, MW_MATH_SOURCE, MW_MATH_LATEXML, MW_MATH_MATHML); // Choose a new default rendering mode for unregistered visitors (NB default is MW_MATH_PNG) $wgDefaultUserOptions['math'] = MW_MATH_MATHML; // See below for the remaining installation requirements and configuration settings:
 * repo-name=Math
 * localsettings=
 * db-update=1
 * custom-steps=
 * Ensure that mediawiki has been installed with the 'Math' extension selected (verify that 'add require_once "$IP/extensions/Math/Math.php";' has been added to your LocalSettings.php file)

Installation requirements (MW_MATH_MATHML/MW_MATH_LATEXML)

 * Compile texvccheck within the texvccheck folder (required for MW_MATH_MATHML and MW_MATH_LATEXML only);
 * navigate to the extensions/Math/texvccheck folder (e.g. cd [yourwikiinstallationpath]/extensions/Math/texvccheck)
 * execute make on the Makefile (e.g. make)
 * Alternatively, set "$wgMathDisableTexFilter = true;" in your LocalSettings.php (required for MW_MATH_MATHML and MW_MATH_LATEXML only);


 * Note if MW_MATH_MATHML or MW_MATH_LATEXML are selected at a later stage, the mediawiki database update script must be rerun (to prevent a "database query error has occurred" error)
 * navigate to the "maintenance" folder of your mediawiki installation (e.g. cd [yourwikiinstallationpath]/maintenance)
 * php update.php

Installation requirements (MW_MATH_PNG)
$wgUploadPath      = "{$wgScriptPath}/images"; $wgUploadDirectory = "{$IP}/images"; $wgMathPath        = "{$wgUploadPath}/math"; $wgMathDirectory   = "{$wgUploadDirectory}/math"; $wgTmpDirectory    = "{$wgUploadDirectory}/tmp"; }}
 * Ensure that mediawiki has been installed with "enable image uploads" selected (required for MW_MATH_PNG only). If not the following definitions must be added to LocalSettings.php, to prevent a "cannot store math image on filesystem" error;
 * Manually create the necessary temporary image folders (required for MW_MATH_PNG only)
 * navigate to the "images" folder of your mediawiki installation;
 * make a new folder called "math" (e.g. mkdir math)
 * make a new folder called "tmp" (e.g. mkdir tmp)
 * give your webserver write permissions to these folders (e.g. sudo chown -R www-data:www-data *)
 * Compile texvc within the math folder (required for MW_MATH_PNG only)
 * navigate to the extensions/Math/math folder (e.g. cd [yourwikiinstallationpath]/extensions/Math/math)
 * install the dependencies listed in the README file (e.g. sudo apt-get install build-essential dvipng ocaml texlive-fonts-recommended texlive-lang-greek texlive-latex-recommended)
 * execute make on the Makefile (e.g. make)

Configuration settings
There are basically 3 possible configuration options.
 * Local LaTeX image rendering (default in Math 1.0, 1.1, now deprecated)
 * Client-side rendering (uses MathJax)
 * Server-side rendering
 * using LaTeXML-service
 * using Mathoid-service

Discussion of pros and cons

 * The choice of the rendering mode heavily depends on the amount of math you wiki uses.
 * Server- side rendering can be done at your server or using a public rendering host
 * latexml.mathweb.org
 * Client-side rendering is slow

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. For now, users will have to opt in to MathJax on their preferences. In the future we hope to make it the default rendering mode.


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

How to modify the MathJax contextual menu?
 * Settings (Math 1.2 // MW 1.23+)

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 rending mode that is going to be used on future Wikipedia. For that the following settings are recommended: Check out Mathoid to find instructions how to run your own Mathoid server. After enabling the MahtML 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

A short guide to install LaTeXML on your own server can be found here: Install LaTeXML
 * Settings (Math 1.2 // MW 1.23+)

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

Local LaTeX image rendering
To use your local webserver 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. The prerequisites are the most recent version of OCAML and LaTeX. Most convenient everything can be installed via  from Linux. After that change to the "extensions/Math/math" subdirectory and run make to compile texvc. This method does not require any change to the default configuration. (i.e. you don't need to add anything else to your Localsettings.php beside .)

List of all configuration setting
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 bugzilla. In addition you should check how your problem relates to the automated unit tests that are generated from the page mediawikiwiki:Extension:Math/CoverageTest.

MathJax errors
MathJax has more bugs that latex. So please check it it's an MediaWiki Bug or a 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 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.