[英]Sphinx LaTeX Table of Contents - avoid toctree nesting of included rst files
I have a Sphinx documentation with the following structure:我有一个具有以下结构的Sphinx文档:
My chapter title
=====================
Chapter intro part 1
--------------------------
Brief introduction that I would like to have in the start of this chapter...
Chapter intro part 2
--------------------------
Another short section ...
.. toctree::
:hidden:
:maxdepth: 2
folder/subchapter1
folder/subchapter2
When I render the HTML based on this, things work as intended - I have a starting page for this chapter and my sub chapters are available from the side menu.当我基于此渲染 HTML 时,一切都按预期进行 - 我有本章的起始页,我的子章节可从侧面菜单中获得。
However, when I build my LaTeX/PDF output, the hierarchy is structured as follows in the Table of Contents and numbering:但是,当我构建我的 LaTeX/PDF output 时,层次结构在目录和编号中如下所示:
0.2 My chapter title
- 0.2.1 Chapter intro part 1
- 0.2.2 Chapter intro part 2
- 0.2.2.1 subchapter1
- 0.2.2.2 subchapter2
What I wanted to have was below:我想要的如下:
0.2 My chapter title
- 0.2.1 Chapter intro part 1
- 0.2.2 Chapter intro part 2
- 0.2.3 subchapter1 title
- 0.2.3 subchapter2 title
Or alternatively:或者:
0.2 My chapter title
0.2.1 subchapter1 title
0.2.2 subchapter2 title
I realize this is probably an attempt to "hack" the toctree
concept a bit, but I'm trying to both satisfy my hierarchy requirements for HTML and LaTeX with the same code.我意识到这可能是试图“破解” toctree
概念,但我试图用相同的代码同时满足我对 HTML 和LaTeX的层次结构要求。
I'm using Sphinx 1.8.5 and default LaTeX build settings.我正在使用Sphinx 1.8.5和默认LaTeX构建设置。
I ended up using a structure as below:我最终使用了如下结构:
Hardware
=============================
.. only:: html
.. include:: hardware/intro.rst
.. toctree::
:hidden:
:maxdepth: 2
hardware/intro
hardware/installation
hardware/connector
In the conf.py
I added:在conf.py
我添加:
if tags.has("output_html"):
exclude_patterns.append("*/intro.rst")
And in my build process I add the tag output_html
as the standard html
tag is not accessible in the conf.py
.在我的构建过程中,我将标签output_html
添加为标准html
标签在conf.py
中不可访问。 With this I got what I wanted.有了这个,我得到了我想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.