【问题标题】:sphinx: Including .tex file via raw:: latexsphinx:通过 raw::latex 包含 .tex 文件
【发布时间】:2017-07-12 17:39:56
【问题描述】:

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

这是我的目录结构

docs/
    source/
        importlatex.rst
        index.rst

    build/
    tex/
       texfile.tex

index.rst 看起来像

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

Contents:

.. toctree::
   :maxdepth: 2

   icnludelatex
   and-other-stuff

icnludelatex.rst 看起来像:

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

.. raw:: latex
    :file: ../tex/texfile.tex

this reference 给出了包含 html 的示例

.. raw:: html
    :file: inclusion.html

为什么会这样?

【问题讨论】:

  • Sphinx 没有为该包含引发任何错误。它创建一个带有标题的页面(我在单独的 .rst 中有标题)
  • tex/ 位于source/ 目录之外,因此请将其移入或添加到您的conf.py 作为源文件的附加路径。
  • 建议创建一个MCVE,并将其推送到公共回购,以便我可以重现该问题。

标签: python latex python-sphinx docstring


【解决方案1】:

当您使用raw 指令时,该块仅由相关的writer 解释。例如,.. raw:: latex 在您生成 LaTeX 但它对 HTML 不可见的情况下有效。

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

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

pandoc -s texfile.tex -o texfile.rst

然后在您的icnludelatex.rst 中使用include 指令。

.. include:: texfile.rst

【讨论】:

  • 谢谢,我以前做过,但是 pandoc 把方程式、表格等弄乱了,所以我希望直接导入乳胶会不那么麻烦
  • @muon 也许您可以先转换为 html(使用 hevea、latexml 或 pdf2htmlex),然后使用 include html。
猜你喜欢
  • 1970-01-01
  • 2019-12-11
  • 2020-12-06
  • 2016-05-13
  • 1970-01-01
  • 2020-07-29
  • 1970-01-01
  • 1970-01-01
  • 2011-11-25
相关资源
最近更新 更多