From a2efd1475a026b09918a276813164fca3880c97c Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 29 Feb 2016 11:25:27 +0900 Subject: [PATCH 1/3] Move tocdepth definition to above of user-preamble (ref #2358) --- CHANGES | 1 + sphinx/writers/latex.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 3c47589dc..93daf6aca 100644 --- a/CHANGES +++ b/CHANGES @@ -30,6 +30,7 @@ Bugs fixed * #1565, #2229: Revert new warning; the new warning will be triggered from version 1.4 on. * #2329: Refresh environment forcely if source directory has changed. * #2019: Fix the domain objects in search result are not escaped +* #2358: Fix user-preamble could not override the tocdepth definition. Release 1.3.5 (released Jan 24, 2016) ===================================== diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index e187ae377..73b7b1721 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -48,6 +48,7 @@ HEADER = r'''%% Generated by Sphinx. %(usepackages)s %(contentsname)s %(numfig_format)s +%(tocdepth)s %(preamble)s \title{%(title)s} @@ -56,7 +57,6 @@ HEADER = r'''%% Generated by Sphinx. \author{%(author)s} \newcommand{\sphinxlogo}{%(logo)s} \renewcommand{\releasename}{%(releasename)s} -%(tocdepth)s %(makeindex)s ''' From 119b97180428d4db93ab8deb973a98f932bddbb9 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Mon, 29 Feb 2016 11:29:07 +0900 Subject: [PATCH 2/3] update doc: LaTeX writer now refers maxdepth option (ref #2358) --- doc/markup/toctree.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/doc/markup/toctree.rst b/doc/markup/toctree.rst index ff0af7535..e089115a0 100644 --- a/doc/markup/toctree.rst +++ b/doc/markup/toctree.rst @@ -223,11 +223,8 @@ The special document names (and pages generated for them) are: .. rubric:: Footnotes -.. [#] The ``maxdepth`` option does not apply to the LaTeX writer, where the - whole table of contents will always be presented at the begin of the - document, and its depth is controlled by the ``tocdepth`` counter, which - you can reset in your :confval:`latex_preamble` config value using - e.g. ``\setcounter{tocdepth}{2}``. +.. [#] The LaTeX writer only refers the ``maxdepth`` option of first toctree + directive in the document. .. [#] A note on available globbing syntax: you can use the standard shell constructs ``*``, ``?``, ``[...]`` and ``[!...]`` with the feature that From e81f7186e8810fd8704a37dfc832a0aee012dff3 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Tue, 1 Mar 2016 13:31:04 +0900 Subject: [PATCH 3/3] Redece tocdepth if `part` or `chapter` is used for top_sectionlevel (ref #2358) --- CHANGES | 1 + sphinx/writers/latex.py | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index 93daf6aca..06bd5e803 100644 --- a/CHANGES +++ b/CHANGES @@ -31,6 +31,7 @@ Bugs fixed * #2329: Refresh environment forcely if source directory has changed. * #2019: Fix the domain objects in search result are not escaped * #2358: Fix user-preamble could not override the tocdepth definition. +* #2358: Redece tocdepth if ``part`` or ``chapter`` is used for top_sectionlevel. Release 1.3.5 (released Jan 24, 2016) ===================================== diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 73b7b1721..a87d6bee3 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -293,6 +293,15 @@ class LaTeXTranslator(nodes.NodeVisitor): self.builder = builder self.body = [] + # determine top section level + if document.settings.docclass == 'howto': + self.top_sectionlevel = 2 + else: + if builder.config.latex_use_parts: + self.top_sectionlevel = 0 + else: + self.top_sectionlevel = 1 + # sort out some elements papersize = builder.config.latex_paper_size + 'paper' if papersize == 'paper': # e.g. command line "-D latex_paper_size=" @@ -363,12 +372,14 @@ class LaTeXTranslator(nodes.NodeVisitor): self.elements['classoptions'] += ',' + \ self.elements['extraclassoptions'] if document.get('tocdepth'): - if document.settings.docclass == 'howto': - self.elements['tocdepth'] = ('\\setcounter{tocdepth}{%d}' % - document['tocdepth']) - else: - self.elements['tocdepth'] = ('\\setcounter{tocdepth}{%d}' % - (document['tocdepth'] - 1)) + # redece tocdepth if `part` or `chapter` is used for top_sectionlevel + # tocdepth = -1: show only parts + # tocdepth = 0: show parts and chapters + # 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)) if getattr(document.settings, 'contentsname', None): self.elements['contentsname'] = \ self.babel_renewcommand(builder, '\\contentsname', @@ -395,13 +406,6 @@ class LaTeXTranslator(nodes.NodeVisitor): self.pending_footnotes = [] self.curfilestack = [] self.handled_abbrs = set() - if document.settings.docclass == 'howto': - self.top_sectionlevel = 2 - else: - if builder.config.latex_use_parts: - self.top_sectionlevel = 0 - else: - self.top_sectionlevel = 1 self.next_section_ids = set() self.next_figure_ids = set() self.next_table_ids = set()