Extension:Math/advancedSettings

The Math extension provides support for rendering mathematical formulas on-wiki via Mathoid and other backends. An overview of what can currently be done with this extension is found at the English Wikipedia's documentation.

Configuration edit

Server-side rendering with Mathoid edit

Beginning from 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 'mathml'; is added to the $wgMathValidModes array;
$wgMathValidModes[] = 'mathml';

// Set Mathoid as default rendering option;
$wgDefaultUserOptions['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

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 (MW 1.23+)
$wgMathValidModes[] = 'latexml'; // adding LaTeXML as rendering option
// Set LaTeXML as default rendering option;
$wgDefaultUserOptions['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.

Historical note edit

Texvc used to be a rendering option before version 1.32. It is now completely replaced by Mathoid, but the subset of AMS-LaTeX it supports remains the basis of this extension.

List of all configuration settings edit

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 (Removed in MW 1.32 due to texvc being gone.)
$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. (Removed in MW 1.32 due to texvc being gone.)
$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.
$wgMathJaxUrl '$IP/extensions/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML' The url to MathJax if not using the default default parser at http://cdn.mathjax.org/.
$wgMathValidModes [ 'png', 'source', 'mathml' ] Defines the mode allowed on the server.
$wgMathMathMLUrl 'https://mathoid-beta.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 'https://latexml.formulasearchengine.com/convert' 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 = [ '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
[
	'format' => 'xhtml',
	'whatsin' => 'math',
	'whatsout' => 'math',
	'pmml',
	'cmml',
	'mathtex',
	'nodefaultresources',
	'preload' => [
		'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'
	],
	'linelength': 90
}
Setting for the LaTeXML renderer for details.
$wgMathDisableTexFilter 'new' Option to disable the tex filter. If set to true any LaTeX expression is parsed this can be a potential security risk. If set to false only a subset of the TeX commands is allowed. See Help:Displaying a formula for details.
$wgMathEnableExperimentalInputFormats false Enables experimental MathML and AsciiMath input format support

Alternate rendering edit

CSS for visual rendering of MathML edit

By default, MathML is only exposed to accessibility tools. However, you can force visual rendering with the following MediaWiki stylesheets:

.mwe-math-mathml-a11y {
    clip: auto !important;
    overflow: visible !important;
    position: static !important;
    width: auto !important;
    height: auto !important;
    opacity: 1 !important;
}
.mwe-math-fallback-image-inline,
.mwe-math-fallback-image-display {
    display: none !important;
}

You can then easily change the style of MathML formulas e.g. to set the math font:

.mw-body, mtext {
    font-family: Latin Modern Roman;
}
math {
    font-family: Latin Modern Math;
}
.mw-body, is added to get the same font appearance for the entire article text. If you do not want to change your main font, then leave this out. Do not forget to remove the comma, as well!

Userscript renderers edit

It is also possible to use other client-side renderers, according to the comments of phab:T99369. None of these options should be actually deployed for general users; they are just for side-stepping parts of the current pipeline for experimentation.

  • JS script for client-side MathJax, interpreting math code directly: phab:T99369#1482730.
  • JS script for client-side MathJax, interpreting MathML: phab:T99369#1484437.
  • JS script for client-side KaTeX, interpreting either TeX code embedded in MathML, or raw "text mode" TeX code: phab:T99369#1484437.

CSS for dark background edit

The Extension always renders formulae in black text by default, which can throw off users and wikis running a dark background color. A skin author can add the following code to invert the lightness of formula images using CSS filters:

.mwe-math-fallback-image-inline,
.mwe-math-fallback-image-display {
    filter: hue-rotate(180deg) invert(1);
}
The hue-rotate keeps the hues roughly constant, so that colors remain somewhat useful. This solution is nowhere near being final. See the linked task and other tickets linked to it for more information.