Extension:Math
<languages /> Template:Extension <translate> The Math extension provides support for rendering mathematical formulae.
More information about installing and configuring this extension, including for older versions, can be found at <tvar name=1>Template:Ll</tvar>.
See an overview of what can currently be done with this extension at [[<tvar name=1>Special:MyLanguage/Extension:Math/Syntax</tvar>|Extension:Math/Syntax]].
Installation
</translate> Template:Bundled Template:ExtensionInstall
<translate> You should additionally go to the page <tvar name=1>Special:MathStatus</tvar> to see whether all of the components of the Math extension now work.</translate> <translate> For any problems you see, the best option is to create a task on <tvar name=url>https://phabricator.wikimedia.org</tvar></translate>
<translate> Unfortunately, there is no well tested guide on installing <tvar name=mathoid>Template:Ll</tvar> and <tvar name=restbase>Template:Ll</tvar> to work with the Math extension, but there is at least a working draft.</translate> <translate> <tvar name=restbase>Template:Ll</tvar> please contribute.</translate>
<translate> In addition, there is a [<tvar name=github>https://github.com/physikerwelt/mathoid-docs/blob/master/Guide%20for%20Installing%20and%20Setting%20up%20Mediawiki%20with%20Restbase%20and%20Mathoid.pdf</tvar> Guide for Installing and Setting up MediaWiki with RESTBase and Mathoid in MW1.28].
Usage
Once installed, you write formulas using [[<tvar name=1>Special:MyLanguage/Extension:Math/Syntax</tvar>|TeX markup syntax]] inside the <tvar name=2>Template:Tag</tvar> tag. For example: </translate>
<math>E=mc^2</math>
<translate> Renders as: </translate>
<translate>
Viewing math
</translate> <translate> The type of output depends on the software that you use to read the page.</translate> <translate> If it can, the Math extension outputs MathML. Otherwise, it outputs images in SVG (converting characters to <path> elements) or PNG.</translate> <translate> Basic math support works for all browsers. But, for best results, you might need to change your settings:</translate>
- <translate> For Firefox or other Gecko browsers, install the [<tvar name=url>https://addons.mozilla.org/firefox/addon/native-mathml/</tvar> Native MathML extension] and [<tvar name=url2>https://developer.mozilla.org/docs/Mozilla/MathML_Project/Fonts</tvar> math fonts].</translate>
<translate> The NVDA, VoiceOver, and Orca screen readers provide accessibility support.</translate> <translate> To read mathematics, NVDA needs the MathPlayer plugin.</translate> - <translate> For Safari or other WebKit browsers, you can also install math fonts and enable native MathML rendering by [[<tvar name=ext>Special:MyLanguage/Extension:Math/advancedSettings#CSS for the MathML with SVG fallback mode</tvar>|inserting some CSS rules]] into the custom style sheet of your browser.</translate>
<translate> The VoiceOver screen reader provides accessibility support. The Orca screen reader does not do so yet.</translate> - <translate> For Chrome, you must [[<tvar name=ext>Special:MyLanguage/Extension:Math/advancedSettings#CSS for the MathML with SVG fallback mode</tvar>|insert some CSS rules]] into the custom style sheet of your browser to get accessibility support with the [<tvar name=url>http://www.chromevox.com/</tvar> ChromeVox] screen reader or visual rendering with the [<tvar name=url2>https://chrome.google.com/webstore/detail/math-anywhere/gebhifiddmaaeecbaiemfpejghjdjmhc</tvar> MathJax plugin].</translate>
<translate>
Configuration settings
</translate>
| <translate> Setting name</translate> | <translate> Default value</translate> | <translate> Description</translate> |
|---|---|---|
| Template:Ll | [ 'source', 'mathml' ]
|
<translate> Defines the mode allowed on the server.</translate> |
| Template:Ll | 'never'
|
<translate> 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 the wikipedia page Help:Math for details.</translate> <translate> Use "always" to disable this feature.</translate> |
| $wgMathFullRestbaseURL | false | <translate> The math extension gets the default config from the Visual Editor, if available.</translate> <translate> Details</translate>. |
| $wgMathPreferRestbaseURL | true | <translate> Whether to allow using of internal RESTBase path instead of $wgMathFullRestbaseURL and $wgVisualEditorFullRestbaseURL. Set false if you want to use external RESTBase in any case.</translate> |
<translate>
Math output modes
</translate> <translate> The setting $wgMathValidModes holds an array with the names of output modes that can be used for rendering.</translate> <translate> If multiple modes are enabled, logged-in users can set a personal preference in the appearance pane of their user preferences page.</translate>
<translate> You can also use the $wgDefaultUserOptions setting to set which of these modes should be the default, e.g.:</translate>
$wgDefaultUserOptions['math'] = 'mathml';
Mathoid
<translate> Mode:</translate> 'mathml' Template:Warning
<translate> You can use [[<tvar name=1>Special:MyLanguage/Manual:Mathoid</tvar>|Mathoid]], an application that uses MathJax on the server side to convert texvc input to MathML+SVG rendering.</translate> <translate> Mathoid is currently the Math rendering mode used on Wikipedia.</translate>
<translate>
Mathoid as a service
"Mathoid as a service" is the recommended approach for the Math extension, and the default one. If you do not add any additional settings to LocalSettings.php, Math will use the Beta cluster's [[<tvar name=mathoid>Special:MyLanguage/Mathoid</tvar>|Mathoid]] and <tvar name=2>Template:Ll</tvar> services to do all math formula rendering. The default settings are: </translate>
// <translate nowrap><!--T:189--> Set MathML as default rendering option</translate>
$wgDefaultUserOptions['math'] = 'mathml';
$wgMathUseInternalRestbasePath = false;
$wgMathFullRestbaseURL = 'https://wikimedia.org/api/rest_';
$wgMathMathMLUrl = 'https://mathoid-beta.wmflabs.org';
<translate> You can modify these settings to use different Mathoid and RESTBase services, potentially including your own.</translate>
<translate>
Mathoid's CLI interface
</translate> <translate> You can instead run Mathoid as a command-line utility on the local server.</translate> <translate> To use this approach, the following settings are recommended:</translate>
// <translate nowrap><!--T:227--> Set MathML as default rendering option</translate>
$wgDefaultUserOptions['math'] = 'mathml';
// <translate nowrap><!--T:228--> Please create a config.yaml in advance. Templates are in the Mathoid repository.</translate>
$wgMathoidCli = ['/path/to/mathoid/cli.js', '-c', '/path/to/mathoid/config.yaml'];
// <translate nowrap><!--T:229--> Raise MediaWiki's memory limit to 1.2G for mathoid.</translate>
$wgMaxShellMemory = 1228800;
LaTeX
Template:MW 1.39 <translate> Mode:</translate> 'png'
<translate> Since MediaWiki 1.32, this mode will also require a Mathoid server to work.</translate> <translate> In older versions, it requires [[<tvar name=1>Special:MyLanguage/Extension:Math/advancedSettings#Installing texvc</tvar>|installing texvc and texvccheck]], which may require the most setup work.</translate>
LaTeXML
<translate> Mode:</translate> 'latexml'
<translate> Uses the <tvar name=LaTeXML>LaTeXML</tvar> utility.</translate> <translate> The rendering is done via an online service (set with <tvar name=1>$wgLaTeXMLUrl</tvar>, which has a default value of <tvar name=2>https://latexml.formulasearchengine.com/convert</tvar>).</translate>
<translate>
Native MathML
</translate> Template:MW 1.40 <translate> Mode:</translate> 'native'
<translate> This mode will generate MathML from LaTeX via PHP without Mathoid.</translate> <translate> Note this mode does not have image fallback, so formulas will only be displayed correctly if the browser supports MathML.</translate> <translate> Firefox and Safari introduced MathML support early (2006 and 2008), but support in Chromium-based browsers is a much more recent addition (Chrome 109, released in 2023).</translate> <translate>
MathJax
</translate> Template:MW 1.42 <translate> Mode:</translate> 'mathjax'
<translate> This mode works the same as Native MathML mode (generating MathML from LaTeX via PHP), but it will use MathJax 3 to render MathML.</translate> <translate> Therefore it will work for browsers that do not have MathML support, with the overhead of loading MathJax library (bundled in Math extension) on page views.</translate> Template:Warning
<translate>
No rendering
</translate> <translate> Mode:</translate> 'source'
<translate> This mode will forward the Latex input without rendering, presenting it in a <tvar name=1>Template:Tag</tvar> element, surrounded by <tvar name=2>$ :formula $</tvar>.
Make sure to set <tvar name=1>$wgMathDisableTexFilter</tvar> to <tvar name=2>'always'</tvar> (see below) if you only want the raw latex formula, else an error will appear due to the failed check for PNG depictions.
Tracking categories
</translate>
<translate> The extension creates a number of {{<tvar name=1>ll|tracking category</tvar>|tracking categories}} to detect errors and deprecated features.</translate>
Their message keys begin with math-.
<translate> Administrators may change a tracking category's name in a wiki by editing the message's value in that wiki's MediaWiki namespace.</translate>
Special:TrackingCategories shows each tracking category's name, message key, and description.
| <translate> MediaWiki page</translate> | <translate> Default</translate> | <translate> Description</translate> |
|---|---|---|
| MediaWiki:Math-tracking-category-error | Category:Pages with math errors | <translate> Pages where there is a syntax error in the formula causing the rendering to fail</translate> |
| MediaWiki:Math-tracking-category-render-error | Category:Pages with math render errors | <translate> Pages where there has been a temporary error in the rendering pipeline causing the rendering to fail. These normally fix themselves</translate> |
| MediaWiki:Math-tracking-category-texvc-deprecation | Category:Pages that use a deprecated format of the math tags | <translate> Pages which use deprecated texvc syntax like <tvar name=1>$ % \and \or \part \ang \C \H \bold \Bbb\ \pagecolor</tvar>, which should be replaced by more standard LaTeX <tvar name=2>\$ \% \land \lor \partial \angle \Complex \mathbb{H} \mathbf \mathbb (removed)</tvar> respectively.</translate> <translate> See <tvar name=1>Template:Ll</tvar>.</translate>
|
| MediaWiki:Math-tracking-category-mhchem-deprecation | Category:Pages that use a deprecated format of the chem tags |
<translate> Deprecated chemical markup, see [[<tvar name=1>Special:MyLanguage/Extension:Math/Roadmap#Step 1 Part C: Manual fixing of mhchem syntax</tvar>|Extension:Math/Roadmap#Step 1 Part C: Manual fixing of mhchem syntax]].</translate> |
<translate>
Tips and tricks
</translate>
- <translate> You can use the Firefox [<tvar name=mathml-copy>https://addons.mozilla.org/de/firefox/addon/mathml-copy</tvar> MathML copy addon] to copy formulae to other applications such as Microsoft Word ([<tvar name=youtube1>https://www.youtube.com/watch?v=FDMfT27zE54</tvar> video]), or Google docs with the [<tvar name=gmath>https://chrome.google.com/webstore/detail/gmath/hhaencnpmaacoojogjkobikbmkhikjmm?utm_source=permalink</tvar> g(Math)] plugin ([<tvar name=youtube2>https://www.youtube.com/watch?v=KKwF6IKRkHU&hd=1</tvar> video])</translate>
- <translate> You can override the user preferred and default rendermode by adding the
forcemathmodeattribute to the <tvar name=1>Template:Tag</tvar> element. e.g. to force an image being rendered <tvar name=2><math forcemathmode="png">...</math></tvar>.</translate> - <translate> All images of rendered formula are stored in a cache and not automatically recreated if the page is viewed or edited.</translate> <translate> To force the re-rendering of all formulas of a page, [[<tvar name=1>Special:MyLanguage/Manual:Purge</tvar>|purge]] using the <tvar name=2>
?action=purge&mathpurge=true</tvar> action.</translate> <translate> For example the URL <tvar name=1>https://en.wikipedia.org/w/index.php?title=Integral&action=purge&mathpurge=true</tvar> will force re-rendering of the w:Integral article.</translate> <translate> Afterwards you need to bypass your browser cache so that the new created images of the formulas are actually downloaded.</translate>
<translate>
Error reporting
If something is wrong with the math extension you can report that at [<tvar name=phabricator>https://phabricator.wikimedia.org/maniphest/task/create/?projects=MediaWiki-extensions-Math</tvar> Phabricator]. In addition you should check how your problem relates to the automated unit tests that are generated from the page [[<tvar name=math-test>Special:MyLanguage/Extension:Math/CoverageTest</tvar>|CoverageTest]].
Further reading
See <tvar name=1>Template:Ll</tvar> for old versions and further information.
Subpages
</translate> Template:Subpages
<translate>
See also
</translate>
- Template:Ll
- Template:Ll
- Template:Ll - <translate> an alternative way to provide support for rendering mathematical formulas on-wiki, without texvc or LaTeX</translate>
- Template:Ll
- Template:Ll
- Template:Ll
Template:OnWikimedia Template:Used by
[[Category:TeX{{#translation:}}]] [[Category:Math display extensions{{#translation:}}]] [[Category:Extensions with VisualEditor support{{#translation:}}]]