5

I have a code line that looks like that

\includegraphics{\complicatedmacro}

The \complicatedmacro returns just the name of the picture file, e.g., mypicture, so that when I write

 \complicatedmacro

In my LaTeX code I get the text mypicture in the output .pdf

Consequently \includegraphics{\complicatedmacro} should just set the picture mypicture in the document. But I get an error

TeX capacity exceeded, sorry [input stack size=5000].

However when I write \includegraphics{mypicture}, everything works fine.

I have the feeling this issue has to do with the expansion process. What is the secret to let the \complicatedmacro be fully expanded before the call to \includegraphics?

I hope this is enough. I would like a general answer. But if you'd really need the "\complicatedmacro", I could write it.

Thanks! :)

The \complicatedmacro's definition

 \newcommand{\usedpicturename}[2]%
    {\ifthenelse{\boolean{shouldusetestpicture}}{#1}{#2}}

Use in the .tex file

Now somewhere in the code I set the boolean

   \setboolean{shouldusetestpicture}{false}
   \includegraphics{\usedpicturename{mypicturetest}{mypicturecool}} %Here pops up the error
3
  • It would be helpful to see the definition of \complicatedmacro.
    – Werner
    Nov 8, 2016 at 0:11
  • Ok. Here we go! :) Nov 8, 2016 at 0:12
  • if \complicatedmacro expanded to mypicture as stated you would not get that error. Nov 8, 2016 at 0:18

1 Answer 1

8

ifthenelse does not work by expansion, it involves assignments so you can not "expand this fully". There are plenty of conditional macros that do work via expansion, such as

\newcommand{\usedpicturename}[2]%
    {\ifshouldusetestpicture #1\else #2\fi}
4
  • I'm glad and honoured that the author of the ifthen package answer my question so speedily :), but on the other hand I feel so stupid that I searched a solution for this problem for soooo long (\expand, \edef, \noexpand, \tracingmacros... ) And the answer is so simple! :-S Thanks and blessings, David. Nov 8, 2016 at 0:33
  • 3
    @loved.by.Jesus note the question (and answer) are only related to ifthen (which you didn't mention at all in the question initially) and not to \includegraphics (for example try \typeout{\usedpicturename{a}{b}}) questions should always have a reproducible test case. Nov 8, 2016 at 0:35
  • "Thought you might answer this one:-) " Nov 8, 2016 at 0:48
  • @StevenB.Segletes touché :-) Nov 8, 2016 at 0:59

You must log in to answer this question.

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