由于toctree
构建器处理索引和标题的方式存在差异,我想为我的 Sphinx 文档的 HTML 和 LaTeX 构建使用不同的“主”文档。
以下几乎可以工作:
def set_master_doc(app):
if app.tags.has("latex"):
app.config.master_doc = "latex"
app.config.exclude_patterns.append("html.rst")
else:
app.config.master_doc = "html"
app.config.exclude_patterns.append("latex.rst")
def setup(app):
app.connect('builder-inited', set_master_doc)
…但由于它修改了配置,每次我从 HTML 切换到 LaTeX 时都会导致完全重建,反之亦然。
我还尝试使用以下索引only::
:
.. only:: html
.. include:: html.rst
.. only:: latex
.. include:: latex.rst
…但这会导致许多问题,包括重复的目录条目,因为这两个文档都被解析和索引。
为我的 LaTeX 和 HTML 构建使用不同的主文档的正确方法是什么?