nbsphinx icon indicating copy to clipboard operation
nbsphinx copied to clipboard

Add additional notebook header levels to toctree?

Open flutefreak7 opened this issue 6 years ago • 2 comments

I have notebooks with headers that go 3 or 4 layers deep, but the Sphinx Table of Contents only appears to show 2 layers of headers. The "H1" header of the notebook appears as a chapter-like header at the same level as Installation and Quickstart. Then the "H2" header of the notebook appears as a subsection. The "H3" and "H4" levels however are not showing up in the table of contents.

I'm building up from the Sphinx Getting Started content which gave me usage/Installation.rst and usage/Quickstart.rst. Then I added notebooks to a folder called features, so now I have like features/Baking.ipynb and features/Grilling.ipynb. I made up cooking examples so its a little less abstract...

Within Baking.ipynb I have an outline like this:

1. Baking
    1.1 Equipment
        1.1.1 Pans
        1.1.2 Sensors
        1.1.3 Utensils
    1.2 Techniques
        1.2.1 Bread
            1.2.1.1 Muffins
            1.2.1.2 Loaves
        1.2.2 Souffle
        1.2.3 Pies
        1.2.4 Protein
            1.2.4.1 Chicken
            1.2.4.2 Beef
        1.2.5 Pasta

In my generated docs, the Baking page is quite long and difficult to navigate since "Techniques" is the lowest level of my TOC. I'd like the user to be able to navigate the full hierarchy with the table of contents and be able to click "Beef" in the TOC if they're interested in roast beef and meat loaf recipes. Is this something to do with the theme or do I need to manipulate my toctree in index.rst?

flutefreak7 avatar Jun 26 '19 21:06 flutefreak7

Figured out my problem as I was writing the question, but I figured I'd post the Q & A in case someone else has this issue.

All you have to do is increase the :maxdepth: value in your index.rst file.

This can be closed.

flutefreak7 avatar Jun 26 '19 21:06 flutefreak7

For folks getting started with making docs out of long Notebooks, it's also very helpful to use a theme where the table of contents stays visible as you scroll down. The first theme I tried besides the default was the theme used by Read the Docs. It keeps the TOC visible and is a very solid choice in general.

https://sphinx-rtd-theme.readthedocs.io/en/stable/installing.html

flutefreak7 avatar Jun 26 '19 21:06 flutefreak7