Extension:數學

This page is a translated version of the page Extension:Math and the translation is 80% complete.
Outdated translations are marked like this.
此扩展已绑定在MediaWiki 1.38及以上版本。 因此您不需要再次下载。 然而,您仍需要跟随提供的其他指示。
MediaWiki的扩展的手冊
Math
發佈狀態: 穩定版本
实现 标签
描述 允许生成数学公式
作者
  • Moritz Schubotz,
  • Tomasz Wegrzanowski,
  • Brion Vibber
  • 以及其他贡献者
最新版本 continuous updates
兼容性政策 快照跟随MediaWiki发布。 master分支不向後兼容。
MediaWiki >= 1.40.0
数据库更改
math
mathoid
mathlatexml
许可协议 GNU通用公眾授權條款2.0或更新版本
下載
  • $wgMathEnableWikibaseDataType
  • $wgMathDefaultLaTeXMLSetting
  • $wgMathUseInternalRestbasePath
  • $wgMathMathMLUrl
  • $wgMathFullRestbaseURL
  • $wgMathTexVCService
  • $wgMathInternalRestbaseURL
  • $wgMathConcurrentReqs
  • $wgMathEnableFormulaLinks
  • $wgMathValidModes
  • $wgMathEntitySelectorFallbackUrl
  • $wgMathWikibasePropertyIdQuantitySymbol
  • $wgMathDisableTexFilter
  • $wgMathMathMLTimeout
  • $wgMathWikibasePropertyIdSymbolRepresents
  • $wgMathWikibasePropertyIdHasPart
  • $wgMathWikibasePropertyIdInDefiningFormula
  • $wgMathWikibasePropertyIdDefiningFormula
  • $wgMathoidCli
  • $wgMathLaTeXMLUrl
  • $wgMathLaTeXMLTimeout
  • $wgMathEnableExperimentalInputFormats
‎<math>
季度下載量 361 (Ranked 31st)
公開的wiki使用 7,934 (Ranked 18th)
翻譯Math的扩展,若在translatewiki.net可用
問題 尚未完成的工作 · 报告錯誤

数学(Math)扩展提供渲染数学公式的支持。有关当前此扩展的功能的概述,请参考m:Help:显示公式

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

查看数学公式

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

安裝

  • 下载文件,并将其放置在您extensions/文件夹中的Math目录内。
  • 将下列代码放置在您的LocalSettings.php 的底部:
    wfLoadExtension( 'Math' );
    
  • 运行更新脚本,它将自动创建此扩展必须依赖的数据库表。
  • 要查看純文本輸出之外的數學輸出模式,請按照以下說明啟用各種數學輸出模式
  • 如果您在尝试使用wikipedia restbase时遇到表示公式的问题,您可以尝试使用以下修复
  •   完成 – 在您的wiki上导航至Special:Version,以验证已成功安装扩展。


Vagrant安装:

  • 如果使用Vagrant ,请通过vagrant roles enable math --provision安装

您还应该转到页面Special:MathStatus以查看Math扩展的所有组件现在是否正常工作。 对于你遇到的任何问题,最好的办法是在https://phabricator.wikimedia.org创建一个任务。

可惜还没有经过良好测试的关于安装Mathoid RESTBase 以使用Math扩展的指南,但至少有个进展中的草稿。 Extension:Math/RESTBase 请贡献。

数学输出模式

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

你也可以使用$wgDefaultUserOptions设置来设置哪个模式是默认的,比如:

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

Mathoid

模式: 'mathml'

您可以使用Mathoid,这是一个在服务器端使用MathJax将texvc输入转换为MathML+SVG渲染的应用。 这是最推荐的选项,Mathoid是维基百科上使用的数学渲染模式。

服务器上的Mathoid

“Mathoid as a service”是Math扩展的推荐方法,也是默认方法。如果您不向LocalSettings.php添加任何其他设置,Math将使用Wikimedia MathoidRESTBase 服务来渲染所有数学公式。默认设置为:

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

您可以修改这些设置,以使用不同的Mathoid和RESTBase服务,可能包括您自己的。

Mathoid的命令行接口

您还可以在本地服务器上将Mathoid作为命令行实用程序运行。 要使用此方法,建议使用以下设置:

// 将MathML设为默认渲染选项
$wgDefaultUserOptions['math'] = 'mathml';
// 请提前创建一个config.yaml。模板位于Mathoid存储库中。
$wgMathoidCli = ['/path/to/mathoid/cli.js', '-c', '/path/to/mathoid/config.yaml'];
// 因为Mathoid,将MediaWiki的内存限制提高到1.2G。
$wgMaxShellMemory = 1228800;

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

setsebool -P httpd_execmem 1
setsebool -P httpd_setrlimit 1

LaTeX

MediaWiki版本:
1.39

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

模式: 'latexml'

Uses the LaTeXML utility. The rendering is done via an online service (set with $wgLaTeXMLUrl, which has a default value of https://latexml.formulasearchengine.com/convert).

未渲染

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

重要的配置设置列表

设置名 默认值 描述
$wgMathValidModes [ '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

提示与技巧

错误报告

如果Math扩展有问题,您可以在Phabricator报告。此外,您应检查您的问题与页面CoverageTest生成的自动化单元测试有何关系。

延伸阅读

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

子页面

參見