You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+67-28
Original file line number
Diff line number
Diff line change
@@ -84,60 +84,100 @@ sections:
84
84
- glob: subfolder/other*
85
85
```
86
86
87
-
### Titles and Captions
87
+
### File and URL titles
88
88
89
-
By default, ToCs will use the initial header within a document as its title.
90
-
91
-
With the `title` key you can set an alternative title for a document or URL in the ToC.
92
-
Each part can also have a `caption`, e.g. for use in ToC side-bars:
89
+
By default, the initial header within a `file` document will be used as its title in generated Table of Contents.
90
+
With the `title` key you can set an alternative title for a document. and also for `url`:
93
91
94
92
```yaml
95
93
root: intro
96
94
parts:
97
-
- caption: Part Caption
98
-
sections:
95
+
- sections:
99
96
- file: doc1
100
-
title: Document 1
97
+
title: Document 1 Title
101
98
- url: https://example.com
102
-
title: Example Site
99
+
title: Example URL Title
103
100
```
104
101
105
-
### Numbering
102
+
### ToC tree (part) options
106
103
107
-
You can automatically add numbers to all docs with a part by adding the `numbered: true` flag to it:
104
+
Each part can be configured with a number of options (see also [sphinx `toctree` options](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-toctree)):
105
+
106
+
- `caption` (string): A title for the whole the part, e.g. shown above the part in ToCs
107
+
- `hidden` (boolean): Whether to show the ToC within (inline of) the document (default `False`).
108
+
By default it is appended to the end of the document, but see also the `tableofcontents` directive for positioning of the ToC.
109
+
- `maxdepth` (integer): A maximum nesting depth to use when showing the ToC within the document.
110
+
- `numbered` (boolean or integer): Automatically add numbers to all documents within a part (default `False`).
111
+
If set to `True`, all sub-parts will also be numbered based on nesting (e.g. with `1.1` or `1.1.1`),
112
+
or if set to an integer then the numbering will only be applied to that depth.
113
+
- `reversed` (boolean): If `True` then the entries in the part will be listed in reverse order.
114
+
This can be useful when using `glob` sections.
115
+
- `titlesonly` (boolean): If `True` then only the first heading in the document will be shown in the ToC, not other headings of the same level.
116
+
117
+
These options can be set at the level of the part:
108
118
109
119
```yaml
110
120
root: intro
111
121
parts:
112
-
- numbered: true
122
+
- caption: Part Caption
123
+
hidden: False
124
+
maxdepth: 1
125
+
numbered: True
126
+
reversed: False
127
+
titlesonly: True
113
128
sections:
114
129
- file: doc1
115
-
- file: doc2
130
+
parts:
131
+
- titlesonly: True
132
+
sections:
133
+
- file: doc2
116
134
```
117
135
118
-
You can also **limit the TOC numbering depth** by setting the `numbered` flag to an integer instead of `true`, e.g., `numbered: 3`.
119
-
120
-
:::{note}
121
-
By default, section numbering restarts for each `part`.
122
-
If you want want this numbering to be continuous, check-out the [sphinx-multitoc-numbering extension](https://github.com/executablebooks/sphinx-multitoc-numbering).
123
-
:::
136
+
or, if you are using the shorthand for a single part, set options under an `options` key:
124
137
125
-
### Defaults
138
+
```yaml
139
+
root: intro
140
+
options:
141
+
caption: Part Caption
142
+
hidden: False
143
+
maxdepth: 1
144
+
numbered: True
145
+
reversed: False
146
+
titlesonly: True
147
+
sections:
148
+
- file: doc1
149
+
options:
150
+
titlesonly: True
151
+
sections:
152
+
- file: doc2
153
+
```
126
154
127
-
To have e.g. `numbered` added to all toctrees, set it under a `defaults` top-level key:
155
+
You can also use the top-level `defaults` key, to set default options for all parts:
128
156
129
157
```yaml
130
-
defaults:
131
-
numbered: true
132
158
root: intro
159
+
defaults:
160
+
titlesonly: True
161
+
options:
162
+
caption: Part Caption
163
+
hidden: False
164
+
maxdepth: 1
165
+
numbered: True
166
+
reversed: False
133
167
sections:
134
168
- file: doc1
135
169
sections:
136
170
- file: doc2
137
-
- url: https://example.com
138
171
```
139
172
140
-
Available keys: `numbered`, `titlesonly`, `reversed`
173
+
:::{warning}
174
+
`numbered`should not generally be used as a default, since numbering cannot be changed by nested parts, and sphinx will log a warning.
175
+
:::
176
+
177
+
:::{note}
178
+
By default, section numbering restarts for each `part`.
179
+
If you want want this numbering to be continuous, check-out the [sphinx-multitoc-numbering extension](https://github.com/executablebooks/sphinx-multitoc-numbering).
180
+
:::
141
181
142
182
## Add a ToC to a page's content
143
183
@@ -159,6 +199,8 @@ MyST Markdown:
159
199
160
200
Currently, only one `tableofcontents` should be used per page (all `toctree` will be added here), and only if it is a page with child/descendant documents.
161
201
202
+
Note, this will override the `hidden` option set for a part.
203
+
162
204
## Excluding files not in ToC
163
205
164
206
By default, Sphinx will build all document files, regardless of whether they are specified in the Table of Contents, if they:
@@ -313,9 +355,6 @@ intro:
313
355
314
356
Questions / TODOs:
315
357
316
-
- add migration CLI command for old jupyter-book format
317
-
- Should `titlesonly` default to `True` (as in jupyter-book)?
318
-
- nested numbered toctree not allowed (logs warning), so should be handled if `numbered: true` is in defaults
319
358
- Add additional top-level keys, e.g. `appendices` (see https://github.com/sphinx-doc/sphinx/issues/2502) and `bibliography`
320
359
- Using `external_toc_exclude_missing` to exclude a certain file suffix:
321
360
currently if you had files `doc.md` and `doc.rst`, and put `doc.md` in your ToC,
0 commit comments