Extension:Math
Math Release status: stable 


Implementation  Tag  
Description  Allows to render mathematical formulas  
Author(s)  Tomasz Wegrzanowski, Brion Vibber and others  
Latest version  1.2.0 (20140328)  
Latest preview version  2.0  
MediaWiki  1.19+  
Database changes  Yes  
Tables  math mathoid mathlatexml 

License  GNU General Public License 2.0  
Download  






Translate the Math extension if it is available at translatewiki.net 

Check usage and version matrix; code metrics  
Bugs: list open list all report 
The Math extension provides support for rendering mathematical formulas onwiki via texvc and other backends. An overview of what can currently be done with this extension is found at the English Wikipedia's documentation.
Contents
Installation[edit  edit source]
 Download and extract the file(s) in a directory called
Math
in yourextensions/
folder. If you're a developer and this extension is in a Git repository, then instead you should clone the repository using:
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/Math.git
 Add the following code at the bottom of your LocalSettings.php:
require_once "$IP/extensions/Math/Math.php"; // See below for installation requirements and configuration settings:
 Run the update script which will automatically create the necessary database tables that this extension needs.
 To see math beyond a plain text output, follow instructions below for enabling various math output modes.
 Done! Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.
Alternatively, multiple linux distributions provide this extension as packages, see Comparison of extensions in distributions.
Installation requirements Mathoid/LaTeXML[edit  edit source]
 Set "$wgMathDisableTexFilter = true;" in your LocalSettings.php or compile texvccheck (it comes already built for linux mediawiki math packages):
cd install/path/extensions/Math/texvcheck # install the dependencies listed in the README file e.g.: sudo aptget install buildessential ocaml make
 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)
Configuration settings[edit  edit source]
The choice of the rendering mode heavily depends on the amount of math the wiki uses. Clientside rendering, e.g. via JavaScript in the users web browser, is slow. Serverside rendering can be done at on the wiki's host server or using a public rendering host, e.g. latexml.mathweb.org. There are basically three possible configuration options:
 Clientside rendering using MathJax.
 Serverside rendering with Mathoid, the rendering mode that is going to be used on future Wikipedia.
 Serverside rendering with LaTeXML.
