Extension:Math

From MediaWiki.org
(Redirected from Manual:Enable TeX)
Jump to: navigation, search

Other languages:
English • ‎español • ‎português do Brasil
MediaWiki extensions manual
Crystal Clear action run.png
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 (2014-03-28)
Latest preview version 2.0
MediaWiki 1.19+
Database changes Yes
Tables math
mathoid
mathlatexml
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 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.

Installation[edit | edit source]

  • Download and extract the file(s) 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 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 apt-get install build-essential 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. Client-side rendering, e.g. via JavaScript in the users web browser, is slow. Server-side 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:

  • Client-side rendering using MathJax.
  • Server-side rendering with Mathoid, the rendering mode that is going to be used on future Wikipedia.
  • Server-side 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.

Client-side rendering with 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. 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)
$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 1.2 // MW 1.23+)
$wgUseMathJax = true; // enabeling MathJax as rendering option
$wgDefaultUserOptions['mathJax'] = true; // setting MathJax as default rendering option (optional)
$wgMathDisableTexFilter = true; // or compile "texvccheck"

See also How to modify the MathJax contextual menu.

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:

// ensure MW_MATH_MATHML; is added to the $wgMathValidModes array;
$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
// Enable LaTeXML as rendering option
$wgUseLaTeXML = true; // this became an unused setting around 1.23
Settings (Math 1.2 // MW 1.23+)
$wgMathValidModes[] = MW_MATH_LATEXML; // adding LaTeXML as rendering option
// 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 www-data:www-data *)
  • Compile texvc (it comes with linux mediawiki math packages):
# install the dependencies listed in the README file e.g.:
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
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 apt-get install mediawiki-math 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";:

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
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".
$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 HTTP-Request 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 $wgMathLaTeXMLUrl: [1]

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 $wgMathLaTeXMLUrl = array ( 'http://latexml.example.com/convert', 'http://latexml2.example.com/convert');

$wgMathLaTeXMLTimeout 240 The timeout for the HTTP-Request sent to the LaTeXML to render an equation, in seconds.
$wgMathDefaultLaTeXMLSetting array(

'format' => 'xhtml', 'whatsin' => 'math', 'whatsout' => 'math', 'pmml', 'cmml', 'nodefaultresources', 'preload' => array( 'LaTeX.pool', 'article.cls', 'amsmath.sty', 'amsthm.sty', 'amstext.sty', 'amssymb.sty', 'eucal.sty', '[dvipsnames]xcolor.sty', 'url.sty', 'hyperref.sty', '[ids]latexml.sty', 'texvc' ), )

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 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 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]