我今天使用附带的更新管理器升级了 Windows 上的 MikTex 安装。更新后,当我尝试使用 XeLaTeX 编译我的 tex 文件时,我收到错误消息,提示找不到图形。
! LaTeX Error: File `Figures/Generic/Symbols/comment.png' not found.
我能够使用以下最少的代码重现该错误:
\documentclass[11pt,a4paper]{book}
\usepackage[a4paper,showframe]{geometry}
\usepackage{graphicx} % graphicx: graphics
\newcommand*{\defCommentSymbolPath}[1]{\def\CommentSymbolPath{#1}}
\defCommentSymbolPath{Figures/Generic/Symbols/comment.png}
\newcommand{\symbolpath}{\CommentSymbolPath}
\begin{document}
\includegraphics[width=0.5\textwidth]{\symbolpath}
\end{document}
我读到过一篇文章,其中提到 includegraphics 只扩展一次,因此实际路径没有被检查。我使用 expandafter 的基本方法(可能很愚蠢)没有产生有效的代码。我不得不承认,在扩展宏的细节方面,我的知识有限。这个问题有解决办法吗?
第二个不太重要的问题是,有人知道在过去 5 个月内 MikTex(XeLaTeX)发生了哪些变化导致了这个问题吗?
unix 下使用的 XeLaTeX 版本(使用旧的/错误的代码):
[det@bad-sr60 scripts]$ /usr/local/texlive/2016/bin/x86_64-linux/xelatex --version
XeTeX 3.14159265-2.6-0.99996 (TeX Live 2016)
kpathsea version 6.2.2
Copyright 2016 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 57.1; using 57.1
Compiled with zlib version 1.2.8; using 1.2.8
Compiled with FreeType2 version 2.6.3; using 2.6.3
Compiled with Graphite2 version 1.3.8; using 1.3.8
Compiled with HarfBuzz version 1.2.6; using 1.2.6
Compiled with libpng version 1.6.21; using 1.6.21
Compiled with poppler version 0.42.0
Compiled with fontconfig version 2.6.0; using 2.8.0
导致该问题的 Windows 版本:
$ "C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\xelatex.exe" --version
MiKTeX-XeTeX 2.9.6412 (0.99998) (MiKTeX 2.9.6400)
(C) 1994-2008 by SIL International, (C) 2009-2012 by Jonathan Kew, (C) 2010-2012 by Han The Thanh, (C) 2012-2013 by Khaled Hosny
TeX is a trademark of the American Mathematical Society.
using bzip2 version 1.0.6, 6-Sept-2010
compiled with curl version 7.54.1; using libcurl/7.54.1 WinSSL
compiled with expat version 2.2; using expat_2.2.0
compiled with fontconfig version 2.12.3; using 2.12.3
compiled with freetype2 version 2.8; using 2.8
compiled with graphite2 version 1.3.10; using 1.3.10
compiled with harfbuzz version 1.4.7; using 1.4.7
compiled with icu version 58.2; using 58.2
compiled with jpeg version 9.2
compiled with liblzma version 50020032; using 50020032
compiled with libpng version 1.6.30; using 1.6.30
compiled with libressl version LibreSSL 2.5.3; using LibreSSL 2.5.3
compiled with MiKTeX Application Framework version 2.6416; using 2.6416
compiled with MiKTeX Core version 2.6413; using 2.6413
compiled with MiKTeX Archive Extractor version 1.6300; using 1.6300
compiled with MiKTeX Package Manager version 1.6403; using 1.6403
compiled with poppler version 0.55.0
using teckit version 2.4
compiled with uriparser version 0.8.4
compiled with zlib version 1.2.11; using 1.2.11
谢谢您的回答。
答案1
该graphics
包仅在传递文件路径之前在路径开头扩展一次宏来获取图像类型的扩展名等等。
代替
\newcommand{\symbolpath}{\CommentSymbolPath}
尝试:
\newcommand{\symbolpath}{}
\edef\symbolpath{\CommentSymbolPath}
或者
\newcommand{\symbolpath}{\CommentSymbolPath}
\edef\symbolpath{\symbolpath}
\edef
定义一个宏,并尽可能地扩展定义文本。这样, 的定义中使用多少个宏和多少个宏级别就无关紧要了\symbolpath
。然后\symbolpath
可以用作 的图像路径参数中的第一个宏\includegraphics
。