Suppose a graphic file myimage contained in a subdirectory images of the current directory.
With the following MCE:
\documentclass{article}
\usepackage{graphicx}
\newcommand{\ImagesDirectory}{images}
\graphicspath{{\ImagesDirectory/}}
\begin{document}
\includegraphics{myimage}
\end{document}
the graphic file myimage is found.
But, with the following MCE where \newcommand{\ImagesDirectory}{...} is replaced by \DeclareDocumentCommand{\ImagesDirectory}{}{...}:
\documentclass{article}
\usepackage{graphicx}
\DeclareDocumentCommand{\ImagesDirectory}{}{images}
\graphicspath{{\ImagesDirectory/}}
\begin{document}
\includegraphics{myimage}
\end{document}
the graphic file myimage is not found.
Why and is there a workaround still relying on \DeclareDocumentCommand or friends (and not \newcommand and friends)?
\DeclareExpandableDocumentCommand. – cabohah May 09 '23 at 14:05DeclareExpandableDocumentCommand– David Carlisle May 09 '23 at 14:05\graphicpath? – Denis Bitouzé May 09 '23 at 14:09\graphicpathis only guaranteed to work if you pass explicit path and does not contain special character etc. If it also works with defined commands it's implementation side effect, but that only work when commands are expandable." -- in the process of "simplifying" LaTeX for the users, expandability things like that are not very well-documented (actually I didn't check the LaTeX book) which imply several things count as "works by implementation". – user202729 May 09 '23 at 14:16