sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.44k stars 2.1k forks source link

The LaTeX builder doesn't handle multiple toctrees with captions well #4977

Open cpitclaudel opened 6 years ago

cpitclaudel commented 6 years ago

Problem

The HTML builder has good support for multiple separate toctrees with captions, like this:

.. toctree::
   :caption: AAA

   A1
   A2

.. toctree::
   :caption: BBB

   B1
   B2

In Alabaster it's rendered like this:

AAA

  A1
  A2

BBB

  B1
  B2

And in the RTD theme A1 and A2 are grouped in the table of contents:

toctrees

The LaTeX builder, on the other hand, gets confused when presented with the same input:

toctrees-latex

Procedure to reproduce the problem

mkdir /tmp/sphinx-repro
cd /tmp/sphinx-repro
sphinx-quickstart --quiet --author x --project y
for i in {A,B}{1,2}; do printf "$i\n==" > "$i.rst"; done
cat > index.rst <<< '.. toctree::
   :caption: AAA

   A1
   A2

.. toctree::
   :caption: BBB

   B1
   B2
'
make latexpdf

Expected results

The table of contents should be split into two parts in LaTeX like in HTML

Environment info

jfbu commented 6 years ago

I think LaTeX should use \part for that (for toplevel toctree). I.E. LaTeX should look something like

\begin{document}

\maketitle
\sphinxtableofcontents
\phantomsection\label{\detokenize{index::doc}}

\part{AAA}
\label{detokenize{index::toctree_aaa}}

\chapter{A1}
\label{\detokenize{index::toctree_aaa::a1}}

\chapter{A2}
\label{\detokenize{index::toctree_aaa::a2}}

\part{BBB}
\label{detokenize{index::toctree_bbb}}

\chapter{B1}
\label{\detokenize{index::toctree_bbb::b1}}

\chapter{B2}
\label{\detokenize{index::toctree_bbb::b2}}

\renewcommand{\indexname}{Index}
\printindex
\end{document}

but also the Table of Contents Heading should not be AAA. Here is with such manual modifications:

capture d ecran 2018-05-26 a 15 53 39

tk0miya commented 6 years ago

I added the :caption: option for toctree to show a caption in content. But I did not intend to show it in ToC. So I feel the captions should not appear in sidebar.

Anyway, as discussed in #4733 (and other issues labeled as toctree), "Part like" ToC mechanism is needed by some users.

jmlarson1 commented 4 years ago

Was there a resolution to this issue?

ScriptAutomate commented 4 years ago

I added the :caption: option for toctree to show a caption in content. But I did not intend to show it in ToC. So I feel the captions should not appear in sidebar.

Anyway, as discussed in #4733 (and other issues labeled as toctree), "Part like" ToC mechanism is needed by some users.

@tk0miya : could you provide some clarification on this? I've been using some themes that make use of the :caption: directive as a way of creating section headers in TOC in the resulting HTML. Though, as experienced by @cpitclaudel, two problems occur:

Note: Another open issue seems to be attempting a similar goal in #3357

Is there current guidance in how users can accomplish this goal at the moment:

.. toctree::
   :caption: AAA

   A1
   A2

.. toctree::
   :caption: BBB

   B1
   B2

In order to achieve both captioned sections with make html and TOC captioned sections with pdf gen?

I'm using:

tk0miya commented 4 years ago

At present, no way to do that. I'll work on it nearly future (after the refinement of autodoc and autosummary...)

ddidier commented 3 years ago

Hi, any progress on this issue?

armando-fandango commented 3 years ago

looking forward to seeing a solution where multiple toctree captions are converted to 'part' in latex.

svenk commented 2 years ago

In case somebody is still looking for a way to generate LaTeX \part{}s from different toctrees in Sphinx, there is a workaround from 2016 posted in https://github.com/sphinx-doc/sphinx/issues/3169#issuecomment-262175220