Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
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 ({}). –  Claudio Fiandrino Oct 21 '12 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 '12 at 9:54
add comment

2 Answers

up vote 3 down vote accepted

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.

share|improve this answer
    
Thank you, works like a charm. –  Mathusalem Oct 21 '12 at 20:48
add comment

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
share|improve this answer
    
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 '12 at 20:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.