如何在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。。我在 {em}前言”中加入了 graphix

为什么会出现此错误?错误消息中如此多的“”引号的来源是什么?

编辑

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

*.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}} % *** ,编辑器将引发错误,如下所示:

!软件包pdftex.def错误:文件'“”“ {img_file}”。jpg'不存在 找到:...

但是,当图像文件名中的大括号Quick Build被删除并将其更改为(标有***的行)时:

{{img_file}.jpg}%***

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

如果保存了 \noindent{\hspace*{\fill}\sphinxincludegraphics{img_file.jpg}}文件,则 _build / latex / 文件夹中的pdf文件将显示图像。

那为什么要在.tex期间从终端插入多余的括号?

解决方法

请勿将图片放在_static下。这是专用文件夹,不适用于图像。例如。创建modules/execute/img/,在其中移动图片,然后.. image:: img/my-image.png

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...