From mediawiki.org
Jump to navigation Jump to search
This page is a translated version of the page Extension:Math/advancedSettings and the translation is 17% complete.
Other languages:
English • ‎Türkçe • ‎español • ‎polski • ‎português do Brasil • ‎日本語

A extensão Math fornece suporte para renderizar fórmulas matemáticas on-wiki via texvc 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.

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
$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.
$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 array( 'png', '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.
	'format' => 'xhtml',
	'whatsin' => 'math',
	'whatsout' => 'math',
	'preload' => array( 
		'texvc' ),
Setting for the LaTeXML renderer for details.
$wgMathDisableTexFilter false 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 estilo:

 .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!