如何在HTML和LaTeX中使用不同的master_文档?

如何在HTML和LaTeX中使用不同的master_文档?,latex,python-sphinx,toctree,Latex,Python Sphinx,Toctree,由于构建者处理索引和toctreecaption的方式存在差异,我想对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.c

由于构建者处理索引和
toctree
caption的方式存在差异,我想对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:: html

   .. include:: html.rst

.. only:: latex

   .. include:: latex.rst
…但这会导致许多问题,包括重复的目录条目,因为这两个文档都经过分析和索引


对于我的LaTeX和HTML构建,使用不同的主文档的正确方法是什么?

我认为金字塔文档中的一个例子可能会有所帮助。这里可能有相关的代码和比较。嗯,是的,这几乎奏效。问题是Sphinx仍然处理(解析和引用)这两个文档(在构建html文档时,它还创建了一个
latexindex.html
),并且指向在这两个位置定义的目标的链接最终指向
latexindex.html