This page covers some of the options you have available to control your book’s behavior via the Table of Contents.
To configure options for all entries of your TOC, use the defaults: configuration at the root of your Table of Contents. This configuration will be applied to every list of chapters or sections within your book.
format: jb-book root: index defaults: # The defaults key will be applied to all chapters and sub-sections titlesonly: True chapters: - file: path/to/chapter1 - file: path/to/chapter2
If you’re only using a single list of chapters, and not organizing them into parts, you can configure the single group of chapters with the options: key.
format: jb-book root: index options: # The options key will be applied to all chapters, but not sub-sections numbered: True chapters: - file: path/to/part1/chapter1 - file: path/to/part1/chapter2
If you’re using parts , then the options: key has no effect. You should configure each part individually (see below).
If you are organizing your book into parts (groups of chapters), configure each part by providing key: value pairs alongside each part entry, like so:
format: jb-book root: index parts: - caption: Name of Numbered Part 1 numbered: True # Only applies to chapters in Part 1. chapters: - file: path/to/part1/chapter1 - file: path/to/part1/chapter2 - caption: Name of Not-numbered Part 2 chapters: - file: path/to/part2/chapter1 - file: path/to/part2/chapter2
In this case, the numbered: only applies to Part 1, and not Part 2. If you want all parts to be numbered, you will need to add numbered: true to all parts entries.
Currently there is no global setting to enable numbered: true across all parts.
defaults: numbered: true
as sphinx will issue warnings due to numbered flag being set for subtrees. It also causes unexpected output.
To add a caption to a Part (so that it shows up in the sidebar, for example) use the caption: option like so:
- caption: My part name chapters: - file: chapter1 .
If you’d like to specify an alternate title from the one defined within a file, you may do so with the title: key. For example:
- file: path/to/myfile title: My alternate page title
Note that this only applies to the sidebar in the table of contents, it does not change the actual chapter/section title.
You can automatically add numbers chapters of your book. Numbers will follow a hierarchy according to the structure defined in your _toc.yml file.
If using a single set of chapters for your book (aka, no Parts), add numbers to them with the numbered: true flag, like so:
format: jb-book root: intro options: numbered: true chapters: - file: chapter1 - file: chapter2
If using one or more parts, add the numbered: true option to each. For example, to number all parts in a two-part book:
format: jb-book root: intro parts: - caption: Part 1 numbered: true chapters: - file: part1/chapter1 - caption: Part 2 numbered: true chapters: - file: part2/chapter1
To number only the second part of a book:
format: jb-book root: intro parts: - caption: Part 1 chapters: - file: part1/chapter1 - caption: Part 2 numbered: true # Only the second part is numbered chapters: - file: part2/chapter1
By default, chapter numbering will be continuous between parts (i.e. they will not re-start each section at 1. each time) using an extension called sphinx-multitoc-numbering.
To restart chapter numbering between parts, use the following setting in your _config.yml file:
html: use_multitoc_numbering: false
If you’d like to limit the depth of numbering, use an integer for the numbered flag. This will be the depth of sub-sections to continue numbering. For example, numbered: 3 .
A few caveats about numbering
Jupyter Book relies on Sphinx to apply section numbering, and this has a few quirks to it. Here are a few gotchas:
If you’d like to add a table of contents for the sub-sections of a page within the page content (in-line with the content on the page), you may do so by using the directive. You can use it like so:
See the source of the content types page for an example.
To control the maximum depth of the Table of Contents that you insert, use the maxdepth: option in your _toc.yml file. For example:
- caption: My part name maxdepth: 2 # The displayed Table of Contents will only have two levels chapters: - file: chapter1 .
A within-page Table of Contents shows the sections that are present on the current page (as opposed to the sub-pages listed in _toc.yml , as inserted by the directive introduced above).
To insert a within-page Table of Contents, use the directive. For example, to insert a list of all sections on the current page (including the page title):
# Page title ``` ```
By default, the directive will include all heading levels in the current page, including heading level 1 (i.e., the title of the page).
To only list the section titles for sub-sections of a specific parent section, add the :local: argument to the directive. For example, to list only the contents of second-level sections on a page (and exclude the title):
# Page title ``` :local: ``` ## Section 1 (will be listed) ### Sub-section 1 (will be listed) ## Section 2 (will be listed)
To list only the contents of the ## Section 1 section:
# Page title ## Section 1 (will not be listed) ``` :local: ``` ### Sub-section 1 (will be listed) ## Section 1 (will not be listed)
You can control the depth of the within-page Table of Contents with the :maxdepth: argument. For example, the following usage lists only the top-level sections underneath the title, even if there are deeper sub-sections (i.e., ## headings, but no ### headings or deeper).
# Page title ``` :local: :depth: 1 ```
By default, Jupyter Book will build all content files that are found in your book’s folder, even if they are not specified in _toc.yml (and will raise a warning if it finds a file that isn’t listed there).
If you’d like Jupyter Book to skip a file entirely, you can do so with the following configuration in _config.yml :
exclude_patterns: [pattern1/*, path/to/myfile.ipynb]
Any files that match the patterns described there will be excluded from the build. If you’d like to exclude files from being executed but still wish for them to be built by Jupyter Book, see Exclude files from execution .
By default, Jupyter Book will build all files that are in your book’s folder, regardless of whether they are specified in the Table of Contents. To disable this behavior and only build files that are specified in the TOC, use the following pattern in _config.yml :
only_build_toc_files: true
Note that files that are in hidden folders (e.g. in .github or .venv ) will still be built even if they are not specified in the TOC. You should exclude these files explicitly.
Structure the Table of Contents
Types of content source files