Open main menu
This page is a translated version of the page Extension:Math and the translation is 52% complete.
Outdated translations are marked like this.
Other languages:
Deutsch • ‎English • ‎Tiếng Việt • ‎dansk • ‎español • ‎français • ‎magyar • ‎português do Brasil • ‎中文 • ‎日本語 • ‎粵語 • ‎한국어
MediaWiki扩展手册
OOjs UI icon advanced.svg
Math
发布状态: 稳定版
ExtensionMath (cropped).png
实现 标签
描述 允许生成数学公式
作者
  • Moritz Schubotz,
  • Tomasz Wegrzanowski,
  • Brion Vibber
  • and others
最新版本 continuous updates
MediaWiki 1.25+
数据庫更新
表格 math
mathoid
mathlatexml
许可协议 GNU通用公眾授權條款2.0 or later
下载

  • $wgUseTeX
  • $wgTexvc
  • $wgTexvcBackgroundColor
  • $wgMathCheckFiles
  • $wgMathPath
  • $wgMathDirectory
  • $wgMathFileBackend
<math>
翻译Math扩展如果在translatewiki.net可用
检查使用和版本矩阵。
问题 开放的工作 · 报告错误

数学扩展端提供渲染数学公式的支持。有关当前此扩展的功能的概述,请参考这个英语维基百科页面

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

查看数学公式

数学扩展正尝试提供MathML输出,分别以SVG或PNG图片形式。

输出的结果是哪一种将取决于你使用的设备的功能。 Basic math support works for all browsers. However, for optimal rendering specific tuning may be needed:

Accessibility support is provided by the VoiceOver screen reader but not by Orca yet.

安装

关于如何在MediaWiki 1.31及其以后版本上安装本扩展的信息,请阅读这个页面
  • 如果使用Vagrant ,请通过vagrant roles enable math --provision安装
手动安装
  • 下载文件,并将其放置在您extensions/文件夹中的Math目录内。
  • 将下列代码放置在您的LocalSettings.php的底部:
    wfLoadExtension( 'Math' );
    // 下面是安装和配置的设置:
    
  • 运行更新脚本,它将自动创建此扩展必须依赖的数据库表。
  • 要查看純文本輸出之外的數學輸出模式,請按照以下說明啟用各種數學輸出模式
  •   完成 – 在您的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. For any problems you see, the best option is to create a task on 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 请贡献。

In addition, there is a Guide for Installing and Setting up Mediawiki with Restbase and Mathoid in MW1.28.

数学输出模式

The setting $wgMathValidModes holds an array with the names of output modes that can be used for rendering. If multiple modes are enabled, logged-in users can set a personal preference in the appearance pane of their user preferences page.

You can also use the $wgDefaultUserOptions setting to set which of these modes should be the default, e.g.:

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

Mathoid

模式: '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 will be used on Wikipedia in the future.

服务器上的Mathoid

为了使用服务器上的Mathoid以获得表现形式上的好处,推荐进行下列设置:

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

See Mathoid for instructions on how to run your own Mathoid server. Note that as of March 2017 this is likely to also require a RESTBase server/installation (see 任务T154394).

Mathoid的命令行接口

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

setsebool -P httpd_execmem 1
setsebool -P httpd_setrlimit 1

to make sure the Apache server allow to change system limits.

LaTeX

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

This is the mode that requires the most setup work, since at least the texvc utility has to be installed for it to work, and ideally texvccheck as well. See Installing texvc for how to install both of these.

LaTeXML

模式: '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).

未渲染

Mode: '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.

MathJax

模式: MW_MATH_MATHJAX

This mode uses the MathJax application for client-side rendering. It is now deprecated, and requires MediaWiki 1.25 or lower in order to run. See Client-side rendering with MathJax for how to use it.

重要的配置设置列表

设置名 默认值 描述
$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. 详情.

提示与技巧

  • You can use the Firefox MathML copy addon to copy formulae to other applications such as Microsoft Word (video), or Google docs with the g(Math) plugin (video)
  • You can override the user preferred and default rendermode by adding the forcemathmode attirbute to the <math> element. eg.. to force an image being rendered <math forcemathmode="png">...</math>.

错误报告

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.

扩展阅读

旧版本以及更多信息可参考Extension:Math/advancedSettings

子页面

参见