How to expand all the subsections on the sidebar toctree in Sphinx? How to expand all the subsections on the sidebar toctree in Sphinx? python python

How to expand all the subsections on the sidebar toctree in Sphinx?


Well, i lost approximately 3.4M neurons trying to read sphinx source code (was it written by a bunch of rabbid reckless raccoons ?! so many levels of abstraction).

So :

  • make your own sphinx theme (use a 3rd party theme as a base, very easy. I use 'readable' theme for that)
  • in the directory where you have theme.conf, add a "fulltoc.html" template, containing one line:

fulltoc.html:

{{ toctree(collapse=False) }}

(Heh, notice the 'collapse' argument?)

  • in sphinx conf.py, modify the html_sidebars option to add your template; and declare your theme

conf.py:

html_theme_path = [customized_readable_theme.get_html_theme_path()]html_theme = 'customized_readable'html_sidebars = {'**': ['fulltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']}
  • rebuild documentation


If you are using sphinx_rtd_theme, you can change the maximum depth of the sidebar menu in the html page by changing the 'toctree maxdepth' value defined in the file layout.html. This file is usually located in the directory source/_themes/sphinx_rtd_theme. There are several solutions:

  • The simplest, fastest solution: Show deeper toctree in sidebar

  • You are using an old version of the theme. Then you can set a new 'maxdepth' value (e.g., 3) in the line that says:

    {% set toctree = toctree(maxdepth=3, collapse=False, includehidden=True) %}
  • You are using a newest version of the theme. Then you may have these lines in the file layout.html:

    {% set global_toc = toctree(maxdepth=theme_navigation_depth|int,                            collapse=theme_collapse_navigation|tobool,                            includehidden=theme_includehidden|tobool,                            titles_only=theme_titles_only|tobool) %}

    In this case, you may define 'theme_navigation_depth' in theme.conf:

    [options]theme_navigation_depth = 3

Recompile after the change is done... and don't forget to enjoy the Sun!