无法加载图片或 PDF 文件 - Xelatex

无法加载图片或 PDF 文件 - Xelatex

最近我在编译.tex文件时遇到了问题。主要是在处理或加载图像时失败,但仅限于 xelatex,而 pdflatex 可以正常工作。

以下是示例代码:

% Setting the page size and font size. %
\documentclass[a4paper,11pt]{article}

% Package used for image formating.
\usepackage{graphicx}
\graphicspath{ {"img"} }


\begin {document}
    \includegraphics[width=0.3 \textwidth, keepaspectratio]{"elasticjawcoupling.png"}
\end{document}

这是使用 xelatex 编译时的输出消息:

This is XeTeX, Version 3.141592653-2.6-0.999996 (TeX Live 2024/Arch Linux) (preloaded format=xelatex)
 restricted \write18 enabled.
entering extended mode
(./test_latex.tex
LaTeX2e <2023-11-01> patch level 1
L3 programming layer <2024-02-20>
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2023/05/17 v1.4n Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size11.clo))
(/usr/share/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/share/texmf-dist/tex/latex/graphics-def/xetex.def)))
(/usr/share/texmf-dist/tex/latex/l3backend/l3backend-xetex.def)
(./test_latex.aux) (/usr/share/texmf-dist/tex/latex/base/ts1cmr.fd)

LaTeX Warning: File `"elasticjawcoupling.png"' not found on input line 10.

! Unable to load picture or PDF file 'elasticjawcoupling.png'.
<to be read again> 
                   }
l.10 ...keepaspectratio]{"elasticjawcoupling.png"}
                                                  
? 

! Package graphics Error: Division by 0.

See the graphics package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.10 ...keepaspectratio]{"elasticjawcoupling.png"}
                                                  
? 
[1] (./test_latex.aux)
xdvipdfmx:fatal: Image inclusion failed. Could not find file: elasticjawcoupling.png

No output PDF file written.
 )
Error 256 (driver return code) generating output;
file test_latex.pdf may not be valid.
Transcript written on test_latex.log.

以下是 的输出xelatex --version

XeTeX 3.141592653-2.6-0.999996 (TeX Live 2024/Arch Linux)
kpathsea version 6.4.0
Copyright 2024 SIL International, Jonathan Kew and Khaled Hosny.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the XeTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the XeTeX source.
Primary author of XeTeX: Jonathan Kew.
Compiled with ICU version 74.2; using 74.2
Compiled with zlib version 1.3.1; using 1.3.1
Compiled with FreeType2 version 2.13.2; using 2.13.2
Compiled with Graphite2 version 1.3.14; using 1.3.14
Compiled with HarfBuzz version 8.3.0; using 8.3.1
Compiled with libpng version 1.6.43; using 1.6.43
Compiled with pplib version v2.2
Compiled with fontconfig version 2.15.0; using 2.15.0

“编译器”应该可以正确处理这些文件。由于可以使用 pdflatex 加载,这意味着问题出在 xelatex 上。使用 pdflatex 只是为了看看它是否能编译文档。

答案1

在尝试了@David Carlisle 和@Ulrike Fischer 的建议后,我成功编译了它,并且运行良好。

我猜这不是问题的根源,但这是一个修复方法,因为之前它运行良好。

编辑:

% Setting the page size and font size. %
\documentclass[a4paper,11pt]{article}

% Package used for image formating.
\usepackage{graphicx}
% quotes removed with a forward slash
\graphicspath{ {img/} }


\begin {document}

% quotes removed
\includegraphics[width=0.3 \textwidth, keepaspectratio]{elasticjawcoupling.png}

\end{document}

相关内容