Release status: stable
|Description||Allows to render mathematical formulas|
|Author(s)||Tomasz Wegrzanowski, Brion Vibber and others|
|Latest version||1.2.0 (2014-03-28)|
|Latest preview version||2.0|
|License||GNU General Public License 2.0|
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 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.
- 1 Math output modes
- 2 Installation
- 3 Configuration
- 4 List of all configuration settings
- 5 Purging pages that contain equations
- 6 Error reporting
- 7 History
- 8 See also
- 9 External links
Math output modes[edit | edit source]
- without command-line access to the server
- no rendering (MW_MATH_SOURCE)
- client-side rendering with MathJax (MW_MATH_MATHJAX)
- with command-line access to the server
- server-side rendering with LaTeX (MW_MATH_PNG)
- server-side rendering with Mathoid (MW_MATH_MATHML), which is the rendering mode used on Wikimedia projects in future.
- server-side rendering with LaTeXML (MW_MATH_LATEXML)
If multiple modes are enabled, logged in users can set a personal preference in the appearance pane of their user preferences page.
Installation[edit | edit source]
- If using Vagrant, install with
vagrant enable-role math && vagrant provision
- Manual Installation
- Download and extract the file(s) in a directory called
extensions/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.
A quick note about texvc[edit | edit source]
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.
[edit | edit source]
[edit | edit source]
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 will have to be done offline. Use
uname -a 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:
sudo apt-get install build-essential dvipng ocaml texlive-fonts-recommended texlive-lang-greek texlive-latex-recommended
Get the Math extension and make texvc etc.:
wget https://extdist.wmflabs.org/dist/Math-REL1_23-d0e998f.tar.gz tar zxvf Math-REL1_23-d0e998f.tar.gz rm Math-REL1_23-d0e998f.tar.gz cd Math make rm *.o tar -pczf texvc-files.tar.gz Math/ # archive the files for easy upload
texvc-files.tar.gz 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.:
texvc /home/wiki/tmp /home/wiki/math "y=x+2" iso-8859-1 "rgb 1.0 1.0 1.0"
On a host with full shell access[edit | edit source]
cd $IP/extensions/Math/ # install the dependencies listed in the README file e.g.: sudo apt-get install build-essential ocaml make
On a (virtual) private server[edit | edit source]
In some Linux distributions texvc and texvccheck come already built in the MediaWiki Math packages. See 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
Configuration[edit | edit source]
Client-side rendering with MathJax[edit | edit source]
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)
$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=TeX-AMS_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=TeX-AMS-MML_HTMLorMML';
$wgMathJaxUrl = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML';
- Settings (Math 1.2 // MW 1.23+)
$wgDefaultUserOptions['mathJax'] = true; // setting MathJax as default rendering option (optional)
$wgMathDisableTexFilter = true; // or compile "texvccheck"
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[edit | edit source]
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[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.
Server-side 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.
Server-side rendering with LaTeX[edit | edit source]
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.
Installation of texvc[edit | edit source]
- If MediaWiki does not have write permissions to
$wgUploadDirectory, see config items below
$wgMathPathyou will have to grant them with e.g. *)sudo chown -R www-data:www-data
- Compile texvc
- Install the required prerequisites and dependencies
sudo apt-get install build-essential texlive texlive-bibtex-extra texlive-font-utils texlive-fonts-extra texlive-latex-extra texlive-math-extra texlive-pictures texlive-pstricks texlive-publishers dvipng gsfonts make ocaml ploticus
- Switch the directory
- Compile texvc
Note: 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
sudo apt-get install mediawiki-math
sudo apt-get install mediawiki-math-texvc
List of all configuration settings[edit | edit source]
The following variables can be defined in LocalSettings.php after calling
|Setting name||Default value||Description|
||Backward compatibility global; no longer does anything.|
||Location of the texvc binary|
||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.|
||Normally when generating math images, we double-check 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 short-circuit it by setting this to false.
||Enables MathJax as rendering option.|
||The url to MathJax if not using the default default parser at http://cdn.mathjax.org/.|
||Defines the mode allowed on the server.|
||The url of the mathoid server.|
||The timeout for the HTTP-Request sent to the MathML to render an equation, in seconds.|
||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
||The timeout for the HTTP-Request sent to the LaTeXML to render an equation, in seconds.|
||Setting for the LaTeXML renderer for details.|
||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.|
||Enables experimental MathML and AsciiMath input format support|
Purging pages that contain equations[edit | edit source]
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[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 if 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]
- Extension:SimpleMathJax, a quicker and easier way to provide support for rendering mathematical formulas on-wiki, without texvc or LaTeX.
- texvc - description of texvc
- Texvc PHP Alternative
- 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
[edit | edit source]
Wiki's rendering formulae with MathJax[edit | edit source]
This lists MediaWiki wiki's using the math extension's MathJax option, (but not those using other MathJax extensions).
|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 high-traffic 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.|