Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Sphinx and latexpdf toc depth?

I have a vanilla sphinx project (Sphinx 1.2b3.) created with "sphinx-quickstart"

I add a basic page.rst with 4 header levels.

I can control the depth of the html toc in index.rst:

.. toctree::
   :maxdepth: 1
   :numbered:

   page

Based upon the documentation http://sphinx-doc.org/latest/markup/toctree.html I adjust the conf.py as follow:

ADDITIONAL_PREAMBLE = """
\setcounter{tocdepth}{1}
"""

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
'papersize': 'a4paper',

# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
'preamble': '\setcounter{tocdepth}{1}'
#'preamble': ADDITIONAL_PREAMBLE
}

Then I build:

$ make clean
$ make html
$ make latexpdf

The html show only level 1 as expected but the pdf keeps showing 2 toc levels - screen shoot enter image description here:

Any hints?

thx

pelle

solution

was provided by jacob -> simply think required level num -1:

'preamble': '\setcounter{tocdepth}{0}'
like image 208
pellekrogholt Avatar asked Nov 19 '13 13:11

pellekrogholt


1 Answers

The default Sphinx latex document class is based on the report class and uses chapters, hence to show only the chapter names in the latex table of contents you have to set

\setcounter{tocdepth}{0} 
like image 67
Jakob Avatar answered Sep 20 '22 02:09

Jakob