2

I have created a new command that takes beamer-arguments (<...>), but I'm not able to pass them on. I suppose it's a \expandafter problem. Does anyone have a clue?

\documentclass{beamer}
\usepackage{tikz}

\pgfkeys{/mypgf/.cd, arg/.store in = \arg}

\newcommand<>\img[2][]{
    \pgfkeys{/mypgf/.cd, #1}

    {
        \def\options{} % set options to something useful based on #1

        % This works:
        \expandafter\includegraphics\expandafter[\options]{#2}

        % But not when I try to add the beamer argument:
        \expandafter\includegraphics#3\expandafter[\options]{#2}
    }
}

\begin{document}

\img<2-4>[arg=val]{example-image}

\end{document}
  • 1
    do you intend the macro to insert a paragraph break before image? (all the white space in the definition has an effect) – David Carlisle Mar 2 '14 at 18:59
3
\expandafter\includegraphics#3\expandafter[\options]{#2}

the first \expandafter will expand the first token (only) of #3 but that is < so nothing expands. I think you intended

\def\foo{\includegraphics#3}%
\expandafter\foo\expandafter[\options]{#2}%
  • Perfect! Do you know why it isn't possible to do \expandafter{\includegraphics#3}\expandafter[\options]{#2}? – Magnar Myrtveit Mar 2 '14 at 19:19
  • 1
    \expandafter{\includegraphics expands the first token after the { (which would be \includegraphics so it is effectively a no-op as { is not expandable so it is the same as {\includegraphics either way \includegraphics is the first thing to expand. – David Carlisle Mar 2 '14 at 19:26

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.