Jump to content

Extension:Math/Native MathML rollout (2024)

From mediawiki.org

The Math extension is transitioning to native MathML, thus replacing the rendering of math formulas via the Mathoid service.

Comparison

[edit]

SVG

[edit]

This below uses SVG. Today, in MediaWiki 1.42 (and as the case on most Wikimedia Foundation wikis) we render Math formulas into an SVG. These SVGs are linked as an HTML image, and served to the web from file storage, generated via an internal Node.js service that runs MathJax whenever MediaWiki saves or previews an edit. In addition to the SVG, this mode also outputs a hidden MathML element generated by the same Node.js service, for the benefit of machine-readable semantic web, portability, and accessibility (e.g. plain text in the clipboard in supporting browsers).

MathML

[edit]

E=mc2

This below uses MathML. The Math extension for MediaWiki supports a new "native MathML" mode written in PHP. This turns math fornulas in wikitext source directly into MathML, using the HTML5 <math> element.

x1+yy=x2z=af(x,y,z)=x+y+z

History

[edit]

The Math extension was originally developed around texvc, an OCaml program compiled and invoked as shell command.

In 2014, the Mathoid service was introduced in addition to textvc. Over the years, this became feature complete (T78046) and added benefits over the status quo including improved legibility (SVG being naturally in high resolution, such as for Retina screens) and improved accessibility/portability of HTML5 MathML. The service used MathJax, which supported these features already. Mathoid was launched as a user preference (labelled "MathML with SVG or PNG fallback"). In 2016, based on a community request this was made the default on all Wikimedia Foundation wikis in 2016 (enwiki RFC , T131177).

In 2018, Mathoid also became the default for the Math extension and thus the MediaWiki release as used by third parties. In order to ease installation, this defaulted to the live wikimedia.org installation of RESTBase/Mathoid. At this time, support for the texvc software was discontinued to ensure consistent feature parity in wikitext syntax (which is important for portability of MediaWiki content across the Internet), and to reduce maintenance burden (T74240, T195871).

In 2019, it was decided to sunset RESTBase (RESTBase/deprecation, T262315, board). By this time, RESTBase and other services from the former Wikimedia Services team had also become unowned or under maintained. Various options were evaluated (T338429) of which native MathML came out as most desirable (T271001). Benefits include reduced operational costs and overall complexity (remove on-going maintenance and operation of the Node.js service, remove need for long-term SVG file storage, remove need for RESTBase database to map hashes to files for all third-party MediaWiki sites), as well as restoring independent operation of MediaWiki as a software, thus resolving the question of MediaWiki LTS support and a long-tail of use cases which became dependant on the live wikimedia.org service (local development, CI, old third-party installs, archival research/benchmarking of the software).

As of 2022, all major browsers support MathML. Chromium was the last to join, thanks to Igalia. Read more at https://mathml.igalia.com/.

NativeML gives the user control over the rendering, including custom rendering via browser extensions, and styling of individual portions of the math formula via CSS and user styles.

Please report bugs on Phabricator. Freel free to mention new bugs in comments, or attach as new sub task, under https://phabricator.wikimedia.org/T271001. This is where blocking bugs, testing, and rollout is tracked.

Example usage

[edit]

In the wikitext source, Math formulas are written using LaTeX, like so:

What Markup Output
Mass–energy equivalence
<math>E=mc^2</math>
E=mc2
Cancellations in fractions
<math>\cfrac{x}{1 + \cfrac{\cancel{y}}{\cancel{y}}} = \cfrac{x}{2}</math>
x1+yy=x2
Multi-line equations
<math>\begin{array}{lcr}
 z & = & a \\
 f(x,y,z) & = & x + y + z
\end{array}</math>
z=af(x,y,z)=x+y+z

See also

[edit]
  • Extension:Math/Syntax, the manual for the LaTeX syntax and how it works for different use cases, along with examples and their (new) native MathML rendering.