Extras#

Here are some cool things you can add to your docs.

Theme#

Sphinx comes with builtin themes. However, this documentation uses the third-party Sphinx Book Theme.

  1. Add the theme to the requirements and install it,

    echo sphinx-book-theme >> docs/requirements.txt
    pip install sphinx-book-theme
    
  2. Go to the conf.py file and add the following lines,

    html_theme = 'sphinx_book_theme'
    

This theme allows you to add hyperlinks to the source repository and more.

Math#

Render math using the mathjax extension.

conf.py#
extensions = [
    ...,
    'sphinx.ext.mathjax',
]

Here is an example,

.. math::

    f(x) = \int_0^\infty x^2 \, dx

which renders as,

\[f(x) = \int_0^\infty x^2 \, dx\]

Generate notebooks#

Use the nbsphinx extension to automatically generate documentation from Jupyter notebooks.

Intersphinx#

Reference external documentation in your docstrings using the intersphinx extension.

Inline tabs#

The sphinx-inline-tabs extension allows you to do things like this using the .. tab:: directive,

This is the first tab.

This is the second tab.

This is the third tab.