2

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.

9
  • 3
    Redefining the frame environment creates much more problems than it solves. Can you make a minimal reproducible example? Dec 6, 2022 at 16:21
  • Welcome to TeX.SX! So, you want to create an environment in which you can put stuff that does not affect ToC, numbering etc.? You can probably just define \NewDocumentEnvironment{Extra}{ +b }{\iffalse #1 \fi}{}. This will essentially comment out everything that is placed between \begin{Extra} and \end{Extra}. Dec 6, 2022 at 22:50
  • 2
    @YohannO. Please add a MWE so we can test alternative approaches Dec 7, 2022 at 16:08
  • 1
    Maybe related: Appendixify: Move selected slides to appendix in Beamer.
    – dexteritas
    Dec 7, 2022 at 17:08
  • 1
    @samcarter_is_at_topanswers.xyz I added a MWE as requested
    – Yohann O.
    Dec 7, 2022 at 19:30

1 Answer 1

0

Instead of messing with the frame environment, you could place your extra frames in the appendix and use \insertmainframenumber instead of \inserttotalframenumber. This way it does not matter if the frames are counted or not.

\documentclass[aspectratio=169, usenames, dvipsnames, hyperref={bookmarks=true}]{beamer}

%\usetheme{mytheme}

\title{Presentation title}
\subtitle{Such a nice presentation}
\date{\today}
\author[Y.O.]{Y.O.}

\makeatletter

\renewcommand<>\appendix{%
  \beamer@inappendixtrue%
  \only#1{%
%  \part{\appendixname}%
  \beamer@appendixwrite%
  \beamer@resetappendix%
  }%
}

%% 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}} )}{
            %% page number on main frames
            \hfill\footnotesize
              \ifbeamer@inappendix%
                \insertmainframenumber/\insertmainframenumber~
              \else%
                \insertframenumber/\insertmainframenumber~
              \fi%
            \vskip3mm
        }{}
    \end{beamercolorbox}%
}
\makeatother

%% new commands to be substituted with \section, \subsection, etc. 
\newcommand{\extrasection}[1]{
    \def\insertextrasection{#1}
}
\newcommand{\extrasubsection}[1]{
    \def\insertextrasubsection{#1}
}

\apptocmd{\appendix}{
    % substitute sections, subsections
    \renewcommand{\section}{\extrasection}
    \renewcommand{\subsection}{\extrasubsection}
    \renewcommand{\insertsection}{\insertextrasection}
    \renewcommand{\insertsubsection}{\insertextrasubsection}
}{}{}

\begin{document}
    
    %% Title page
    \section*{Title}
    \begin{frame}[noframenumbering]
        \titlepage
    \end{frame}

    %% TOC
    \section*{TOC}
    \begin{frame}[noframenumbering]
        \frametitle{Table of Contents}
        \tableofcontents[
                    currentsection, 
                    sectionstyle=show, 
                    subsectionstyle=hide,
        ]
    \end{frame}

    %% A random frame
    \section{Section 1}
    \subsection{The subsection title, usually describing a specific slide}
    \begin{frame}{\insertsection}{\insertsubsection}
        %% frame body
        Some very interesting text here
    \end{frame}

    %% A random frame
    \section{Section 2}
    \subsection{The subsection title, usually describing a specific slide}
    \begin{frame}{\insertsection}{\insertsubsection}
        %% frame body
        Some very interesting text here
    \end{frame}
    
    \appendix
        
        %% A random frame, copy/pasted from the rest of the document
        \section{Section 3}
        \subsection{The subsection title, usually describing a specific slide}
        \begin{frame}{\insertsection}{\insertsubsection}
            %% frame body
            Some very interesting text here
        \end{frame}


\end{document}
6
  • @YohannO. See my updated answer Dec 7, 2022 at 19:54
  • That's a pretty neat answer, thanks! The parts about modifying the appendix and using \ifbeamer@inappendix are a bit beyond my current mastery of LaTeX, but it eliminates the need for a new environment and Extra section. I'll wait until tomorrow and if no one has anything to add, I'll accept this answer.
    – Yohann O.
    Dec 7, 2022 at 19:58
  • @YohannO. You're welcome! Dec 7, 2022 at 20:07
  • I noticed a small detail: if I use this solution and completely remove the Extra environment and associated section from the my document, then the appendix falls within the Thanks section, and page numbers are not displayed. I corrected this behavior by moving the \ifbeamer@inappendix to the "else" part of \ifboolexpr in the footline definition.
    – Yohann O.
    Dec 7, 2022 at 20:32
  • Personally I wouldn't use this conditional in the footline. Instead you could use a different (empty) footline template for these special frames, see e.g. topanswers.xyz/tex?q=1004#a1198 for an example. This has the advantage that you don't check for hard coded section names and it would still work if e.g. you rename the toc to outline.. Dec 7, 2022 at 21:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .