To ease the typesetting of nontrivial beamer frames I often employ local helper macros. This is not too easy in beamer, as defining a macro with parameters (e.g., \def\myfmt#1{\emph{#1}}
) between \begin{frame}
and \end{frame}
fails with:
! Illegal parameter number in definition of \beamer@doifinframe.
<to be read again>
1
l.11 \end{frame}
The commonly mentioned workaround for this is to define the macro outside of the frame together with the latter inside a group:
\bgroup
\def\myfmt#1{\emph{#1}}
\begin{frame}[label=problem]{A frame that uses a ,,local'' macro}
\myfmt{Slide content}
\end{frame}
\egroup
This, however, does not work if one wants to use the frame with \againframe
later (complete MWE):
\documentclass{beamer}
\begin{document}
\bgroup
\def\myfmt#1{\emph{#1}}
\begin{frame}[label=problem]{A frame that uses a ,,local'' macro}
\myfmt{Slide content}
\end{frame}
\egroup
\bgroup
\def\myfmt#1{\color{red} #1}
\begin{frame}{Another frame that uses a ,,local'' macro}
\myfmt{Slide content}
\end{frame}
\egroup
% fails with "Undefined control sequence \myfmt"
\againframe{problem}
\end{document}
Apparently, \againframe
does insert only the content that was defined between \begin{frame}
and \end{frame}
- which makes sense, of course.
So how can I define "frame-local" helper macros that work with \againframe
?
fragile
option or try to double the#
:\begin{frame}[label=problem]{A frame that uses a ,,local'' macro} \def\myfmt##1{\emph{##1}} \myfmt{Slide content} \end{frame}
. Theframe
environment is a pseudo-environment, i.e. actually\frame{ .. }
in disguise. The argument is stored in a parameter-less macro and therefore the#1
is taken as its argument.\def\myfmt####1{\emph{####1}}
works for me in the frame, but not with\againframe
. So usingfragile
seems to be the way to go.#
, but not with four, nice :-) However,fragile
seems not to help wrt to\againframe
; have you tested this?