Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a macro that I want to run just before every new beamer frame. I could just a define myframe environment that runs the macro then starts a standard frame, but I'd rather do it differently if I can.

Beamer has neat \AtBeginSection functionality, but am I right in thinking there's no such analogue like \AtBeginFrame...

And would the situation be different if I actually wanted to do something before setting each slide? [Edit: I asked this last part as a separate question]

share|improve this question
    
Do you need to process options to frames? A patch or such a myframe environment would need to consider that. –  Stefan Kottwitz Dec 15 '10 at 0:41
    
Because without options, ` \g@addto@macro\frame\yourmacro` would be a possibility. –  Stefan Kottwitz Dec 15 '10 at 2:30
add comment

1 Answer

up vote 9 down vote accepted

Use the patching facilities of etoolbox to patch \frame to do what you want.

Since \frame is parameterless, it'd seem like you want to do

\preto\frame{\foo}

This will cause \foo to happen before the frame.

If you want things to happen after all of the argument processing, it's significantly more complex because it appears that beamer follows lots of different paths. (I sort of gave up after \beamer@@@@frame which then sets \beamer@howtotreatframe in a bunch of different ways depending on some conditions.)

Here's a simple example:

\documentclass{beamer}
\usepackage{etoolbox}
\preto\frame{\typeout{Starting new frame.}}

\begin{document}
\begin{frame}
asdf
\end{frame}
\begin{frame}
asdf
\end{frame}
\end{document}
share|improve this answer
    
Could you give an example of how I might patch the frame enviroment to execute the \foo macro before each frame? –  Seamus Dec 15 '10 at 14:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.