8

I'm currently generating some presentations with beamer for students of my course. Some like to print the material, so I created a handout. Some students prefer to have 2,3,4,6 etc. pages per sheet of A4 paper. How can I go about to automatize the following code, so that it outputs 4 different files in 1x2,1x3,2x2,2x3 format?

I'd like to avoid having to compile it again everytime for the different formats.

\documentclass[a4paper]{article}
\usepackage{pdfpages}

\begin{document}
\includepdf[pages=1-last,nup=1x2,landscape=false,frame=true,
            noautoscale=false,scale=1,delta=0mm 5mm]{Pres7Chap13-Handout.pdf}
\end{document}
2
  • 1
    Welcome to TeX.SX. A tip: If you indent lines by 4 spaces, then they're marked as a code sample. You can also highlight the code and click the "code" button ({}). Oct 21, 2012 at 9:32
  • There is no possibility to get four output files with a single run. But, depending on your operating system, it's possible to automatize the business anyway.
    – egreg
    Oct 21, 2012 at 9:54

2 Answers 2

6

Compile this with pdflatex option --shell-escape:

\documentclass[a4paper]{article}
\usepackage{pdfpages}
\usepackage{filecontents}
%
\begin{filecontents*}{1x2.tex}
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=1-last,nup=1x2,landscape=false,frame=true,
            noautoscale=false,scale=1,delta=0mm 5mm]{template.pdf}
\end{document}
\end{filecontents*}
%
\begin{filecontents*}{1x3.tex}
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=1-last,nup=1x3,landscape=false,frame=true,
            noautoscale=false,scale=1,delta=0mm 5mm]{template.pdf}
\end{document}
\end{filecontents*}
%
\begin{filecontents*}{2x2.tex}
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages=1-last,nup=2x2,landscape=false,frame=true,
            noautoscale=false,scale=1,delta=0mm 5mm]{template.pdf}
\end{document}
\end{filecontents*}
%
\immediate\write18{pdflatex 1x2}
\immediate\write18{pdflatex 1x3}
\immediate\write18{pdflatex 2x2}
%
\begin{document}
\includepdf[pages=1-last,nup=2x3,landscape=false,frame=true,
            noautoscale=false,scale=1,delta=0mm 5mm]{template.pdf}
\end{document}

You will get 3 new .tex files - 1x2.tex, 1x3.tex and 2x2.tex and 4 pdf files correspondingly (3 + 1) in the same folder.

0
4

Let's say that mathusalem-handout.pdf is the file you want to print in N-up format multiple times.

Prepare a mathusalem-print-handouts.tex file that contains

\documentclass{article}
\usepackage{pdfpages}
\begin{document}

\begingroup\edef\x{\endgroup
  \noexpand\includepdf[pages=-,nup=\handoutformat,landscape=false,frame=true,
    noautoscale=false,scale=1,delta=0mm 5mm]{mathusalem-handout.pdf}}\x

\end{document}

and a mathusalem-produce-handouts.tex that contains

\def\ahandout#1{\immediate\write18{pdflatex -jobname=mathusalem-handout-#1 %
  "\def\noexpand\handoutformat{#1}\noexpand\input{mathusalem-print-handouts}"}}

\ahandout{1x2}
\ahandout{1x3}
\ahandout{2x2}
\ahandout{2x3}
\stop

Edit the lines to add or remove formats. Then run the last file through pdflatex with shell escape enabled:

pdflatex -shell-escape mathusalem-produce-handouts

and you'll get the four PDF files

mathusalem-handout-1x2.pdf
mathusalem-handout-1x3.pdf
mathusalem-handout-2x2.pdf
mathusalem-handout-2x3.pdf
1
  • Thank you. There are certain things about expanding I don't understand. This is the good time to get my head around these mysterious Latex things. Works nicely though, thanks.
    – Mathusalem
    Oct 21, 2012 at 20:49

You must log in to answer this question.

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