# Beamer: how to convince “includeslide” to include the last slide of a frame

I'm using \includeslide to create copies of my Beamer presentation slides in handouts, but have hit a small snag. By default, it appears to choose the first slide in a frame unless I specify the page number with an option or a suffix:

% assume 4 slides in the frame
\includeslide{mylabel}  % this shows the first slide
\includeslide{mylabel<4>} % this shows the fourth slide


Now, my presentation is very big, so I'm using a lot of new commands and environments to speed things up. Is there some way I can convince \includeslide to default to the last slide in a frame? e.g. is there a Beamer variable that contains the number of slides, or an option to pgfimage I can somehow hack into a new version of includeslide?

-
Why aren't you using the handout option? That defaults to the last slide, I believe... – Seamus Sep 27 '10 at 14:39
@Seamus: not quite, I find it gets a bit confused on a slide with lots of \onlys - it tends to include them all. Nonetheless, using the handout specification would be a way to ensure that you get exactly what you want - except that it would involve manually editing every frame (or at least, those that were a little off-kilter). Depending on the size of the presentation, this could be a lot. – Loop Space Oct 27 '10 at 10:42
Yes, if you have a lot of \only commands, you'd need to put \only<2|handout:0> or soemthing like that, to stop the handout printing all the intermediates. – Seamus Oct 27 '10 at 14:50
It's ten full days worth of bespoke training/talks on four different topics. That's what I meant by "very big" :) – Jeremy Smyth Oct 28 '10 at 8:02

When I started doing presentations with beamer, I kept getting caught out by the fact that I'd forget exactly when the end of a frame was going to happen so I'd jump to the next frame before I intended as I wasn't sure that everything on the current frame had been displayed. (Now, of course, I print out the handout version and have it in front of me.) So I came up with a hack that modified the title when it was on the last frame to give me a visual clue that it was the last frame. This might be adaptable to what you want (though there may well be a better solution) as it uses a counter to keep track of the last frame number. It's not completely robust as it can get confused if a frame changes size radically between compilations (in which case, delete the aux file).

This was my "experiment" file to test the system. It also allows for one to define an "offset".

\documentclass[12pt,color=dvipsnames]{beamer}

\newcounter{last}
\setcounter{last}{1}
\setcounter{lastoffset}{0}

\newcommand{\last}{%
\setcounter{last}{1}%
}

\newcommand{\lastlabel}[1]{%
\last%
\label<\value{last}>{#1}%
}

\definecolor{last}{named}{purple}

\newcommand{\lastframetitle}[1]{%
\last%
\frametitle{\color<\value{last}| trans:0>{last}#1}
}

% Either: \reset redefines \last
% Or: just redefine the \lastframetitle and \lastlabel to the originals.

\newcommand{\reset}{%
\renewcommand{\last}{%
\setcounter{last}{1}%
}}

\begin{document}

\begin{frame}
\setcounter{lastoffset}{-1}
\lastframetitle{Example Frame}
\lastlabel{ex}

\arabic{lastoffset}

This is an example frame.
\pause

Wait here
\pause

Paws for Thought

\onslide
Visible all along?
\end{frame}

\begin{frame}
\lastframetitle{Second Frame}

\arabic{lastoffset}

This is the second frame.
\pause

Another slide appears
\pause

Yet more appear
\pause

Wait until the end
\onslide

Should be here any time soon
\pause

What's going on?
\onslide

When do all these appear?
\pause

Phew, that's all folks.
\end{frame}

\end{document}

-