Skip to content
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Contributors
* Dimitri Papadopoulos Orfanos -- linting and spelling
* Dmitry Shachnev -- modernisation and reproducibility
* Doug Hellmann -- graphviz improvements
* Elijah Greenstein -- numfig_restart option
* Eric Larson -- better error messages
* Eric N. Vander Weele -- autodoc improvements
* Eric Wieser -- autodoc improvements
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ Features added
Patch by Jean-François B.
* #13508: Initial support for :pep:`695` type aliases.
Patch by Martin Matouš, Jeremy Maitin-Shepard, and Adam Turner.
* #14081: Add :confval:`numfig_restart` option to make it possible to restart
figure numbering at each ``:numbered:`` toctree.
Patch by Elijah Greenstein.
* #14023: Add the new :confval:`mathjax_config_path` option
to load MathJax configuration from a file.
Patch by Randolf Scholz and Adam Turner.
Expand Down
19 changes: 19 additions & 0 deletions doc/usage/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,25 @@ Options for figure numbering

.. versionadded:: 1.3


.. confval:: numfig_restart
:type: :code-py:`bool`
:default: :code-py:`False`

If :code-py:`True`, then Sphinx restarts figure numbering every time Sphinx
encounters a :rst:dir:`toctree` directive with the ``:numbered:`` option
activated. You can use this option to make HTML/EPUB figure numbers
correspond to LaTeX figure numbers when using :confval:`latex_documents` to
group files into multiple LaTeX documents.

.. note::

This option does not change the figure numbers assigned by the LaTeX
builder.

.. versionadded:: 8.3


.. confval:: numfig_secnum_depth
:type: :code-py:`int`
:default: :code-py:`1`
Expand Down
1 change: 1 addition & 0 deletions sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class Config:
'numfig_secnum_depth': _Opt(1, 'env', frozenset((int, types.NoneType))),
# numfig_format will be initialized in init_numfig_format()
'numfig_format': _Opt({}, 'env', frozenset((dict,))),
'numfig_restart': _Opt(False, 'env', frozenset((bool,))),
'maximum_signature_line_length': _Opt(
None, 'env', frozenset((int, types.NoneType))
),
Expand Down
2 changes: 2 additions & 0 deletions sphinx/environment/collectors/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ def _walk_doctree(
else:
_walk_doctree(docname, subnode, secnum)
elif isinstance(subnode, addnodes.toctree):
if docname in env.numbered_toctrees and env.config.numfig_restart:
fignum_counter.clear()
for _title, subdocname in subnode['entries']:
if url_re.match(subdocname) or subdocname == 'self':
# don't mess with those
Expand Down
Loading
Loading