If multiple modes are enabled, logged in users can set a personal preference in the appearance pane of their user preferences page.
Text mode displays math as the raw LaTeX source. This may be useful for troubleshooting or for text only browsers. Text mode is enabled as an option by default, as MW_MATH_SOURCE in $wgMathValidModes.
Clientside rendering with MathJax[edit  edit source]
From 1.19/1.20, the Math extension supports rendering via MathJax, a clientside JavaScript library for parsing latex or mathml code and producing inbrowser 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 highresolution 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)
$wgDefaultUserOptions['math'] = MW_MATH_MATHJAX; // setting MathJax as default rendering option (optional)
/**
* The default parser for MathJax is 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeXAMS_HTML'
* If you don't want to or can't use the default and your run your own locally
* replace the below url with something like:
* $wgMathJaxUrl = '/mathjax/MathJax.js?config=TeXAMSMML_HTMLorMML';
*/
$wgMathJaxUrl = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeXAMS_HTML';
 Settings (Math 1.2 // MW 1.23+)
$wgDefaultUserOptions['mathJax'] = true; // setting MathJax as default rendering option (optional)
$wgMathDisableTexFilter = true; // or compile "texvccheck"
See also How to modify the MathJax contextual menu.
Serverside rendering with Mathoid[edit  edit source]
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:
$wgMathValidModes[] = MW_MATH_MATHML;
// Set Mathoid as default rendering option;
$wgDefaultUserOptions['math'] = MW_MATH_MATHML;
Check out 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.
Serverside rendering with LaTeXML[edit  edit source]
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
$wgUseLaTeXML = true; // this became an unused setting around 1.23
 Settings (Math 1.2 // MW 1.23+)
// Set LaTeXML as default rendering option;
$wgDefaultUserOptions['math'] = MW_MATH_LATEXML;
// Specify the path to your LaTeXML instance that converts the \TeX commands to MathML (optional)
$wgLaTeXMLUrl = 'http://example.com/';
A short guide to install LaTeXML on your own server can be found here: Install LaTeXML
After enabling the LaTeXML rendering mode you have to run the database update script again to create the required table.
Local LaTeX image rendering[edit  edit source]
Local LaTeX image rendering (default in Math 1.0, 1.1), is now deprecated.
Installation requirements[edit  edit source]
 If mediawiki does not have write permissions to $wgUploadDirectory, see config items below $wgMathPath $wgMathDirectory $wgMathPath.
 give your webserver write permissions to these folders (e.g. sudo chown R wwwdata:wwwdata *)
 Compile texvc (it comes with linux mediawiki math packages):
# install the dependencies listed in the README file e.g.: sudo aptget install buildessential texlive texlivebibtexextra texlivefontutils texlivefontsextra texlivelatexextra texlivemathextra texlivepictures texlivepstricks texlivepublishers dvipng gsfonts make ocaml ploticus cd install/path/extensions/Math/math make
Image rendering[edit  edit source]
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 sudo aptget install mediawikimath
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 require_once "$IP/extensions/Math/Math.php";
.)
List of all configuration settings[edit  edit source]
The following variables can be defined in LocalSettings.php after calling require_once "$IP/extensions/Math/Math.php";
:
Setting name  Default value  Description 

$wgUseTeX  true 
Backward compatibility global; no longer does anything. 
$wgTexvc  dirname( __FILE__ ) . '/math/texvc' 
Location of the texvc binary 
$wgTexvcBackgroundColor  'transparent' 
Texvc background color; use LaTeX color format as used in \special function. For transparent background use value 'Transparent' for alpha transparency or 'transparent' for binary transparency. 
$wgMathCheckFiles  true 
Normally when generating math images, we doublecheck that the directories we want to write to exist, and that files that have been generated still exist when we need to bring them up again.
This lets us give useful error messages in case of permission problems, and automatically rebuild images that have been lost. On a big site with heavy NFS traffic this can be slow and flaky, so sometimes we want to shortcircuit it by setting this to false. 
$wgMathPath  false 
The URL path of the math directory. Defaults to "{$wgUploadPath}/math". 
$wgMathDirectory  false 
The filesystem path of the math directory. Defaults to "{$wgUploadDirectory}/math". 
$wgUseMathJax  false 
Enables MathJax as rendering option. 
$wgMathValidModes  array( MW_MATH_PNG, MW_MATH_SOURCE ) 
Defines the mode allowed on the server. 
$wgMathMathMLUrl  'http://mathoid.testme.wmflabs.org' 
The url of the mathoid server. 
$wgMathMathMLTimeout  20 
The timeout for the HTTPRequest sent to the MathML to render an equation, in seconds. 
$wgMathLaTeXMLUrl  'http://gw125.iu.xsede.org:8888' 
Use of LaTeXML.
If you want or need to run your own server, follow these installation instructions and override If you expect heavy load you can specify multiple servers. In that case one server is randomly chosen for each rendering process. Specify the list of servers in an array e.g 
$wgMathLaTeXMLTimeout  240 
The timeout for the HTTPRequest sent to the LaTeXML to render an equation, in seconds. 
$wgMathDefaultLaTeXMLSetting  array(

Setting for the LaTeXML renderer for details. 
$wgMathDisableTexFilter  false 
Option to disable the tex filter. If set to true any LaTeX espression is parsed this can be a potential security risk. If set to false only a subset of the TeX commands is allowed. See the wikipedia page Help:Math for details. 
$wgMathEnableExperimentalInputFormats  false 
Enables experimental MathML and AsciiMath input format support 
Purging pages that contain equations[edit  edit source]
Specifying the URLparameter action=purge does not force the math equation to rerender the math tags. If a complete rerendering of the math tags is desired the URLparameter 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 TeXinputstring as the caching key. e.g. if you would force the rerending 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[edit  edit source]
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 CoverageTest.
MathJax errors[edit  edit source]
MathJax has more bugs than 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.
History[edit  edit source]
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)".
See also[edit  edit source]
 texvc  description of texvc
 If you are on a shared host and cannot compile texvc or a local mimetex server, you can follow the instructions at LaTeX on a shared host to get math up and running. This scenario is typical of shared hosting environments.
 Another alternative is to use LaTeX with Google Chart Tools.
 Extension:Math/Roadmap for further development
 Manual:Enable_TeX/problems
This extension is being used on one or more Wikimedia projects. This probably means that the extension is stable and works well enough to be used by such hightraffic websites. Look for this extension's name in Wikimedia's CommonSettings.php and InitialiseSettings.php configuration files to see where it's installed. A full list of the extensions installed on a particular wiki can be seen on the wiki's Special:Version page. 
 Extensions with unknown license
 Stable extensions
 Tag extensions
 GPL licensed extensions
 Extensions in Wikimedia version control
 ParserFirstCallInit extensions
 GetPreferences extensions
 LoadExtensionSchemaUpdates extensions
 ParserTestTables extensions
 ParserTestParser extensions
 UnitTestsList extensions
 All extensions
 Extensions used on Wikimedia
 TeX
 Math display extensions