如何在Sphinx+Latex PDF文件中包含图像文件 [英] How to include image files in Sphinx + Latex Pdf files

查看:23
本文介绍了如何在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前言中。

为什么我会收到此错误?错误消息中这么多引号的来源是什么?

编辑

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:


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

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

!程序包pdftex.def错误:文件`";";";{img_file}";.jpg‘不是 找到:...

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

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

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

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

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

推荐答案

请勿将图片放在_static下。这是一个特殊用途的文件夹,不是放图像的。例如,创建modules/execute/img/,将图像移到那里,以及.. image:: img/my-image.png

这篇关于如何在Sphinx+Latex PDF文件中包含图像文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