【发布时间】:2020-12-06 15:48:50
【问题描述】:
我正在使用 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.我已将 graphix 包含在 conf.pypreamble 中。
为什么会出现此错误?错误消息中那么多“””引号的来源是什么?
编辑
在 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 错误:文件 `"""{img_file}".jpg' 不是 发现:...
但是,当图像文件名中的大括号 {{img_file}.jpg} 被删除并更改为(标记为 *** 的行):
\noindent{\hspace*{\fill}\sphinxincludegraphics{img_file.jpg}}%***
文档编译成功,可以在pdf文件中看到图片。
如果保存.tex文件,_build/latex/文件夹中的pdf文件会显示图片。
那么为什么在终端的make latexpdf 期间插入了额外的括号?
【问题讨论】:
-
我发现了一些东西possibly related in the Sphinx docs。这超出了我的深度。除了 Sphinx 文档,您是否尝试过搜索 TeX community 或 Sphinx issue tracker?
-
我无法重现这一点,但我可以说
sys.path.insert(...)对图像没有影响。该设置仅在使用 autodoc 时适用。 -
@StevePiercy - 已经检查了您指出的部分,但是正如文档本身所说 源文件中引用的图像文件(例如通过 .. image::) 会自动复制。 而且,正如文档所说,引用的图像文件被复制到
_build/latex文件夹,这(我认为)意味着 LaTeX 正在访问 中引用的图像文件b>文件file_with_image.rst。 PS。我已经检查了两个(其他)来源,但没有提出与此问题相关的任何内容。在Github 上发布问题。 -
@mzjn - 没错。我用过
sys.path.append(os.path.abspath('../<proj_folder>/docs')),结果是一样的。 -
@StevePiercy - 我创建了一个新的 (Sphinx) 项目,看看是否像我之前所做的那样将它从我的 Django 应用程序中分离出来,会改变这种情况。即使这样,它也无法访问图像文件。我在某处读到(在Tex 上,可能是),在 conf.py 中调用
\usepackage的顺序也可能有一些影响。但即使将graphicx作为最后一个被调用的,也无济于事。有什么想法吗?
标签: python-sphinx pdflatex pdftex