Debian Codegraph @

doc/tutorial/more-sphinx-customization.rst

raw
1 More Sphinx customization
2 =========================
3
4 There are two main ways to customize your documentation beyond what is possible
5 with core Sphinx: extensions and themes.
6
7 Enabling a built-in extension
8 -----------------------------
9
10 In addition to these configuration values, you can customize Sphinx even more
11 by using :doc:`extensions </usage/extensions/index>`. Sphinx ships several
12 :ref:`builtin ones <builtin-extensions>`, and there are many more
13 :ref:`maintained by the community <third-party-extensions>`.
14
15 For example, to enable the :mod:`sphinx.ext.duration` extension,
16 locate the ``extensions`` list in your ``conf.py`` and add one element as
17 follows:
18
19 .. code-block:: python
20 :caption: docs/source/conf.py
21
22 # Add any Sphinx extension module names here, as strings. They can be
23 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
24 # ones.
25 extensions = [
26 'sphinx.ext.duration',
27 ]
28
29 After that, every time you generate your documentation, you will see a short
30 durations report at the end of the console output, like this one:
31
32 .. code-block:: console
33
34 (.venv) $ make html
35 ...
36 The HTML pages are in build/html.
37
38 ====================== slowest reading durations =======================
39 0.042 temp/source/index
40
41 Using a third-party HTML theme
42 ------------------------------
43
44 Themes, on the other hand, are a way to customize the appearance of your
45 documentation. Sphinx has several :ref:`builtin themes <builtin-themes>`, and
46 there are also `third-party ones <https://sphinx-themes.org/>`_.
47
48 For example, to use the `Furo <https://pradyunsg.me/furo/>`_ third-party theme
49 in your HTML documentation, first you will need to install it with ``pip`` in
50 your Python virtual environment, like this:
51
52 .. code-block:: console
53
54 (.venv) $ pip install furo
55
56 And then, locate the ``html_theme`` variable on your ``conf.py`` and replace
57 its value as follows:
58
59 .. code-block:: python
60 :caption: docs/source/conf.py
61
62 # The theme to use for HTML and HTML Help pages. See the documentation for
63 # a list of builtin themes.
64 #
65 html_theme = 'furo'
66
67 With this change, you will notice that your HTML documentation has now a new
68 appearance:
69
70 .. figure:: /_static/tutorial/lumache-furo.png
71 :width: 80%
72 :align: center
73 :alt: HTML documentation of Lumache with the Furo theme
74
75 HTML documentation of Lumache with the Furo theme
76
77 It is now time to :doc:`expand the narrative documentation and split it into
78 several documents </tutorial/narrative-documentation>`.