选择Sphinx中的图像拓展

2024-04-16 09:27:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在使用Sphinx为我的Python包编写文档。我有我想使用的矢量图像,但是HTML文档只接受SVG,而PDF文档只处理PDF文件。没问题,我有两个版本的图片。你知道吗

我正在尝试使用only指令来选择要包含在不同版本的文档中的图像,如下所示:

.. only:: latex

    .. image:: ../docs/alpha-strat.pdf

.. only:: html

    .. image:: ../docs/alpha-strat.svg

然后我用make clean pdflatex html编译它,但是Sphinx在两个版本的文档中都使用PDF图像。有什么想法吗?你知道吗


Tags: 文件文档svg图像image版本alphadocs
1条回答
网友
1楼 · 发布于 2024-04-16 09:27:10

您可以通过replacing the image filename extension with an asterisk使后端自动使用支持格式的图像:

.. image:: ../docs/alpha-strat.*

从斯芬克斯的文件链接到上面:

Sphinx then searches for all images matching the provided pattern and determines their type. Each builder then chooses the best image out of these candidates.

相关问题 更多 >