2015-11-30

Extension:Math/new-version added to category

New page

<languages/>

{{TNT|Extension

|name = Math

|status = stable

|type1 = tag

|hook1 = ParserFirstCallInit

|hook2 = GetPreferences

|hook3 = LoadExtensionSchemaUpdates

|hook4 = ParserTestTables

|hook5 = ParserTestParser

|hook6 = UnitTestsList

|author = <translate><!--T:68-->

Tomasz Wegrzanowski, Brion Vibber and others</translate>

|description = <translate><!--T:69-->

Allows to render mathematical formulas</translate>

|version = continuous updates

|update =

|version preview =

|update preview =

|schema-registry = Yes

|download = {{TNT|WikimediaDownload|Math}}

|needs-updatephp = Yes

|mediawiki = <translate><!--T:71-->

1.19+</translate>

|license = {{TNT|EL|GNUGPL2}}

|parameters = * $wgUseTeX

* $wgTexvc

* $wgTexvcBackgroundColor

* $wgMathCheckFiles

* $wgMathPath

* $wgMathDirectory

* $wgMathFileBackend

|tags = <math>

|bugzilla = Math

|table1 = math

|table2 = mathoid

|table3 = mathlatexml

|phabricator = Math

}}

<translate>

<!--T:1-->

The '''Math''' extension provides support for rendering mathematical formulae. An overview of what can currently be done with this extension is found at [[w:Help:Displaying a formula|the English Wikipedia's documentation]].

==Installation== <!--T:2-->

</translate>

{{TNT|ExtensionInstall

|vagrant=math

|repo-name=Math

|localsettings=

// See below for installation requirements and configuration settings:

|db-update=1

|custom-steps=

* To see math beyond a plain text output, follow instructions below for enabling various [[#Math output modes|math output modes]].

}}

<translate>

==Configuration== <!--T:87-->

<!--T:142-->

Please make sure to put the configuration after <tvar|code><code>require_once "$IP/extensions/Math/Math.php";</code></>, otherwise the ''MW_MATH_XXX'' constants will be undefined.

=== Client-side rendering with MathJax === <!--T:73-->

<!--T:153-->

{{Note|Starting with MediaWiki 1.26 (REL1_26) MathJax is no longer supported as a rendering service. See [[Phab:T99369|Task 99369]] ([[Gerrit:212270]]) for further information. If it's required (e.g. if you are on shared hosting) an older version of this extension will have to be installed. Alternately use extension [[Extension:SimpleMathJax|SimpleMathJax]].|gotcha}}

<!--T:108-->

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.

<!--T:16-->

This can render math expressions more sharply (using [[w:Subpixel rendering|subpixel antialiasing]]) and larger (scaling up for zoomed view, printing, or high-resolution screens).

<!--T:17-->

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.

<!--T:18-->

;Settings (MW 1.19 - 1.22)

</translate>

<syntaxhighlight lang="php" enclose="div" style="overflow:auto;">

$wgUseMathJax = true; // enabling 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';

</syntaxhighlight>

<translate>

<!--T:19-->

;Settings (MW 1.23 - 1.25)

</translate>

<syntaxhighlight lang="php" enclose="div" style="overflow:auto;">

$wgMathValidModes[] = MW_MATH_MATHJAX; // Define MathJax as one of the valid math rendering modes

$wgUseMathJax = true; // Enable MathJax as a math rendering option for users to pick

$wgDefaultUserOptions['math'] = MW_MATH_MATHJAX; // Set MathJax as the default rendering option for all users (optional)

$wgDefaultUserOptions['mathJax'] = true; // Enable the MathJax preference option by default (optional)

$wgMathDisableTexFilter = true; // or compile "texvccheck"

</syntaxhighlight>

<translate>

<!--T:20-->

See also [[<tvar|ext-MathJaxMenu>Special:MyLanguage/Extension:Math/MathJaxMenu</>|How to modify the MathJax contextual menu.]]

</translate>

; <translate><!--T:148-->

Forcing MathJax as the only rendering option (MW 1.23+)</translate>

<translate>

<!--T:149-->

If you have a wiki where MathJax is the only available rendering mode, and wish to force it to be enabled, add the following to LocalSettings.php instead of the above:

</translate>

<syntaxhighlight lang="php" enclose="div" style="overflow:auto;">

$wgMathValidModes = array(MW_MATH_MATHJAX); // Define MathJax as the only valid math rendering mode

$wgUseMathJax = true; // Enable MathJax

$wgDefaultUserOptions['math'] = MW_MATH_MATHJAX; // Set MathJax as the default rendering option

$wgDefaultUserOptions['mathJax'] = true; // Enable the MathJax checkbox option

$wgHiddenPrefs[] = 'math'; // Hide math preference

$wgHiddenPrefs[] = 'mathJax'; // Hide MathJax checkbox

$wgMathDisableTexFilter = true; // or compile "texvccheck"

</syntaxhighlight>

<translate>

<!--T:150-->

This will switch on MathJax by default for all anonymous users and those without preferences saved for the Math extension.</translate>

<translate>

<!--T:151-->

Note that if registered users had an alternate rendering mode selected, it will be necessary for them to open Preferences > Appearance and click Save for the new forced setting to take effect.</translate>

<translate>

<!--T:152-->

Articles should advise users about the requirement for JavaScript to be enabled in order to see formulae (e.g. through a template for articles including TeX formulae).

==== MathJax localization ==== <!--T:122-->

<!--T:123-->

MathJax is an upstream project, but its user interface is translated at [[translatewiki.net]], the same website where MediaWiki and its extension are translated. Translations made there are exported to the MathJax source code, and they will be used in the MediaWiki extension, too. For more information about translating MathJax's menus see [[:translatewiki:Translating:MathJax]].

=== Server-side rendering with Mathoid === <!--T:21-->

<!--T:22-->

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:</translate>

<syntaxhighlight lang="php" enclose="div" style="overflow:auto;">

// 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;

</syntaxhighlight>

<translate>

<!--T:23-->

Check out [[<tvar|mathoid>Special:MyLanguage/Mathoid</>|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 === <!--T:24-->

<!--T:25-->

A convenient option to render LaTeX is to use the LaTeXML web service. This service converts LaTeX to high quality MathML.

<!--T:26-->

;Settings (MW 1.22) most or all of the 1.23+ settings also work

</translate>

<syntaxhighlight lang="php" enclose="div" style="overflow:auto;">

// Enable LaTeXML as rendering option

$wgUseLaTeXML = true; // this became an unused setting around 1.23

</syntaxhighlight>

<translate><!--T:27-->

;Settings (MW 1.23+)

</translate>

<syntaxhighlight lang="php" enclose="div" style="overflow:auto;">

$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/';

</syntaxhighlight>

<translate>

<!--T:28-->

A short guide to install LaTeXML on your own server can be found here: [<tvar|engine>http://www.formulasearchengine.com/node/3</> Install LaTeXML]

<!--T:29-->

After enabling the LaTeXML rendering mode you have to run the database update script again to create the required table.

=== Server-side rendering with LaTeX === <!--T:109-->

<!--T:75-->

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 [[<tvar|texvc>Special:MyLanguage/texvc</>|texvc]].

==== Installation of texvc ==== <!--T:110-->

<!--T:77-->

# If MediaWiki does not have write permissions to <code>$wgUploadDirectory</code>, see config items below <code>$wgMathPath</code>, <code>$wgMathDirectory</code> and <code>$wgMathPath</code> you will have to grant them with e.g. *) <syntaxhighlight lang="bash" enclose="div">sudo chown -R www-data:www-data</syntaxhighlight>

<!--T:126-->

# Compile texvc

<!--T:127-->

:;Install the required prerequisites and dependencies

</translate>

:<syntaxhighlight lang="bash" enclose="div">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</syntaxhighlight>

<translate>

<!--T:128-->

:;Switch the directory

</translate>

:<syntaxhighlight lang="bash" enclose="div">cd install/path/extensions/Math/math</syntaxhighlight>

<translate>

<!--T:129-->

:;Compile texvc

</translate>

:<syntaxhighlight lang="bash" enclose="div">make</syntaxhighlight>

{{TNT|Note}} <translate><!--T:130-->

To make the rendering of mathematical formulas possible with the [[Extension:Collection|Collection]] extension texvc must be installed in PATH (see the alternative installation methods just below)</translate>

<translate>

<!--T:131-->

;Alternatively install the mediawiki math packages

<!--T:132-->

#<tvar|code><syntaxhighlight lang="bash" enclose="div">sudo apt-get install mediawiki-math</syntaxhighlight></> (MediaWiki, Math, texvc and texvccheck) or

<!--T:133-->

#<tvar|code><syntaxhighlight lang="bash" enclose="div">sudo apt-get install mediawiki-math-texvc</syntaxhighlight></> (just texvc)

==List of all configuration settings == <!--T:34-->

<!--T:35-->

The following variables can be defined in LocalSettings.php after calling <code>require_once "$IP/extensions/Math/Math.php";</code>:</translate>

{{TNT|note|<translate><!--T:57-->

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</translate>}}

{| class="wikitable sortable"

! <translate><!--T:36-->

Setting name</translate>

! <translate><!--T:37-->

Default value</translate>

! <translate><!--T:38-->

Description</translate>

|-

| {{ll|Manual:$wgUseTeX|$wgUseTeX}}

| <code>true</code>

| <translate><!--T:39-->

Backward compatibility global; no longer does anything.</translate>

|-

| {{ll|Manual:$wgTexvc|$wgTexvc}}

| <source lang="php" inline>dirname( __FILE__ ) . '/math/texvc'</source>

| <translate><!--T:40-->

Location of the texvc binary</translate>

|-

| {{ll|Manual:$wgTexvcBackgroundColor|$wgTexvcBackgroundColor}}

| <code>'transparent'</code>

| <translate><!--T:41-->

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.</translate>

|-

| {{ll|Manual:$wgMathCheckFiles|$wgMathCheckFiles}}

| <code>true</code>

| <translate><!--T:42-->

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.

<!--T:43-->

This lets us give useful error messages in case of permission problems, and automatically rebuild images that have been lost.

<!--T:44-->

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.</translate>

|-

| {{ll|Manual:$wgMathPath|$wgMathPath}}

| <code>false</code>

| <translate><!--T:45-->

The URL path of the math directory. Defaults to</translate> "<tvar|math>{<nowiki />{{ll|Manual:$wgUploadPath|$wgUploadPath}}}/math</>".

|-

| {{ll|Manual:$wgMathDirectory|$wgMathDirectory}}

| <code>false</code>

| <translate><!--T:46-->

The filesystem path of the math directory. Defaults to</translate> "<tvar|math>{<nowiki />{{ll|Manual:$wgUploadDirectory|$wgUploadDirectory}}}/math</>".

|-

| {{ll|Manual:$wgUseMathJax|$wgUseMathJax}}

| <code>false</code>

| <translate><!--T:47-->

Enables MathJax as rendering option.</translate>

|-

| {{ll|Manual:$wgMathJaxUrl|$wgMathJaxUrl}}

| <code>'$IP/extensions/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML'</code>

| The url to [[Extension:Math#MathJax|MathJax]] if not using the default default parser at <nowiki>http://cdn.mathjax.org/</nowiki>.

|-

| {{ll|Manual:$wgMathValidModes|$wgMathValidModes}}

| <code>array( MW_MATH_PNG, MW_MATH_SOURCE )</code>

| Defines the mode allowed on the server.

|-$wgMathJaxUrl

| {{ll|Manual:$wgMathMathMLUrl|$wgMathMathMLUrl}}

| <code>'http://mathoid.testme.wmflabs.org'</code>

| <translate><!--T:48-->

The url of the [[<tvar|mathoid>Special:MyLanguage/Mathoid</>|mathoid server]].</translate>

|-

| {{ll|Manual:$wgMathMathMLTimeout|$wgMathMathMLTimeout}}

| <code>20</code>

| <translate><!--T:49-->

The timeout for the HTTP-Request sent to the MathML to render an equation, in seconds.</translate>

|-

| {{ll|Manual:$wgMathLaTeXMLUrl|$wgMathLaTeXMLUrl}}

| <code>'http://gw125.iu.xsede.org:8888'</code>

| <translate><!--T:50-->

Use of [<tvar|latexml>http://latexml.mathweb.org/help</> LaTeXML].

<!--T:51-->

If you want or need to run your own server, follow these installation

instructions and override <code>$wgMathLaTeXMLUrl</code>: <tvar|formula-latexml>[http://www.formulasearchengine.com/LaTeXML]</>

<!--T:52-->

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

|-

| {{ll|Manual:$wgMathLaTeXMLTimeout|$wgMathLaTeXMLTimeout}}

| <code>240</code>

| <translate><!--T:53-->

The timeout for the HTTP-Request sent to the LaTeXML to render an equation, in seconds.</translate>

|-

| {{ll|Manual:$wgMathDefaultLaTeXMLSetting|$wgMathDefaultLaTeXMLSetting}}

| <source lang="php">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' ),

)</source>

| <translate><!--T:54-->

Setting for the [<tvar|renderer>http://dlmf.nist.gov/LaTeXML/manual/commands/latexmlpost.xhtml</> LaTeXML renderer] for details.</translate>

|-

| {{ll|Manual:$wgMathDisableTexFilter|$wgMathDisableTexFilter}}

| <code>false</code>

| <translate><!--T:55-->

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 [[wikipedia:Help:Math|Help:Math]] for details.</translate>

|-

| {{ll|Manual:$wgMathEnableExperimentalInputFormats|$wgMathEnableExperimentalInputFormats}}

| <code>false</code>

| <translate><!--T:56-->

Enables experimental MathML and AsciiMath input format support</translate>

|}

<translate>

==Purging pages that contain equations== <!--T:58-->

<!--T:59-->

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 == <!--T:60-->

<!--T:61-->

If something is wrong with the math extension you can report that at [<tvar|phabricator>https://phabricator.wikimedia.org/maniphest/task/create/?projects=MediaWiki-extensions-Math</> Phabricator]. In addition you should check how your problem relates to the automated unit tests that are generated from the page [[<tvar|math-test>Special:MyLanguage/Extension:Math/CoverageTest</>|CoverageTest]].

=== MathJax errors === <!--T:62-->

<!--T:63-->

MathJax has more bugs than latex. So please check if it's an MediaWiki Bug or a [<tvar|github>https://github.com/mathjax/mathjax/issues</> 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 [<tvar|dev-env>http://formulasearchengine.com/review</> 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.

== CSS for the MathML with SVG fallback mode == <!--T:138-->

</translate>

<source lang="css">

/* By default, MathML is exposed to accessibility tools and displayed in Gecko

browsers. You can force visual rendering with the following style: */

.mwe-math-mathml-a11y {

clip: auto;

overflow: visible;

position: static;

width: auto;

height: auto;

opacity: 1;

}

.mwe-math-fallback-image-inline, .mwe-math-fallback-image-display {

display: none !important;

}

/* To force the SVG fallback in Gecko browsers, use the following style: */

span.mwe-math-mathml-inline, div.mwe-math-mathml-display {

display: none !important;

}

span.mwe-math-mathml-inline + .mwe-math-fallback-image-inline {

display: inline !important;

}

div.mwe-math-mathml-display + .mwe-math-fallback-image-display {

display: block !important;

}

/* When MathML is displayed, you can easily style it via CSS (font-family,

font-size, color etc). Below are some examples of math font families,

with some suggested text fonts to go with. */

/* Asana Math (Palatino style) */

.mw-body, mtext {

font-family: Palatino Linotype, URW Palladio L, Asana Math;

}

math {

font-family: Asana Math;

}

/* Cambria (Microsoft Office style) */

.mw-body, mtext {

font-family: Cambria;

}

math {

font-family: Cambria Math;

}

/* Latin Modern (Computer Modern style) */

.mw-body, mtext {

font-family: Latin Modern Roman;

}

math {

font-family: Latin Modern Math;

}

/* STIX/XITS (Times New Roman style) */

.mw-body, mtext {

font-family: XITS, STIX;

}

math {

font-family: XITS Math, STIX Math;

}

/* TeX Gyre Bonum (Bookman style) */

.mw-body, mtext {

font-family: TeX Gyre Bonum;

}

math {

font-family: TeX Gyre Bonum Math;

}

/* TeX Gyre Pagella (Palatino style) */

.mw-body, mtext {

font-family: TeX Gyre Pagella;

}

math {

font-family: TeX Gyre Pagella Math;

}

/* TeX Gyre Schola (Century Schoolbook style) */

.mw-body, mtext {

font-family: TeX Gyre Schola;

}

math {

font-family: TeX Gyre Schola Math;

}

/* TeX Gyre Termes (Times New Roman style) */

.mw-body, mtext {

font-family: TeX Gyre Termes;

}

math {

font-family: TeX Gyre Termes Math;

}

</source>

<translate>

==History== <!--T:64-->

<!--T:78-->

The Math extension was a part of the core MediaWiki software until MediaWiki 1.18. See the related bug [[bugzilla:14202|T16202 on Phabricator]].

<!--T:65-->

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)".

==Developing== <!--T:143-->

<!--T:144-->

A introduction to code review for the Math extension is available from <tvar|url>http://www.formulasearchengine.com/review</>.

<!--T:145-->

From version wmf1.25 composer is required.</translate>

<translate>

<!--T:146-->

If you can not run composer in your development environment make copy the required modules to your <tvar|vendor><code>mediawiki/vendor</code></> folder.</translate>

<translate>

<!--T:147-->

There should be at least <tvar|log><code>mediawiki/vendor/psr/log</code></>-folder which enables auto completion for the debug commands in your IDE.

==See also== <!--T:66-->

<!--T:67-->

* [[<tvar|ext-simplemath>Special:MyLanguage/Extension:SimpleMathJax</>|Extension:SimpleMathJax]], an alternative way to provide support for rendering mathematical formulas on-wiki, without texvc or LaTeX.

*

* [[<tvar|texvc>Special:MyLanguage/texvc</>|texvc]] - description of texvc

* [[<tvar|texvc-alt>Special:MyLanguage/Texvc PHP Alternative</>|Texvc PHP Alternative]]

* If you are on a shared host and cannot compile texvc or a local mimetex server, you can follow the instructions at [[<tvar|tex-host>Special:MyLanguage/LaTeX on a shared host</>|LaTeX on a shared host]] to get math up and running. This scenario is typical of shared hosting environments.

* Another alternative is to use [[<tvar|chart>Special:MyLanguage/LaTeX with google chart</>|LaTeX with Google Chart Tools]].

* [[<tvar|roadmap>Special:MyLanguage/Extension:Math/Roadmap</>|Extension:Math/Roadmap]] for further development

* [[<tvar|man-texproblems>Special:MyLanguage/Manual:Enable_TeX/problems</>|Manual:Enable_TeX/problems]]

*[[Manual:Math]]</translate>

<translate>

<!--T:141-->

*[[Mathoid]]

==External links== <!--T:112-->

===Wikis rendering formulae with MathJax === <!--T:114-->

<!--T:135-->

This lists MediaWiki wiki's using the math extension's MathJax option, (but not those using other MathJax extensions).

<!--T:136-->

*[<tvar|spice>http://www.blue-spice.org/</> BlueSpice for MediaWiki], and [http://en.demo.blue-spice.org/wiki/Main_Page demo wiki]

<!--T:137-->

*[<tvar|sklogwiki>http://www.sklogwiki.org/SklogWiki/index.php/Main_Page</> SklogWiki], thermodynamics and statistical mechanics

</translate>

{{TNT|OnWikimedia}}

[[Category:TeX{{translation}}]]

[[Category:Math display extensions{{translation}}]]

[[Category:Extensions with VisualEditor support]]

Show more