mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
`:maxdepth:
option of toctree affects
secnumdepth
` (ref: #2547)
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -15,6 +15,7 @@ Features added
|
||||
* #2471: Add config variable for default doctest flags.
|
||||
* Convert linkcheck builder to requests for better encoding handling
|
||||
* #2463, #2516: Add keywords of "meta" directive to search index
|
||||
* ``:maxdepth:`` option of toctree affects ``secnumdepth`` (ref: #2547)
|
||||
|
||||
Bugs fixed
|
||||
----------
|
||||
|
@@ -52,6 +52,7 @@ HEADER = r'''%% Generated by Sphinx.
|
||||
%(numfig_format)s
|
||||
%(pageautorefname)s
|
||||
%(tocdepth)s
|
||||
%(secnumdepth)s
|
||||
%(preamble)s
|
||||
|
||||
\title{%(title)s}
|
||||
@@ -77,6 +78,7 @@ FOOTER = r'''
|
||||
'''
|
||||
|
||||
URI_SCHEMES = ('mailto:', 'http:', 'https:', 'ftp:')
|
||||
SECNUMDEPTH = 3
|
||||
|
||||
|
||||
class collected_footnote(nodes.footnote):
|
||||
@@ -323,6 +325,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
'transition': '\n\n\\bigskip\\hrule{}\\bigskip\n\n',
|
||||
'figure_align': 'htbp',
|
||||
'tocdepth': '',
|
||||
'secnumdepth': '',
|
||||
'pageautorefname': '',
|
||||
}
|
||||
|
||||
@@ -438,8 +441,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
# tocdepth = 1: show parts, chapters and sections
|
||||
# tocdepth = 2: show parts, chapters, sections and subsections
|
||||
# ...
|
||||
self.elements['tocdepth'] = ('\\setcounter{tocdepth}{%d}' %
|
||||
(document['tocdepth'] + self.top_sectionlevel - 2))
|
||||
tocdepth = document['tocdepth'] + self.top_sectionlevel - 2
|
||||
self.elements['tocdepth'] = '\\setcounter{tocdepth}{%d}' % tocdepth
|
||||
if tocdepth >= SECNUMDEPTH:
|
||||
# Increase secnumdepth if tocdepth is depther than default SECNUMDEPTH
|
||||
self.elements['secnumdepth'] = '\\setcounter{secnumdepth}{%d}' % tocdepth
|
||||
if getattr(document.settings, 'contentsname', None):
|
||||
self.elements['contentsname'] = \
|
||||
self.babel_renewcommand('\\contentsname', document.settings.contentsname)
|
||||
|
9
tests/roots/test-toctree-maxdepth/qux.rst
Normal file
9
tests/roots/test-toctree-maxdepth/qux.rst
Normal file
@@ -0,0 +1,9 @@
|
||||
test-toctree-max-depth
|
||||
======================
|
||||
|
||||
.. toctree::
|
||||
:numbered:
|
||||
:maxdepth: 4
|
||||
|
||||
foo
|
||||
bar
|
@@ -589,6 +589,7 @@ def test_toctree_maxdepth_manual(app, status, warning):
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert '\\setcounter{tocdepth}{1}' in result
|
||||
assert '\\setcounter{secnumdepth}' not in result
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='toctree-maxdepth',
|
||||
@@ -603,6 +604,7 @@ def test_toctree_maxdepth_howto(app, status, warning):
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert '\\setcounter{tocdepth}{2}' in result
|
||||
assert '\\setcounter{secnumdepth}' not in result
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='toctree-maxdepth',
|
||||
@@ -614,6 +616,7 @@ def test_toctree_not_found(app, status, warning):
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert '\\setcounter{tocdepth}' not in result
|
||||
assert '\\setcounter{secnumdepth}' not in result
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='toctree-maxdepth',
|
||||
@@ -625,6 +628,19 @@ def test_toctree_without_maxdepth(app, status, warning):
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert '\\setcounter{tocdepth}' not in result
|
||||
assert '\\setcounter{secnumdepth}' not in result
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='toctree-maxdepth',
|
||||
confoverrides={'master_doc': 'qux'})
|
||||
def test_toctree_with_deeper_maxdepth(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'Python.tex').text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert '\\setcounter{tocdepth}{3}' in result
|
||||
assert '\\setcounter{secnumdepth}{3}' in result
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='toctree-maxdepth',
|
||||
|
Reference in New Issue
Block a user