# Appendixify: Move selected slides to appendix in Beamer

When working with Beamer I often have slides that I initially write in the body of the presentation, then decide they should be consigned to an appendix. This is also useful when reapplying slides from a long talk to a briefer occasion. Effectively, though, this results in an appendix whose sections parallel the body of the talk.

Cutting and pasting a slide from the body TeX loses the cohesion of the sections there. It would be nicer to be able to mark some slides as appendix slides, and let a macro rebuild the section structure in the appendix to parallel.

Thus:

\documentclass{beamer}
\usepackage{appendixify}
\begin{document}

\section{Hello world}
\begin{frame}{1}\end{frame}
\appendixify{\begin{frame}{2}\end{frame}}
\begin{frame}{3}\end{frame}

\section{Farewell world}
\appendixify{\begin{frame}{4}\end{frame}}
\begin{frame}{5}\end{frame}

\appendix
\appendixified
\end{document}


should render as if it were:

\documentclass{beamer}
\begin{document}

\section{Hello world}
\begin{frame}{1}\end{frame}
\begin{frame}{3}\end{frame}

\section{Farewell world}
\begin{frame}{5}\end{frame}

\appendix

\section{Hello world}
\begin{frame}{2}\end{frame}

\section{Farewell world}
\begin{frame}{4}\end{frame}

\end{document}


Ideally, this macro might also generate navigation widgets to flip from a section to the corresponding appendix section, and back again; or flag that there is one or more appendix slide following a particular body slide by providing a link to them, thus allowing the presenter to optionally detour via the appendix deck. (Obviously there will be some side-effects like macro references will reflect the state at the time of appendix, not the place of insertion.)

I have attempted to implement a macro to write marked content to an auxiliary file -- or to keep them in memory -- then reproduce them in the appendix (not worrying about reproducing the document structure). But - alas! - I am defeated, and would love to see someone else contribute this feature, or give me the building blocks to do so myself. (The chief building block I am missing is writing content verbatim to a file.)

• I might actually find what I need here: tex.stackexchange.com/questions/20957/… Jun 29 '15 at 14:22
• I think you still have problem with sections, i have an idea of partial solution that could help, i'll post it later. Jun 29 '15 at 16:06

The beamersubframe package provides a convenient way to move frames to the backup without moving the actual code around:

\documentclass{beamer}

\usepackage[append]{beamersubframe}

\begin{document}

\begin{frame}
abc
\end{frame}

\begin{subframe}
moved to appendix
\end{subframe}

\begin{frame}
abc
\end{frame}

\appendix

\appendsubframes
\end{document}


For section navigation etc. the one from the parent section will be shown on the "appendixified" frames.

For detailed information on creating convenient navigation to and from the appended frames, please see the package documentation.

• +1 This package also replicates the section structure as wished in the question. May 8 '18 at 14:01
• @dexteritas Oh really! That is even better than I thought. Do you know what needs to be changed to replicate the section structure? May 8 '18 at 14:09
• There's nothing to do. I just added a beamer theme, that shows the current section in the header to test it. May 8 '18 at 14:15
• @dexteritas Ah, yes. It uses the section navigation etc. from the parent section. I'll add a note to the answer. May 8 '18 at 14:20

Here is my solution. Probably not good, but it works for me.

