2016-09-05 Many variants of a Beamer presentation – part I

Some time ago I decided to prepare slides for a certain lecture using Beamer. I thought it would be nice to have a few versions of the slides. For starters, I wanted to prepare lecture notes for the students. Also, I wanted to check how the “notes” feature works (spoiler: it works nice, though it does not play extremely well with hyperref).

I encountered one irritating problem, though. Of course, I did not want to change the settings in my TeX file all the time to produce various variants. The Beamer manual recommends keeping the document body in a separate file, and including it in a few “driver” files – one for lecture notes, one for slides with notes, one for slides without notes etc. This works fine, with one exception: AUCTeX’s “partial compilation” feature (i.e., the TeX-command-region command, usually bound to C-c C-r) does not work.

Here’s the thing. Assume we have the following three files, presentation-slides.tex, presentation-preamble.tex and presentation-body.tex. (For the sake of simplicity, I omit the “slides with notes” and “lecture notes” features now – it’s not difficult to imagine what presentation-slides-with-notes.tex might look like, and I will show a working example in a minute.)

% presentation-slides.tex
\documentclass{beamer}

\input{presentation-preamble}
\input{presentation-body}
% presentation-preamble.tex

\author{Anthony U.~Thor}
\title{Example slides}
% presentation-body.tex
\begin{document}

\begin{frame}
  \titlepage
\end{frame}

\section{Introduction}
\begin{frame}
  \frametitle{Introductory slide}
  [contents]
\end{frame}

\section{First real section}
\begin{frame}
  \frametitle{First real slide}
  [content]
\end{frame}
\end{document}

% Local Variables:
% TeX-master: "presentation-slides.tex"
% End:

The only thing you might find strange is the Local Variables: part of the presentation-body.tex file. This is Emacs-specific way of saying that compiling this file in AUCTeX (Emacs’ advanced LaTeX mode) should launch pdflatex presentation-slides.tex and not pdflatex presentation-body.tex (which wouldn’t make sense).

Now that’s all fine, and it even works, and – as I said – it can be easily expanded to incorporate more than one variant (which is the ultimate goal of this whole exercise). The main problem is that C-c C-r-ing on a region in presentation-body.tex doesn’t work. And that sucks, since my presentation has more than 400 slides, is still growing and takes almost 20 seconds to compile. So, I was quite determined to find a solution.

And so I did.

The reason the above version won’t work is that the “current” file (in this case, the presentation-body.tex file) does not contain a proper preamble, with \documentclass and \begin{document} and \end{document}. Of course, you can’t \include such a file in LaTeX – or can you?

Surprise! There exists a package called docmute whose sole purpose is to enable this. (The documentation mentiones a few alternatives with a larger feature set, but I didn’t need any of those in my use-case.) With it, I can write the following files.

% presentation-slides.tex
\documentclass{beamer}
\setbeameroption{show notes}

\input{presentation-preamble}

\begin{document}
\begin{frame}
  \titlepage
\end{frame}

\section{Introduction}
\begin{frame}
  \frametitle{Introductory slide}
  [contents]
  \note{Note to self: remember to introduce yourself}
\end{frame}

\section{First real section}
\begin{frame}
  \frametitle{First real slide}
  [content]
\end{frame}
\end{document}
% presentation-preamble.tex

\author{Anthony U.~Thor}
\title{Example slides}

% Local Variables:
% TeX-master: "presentation-slides.tex"
% End:
% presentation-slides-without-notes.tex
\documentclass{beamer}

\usepackage{docmute}
\input{presentation-preamble}

\begin{document}
\input{presentation-slides}
\end{document}

And voilà – that’s it! I can now compile either presentation-slides.tex, or presentation-slides-without-notes.tex, and also I can easily partially compile presentation-slides.tex with C-c C-r in AUCTeX. How cool is that?

In another post, I will show a more advanced setup, which allows compiling lecture notes from the same source, too. But it’s enough for now. Happy TeXing!

Note: 2016-10-03 Many variants of a Beamer presentation – part II

CategoryEnglish, CategoryBlog, CategoryTeX, CategoryLaTeX, CategoryBeamer