Extensão:Math/advancedSettings

This page is a translated version of the page Extension:Math/advancedSettings and the translation is 14% complete.
Other languages:

A extensão Math fornece suporte para renderizar fórmulas matemáticas on-wiki via Mathoid e outros backends. Uma visão geral do que pode ser feito atualmente com esta extensão é encontrada na documentação da Wikipedia em inglês.

Atenção Atenção: Information about configurating the extension in older MediaWiki versions is removed from this page. It may be found in the page history.


Server-side rendering with Mathoid

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

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

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

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

CSS for the MathML with SVG fallback mode

Por padrão, o MathML é exposta apenas às ferramentas de acessibilidade. No entanto, você pode forçar o processamento visual, com o seguinte folhas de estilo MediaWiki:

.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;
}

Você pode então facilmente alterar o estilo MathML fórmulas e.g, por exemplo, para definir a fonte matemática:

.mw-body, mtext {
    font-family: Latin Modern Roman;
}
math {
    font-family: Latin Modern Math;
}
.mw-body, é adicionado para obter a mesma aparência de fonte para o texto do artigo inteiro. Se você não quer mudar sua fonte principal, então deixe isso de fora. Não se esqueça de remover a vírgula, também!

CSS for dark background

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.