How can I add a table of contents to a Jupyter / JupyterLab notebook?

后端 未结 10 1816
深忆病人
深忆病人 2020-12-12 11:12

The documentation at http://ipython.org/ipython-doc/stable/interactive/notebook.html says

You can provide a conceptual structure for your computationa

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-12 12:00

    nbextensions ToC instructions

    Introduction

    As @Ian and @Sergey have mentioned, nbextensions is a simple solution. To elaborate their answer, here is a few more information.

    What is nbextensions?

    The nbextensions contains a collection of extensions that add functionality to your Jupyter notebook.

    For example, just to cite a few extensions:

    • Table of Contents

    • Collapsible headings

    Install nbextensions

    The installation can be done through Conda or PIP

    # If conda:
    conda install -c conda-forge jupyter_contrib_nbextensions
    # or with pip:
    pip install jupyter_contrib_nbextensions
    

    You will see the new tab Nbextensions in the jupyter notebook menu. Uncheck the checkbox at the top disable configuration for nbextensions without explicit compatibility (they may break your notebook environment, but can be useful to show for nbextension development) and then check Table of Contents(2). That is all. Screenshot:

    Copy js and css files

    To copy the nbextensions' javascript and css files into the jupyter server's search directory, do the following:

    jupyter contrib nbextension install --user
    

    Toggle extensions

    Note that if you are not familiar with the terminal, it would be better to install nbextensions configurator (see the next section)

    You can enable/disable the extensions of your choice. As the documentation mentions, the generic command is:

    jupyter nbextension enable 
    

    Concretely, to enable the ToC (Table of Contents) extension, do:

    jupyter nbextension enable toc2/main
    

    Install Configuration interface (optional but useful)

    As its documentation says, nbextensions_configurator provides config interfaces for nbextensions.

    It looks like the following:

    To install it if you use conda:

    conda install -c conda-forge jupyter_nbextensions_configurator
    

    If you don't have Conda or don't want to install through Conda, then do the following 2 steps:

    pip install jupyter_nbextensions_configurator
    jupyter nbextensions_configurator enable --user
    

提交回复
热议问题