% Moving slides to appendix
% Define a variable to store everything to move
\newcommand{\backupSlides}{}
% Define command to append text to backup variable
\newcommand{\backup}[1]{
\expandafter\def\expandafter\backupSlides\expandafter{\backupSlides#1}
}


To appendixify a frame simply put it into a backup command:

\backup{
\begin{frame}...\end{frame}
}


\backupSlides

• It's a useful start, but does not attempt to replicate the section structure as sought. Nov 21 '15 at 21:34
• \backupSlides does not produce anything... Apr 30 '17 at 20:43

Here is a first attempt that seems to provide section cloning and moving to the appendix (although I changed the macro names to be a little more self-documenting). But I'm very unfamiliar with TeX macro hacking, and I'd like some suggestions to make it more idiomatic, safe, and functionality-complete.

Update: this seems to create all sorts of rendering errors for me, not least that any \hlines have disappeared from my appendix tabulars, so really I would love to see a real TeX/Beamer hacker rewrite it.

\documentclass{beamer}

\usepackage{verbatim}
\makeatletter
\newwrite\appendix@out

\newcommand\toappendix{\obeylines\expandafter\toappendixArg\noexpand}

\newcommand\toappendixArg{
\begingroup
\@bsphack%
\let\do\@makeother\dospecials%
\catcode\^^M\active%
\def\verbatim@processline{%
\immediate\write\appendix@out{\the\verbatim@line}}%
\verbatim@start}

\def\endtoappendix{\endgroup}
\let\oldAppendix\appendix
\def\appendix{\immediate\closeout\appendix@out\@esphack\oldAppendix}
\let\oldSection\section
\renewcommand\section[1]{%
\immediate\write\appendix@out{\unexpanded{\oldSection{#1}}}\oldSection{#1}}
\let\oldSubsection\subsection
\renewcommand\subsection[1]{%
\immediate\write\appendix@out{\unexpanded{\oldSubsection{#1}}}\oldSubsection{#1}}

\makeatother

\begin{document}

\section{Hello world}
\begin{frame}{1}\end{frame}

\begin{toappendix}
\begin{frame}{2}\end{frame}
\end{toappendix}
\begin{frame}{3}\end{frame}

\section{Farewell world}
\begin{toappendix}
\begin{frame}{4}\end{frame}
\end{toappendix}
\begin{frame}{5}\end{frame}

\appendix
\makeappendix

\end{document}

• You need to remember all counters then. I was thinking if frame-2 could be compiled as usual and be \includepdfed later. Jun 30 '15 at 2:18
• Could you give me a sense of when it will be a practical issue that I've not remembered all counters? Jun 30 '15 at 2:21
• Won't includepdf make other issues with slide counters? We still want this to act like an appendix... Also, there seem to be other problems with this approach: my \hlines are not showing up, for one thing. Jun 30 '15 at 2:23
• Your approach is canonical and it should always work. By counters I mean equation-numbering or figures or so. The problem with \includepdf is that one cannot simply include (part of) itself. Jun 30 '15 at 2:27
• Well, even if it should always work it doesn't seem to work. It's making a mess of sections in the body and the appendix... Jun 30 '15 at 2:32

Here is an idea

\documentclass{beamer}

\newwrite\mtwrite
\immediate\openout\mtwrite=app\jobname

\newif\ifsec
\newif\ifsubsec

% this is not the best way to redefine (sub)section \command
\let\mtsection\section
\renewcommand{\section}[1]{%
\mtsection{#1}%
\def\mtsec{#1}%
\sectrue\subsecfalse}

\let\mtsubsection\subsection
\renewcommand{\subsection}[1]{%
\mtsubsection{#1}%
\def\mtsubsec{#1}%
\subsectrue}

\makeatletter
\newcommand{\appendixify}[1]{%
\ifsec
\immediate\write\mtwrite{\string\section{\mtsec}}
\secfalse\fi%
\ifsubsec
\immediate\write\mtwrite{\string\subsection{\mtsubsec}}
\subsecfalse\fi%
\immediate\write\mtwrite{\unexpanded{#1}}}
\makeatother

\begin{document}

\begin{frame}
\tableofcontents
\end{frame}

\section{Hello world}
\subsection{and hellow}

\begin{frame}{1}\end{frame}
\begin{frame}{2}\end{frame}

\section{Farewell world}

\appendixify{\begin{frame}{3}\end{frame}}
\begin{frame}{4}\end{frame}

\subsection{and world}

\appendixify{\begin{frame}{5}\end{frame}}
\begin{frame}{6}\end{frame}

\section{Last  word}
\subsection{and last}

\appendixify{\begin{frame}{7}\end{frame}}

\subsection{and last end}

\begin{frame}{8}\end{frame}
\begin{frame}{9}\end{frame}

\immediate\closeout\mtwrite
\let\section\mtsection
\let\subsection\mtsubsection
\input{app\jobname}
\end{document}


it would be better if one save the contents into a toks or a macro rather than write to external file.

• Great! It works for cases mine breaks on. However, it seems to be incompatible with frame macros like \newcommand{\stopcenter}{\end{center}} \newenvironment{centerframe}[1]{% \begin{frame}[environment=centerframe] \frametitle{#1} \begin{center} }{\stopcenter \end{frame} }. Any idea why these can't be appendixified, e.g. \appendixify{\begin{centerframe}{title}Contents\end{centerframe}} Jul 3 '15 at 4:14
• the problem is that centerframe doesn't work even in normal mode (without appendixify). You can redefine it like this \newenvironment{centerframe}[1]{% \begin{frame}[environment=centerframe] \frametitle{#1}\center}{\endcenter\end{frame}}` Jul 3 '15 at 6:01