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.


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?



% Load packages

% Set graphics path

% Enable appending to graphics path

% This command loops over a comma-separated list to add graphics paths

% Set the paths that my document depends on


A title



1 Answer 1


You need to expand \p so

  • I knew it, I need more knowledge on expansion! Would you be so kind to add an explanation on why you placed \expandafter in those locations?
    – Steven
    Nov 9, 2022 at 9:56
  • @Steven the first \expandafter expands the second, the second expands the third, and the third expands \p after which the input buffer looks like \appendGraphicsPath{{mypath Nov 9, 2022 at 10:31
  • by any chance, do you know how to do in case I do \providecommand{\main}{.} and call \appendGraphicsPath{{\main/\p/Resources/Images/}} in the for loop?
    – Steven
    Nov 16, 2022 at 7:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .