sphinx:通过 raw:: latex 包含 .tex 文件

muo*_*uon 5 python latex docstring python-sphinx

我想在 sphinx 中包含乳胶文档。sphinx html build 不包括使用.. raw:: latex指令链接的乳胶文件。我有

这是我的目录结构

docs/
    source/
        importlatex.rst
        index.rst

    build/
    tex/
       texfile.tex
Run Code Online (Sandbox Code Playgroud)

index.rst 好像

Welcome to documentation!
=========================

Contents:

.. toctree::
   :maxdepth: 2

   icnludelatex
   and-other-stuff
Run Code Online (Sandbox Code Playgroud)

icnludelatex.rst 好像:

Include Latex
=============

.. raw:: latex
    :file: ../tex/texfile.tex
Run Code Online (Sandbox Code Playgroud)

此参考提供了包含 html 的示例

.. raw:: html
    :file: inclusion.html
Run Code Online (Sandbox Code Playgroud)

为什么会这样?

cos*_*bur 7

当您使用raw指令时,块仅由关联的编写器解释。例如,.. raw:: latex如果您生成 LaTeX 但它对 HTML 不可见,则有效。

您需要的是 LaTeX 的解析器,但在快速搜索中,我只找到了Markdown ( recommonmark ) 和 jupyter notebook ( nbsphinx ) 的解析器。

也许,一个快速而肮脏的解决方案是使用 pandoc 将您的乳胶文档转换为 rst(您可能会丢失一些格式化文本)。

pandoc -s texfile.tex -o texfile.rst
Run Code Online (Sandbox Code Playgroud)

然后include在您的icnludelatex.rst.

.. include:: texfile.rst
Run Code Online (Sandbox Code Playgroud)