6

What I wanted

With the nbextension toc, jupyter notebooks have table of content capabilities which is said to be transferable to html via nbconvert --to html_toc function, or via the dropdown menue "download as html with toc". However, neither option works in my case.

What I have tried

  1. Download as html with toc initially gave an error similar to TemplateNotFound: toc2
  2. All recommended commands like jupyter nbconvert FILE.ipynb --template toc jupyter nbconvert FILE.ipynb --template toc2 (These two appear to be incomplete but are supplied like this) jupyter nbconvert --to html_toc FILE.ipynb (same error as above via menue)
  3. As here and here the toc2.tpl file is mentioned, I placed this file together with the main.css and toc2.js file into the same directory as the ipynb notebook to be converted. Now the download as html with toc menue gives error "nbconvert failed: toc2" and the jupyter nbconvert FILE.ipynb --template toc2 gives error "jinja2.exceptions.TemplateNotFound: toc2" I still have not understood the role of the toc2 template. Is it (still) necessary? Why? How (with the other files?)? Where (how is the location provided)? What exactly is needed where and how to make use of this extremely usefull functionality?
  4. The downgrade mentioned here was not possible due to resulting incompab.

Used Conditions / Versions in conda virtual environment

(Please tell me if you need more information)

jupyter core     : 4.7.1
jupyter-notebook : 6.2.0
qtconsole        : 5.0.2
ipython          : 7.20.0
ipykernel        : 5.3.4
jupyter client   : 6.1.7
jupyter lab      : 3.0.8
nbconvert        : 6.0.7
ipywidgets       : 7.6.3
nbformat         : 5.1.2
traitlets        : 5.0.5
le8rning
  • 145
  • 2
  • 6
  • I don't know if my problem is related, but I was missing `html` as an available format in `nbconvert --execute`, and `papermill` was also producing garbage (the original .ipynb JSON, as it seemed). It could have something to do with Python 3.9 - I switched to an older Conda env at Python 3.7, and the conversion to HTML was working. I think it's a bug that will go away some time in the future. – Tomasz Gandor Apr 15 '21 at 17:40
  • Hi there! Any improvements so far? – Xopi García Dec 27 '21 at 16:25
  • @XopiGarcía Thank you for asking but I have not followed this further. Not important enough at the moment :) – le8rning Feb 20 '22 at 14:55

2 Answers2

3

This workaround worked for me:

pip install "nbconvert<6"
Jaeyoung Chun
  • 671
  • 9
  • 6
1

You can try running the following command:

pip install "nbconvert<6"

Then check that it installed nbconvert-5.6.1 (5.6.1 version).

After that, execute the following:

jupyter nbconvert --to html_toc YOURFILENAME.ipynb
Dov Benyomin Sohacheski
  • 7,133
  • 7
  • 38
  • 64
Joab
  • 11
  • 1