`:maxdepth: option of toctree affects secnumdepth` (ref: #2547)

This commit is contained in:
Takeshi KOMIYA
2016-05-26 23:23:07 +09:00
parent 2578f47664
commit 771e715f50
4 changed files with 34 additions and 2 deletions

View File

@@ -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
----------

View File

@@ -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)

View File

@@ -0,0 +1,9 @@
test-toctree-max-depth
======================
.. toctree::
:numbered:
:maxdepth: 4
foo
bar

View File

@@ -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',