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
  • 1
    do you intend the macro to insert a paragraph break before image? (all the white space in the definition has an effect) Mar 2, 2014 at 18:59

1 Answer 1

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}%
2
  • Perfect! Do you know why it isn't possible to do \expandafter{\includegraphics#3}\expandafter[\options]{#2}? Mar 2, 2014 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. Mar 2, 2014 at 19:26

You must log in to answer this question.

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