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
  • It would be helpful to see the definition of \complicatedmacro. – Werner Nov 8 '16 at 0:11
  • Ok. Here we go! :) – loved.by.Jesus Nov 8 '16 at 0:12
  • if \complicatedmacro expanded to mypicture as stated you would not get that error. – David Carlisle Nov 8 '16 at 0:18
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}
  • 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. – loved.by.Jesus Nov 8 '16 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. – David Carlisle Nov 8 '16 at 0:35
  • "Thought you might answer this one:-) " – Steven B. Segletes Nov 8 '16 at 0:48
  • @StevenB.Segletes touché :-) – David Carlisle Nov 8 '16 at 0:59

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.