# Expand Macro in \includegrapics

I have upgraded my Windows installation of MikTex today using the included update manager. After the update I received error messages when trying to compile my tex files using XeLaTeX that a figure could not be found.

! LaTeX Error: File Figures/Generic/Symbols/comment.png' not found.


I was able to reproduce the error using following minimal code:

\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}


I have read somewhere that includegraphics only expands once and therefore not the actual path is check. My basic (and probably stupid) approaches using expandafter did not result in working code. I have to admit that my knowledge is limited when it comes to the details of expanding macros. Is there a solution to this problem.

A second and far less important question, does somebody know what has been changed in the last 5 months in MikTex (XeLaTeX) which caused the issue?

Version of XeLaTeX used under unix (working with old/wrong the code):

[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  The windows version "causing" the issue: $ "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


Thank you for your answer.

• I don't think that anything has changed. It doesn't work for me in older systems either. – Ulrike Fischer Aug 3 '17 at 17:45
• @UlrikeFischer I tested the exact same file(s) in the exact same environment. Before the update the file compiled, it did not later. Actually, the production code (which runs on unix not on windows, so it might not be comparable) still runs the old version without the expansion. I looked up the version of XeLaTeX and edited into the question. – wrYch Aug 3 '17 at 18:49
• the version engine is imho not relevant. The versions of the graphicx drivers could matter. But I get errors with older texlive versions too. – Ulrike Fischer Aug 3 '17 at 19:31

## 1 Answer

The graphics package only expands a macro at the beginning of the path once before passing the file path to get the extension for the image type and so on.

Instead of

\newcommand{\symbolpath}{\CommentSymbolPath}


try:

\newcommand{\symbolpath}{}
\edef\symbolpath{\CommentSymbolPath}


or

\newcommand{\symbolpath}{\CommentSymbolPath}
\edef\symbolpath{\symbolpath}


\edef defines a macro and expands the definition text as much as possible. This way, it does not matter, how many macros and how many macro levels are used in the definition of \symbolpath. Then \symbolpath can be used as first macro in the image path argument of \includegraphics.

• I actually ended up using the second solution. The reason why is that I have multiple options for the \symbolpath (i.e. an if case where it is \CommentSymbolPath, \WarningSymbolPath or another symbol). The second option allowed my to only add the line \edef\symbolpath{\symbolpath} after the "if" case. Thank you again for the solution – wrYch Aug 3 '17 at 17:52
• \newcommand*` would be even better? – cfr Aug 4 '17 at 1:50
• @cfr The macro does not have parameters, thus it does not matter here. – Heiko Oberdiek Aug 4 '17 at 7:32