Extension:Math

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
Math

Release status: stable

Implementation Tag
Description Allows to render mathematical formulas between <math> ... </math> tags
Author(s) Tomasz Wegrzanowski, Brion Vibber and others
Latest version 1.2.0 (2014-03-28)
Latest preview version 2.0
MediaWiki 1.19+
Database changes Yes
Tables math
License GNU General Public License 2.0
Download
Parameters
  • $wgUseTeX
  • $wgTexvc
  • $wgTexvcBackgroundColor
  • $wgMathCheckFiles
  • $wgMathPath
  • $wgMathDirectory
  • $wgMathFileBackend
  • $wgUseMathJax
Tags
<math>
Hooks used
ParserFirstCallInit

GetPreferences
LoadExtensionSchemaUpdates
ParserTestTables
ParserTestParser
UnitTestsList

Translate the Math extension if possible

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.

Download[edit | edit source]

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 the name of the tag you want to download
  • Click "snapshot"
The latest version of one of the extensions branches

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[edit | edit source]

  • Download and extract the files in a directory called Math in your extensions/ folder. If you're a developer and this extension is in a Git repository, then instead you should clone the repository.
  • Add the following code at the bottom of your LocalSettings.php:
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 texvccheck or set
    $wgMathDisableTexFilter = true;
    
    in your LocalSettings.php
  • Compile texvc if you want to use the PNG images. 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[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 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[edit | edit source]

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)
$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';
Settings (Math 2.0 // MW 1.23+)
$wgMathValidModes[] = MW_MATH_MATHJAX; // adding MathJax as rendering option
// or
$wgMathValidModes = array( MW_MATH_MATHJAX ); // setting MathJax as only rendering option (optional)

$wgUseMathJax = true; // enabeling MathJax as rendering option
$wgDefaultUserOptions['math'] = MW_MATH_MATHJAX; // setting MathJax as default rendering option (optional)

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.

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. If you're a developer and this extension is in a Git repository, then instead you should clone the repository.
  • 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[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 mediawikiwiki:Extension:Math/CoverageTest.

MathJax errors[edit | edit source]

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.

See also[edit | edit source]

  • 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 <math>x</math>.
  • Another alternative is to use LaTeX with Google Chart Tools.
  • Extension:Math/Roadmap roadmap for further development