Python sphinx Sphinx rst2pdf和角色指令

Python sphinx Sphinx rst2pdf和角色指令,python-sphinx,restructuredtext,rst2pdf,Python Sphinx,Restructuredtext,Rst2pdf,在Sphinx2.x上的reStructuredText中,我想放置一个根据输出格式而变化的内容 在任何源文档(例如index.rst)中,添加以下行: .. role:: pdf(raw) :format: pdf .. role:: latex(raw) :format: latex .. role:: html(raw) :format: html .. |foo| replace:: :pdf:`PDF!` :latex:`LaTeX!` :ht

在Sphinx2.x上的reStructuredText中,我想放置一个根据输出格式而变化的内容

在任何源文档(例如index.rst)中,添加以下行:

.. role:: pdf(raw)
   :format: pdf

.. role:: latex(raw)
   :format: latex

.. role:: html(raw)
   :format: html

.. |foo| replace::
   :pdf:`PDF!`
   :latex:`LaTeX!`
   :html:`HTML!`

I am |foo|
当输出格式为HTML时,我希望它显示“我是HTML!”,如果它是LaTeX(即使在通过pdflatex将产品转换为PDF之后),则显示“我是LaTeX!”,如果它是PDF,则显示“我是PDF!”

我使用
makehtml
制作HTML版本,我在web浏览器中只看到“我是HTML!”正如我预期的那样:

安装
rst2pdf
。将以下行放入
conf.py

extensions = [
    'rst2pdf.pdfbuilder'
]

pdf_documents = [(
    'index',
    u'testRst2Pdf',
    u'Test Title',
    u'Sarah Author')]
使用

sphinx-build -b pdf ./source/ ./build/
更新。下面是输出。没有错误。我使用WSL1(Ubuntu18.04)运行了这个程序

我看到“我是PDF!LaTeX!HTML!”包含所有这三项

有没有办法在PDF文件中获取“我是PDF!”或“我是LaTeX!”

注意

  • 在将此行为报告为bug之前,请有人帮助我检查它是否为意外行为或设计的行为
  • 这个问题来源于我之前问的另一个问题:

rst2pdf实际上没有条件,但您可能会发现带类开关的--strip元素有用吗?将可选部分放入一个类名中,如果该类对这种格式没有意义,则使用开关将其删除


手册就在这里,如果有更多有用的信息,我也在博客(基本上是第一段的较长版本)上写了这篇文章。

你也可以在谷歌群组sphinx-users.rst2pdf不是sphinx。它可能不支持其所有指令。您是否看到任何警告或错误,或者是否可以启用它们?否,无错误。请用“Update.down”搜索此页面,并查看我刚才添加的结果。你会推荐Xeletex更好吗?我可以复制这个,当使用rst2pdf构建时,3个替换出现,而不是1个。
Running Sphinx v2.4.3
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [pdf]: targets for 1 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
processing testRst2Pdf...
index
resolving references...
done
writing testRst2Pdf...
done
build succeeded.