Brandon Rozek

Photo of Brandon Rozek

PhD Student @ RPI studying Automated Reasoning in AI and Linux Enthusiast.

Sphinx & MathJax

Published on

Updated on

Warning: This post has not been modified for over 2 years. For technical posts, make sure that it is still relevant.

To include mathematical notation in Python docs generated by Sphinx, it should look like the following:

class Line:
    Holds the equation for a line.
    :math:`y = mx + \frac{b}{1}`
    In this equation, :math:`m` is the slope and :math:`b` is the y-intercept.

The content after :math: and inside the backticks is treated as inline math. The r in front of the triple quotes is used to make it a raw string and so that LaTex commands such as \frac{}{} operate as intended. There also cannot be a space between :math: and the backtick.

The Sphinx configuration needs to have the mathjax extension loaded as well.

extensions = [
    # ....
    # ....
Reply via Email Buy me a Coffee
Was this useful? Feel free to share: Hacker News Reddit Twitter

Published a response to this? :