knitr: automate producing multiple versions of PDF for beamer slides

172 views Asked by At

For lectures, I am using knitr to produce LaTeX beamer slides as a PDF. For a given lecture, I want to produce also (a) 1-up handout (using the handout option, and (b) the same handout formatted 4-up.

I find I have to run knitr 3 times to do this as shown below. Is there a way to simplify this work flow?

A lecture stub:

\documentclass[10pt,table]{beamer} 

\input{inputs/beamer-setup}
\input{inputs/defs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
 ...
\end{document}

And I run knitr as

knit2pdf("Lecture1.Rnw")

To get the 1-up handout (which suppresses the separate pages when you use transitions), I edit the first line to:

\documentclass[10pt,table,handout]{beamer} 

and run

knit2pdf("Lecture1.Rnw" output="Lecture1-1up.tex")

Finally, to get the 2 x 2 version, I use the LaTeX pgfpages package,

\documentclass[10pt,table,handout]{beamer} 

\input{inputs/beamer-setup}
\input{inputs/defs}

\usepackage{pgfpages}
\pgfpagesuselayout{4 on 1}[letterpaper,landscape]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

And run:

knit2pdf("Lecture1.Rnw" output="Lecture1-4up.tex")

(I found that with beamer, I could not simply print the PDF 4-up using Adobe Acrobat -- it generated a corrupt PDF file. I was forced to use pgfpages)

Then, of course I have to revert my .Rnw file to the original if I need re-do the slides. Very tedious. There must be a better way.

0

There are 0 answers