如何在Sphinx+Latex Pdf文件中包含图像文件



我正在使用Sphinx文档工具和LaTeX生成pdf文件。

在试图将图像包含在pdf文件中时,我在编译过程中遇到了以下错误:

LaTeX Warning: File `{img_file}.jpg' not found on input line 920.

! Package pdftex.def Error: File `"""{img_file}".jpg' not found: using dra
ft setting.
See the pdftex.def package documentation for explanation.
Type  H <return>  for immediate help.
...                                              

l.920 ...phinxincludegraphics{{img_file}.jpg}
}
? 

以下是一些关键的环境变量:

A在我的conf.py中,我将绝对路径定义为:sys.path.insert(0, os.path.abspath('..'))

B。这是目录树:

docs/           # (Sphinx) Documentation folder 
_build/
_static/
css/
images/
abc.jpg
img_file.jpg          <= This image file is in the root ("_static") directory
_templates/
conf.py
index.rst
modules/                  <= Folder containing my source (.rst) files
execute/
file_with_image.rst           <= I am trying to put the image in this source file
some_other_file.rst

C。为了包含图像,我使用了以下内容

.. image:: /_static/img_file.*

D我已将图形包含在conf.py序言中。

为什么会出现此错误?这么多"quot;错误消息中的引号

编辑

Tex编辑器中打开*.tex文件时,图像插入部分的代码片段显示如下:

subsection{Add Image}
label{detokenize{modules/aud_execution/add_image_with_image_directive:add-image}}label{detokenize{modules/aud_execution/add_image_with_image_directive::doc}}
sphinxstylestrong{Adding an image}
Example of image usage using “image” directive:
noindent{hspace*{fill}sphinxincludegraphics{{img_file}.jpg}} % ***

使用Quick Build,编辑器抛出如下错误:

!包pdftex.def错误:文件`quot"quot;{img_file}";。jpg'不是已找到:。。。

但是,当图像文件名{{img_file}.jpg}中的花括号被删除并将其更改为(标有***的行(:

noindent{hspace*{fill}sphinxincludegraphics{img_file.jpg}}%***

文档成功编译,图像可以在pdf文件中看到。

如果保存了.tex文件,_build/latex/文件夹中的pdf文件将显示图像。

那么,为什么在make latexpdf期间要从终端插入额外的括号呢

不要将图像放在_static下。它是专用文件夹,不用于图像。例如,创建modules/execute/img/,在那里移动图像,以及.. image:: img/my-image.png

最新更新