MathJax Documentation

repository·master·Indexed 19 days ago

https://github.com/mathjax/mathjax-docs

Documentation for MathJax, a JavaScript engine that renders high-quality, accessible mathematics (LaTeX, MathML, AsciiMath) in web browsers and Node.js. Includes details on the processing model (Input and Output jax), the MathDocument and MathItem abstractions, synchronization mechanisms, and the use of pre- and post-filters to customize the typesetting pipeline.

Tokens
146.6K
Snippets
439
Records
682
Agent score
68%

What's inside MathJax

  1. Overview of MathJax

    master

    MathJax is an open-source JavaScript display engine designed to render LaTeX, MathML, and AsciiMath notation in all modern browsers.

    Key features include:

    • Accessibility: Built-in support for assistive technology like screen readers, featuring automatic speech generation and an expression explorer for granular investigation of typeset mathematics.
    • Version 4.0 Enhancements: Adds support for multiple mathematical fonts, in-line and displayed equation line breaking, and HTML within MathML and LaTeX expressions.

    Note on Versioning: MathJax v3 and v4 use a significantly different usage and configuration model compared to MathJax v2. If you are using v2, you should refer to the version 2 documentation specifically.

  2. Overview of MathJax Accessibility Components

    master

    MathJax provides five specialized components to support assistive technology:

    • a11y/semantic-enrich: Connects MathJax with the Speech Rule Engine to add semantic structure attributes to mathematics. This improves line-breaking and speech generation.
    • a11y/speech: Uses the Speech Rule Engine to generate speech strings. It runs in web-workers to prevent UI lag during time-consuming speech computations.
    • a11y/explorer: Enables interactive exploration of mathematical expressions. Users can tab to an expression and use arrow keys to navigate through sub-expressions (Down for more detail, Up for more complete expressions, Left/Right for siblings).
    • a11y/complexity: Computes complexity measures for elements, allowing complex expressions to "collapse" for readability. Collapsed parts can be expanded via mouse click or keyboard actions within the explorer component.
    • a11y/assistive-mml: Embeds visually hidden MathML alongside visual rendering. While explorer is the default in v4, assistive-mml can be re-enabled via the MathJax contextual menu or configuration.
  3. What is MathJax?

    master

    MathJax is an open-source JavaScript display engine designed to render LaTeX, MathML, and AsciiMath notation in modern web browsers. It produces high-quality, text-based typesetting using web fonts, ensuring that mathematics is scalable, printable at full resolution, and searchable by search engines.

    Key features include:

    • Multiple Input Formats: Supports TeX/LaTeX, MathML, and AsciiMath.
    • Multiple Output Formats: Can generate HTML with CSS styling or Scalable Vector Graphics (SVG).
    • Accessibility: Generates speakable text for screen readers and provides interactive tools like an expression explorer and expression collapsing to assist visually impaired users.
    • Modular & Extensible: Components are loaded only when necessary, and the engine can be extended with new capabilities.
    • Environment Support: Works in both web browsers and on servers (e.g., as part of a node.js application) for pre-processing web pages.
  4. Overview of MathJax synchronization mechanisms

    master

    MathJax provides several ways to synchronize your custom code with its internal processing workflow. You can hook into the MathJax lifecycle using the following methods:

    • Promises: Use functions that return promises to wait for specific MathJax operations to complete.
    • Render Actions: Add your own actions to a processing queue.
    • Filters: Use input and output jax filter queues to run functions before or after MathJax processes math.
    • Hooks/Configuration: Use configuration options to perform actions at startup once MathJax is ready to process math.
  5. New features in MathJax v2.2

    master

    MathJax v2.2 introduced several key features:

    • Localization: The user interface can now be localized (German and French translations are available alongside English).
    • AMScd Extension: Support for commutative diagrams via the AMScd extension.
    • Safe-mode Extension: A new extension to restrict potentially dangerous features (like href to javascript, specific styles, or classes) when MathJax is used in shared or untrusted environments.
    • Improved MathML Rendering: Enhanced support for mfenced and mlabeldtr elements in browsers with limited native support.
    • Experimental Content MathML: Added experimental support for Content MathML.
  6. Choose a method for using MathJax in Node.js

    master

    MathJax can be integrated into Node.js applications using four primary approaches, depending on your requirements for control, ease of use, and environment:

    1. Experimenting (Simple): A quick way to start testing MathJax in Node, but it is not intended for production use and cannot be used in a browser.
    2. MathJax Components (Standard): Uses the same component-based mechanism used in browsers. This allows you to load smaller pieces of MathJax as needed. Note that loading components is generally asynchronous, so you must handle Promises in your code.
    3. Synchronous Components (Pre-loading): To avoid the complexity of asynchronous component loading during expression processing, you can pre-load all required components. This allows you to use the component framework more predictably.
    4. Direct Module Access (Advanced): Calling MathJax code modules directly, bypassing the components framework. This provides the highest level of control but lacks the convenience and abstraction provided by the components system.
  7. Components of MathJax

    master

    MathJax is composed of several functional modules:

    • Input jax: Translates input formats (TeX/LaTeX, MathML, AsciiMath) into internal MathML JavaScript objects. They define how to locate math using delimiters.
    • Input extensions: Optional modules for the TeX input jax that add LaTeX macros or features. These can be loaded via configuration, the tex-autoload extension, or the \require{extension-name} macro within a math expression.
    • Output jax: Converts internal MathML into visual formats like CHTML (HTML/CSS) or SVG (Scalable Vector Graphics).
    • Fonts: Provide the visual glyphs for output jax. In v4, authors can create custom fonts or extensions.
    • Contextual Menu: A user-facing interface that allows readers to copy notation, generate SVG images, or modify MathJax settings (e.g., line length, renderer, or speech/accessibility settings).
    • MathDocument: The internal engine that coordinates all actions on a page. In applications using the MathJax Components framework, the instance can be accessed via MathJax.startup.document.
  8. Available MathJax output components

    master

    MathJax currently provides two primary output formats, each available as a separate component:

    1. output/chtml: The CommonHTML output processor.
    2. output/svg: The SVG output processor.

    Note on MathML: The NativeMML output jax from MathJax version 2 has not been ported to version 3 and above and is unlikely to be supported in future versions.

  9. Identify improvements in MathJax 2.0

    master

    MathJax 2.0 introduced several major enhancements over previous versions, including:

    • Performance: Major speed improvements for HTML-CSS output, especially in Internet Explorer, and reduced flickering during typesetting.
    • TeX Features: Automatic equation numbering of TeX formulas and automatic line breaking for long displayed equations.
    • New Input/Output: Support for AsciiMath input jax and SVG output jax.
    • Configuration: Introduction of new combined configuration files.
    • Accessibility & UI: Improved support for screen readers, a MathJax contextual menu available on mobile devices, and font enhancements.
    • Interface: General interface improvements and many new TeX additions/enhancements.
  10. Understand the core improvements in MathJax v3.0

    master

    MathJax v3.0 is a complete rewrite designed for modern web development. Key improvements include:

    • Performance: Rendering speeds are significantly faster, with tests showing a 60-80% reduction in rendering time for pages with several hundred expressions.
    • Flexibility: The typesetting process is broken into smaller, modular units (actions) that can be individually called, replaced, or removed.
    • Modern JavaScript: Built with ES6 modules and TypeScript. It supports asynchronous operations via standard ES6 Promises instead of the custom queues, signals, and callbacks used in v2.
    • Environment Support: Designed to work seamlessly in both browsers and Node.js environments using the same configuration patterns.
    • Package Management: Better interoperability with modern bundlers like webpack through custom single-file builds or component-based loading.
  11. Browser compatibility for MathJax

    master

    MathJax v3 and above requires modern browser features and no longer supports older browsers.

    • Supported Output Formats: CommonHTML and SVG output support all modern browsers (Chrome, Safari, Firefox, Edge) and most mobile browsers.
    • Internet Explorer Support: MathJax v4 no longer supports any version of Internet Explorer. While some expressions might render, no testing or accommodations are made for IE.

    If you encounter issues, it is recommended to provide screenshots using services like browsershots.org, saucelabs.com, or browserstack.com when filing GitHub issues.

  12. Configure Input Processor Options

    master

    MathJax supports multiple input processors, including TeX, MathML, and AsciiMath. Each processor has its own specific set of configuration options. To configure a specific processor, you must use the options relevant to that input format.

    Available input processors documented in this section:

    • TeX
    • MathML
    • AsciiMath