This page is a translated version of the page Extension:Math and the translation is 67% complete.
OOjs UI icon advanced-invert.svg
发布状态: 稳定版
ExtensionMath (cropped).svg
实现 标签
描述 允许生成数学公式
  • Moritz Schubotz,
  • Tomasz Wegrzanowski,
  • Brion Vibber
  • 以及其他贡献者
最新版本 continuous updates
兼容性方针 快照跟随MediaWiki发布。 master分支不向后兼容。
MediaWiki 1.25+
许可协议 GNU通用公眾授權條款2.0或更新版本
  • $wgMathEnableWikibaseDataType
  • $wgMathDefaultLaTeXMLSetting
  • $wgMathWikibasePropertyIdHasPart
  • $wgMathoidCli
  • $wgMathLaTeXMLTimeout
  • $wgMathWikibasePropertyIdQuantitySymbol
  • $wgMathDisableTexFilter
  • $wgMathMathMLTimeout
  • $wgMathLaTeXMLUrl
  • $wgMathEnableExperimentalInputFormats
  • $wgMathValidModes
  • $wgMathWikibasePropertyIdDefiningFormula
  • $wgMathFullRestbaseURL
  • $wgMathMathMLUrl
  • $wgMathConcurrentReqs
  • $wgMathEnableFormulaLinks


问题 尚未完成的工作 · 回報錯誤


更多有关安装和配置此扩展(包括旧版本)的信息,可在Extension:Math/advancedSettings 中查阅。


数学扩展会依次尝试输出MathML、SVG图片(将字符转换成<路径>)或PNG图片(最低优先级)。 输出的结果将取决于你使用的设备的兼容性。 基本數學支持適用於所有瀏覽器。但是,為了獲得最佳渲染,可能需要進行特定的調整:



  • 如果使用Vagrant ,请通过vagrant roles enable math --provision安装
  • 下载文件,并将其放置在您extensions/文件夹中的Math目录内。
  • 将下列代码放置在您的LocalSettings.php的底部:
    wfLoadExtension( 'Math' );
    // 下面是安装和配置的设置:
  • 运行更新脚本,它将自动创建此扩展必须依赖的数据库表。
  • 要查看純文本輸出之外的數學輸出模式,請按照以下說明啟用各種數學輸出模式
  • If you have problems for represent formulas when trying to use wikipedia restbase, you can try using the following patch
  •   完成 – 在您的wiki上导航至Special:Version,以验证已成功安装扩展。

You should additionally go to the page Special:MathStatus to see whether all of the components of the Math extension now work. 对于你遇到的任何问题,最好的办法是在https://phabricator.wikimedia.org创建一个任务。

Unfortunately, there is no well tested guide on installing Mathoid and RESTBase to work with the Math extension, but there is at least a working draft. Extension:Math/Restbase 请贡献。

此外,GitHub上有个通过Restbase和MW 1.28的Mathoid安装并设置MediaWiki的教程


设置$wgMathValidModes包含含有可以用于渲染的输出模式的名称的序列。 如果多个模式启用,已登录的用户可以在用户参数设置页面的appearance面板中设置个人偏好。


$wgDefaultUserOptions['math'] = 'mathml';


模式: 'mathml' (pre-July 2015: MW_MATH_MATHML)

For MW 1.23 and higher, you can use a Mathoid server that uses MathJax to convert texvc input on the server side to MathML+SVG rendering. This is the most recommended option; Mathoid is the rendering mode that is on Wikipedia.



// 将MathML设为默认渲染选项
$wgDefaultUserOptions['math'] = 'mathml';
$wgMathFullRestbaseURL = 'https://en.wikipedia.org/api/rest_';
$wgMathMathMLUrl = 'https://mathoid-beta.wmflabs.org/';

关于自行搭建Mathoid服务器的指南在Mathoid页面 Note that as of March 2017 this is likely to also require a RESTBase server/installation (see 任务T154394).


