Hi community I have a weird problem. It seems that includegraphics won't accept the entire argument, it always trims off the directory part!

The argument was manipulated and concatenated in another command before passing to the concerned command. But \typeout the argument shows that the argument contains correct string. What happened!?




    \expandafter\gdef\csname useInset#1\endcsname{1}%
    \expandafter\gdef\csname inset#1Color\endcsname{#2}%
    \expandafter\gdef\csname crop#1X\endcsname{#3}%
    \expandafter\gdef\csname crop#1Y\endcsname{#4}%
    \expandafter\gdef\csname crop#1W\endcsname{#5}%
    \expandafter\gdef\csname crop#1H\endcsname{#6}%

    \typeout{OMG #1}

            % setting \cropfile manually works! e.g.
            % \def\cropfile{figures/lr_img_053-png-19.25x19.25+176.5+123.75}
            \addInset{\cropfile.png}{\insetAColor} % works if I hardcode \addInset{figures/\cropfile.png}



Calling \mycommand{red}{figures/figure.png} always gives me error Not found.

  • 1
    Can you make a minimal working example (MWE)? – user36296 Feb 19 '18 at 19:37
  • @samcarter please have a look now :) – yfi Feb 19 '18 at 20:16
  • Are all your images in the folder figures? If yes, I'd simply suggest to add it to the graphic path. – user36296 Feb 19 '18 at 20:24
  • What's the purpose of inserting . and then to change it into -? Wouldn't it be simpler to directly do \edef\baseFileName{\filename@area\filename@base-\filename@ext}? – egreg Feb 20 '18 at 0:57
  • yeah except there might be other . i wanna change - in the base and ext. – yfi Feb 20 '18 at 13:07

\includegraphics uses \filename@parse internally. Because you used \def\cropfile instead of \edef\cropfile, \baseFileName isn't expanded and depends on the value of \filename@area. \filename@parse inside \includegraphics overwrites the value of \filename@area before expanding the argument, so it sees the value of \filename@area it already reset instead of the value assigned by your \filename@parse in \addInsets.

So you can fix this like @Ian Thompson suggested by writing


instead of


or by renaming your version of \filename@area:

    \let\myFileArea\filename@area % \edef could be used here too

I'm too tired to work out what's going on here, but the problem seems to go away if you change \def to \edef in


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.