The documentation at http://ipython.org/ipython-doc/stable/interactive/notebook.html says
You can provide a conceptual structure for your computational document as a whole using different levels of headings; there are 6 levels available, from level 1 (top level) down to level 6 (paragraph). These can be used later for constructing tables of contents, etc.
However, I can't find instructions anywhere on how to use my hierarchical headings to create such a table of contents. Is there a way to do this?
NB: I'd also be interested in other kinds of navigation using ipython notebook headings, if any exist. For instance, jumping back and forward from heading to heading in order to quickly find the start of each section, or hiding (folding) the contents of an entire section. This is my wish-list - but any kind of navigation at all would be of interest. Thanks!
Here is my approach, clunky as it is and available in github:
Put in the very first notebook cell, the import cell:
Somewhere after the import cell, put in the genTOCEntry cell but don't run it yet:
Below the genTOCEntry cell`, make a TOC cell as a markdown cell:
As the notebook is developed, put this genTOCMarkdownCell before starting a new section:
Move the genTOCMarkdownCell down to the point in your notebook where you want to start a new section and make the argument to genTOCMarkdownCell the string title for your new section then run it. Add a markdown cell right after it and copy the output from genTOCMarkdownCell into the markdown cell that starts your new section. Then go to the genTOCEntry cell near the top of your notebook and run it. For example, if you make the argument to genTOCMarkdownCell as shown above and run it, you get this output to paste into the first markdown cell of your newly indexed section:
Then when you go to the top of your notebook and run genTocEntry, you get the output:
Copy this link string and paste it into the TOC markdown cell as follows:
After you edit the TOC cell to insert the link string and then you press shift-enter, the link to your new section will appear in your notebook Table of Contents as a web link and clicking it will position the browser to your new section.
One thing I often forget is that clicking a line in the TOC makes the browser jump to that cell but doesn't select it. Whatever cell was active when we clicked on the TOC link is still active, so a down or up arrow or shift-enter refers to still active cell, not the cell we got by clicking on the TOC link.
How about using a Browser plugin that gives you an overview of ANY html page. I have tried the following:
They both work pretty well for IPython Notebooks. I was reluctant to use the previous solutions as they seem a bit unstable and ended up using these extensions.
There is an ipython nbextension that constructs a table of contents for a notebook. It seems to only provide navigation, not section folding.
You can add a TOC manually with Markdown and HTML. Here's how I have been adding:
Create TOC at top of Jupyter Notebook:
Add html anchors throughout body:
It may not be the best approach, but it works. Hope this helps.
There are now two packages that can be used to handle Jupyter extensions:
jupyter_contrib_nbextensions that installs extensions, including table of contents;
jupyter_nbextensions_configurator that provides graphical user interfaces for configuring which nbextensions are enabled (load automatically for every notebook) and provides controls to configure the nbextensions' options.
I recently created a small extension to Jupyter named jupyter-navbar. It searches for headers written in markdown cells, and displays links to them in the sidebar in a hierarchical fashion. The sidebar is resizable and collapsible. See screenshot below.
It is easy to install, and takes advantage of the 'custom' JS and CSS codes that get executed whenever a notebook is opened, so you don't need to manually run it.