由于构建器处理索引和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版本使用不同的主文档的正确方法是什么?