SIAM News Blog
SIAM News
Print

MathJax: The Present and the Future

By Davide P. Cervone and Volker Sorge

At the Joint Mathematics Meetings in January 2010, we announced version 1.0 of the MathJax JavaScript library for accurately typesetting mathematics in web pages. Almost immediately, MathJax became the de facto standard for formatting mathematics on the web. A wide range of online journals, including the American Mathematical Society’s (AMS) MathSciNet website and SIAM News Online, employ MathJax. It allows online blogs, wikis, and question-and-answer sites—such as StackExchange and Wikipedia—to include mathematical expressions; provides the mathematics for online homework systems like WeBWorK and learning management systems like Moodle; and is incorporated into e-book readers, screen readers, and other similar products.

In the 10 years since its introduction, MathJax has expanded to include LaTeX, MathML, and AsciiMath input formats, as well as output formats like HTML-with-CSS, Scalable Vector Graphics (SVG), and MathML. The introduction of sophisticated semantic enrichment and speech-generation functionality in June 2016 made MathJax a crucial component in the creation of web pages and e-books that are accessible to blind or low-vision readers who utilize assistive technology, such as screen readers or Braille output devices. In short, MathJax increases the accessibility of online course materials and published research, which is even more valuable in the age of distance learning.

Much has changed in web technology since MathJax’s introduction. New web libraries and improvements to the JavaScript language have altered the way in which web-page designers wish to use MathJax, and some of the initial approaches that were built into the library are not compatible with modern workflows. For the last three years, MathJax has been undergoing a complete rewrite with the goal of modernizing its internal infrastructure, increasing its flexibility for use with contemporary web technologies, facilitating its use for preprocessing and server-side support, and expediting the production of typeset mathematics. The release of MathJax version 3.0 in August 2019 brought these hopes to fruition.

Version 3 is written in the TypeScript language, a form of JavaScript in which one can add types to variables and functions that a compiler then checks for correctness. This helps identify errors earlier in the process, yields more reliable code that users can easily understand, and makes it easier for others to contribute to MathJax. Version 3 also lets users exploit new features of JavaScript that are part of the latest ES6 standard, while still supporting older browsers that have not implemented these features. For example, we now use ES6's modern class structure and take advantage of asynchronous features like promises. Because these options were not available 10 years ago, v2 implemented its own object system and provided custom signals, queues, and callbacks for asynchronous operation.

Version 3’s new internal structure and modern ES6 features—which today’s JavaScript interpreters can exploit for run-time optimization—remove performance issues that were inherent in the design of v2, thus improving MathJax’s rendering speed. Although it is difficult to make precise comparisons because the two versions operate so differently, tests that render a complete page with several hundred expressions see a reduction of between 60 and 80 percent in rendering time (depending on the browser and operating system).

MathJax v2 used its own loading mechanism for accessing its components, which did not work well with modern JavaScript packaging systems like webpack or Rollup. Version 3 resolves this problem and interoperates more effectively with modern web workflows; for instance, users can make custom single-file builds of MathJax or include it as one component of a larger asset file.

New in version 3 is the ability to run MathJax synchronously; this was not possible in v2, as its operation is inherently asynchronous. In particular, v3 provides functions that can translate an input string (a TeX expression, for example) into an output Document Object Model tree (such as an SVG image). One can apply these functions to individual expressions or entire documents. This is especially important when preparing rendered pages for offline consumption.

MathJax was originally designed for use in a web browser, which left the desire to pre-process mathematics on a server unaddressed. Version 3, which was redesigned to make this possible, can be used within node applications in essentially the same way as in a browser. That is, one can load MathJax components, configure them through the MathJax global variable, and call the same functions for typesetting and conversion as in a browser. This simplifies parallel development for both the browser and the server. Moreover, node applications can access MathJax modules directly (without the packaging needed for MathJax’s use in a browser). This provides the most direct access to MathJax’s features and the most flexibility in controlling MathJax’s actions.

MathJax makes mathematics accessible to readers with disabilities, which distinguishes the library from other math-rendering solutions. While its initial goal was to work with the third-party assistive technology software that was available at the time, all iterations of MathJax since version 2.7 have offered their own accessibility solutions that are meant to operate independently of the user’s browser, operating system, and assistive technology solutions (e.g., screen readers). The extension provides support for readers with functional needs, such as blindness, low vision, dyslexia, or dyscalculia.

The accessibility extension uses the speech rule engine library to translate mathematical expressions into speech strings. Its core components comprise the automatic voicing of formulas together with interactive navigation and synchronized highlighting, as well as an abstraction feature that enables visual simplification and summary speech description of formulas.

MathJax v3 greatly extends these capabilities, which make use of its new modular setup to enable a flexible pick-and-mix personalization of accessibility tools. In particular, MathJax now offers a number of different rule sets for voicing mathematics that one can pre-select or switch on the fly. For instance, readers can choose a different rule set while interactively exploring an expression; the expression is thus spoken in a different way, which provides a new view of it. Version 3 also improves low-vision support by enabling magnification, not only for entire formulas but also for sub-expressions. It even provides better accessibility to advanced mathematical material by exploiting information from the original LaTeX code to generate more appropriate speech for different areas of mathematics, as well as subjects like physics, chemistry, and logic.

MathJax was originally meant to be a stop-gap measure, until browsers implemented native math rendering through MathML. Yet after more than 10 years, browser support for MathML is still not universal, and MathJax continues to bring quality math typesetting to all modern browsers. Our work has been supported by grants from the Sloan Foundation and the Simons Foundation, as well as generous contributions from our sponsors, including the AMS, SIAM, Elsevier, the Institute of Electrical and Electronics Engineers, and a variety of professional societies, publishers, and websites. Without their ongoing financial support, MathJax would not be possible. The version 3 rewrite puts MathJax in a strong position to continue making beautiful and accessible mathematics available on the web for years to come.


A similar version of this article also appeared in the November issue of Notices of the American Mathematical Society.

Davide P. Cervone is a professor of mathematics at Union College, where he has taught for nearly 25 years.  He has been the lead developer for MathJax since its inception in 2008. Volker Sorge is a professor of document analysis and accessibility in the School of Computer Science at the University of Birmingham. He has served as the Tech Lead for Accessibility of the MathJax Consortium since 2015.

blog comments powered by Disqus