Objective
I wanted to create a command that enables me to add a collection of paths in a comma-separated list to my graphics path, next to a bunch of other instructions for each path that I will not include.
To append the graphics path, I use the code written by @egreg, see link.
The result is \setDependentPaths
, see the MWE below.
Issue
In the MWE, I placed an image image.png
in the relative folder mypath/Resources/Images
. So, I want to add mypath
as a 'dependent path'. If I compile the document with the \includegraphics
command commented out, it does not produce an error. When I don't comment it out, it produces the following error:
! Undefined control sequence.
\p ->\@nil
I suspect that the loop variable \p
is used literally, such that \p/Resources/Images
is used as the graphics path instead of mypath/Resources/Images
. However, I'm not sure, and even if that's the case, I don't know how to solve it.
Anyone any clues?
MWE
\documentclass{book}
% Load packages
\usepackage{graphicx}
% Set graphics path
\graphicspath{
{Resources/Images/}
}
% Enable appending to graphics path
\makeatletter
\newcommand{\appendGraphicsPath}[1]{%
\g@addto@macro\Ginput@path{#1}%
}
\makeatother
% This command loops over a comma-separated list to add graphics paths
\makeatletter
\newcommand{\setDependentPaths}[1]{%
\@for\p:=#1\do{%
\appendGraphicsPath{{\p/Resources/Images/}}%
}%
}
\makeatother
% Set the paths that my document depends on
\setDependentPaths{mypath,anotherpath}
\begin{document}
A title
\includegraphics{image.png}
\end{document}