MathJax in Sphinx

Using any math on a page causes Sphinx to automatically load MathJax: \(e^{i\pi} = -1\).

If you want to highlight pieces of code with MathJax, too, then you can either:

  • Use a custom mathjax config script (see the discussion in recipes/mathjax.rst, the configuration in conf.py, and the implementation in recipes/sphinx/_static/mathjax_config.js). Math in the following snippet is highlighted using this technique; look for the link to mathjax_config.js in the <head> of this webpage:

    Notation "\mathbb{N}" := nat.
    
    Inductive nat : Set := O : \mathbb{N} | S : \mathbb{N} -> \mathbb{N} Arguments S _%nat_scope
  • Use a custom script on a single page; this works best if you need MathJax on just one page and you do not need to customize MathJax further. Math in the following Coq snippet is highlighted that way (view the source of this page to see the custom script):

    Notation "\mathbb{B}" := bool.
    
    Inductive bool : Set := true : \mathbb{B} | false : \mathbb{B}