mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #771: latex output doesn't set tocdepth
This commit is contained in:
parent
d0576cd012
commit
b0a5a1339e
2
CHANGES
2
CHANGES
@ -30,7 +30,7 @@ Bugs fixed
|
||||
* #1894: Unlisted phony targets in quickstart Makefile
|
||||
* #2125: Fix unifies behavior of collapsed fields (``GroupedField`` and ``TypedField``)
|
||||
* #1408: Check latex_logo validity before copying
|
||||
|
||||
* #771: Fix latex output doesn't set tocdepth
|
||||
Release 1.3.3 (released Dec 2, 2015)
|
||||
====================================
|
||||
|
||||
|
@ -95,6 +95,14 @@ class LaTeXBuilder(Builder):
|
||||
destination_path=path.join(self.outdir, targetname),
|
||||
encoding='utf-8')
|
||||
self.info("processing " + targetname + "... ", nonl=1)
|
||||
toctrees = self.env.get_doctree(docname).traverse(addnodes.toctree)
|
||||
if toctrees:
|
||||
if toctrees[0].get('maxdepth'):
|
||||
tocdepth = int(toctrees[0].get('maxdepth'))
|
||||
else:
|
||||
tocdepth = None
|
||||
else:
|
||||
tocdepth = None
|
||||
doctree = self.assemble_doctree(
|
||||
docname, toctree_only,
|
||||
appendices=((docclass != 'howto') and self.config.latex_appendices or []))
|
||||
@ -106,6 +114,7 @@ class LaTeXBuilder(Builder):
|
||||
doctree.settings.contentsname = self.get_contentsname(docname)
|
||||
doctree.settings.docname = docname
|
||||
doctree.settings.docclass = docclass
|
||||
doctree.settings.tocdepth = tocdepth
|
||||
docwriter.write(doctree, destination)
|
||||
self.info("done")
|
||||
|
||||
|
@ -53,6 +53,7 @@ HEADER = r'''%% Generated by Sphinx.
|
||||
\author{%(author)s}
|
||||
\newcommand{\sphinxlogo}{%(logo)s}
|
||||
\renewcommand{\releasename}{%(releasename)s}
|
||||
%(tocdepth)s
|
||||
%(makeindex)s
|
||||
'''
|
||||
|
||||
@ -273,6 +274,7 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
'printindex': '\\printindex',
|
||||
'transition': '\n\n\\bigskip\\hrule{}\\bigskip\n\n',
|
||||
'figure_align': 'htbp',
|
||||
'tocdepth': '',
|
||||
}
|
||||
|
||||
# sphinx specific document classes
|
||||
@ -357,6 +359,13 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
if self.elements['extraclassoptions']:
|
||||
self.elements['classoptions'] += ',' + \
|
||||
self.elements['extraclassoptions']
|
||||
if document.settings.tocdepth:
|
||||
if document.settings.docclass == 'howto':
|
||||
self.elements['tocdepth'] = ('\\setcounter{tocdepth}{%d}' %
|
||||
document.settings.tocdepth)
|
||||
else:
|
||||
self.elements['tocdepth'] = ('\\setcounter{tocdepth}{%d}' %
|
||||
(document.settings.tocdepth - 1))
|
||||
|
||||
self.highlighter = highlighting.PygmentsBridge(
|
||||
'latex',
|
||||
|
@ -3,6 +3,7 @@ test-tocdepth
|
||||
|
||||
.. toctree::
|
||||
:numbered:
|
||||
:maxdepth: 2
|
||||
|
||||
foo
|
||||
bar
|
||||
|
@ -428,3 +428,31 @@ def test_latex_logo_if_not_found(app, status, warning):
|
||||
assert False # SphinxError not raised
|
||||
except Exception as exc:
|
||||
assert isinstance(exc, SphinxError)
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='tocdepth',
|
||||
confoverrides={'latex_documents': [
|
||||
('index', 'SphinxTests.tex', 'Sphinx Tests Documentation',
|
||||
'Georg Brandl', 'manual'),
|
||||
]})
|
||||
def test_toctree_maxdepth_manual(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert '\\setcounter{tocdepth}{1}' in result
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='tocdepth',
|
||||
confoverrides={'latex_documents': [
|
||||
('index', 'SphinxTests.tex', 'Sphinx Tests Documentation',
|
||||
'Georg Brandl', 'howto'),
|
||||
]})
|
||||
def test_toctree_maxdepth_howto(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
|
||||
print(result)
|
||||
print(status.getvalue())
|
||||
print(warning.getvalue())
|
||||
assert '\\setcounter{tocdepth}{2}' in result
|
||||
|
Loading…
Reference in New Issue
Block a user