# Extension:Math

MediaWiki extensions manual - list
Math

Release status: stable

Implementation Tag
Description Allows to render mathematical formulas between $ ... $ tags
Author(s) Tomasz Wegrzanowski, Brion Vibber and others
Last version 1.1 (2013-05-14)
MediaWiki 1.19+
Database changes Yes
Tables math
Parameters
• $wgUseTeX •$wgTexvc
• $wgTexvcBackgroundColor •$wgMathCheckFiles
• $wgMathPath •$wgMathDirectory
• $wgMathFileBackend •$wgUseMathJax
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. It was a part of the core MediaWiki software until MediaWiki 1.18, r85706. See also the related bug #14202 on Bugzilla.

## Contents

You can download the extension directly from the MediaWiki source code repository (browse code). You can get:

One of the extensions tags

Not all extensions have tags. Some extensions have tags for each release, in which case those tags have the same stability as the release. To download a tag

• Go to the tags list
• Click "snapshot"

Each extension has a master branch containing the latest code (might be unstable). Extensions can have further branches as well.

• Go to the branches list
• Click the branch name
• Click "snapshot"
A snapshot made during the release of a MediaWiki version.

This might be unstable and is not guaranteed to work with the associated MediaWiki version.

After you've got the code, save it into the extensions/Math directory of your wiki.

If you are familiar with git and have shell access to your server, you can obtain the extension, with all its tags and branches, as follows:

cd extensions
git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/Math.git


## Installation

• Download and extract the files in a directory called Math in your extensions/ folder.
require_once "$IP/extensions/Math/Math.php"; // Set this if you don't use MediaWiki Math's texvc:$wgTexvc =  '/your/path/to/texvc';

// Be sure to have a math directory with writing
// permission and that these two variables are set or
// default to that directory:
$wgMathDirectory = 'filesystem/path/of/the/math/directory';$wgMathPath = 'URL/path/of/the/math/directory';
• Run the update script which will automatically create the necessary database tables that this extension needs.
• Compile texvc. If you don't have permission on your server to compile code in the environment, read the see also section below.
• Done – Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed.

## Configuration settings

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 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.$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". On the individual pages for these settings, it says deprecated in 1.18, since this extension was split from core mediawiki in that version. If you've installed the extension, these settings apply regardless ## 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
$wgUseMathJax = true; // enabeling MathJax as rendering option$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';

## LaTeXML

A convenient option to render LaTeX is to use the LaTeXML web service. This service converts LaTeX to high quality MathML.

You can enable the LaTeXML rendering option with the following settings

Settings
// Enable LaTeXML as rendering option
$wgUseLaTeXML = true; // Set LaTeXML as default rendering option (optional)$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 The installation of Math is simplified to: • Download and extract the files in a directory called Math in your extensions/ folder. • Add the following code at the bottom of your LocalSettings.php: require_once "$IP/extensions/Math/Math.php";
$wgUseLaTeXML = true;$wgUseMathJax = true;
$wgDefaultUserOptions['math'] = MW_MATH_LATEXML; • Run the update script which will automatically create the necessary database tables that this extension needs. • Done – Navigate to "Special:Version" on your wiki to verify that the extension is successfully installed. ## 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. ## See also • Enabling TeX • en:Wikipedia: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 here to get math up and running. This scenario is typical of shared hosting environments. • An alternative is to use Extension:MathJax which enables more common LaTeX formula delimiters, e.g., you can write$x\$ instead of $x$.
• Another alternative is to use LaTeX with Google Chart Tools.