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.

Following on from this question, is there an easy way to call a macro before each slide? So that question answers how to get at each frame, but I want finer control...

I want a macro that sets a counter to the current fraction of slides we've go through so far. I can't get at it through etoolbox's patching controls, because the slides are controlled more internally than that...

share|improve this question
    
What are you going to do with this counter? (It can't be a counter if it's a fraction, but that's not the point) Can you not just compute it at the time of placement? –  Matthew Leingang Dec 19 '10 at 23:19
    
I want it to change the colour of the structure elements, so "time of placement" is the start of the slide. –  Seamus Dec 20 '10 at 13:04
add comment

2 Answers

up vote 3 down vote accepted
\documentclass{beamer}
\newcounter{myctr}
\renewcommand\themyctr{frame~\arabic{myctr}}
\makeatletter
\def\beamer@checkframetitle{\stepcounter{myctr}%
  \@ifnextchar\bgroup\beamer@inlineframetitle{}}
\makeatother
\begin{document}

\begin{frame}{foo}{\themyctr}
foo
\end{frame}
\begin{frame}{foo}{\themyctr}
foo
\end{frame}
\begin{frame}{foo}{\themyctr}
foo
\end{frame}
\begin{frame}{foo}{\themyctr}
foo
\end{frame}

\end{document}
share|improve this answer
1  
This works. You could make your MWE neater by adding a couple of \pause s to show what it can do within a frame! Could you explain how it works? Is \beamer@checkframetitle the first thing beamer does with a frame? –  Seamus Dec 20 '10 at 13:55
add comment

This works for me!

  \makeatletter
  \g@addto@macro{\frame}{Test}
  \makeatother

\g@addto@macro is defined in LaTeX, etoolbox has an exact clone, but I can't remember the exact command:)

share|improve this answer
    
That runs something at the beginning of each frame, but Seamus is asking for something at the beginning of each slide. (A slide is one of the overlays on a frame.) –  Matthew Leingang Dec 19 '10 at 23:16
    
@Matthew is right, this doesn't do what I want it to. The etoolbox version is, I think, \appto –  Seamus Dec 20 '10 at 12:34
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.