I have to make presentations with beamer regularly, and I tend to make slides that I can reuse later from one presentation to the next. When not using the slides, I like to keep them "hidden" at the end of my presentations so that they can be used for further explanations (they appear at the end of the PDF), and are always just a copy/paste away when I need them again.
Another thing worth pointing out is that I use sections and subsections as frame titles and frame subtitles in order to take advantage of automatic TOC building and PDF bookmarking.
Now, I recently thought about creating a new environment (that I call Extra) at the end of my beamer file, to "keep and hide" the extra slides. The idea is to be able to copy/paste sections, subsections and frames, to that Extra environment, but prevent sections from appearing in the TOC and bookmarks, and prevent beamer from counting the extra frames in \inserttotalframenumber.
Edit: I still want the frames to be included at the end of the PDF file.
So far, I proceeded as follows (MWE):
% arara: xelatex: { shell: yes }
% arara: xelatex: { shell: yes }
\documentclass[aspectratio=169, usenames, dvipsnames, hyperref={bookmarks=true}]{beamer}
%% Requirements usually in my theme file
\RequirePackage{etoolbox}% % used for conditions, etc.
\RequirePackage[utf8]{inputenc}
%% Navigation
\setbeamertemplate{navigation symbols}{} %% replace the navigation symbols
%% Footline, with the ability to "fake" the page number in the Extra section
\setbeamertemplate{footline}{
\hfill\begin{beamercolorbox}[wd=20mm, rightskip=5mm, ht=10mm]{page number in head/foot}
%% Other sections except Title, TOC, Thanks and Extra
\ifboolexpr{ ( not test {\ifcsstring{secname}{Title}} ) and ( not test {\ifcsstring{secname}{TOC}} ) and ( not test {\ifcsstring{secname}{Thanks}} ) and ( not test {\ifcsstring{secname}{Extra}} ) }{
%% page number on main frames
\hfill\footnotesize\insertframenumber/\inserttotalframenumber
\vskip3mm
}{
%% specified number on the Extra pages
%% allows me to have links to the extra pages to answer questions,
%% while virtually "staying on the same page"
\ifboolexpr{ test {\ifcsstring{secname}{Extra}} }{
\hfill\footnotesize\insertrefpage/\inserttotalframenumber
\vskip3mm
}{} %% no else statement
}
\end{beamercolorbox}%
}
%% For Extra slides
\newcommand{\refpage}[1]{
%\hypertarget{extra:#1}{}
\def\insertrefpage{#1}
}
\newcommand{\extrasection}[1]{
\def\insertextrasection{#1}
}
\newcommand{\extrasubsection}[1]{
\def\insertextrasubsection{#1}
}
\makeatletter
\newenvironment{Extra}{
\refpage{\inserttotalframenumber}
%% deactivate sections, subsections
\renewcommand{\section}{\extrasection}
\renewcommand{\subsection}{\extrasubsection}
\renewcommand{\insertsection}{\insertextrasection}
\renewcommand{\insertsubsection}{\insertextrasubsection}
%% This is the part I accidentally came up with
\renewenvironment{frame}{
\beamer@frameenv
}{
\endframe
}
%% explanations or alternatives would be welcome
}{}
\makeatother
%%% Main title %%%
\title{My awesome presentation}
\subtitle{A nice subtitle}
\date{\today}
\author[YO]{Y O }
\begin{document}
%% Title page
\section*{Title}
\begin{frame}[noframenumbering]
\titlepage
\end{frame}
%% TOC
%% Note: no need for a TOC if only one section
\section*{TOC}
\begin{frame}[noframenumbering]
\frametitle{Table of Contents}
\tableofcontents[
currentsection,
sectionstyle=show,
subsectionstyle=hide,
]
\end{frame}
%%% Main frames %%%
\section{Section 1}
\subsection{This example works}
\begin{frame}{\insertsection}{\insertsubsection}
%
Some awesome stuff
%
\end{frame}
\section{Section 2}
\subsection{But I don't understand why}
\begin{frame}{\insertsection}{\insertsubsection}
%
Some awesome stuff
%
\end{frame}
%%% I keep this page as a closure %%%
\section*{Thanks}
\begin{frame}[noframenumbering]{Thank you for your attention}{}
\Large\textbf{Thanks}
\end{frame}
%% Here I just copy paste things that I want to
%% "hide" at the end of the pdf
\section*{Extra}
\begin{Extra}
%% this command lets me fake the page number
\refpage{2}
%% Here I don't want the section to appear in the TOC or bookmarks
%% But for saving time I would rather not modify it
%% (this is a copy/paste of former main frames)
\section{Reminder: Things from last week 1}
\subsection{And a subtitle}
\begin{frame}{\insertsection}{\insertsubsection}
%
Some awesome stuff
%
\end{frame}
\refpage{\inserttotalframenumber}
\section{Reminder: Things from last week 2}
\subsection{And a subtitle}
\begin{frame}{\insertsection}{\insertsubsection}
%
Some awesome stuff
%
\end{frame}
\end{Extra}
\end{document}
The part about modifying the frame environment came more or less by accident while I was testing something else, but I don't understand why it has the desired effect, nor whether a better alternative exists.
I am talking about:
%% Adapted from beamer's definition of frame
%% added to the opening definition of Extra
\makeatletter
\renewenvironment{frame}{
\beamer@frameenv
}{
\endframe
}
\makeatother
If anyone is willing to share some insights regarding why this seems to work and how to maybe do better, I would be glad to know.
PS: I am using XeLaTeX with the Beamer class.
\NewDocumentEnvironment{Extra}{ +b }{\iffalse #1 \fi}{}. This will essentially comment out everything that is placed between\begin{Extra}and\end{Extra}. – Jasper Habicht Dec 06 '22 at 22:50\end{document}is ignored, so this might as well be an easy solution to store stuff in your document in a "hidden" way. – Jasper Habicht Dec 06 '22 at 22:56