I am using beamer for a presentation (of sorts) and want to add a frame every n frames (let's keep things general). As an additional challenge, I want these extra slides to not be counted in the regular numbering (although this is maybe better solved by using a custom counter? See below).
What I've tried
I'm really close to getting this done, but my approach I guess can be improved.
What I've been trying so far is to use everypage to perform a check at every page to see if an extra slide should go after (I do this check using pgf), and if it is, I insert a frame with afterpage.
This works, but it adds one too many additional slides, because in a 10 page presentation it adds an extra one at the end (after page 10, which technically is not wrong, but is not what I want). Also, it means I need to add two packages, just for this (and that's just because I get pgf for free with beamer)!
Also, for this I've been using framenumber, but it's very possible that it would be better to use a different, custom counter (since beamer, you know... uses framenumber).
\documentclass{beamer}
\usepackage{afterpage}
\usepackage{everypage}
% Regular slide
\newcommand{\baseslide}[1]{
\begin{frame}{\phantom{bg}}
\begin{center}%
\LARGE #1
\end{center}
\end{frame}
}
% Extra slide
\newcommand{\extraslide}{
\baseslide{This slide was inserted}
\addtocounter{framenumber}{-1}
}
% Modulo test using pgfmathparse
% Based on http://tex.stackexchange.com/a/15303/18982
\newcommand\modulo[4]{
\begingroup
\pgfmathsetmacro{\a}{#1}
\pgfmathsetmacro{\b}{#2}
\pgfmathparse{mod(\a,\b)==0}
\ifdim\pgfmathresult pt= 1 pt
#3
\else
#4
\fi
\endgroup
}
% At every page, check if the next should come before an inserted slide
\AddEverypageHook{
\modulo{\value{framenumber}+1}{5}{
% If so, add a slide after that page
\afterpage{\extraslide}
}{}
}
\begin{document}
\baseslide{This is test \insertframenumber}
\baseslide{This is test \insertframenumber}
\baseslide{This is test \insertframenumber}
\baseslide{This is test \insertframenumber}
\baseslide{This is test \insertframenumber}
% Slide should go here
\baseslide{This is test \insertframenumber}
\baseslide{This is test \insertframenumber}
\baseslide{This is test \insertframenumber}
\baseslide{This is test \insertframenumber}
\baseslide{This is test \insertframenumber}
% But it also goes here, and it shouldn't!
\end{document}
So, my questions:
- Is there a better way to do this?
- How can I make sure that these pages are only added within the document (not as the first or last page)?
Additional, perhaps not necessarily useful background
I'm using beamer to generate a series of slides with some text that I can show to people one at a time to elicit certain responses. In this particular case, they are sentences to be read during a recording session.
The extra slides I'm inserting are "breaks", so that I can give the participant (performer?) some time to rest, drink some water, or do whatever it is people do when they relax.
\moduloto check if the considered page number is equal to the last page number (this requires of course two compilations) plus the number of inserted slides. If it is, you should not insert a blank frame, since it means the considered slide is the last one. Hope it gives you some ideas before more elegant solutions come. – anderstood Jul 10 '14 at 06:28framenumbercounter by hand, you could use thenoframenumberingoption for the extra slides: http://tex.stackexchange.com/q/30461/3323 – diabonas Jul 11 '14 at 07:49