To use Mathoid's CLI interface, which is possibly easier to set up and resulting in less permanent memory consumption, while degrading performance, the following settings are recommended:

// 将MathML设为默认渲染选项
$wgDefaultUserOptions['math'] = 'mathml';
// Please create a config.yaml in advance. Templates are in the Mathoid repository.
$wgMathoidCli = ['/path/to/mathoid/cli.js', '-c', '/path/to/mathoid/config.yaml'];
// Raise MediaWiki's memory limit to 1.2G for mathoid.
$wgMaxShellMemory = 1228800;

If you run MediaWiki under system containing SELinux and you get Mathoid cli '/path/to/mathoid/cli.js' is not executable message from the error log, you can run the following to make sure the Apache server allow to change system limits:

setsebool -P httpd_execmem 1
setsebool -P httpd_setrlimit 1


模式: 'png' (pre-July 2015: MW_MATH_PNG)

Since MediaWiki 1.32, this mode will also require a Mathoid server to work. In older versions, it requires installing texvc and texvccheck, which may require the most setup work.


模式: 'latexml' (pre-July 2015: MW_MATH_LATEXML)

Uses the LaTeXML utility. The rendering is done via an online service (set with $wgLaTeXMLUrl, which has a default value).


模式: 'source', (pre-July 2015: MW_MATH_SOURCE)

This mode will forward the Latex input without rendering, presenting it in a ‎<span> element, surrounded by $ :formula $.

Make sure to set $wgMathDisableTexFilter to 'always' (see below) if you only want the raw latex formula, else an error will appear due to the failed check for PNG depictions.


  警告: The client-side MathJax rendering mode is removed in MediaWiki 1.26. 另请参阅擴展:SimpleMathJax


设置名 默认值 描述
$wgMathValidModes array( 'png', 'source', 'mathml' ) 定义该服务器上可用的渲染模式
$wgMathDisableTexFilter 'never' 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. Use "always" to disable this feature.
$wgMathFullRestbaseURL false The math extension gets the default config from the Visual Editor, if available. 详情.


扩展会创建一系列跟踪分类,以检测错误和不被推荐的特性。 分类的准确名称由MediaWiki名字空间内的页面决定。

MediaWiki页面 默认 描述
MediaWiki:Math-tracking-category-error Category:Pages with math errors 含有导致渲染失败的公式语法错误的页面
MediaWiki:Math-tracking-category-render-error Category:Pages with math render errors Pages where there has been a temporary error in the rendering pipeline causing the rendering to fail. These normally fix themselves
MediaWiki:Math-tracking-category-texvc-deprecation Category:Pages that use a deprecated format of the math tags Pages which use deprecated texvc syntax like $ % \and \or \part \ang \C \H \bold \Bbb\ \pagecolor, which should be replaced by more standard LaTeX \$ \% \land \lor \partial \angle \Complex \mathbb{H} \mathbf \mathbb (removed) respectively. 参见Extension:Math/Roadmap
MediaWiki:Math-tracking-category-mhchem-deprecation Category:Pages that use a deprecated format of the chem tags

不被推荐的化学标记,参见Extension:Math/Roadmap#Step 1 Part C: Manual fixing of mhchem syntax


  • You can override the user preferred and default rendermode by adding the forcemathmode attribute to the ‎<math> element. e.g. to force an image being rendered <math forcemathmode="png">...</math>.
  • All images of rendered formula are stored in a cache and not automatically recreated if the page is viewed or edited.

To force the re-rendering of all formulas of a page, purge using the ?action=purge&mathpurge=true action. For example the URL https://en.wikipedia.org/w/index.php?title=Integral&action=purge&mathpurge=true will force re-rendering of the w:Integer article. Afterwards you need to bypass your browser cache so that the new created images of the formulas are actually downloaded.


If something is wrong with the math extension you can report that at Phabricator. In addition you should check how your problem relates to the automated unit tests that are generated from the page CoverageTest.