Skip to content

MathJax

MathJax is a beautiful and accessible way to display mathematical content in the browser, allows for writing formulas in different notations, including LaTeX, MathML and AsciiMath, and can be easily integrated with Material for MkDocs.

Configuration

Arithmatex

Source · Extension

The Arithmatex extension, which is part of of Python Markdown Extensions, allows the rendering of block and inline block equations, and can be enabled via mkdocs.yml:

markdown_extensions:
  - pymdownx.arithmatex:
      generic: true

Besides enabling the extension in mkdocs.yml, a MathJax configuration and the JavaScript runtime need to be included, which can be done with additional JavaScript:

window.MathJax = {
  tex: {
    inlineMath: [["\\(", "\\)"]],
    displayMath: [["\\[", "\\]"]],
    processEscapes: true,
    processEnvironments: true
  },
  options: {
    ignoreHtmlClass: ".*|",
    processHtmlClass: "arithmatex"
  }
};
extra_javascript:
  - javascripts/config.js
  - https://polyfill.io/v3/polyfill.min.js?features=es6
  - https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js

MathJax can be configured in many different ways, for which Material for MkDocs might not provide native support. See the official documentation for more information.

Using MathJax with instant loading

There's no additional effort necessary to integrate MathJax 3 with instant loading – it's expected to work straight away. However, a previous version of this document explained how to integrate Material for MkDocs with MathJax 2, which doesn't exhibit this behavior. It's therefore highly recommended to switch to MathJax 3.

Usage

Using block syntax

Blocks must be enclosed in $$...$$ or \[...\]on separate lines:

Example:

$$
\operatorname{ker} f=\{g\in G:f(g)=e_{H}\}{\mbox{.}}
$$

Result:

\[ \operatorname{ker} f=\{g\in G:f(g)=e_{H}\}{\mbox{.}} \]

Using inline block syntax

Inline blocks must be enclosed in $...$ or \(...\):

Example:

The homomorphism $f$ is injective if and only if its kernel is only the 
singleton set $e_G$, because otherwise $\exists a,b\in G$ with $a\neq b$ such 
that $f(a)=f(b)$.

Result:

The homomorphism \(f\) is injective if and only if its kernel is only the singleton set \(e_G\), because otherwise \(\exists a,b\in G\) with \(a\neq b\) such that \(f(a)=f(b)\).