Search code examples
python-sphinxmathjax

How can the mathjax physics package be used in a sphinx documentation?


The following section in sphinx

.. math::

   \vb{R} = \vb{T} \vb{U}^{-1} = \vb{V}^{-1} \vb{T}

is rendered as

enter image description here

What I actually want is this:

enter image description here

But right now this is only possible if I write

.. math::

   \mathbf{R} = \mathbf{T} \mathbf{U}^{-1} = \mathbf{V}^{-1} \mathbf{T}

or by including the \require{physics} tag in the ..math block, which is not ideal since this is also part of a docstring that is being documented with sphinx autodoc.

I have already tried to adopt the solution from this thread by adding

mathjax_path = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"    

to my conf.py file, but it did not work. How can I properly display desired latex code on my website?


Solution

  • Adding

    mathjax3_config = {
      'loader': {'load': ['[tex]/physics']},
      'tex': {'packages': {'[+]': ['physics']}},
    }
    

    to the conf.py resolves the issue by instructing MathJax to load the physics package.