3

Im new to tex so I'm sorry if this is something is actually easy to do but I cannot find a solution.

I want to print a signature/booklet of my book by printing two separate parts of the sig on one piece of paper. Here's an example with a 16 page signature

   |  Page 1  A side  |  Page 1  B side  |  |  Page 2  A side  |  Page 2  B side  |
   |                  |                  |  |                  |                  |
   |   P        A     |     B       O    |  |   L         E    |   F         K    |
   |                  |                  |  |                  |                  |
   | Page 16  Page 1  |   Page 2 Page 15 |  | Page 12   Page 5 | Page 6   Page 11 |
   |                  |                  |  |                  |                  |
   |   N        C     |    D       M     |  |   J         G    |    H        I    |
   |                  |                  |  |                  |                  |
   | Page 14  Page 3  |  Page 4  Page 13 |  | Page 10   Page 7 |  Page 8   Page 9 |     

I would then cut the pages in half and put the signatures together. Before I discovered TEX I would use a regular word processing program and output the pdfs by specifying the order by hand like this:

16,1,14,3,2,15,4,13,12,5,10,7,6,11,8,9

which is fine when it's something as small as this but figuring out the order and checking for typos for 40+ pages in each of the 8 signatures in a book takes a long time as you can imagine.

What I'm asking is, Is there a way or a package to automatically preform this kind of page ordering when outputting a pdf in TEX?

Many thanks in advance.

Edit: I just wanted to add to add a quick bat code I use to quickly run a pdf through the tex code that Malipivo posted (thanks again!) without having to run each file one by one

ECHO

SET /P UserInput=Please Enter File Name(including path):

copy %UserInput% "c:\path to the tex files folder\Book.pdf"

cd "c:\path to the tex files folder\"

pdflatex order.tex

pdflatex order2.tex

pdflatex order3.tex

pdflatex order4.tex

%This part is optional but it's nice to automatically move the finished file out of the working folder
rename order4.pdf Signature.pdf

move Signature.pdf Signatures\
  • You mention that you have a book - a finished PDF version of a document - already. You can use TeX to arrange this layout in a document via pdfpages, which wouldn't require you to "check for typos for 40+ pages... – Werner May 19 '14 at 17:22
  • Possible duplicate: tex.stackexchange.com/questions/36558/… When using the pdfpages package there is a booklet option or you could use signature=40 (any number which is a multiple of 4 is fine) if that option wouldn't be sufficient for you. – Malipivo May 19 '14 at 18:35
  • @werner Ah I dont have the pdf. Sorry, by book I was referring to my doc. Ill edit the post to prevent further misunderstandings. I already had the document formatted in another program when i discovered TEX I was going to use a converting program like writer2latex. I'll try making a pdf in the other program after reading through the documentation for pdfpages and see how it goes. – SupahHakahDaru May 19 '14 at 18:43
  • @Malipivo Ah thanks for the link! It's similar to what I need but unless I'm misunderstanding, this is only for 2 full pages on each side of the sheet and not the 4 full pages on each side plus the booklet mode. I'll try changing some of the options and see if it'll work though in a bit (I assume [2TOPSIDE] needs to be [4TOPSIDE]) – SupahHakahDaru May 19 '14 at 19:14
  • I also found this question too that might help me a lot while working on this. – SupahHakahDaru May 19 '14 at 19:21
6

When we cannot use one- nor two-step arranging, why not to use an approach with even more steps? I haven't found better way so far, ConTeXt is probably offering solution out-of-box.

I've prepared a series of TeX files:

  • A book with specific number of pages (mal-arrange-0.tex). Let it be 16 pages as in the OP's example. A multiple of 8 should be used. I've tested other pages (20, 21, 22) and rearranging is working but there are empty pages added upto nearest multiple of 8.
  • A basic booklet rearranging of the book (mal-arrange-1.tex). In production we wouldn't use frame parameter.
  • A rotation of even pages by 180 degrees (mal-arrange-2.tex) for further use.
  • The final arrangement of one paper using basic nup=2x2 (mal-arrange-3.tex). This is the version the OP is asking for.
  • Splitting up paper into two pages (Side A, Side B) (mal-arrange-4.tex), if needed.

We can run any major LaTeX engine - I've tested pdflatex, xelatex, and lualatex, e.g.

pdflatex mal-arrange-0.tex  
pdflatex mal-arrange-1.tex  
pdflatex mal-arrange-2.tex  
pdflatex mal-arrange-3.tex  
pdflatex mal-arrange-4.tex  

An alternative. In Linux-like environments we would probably use something like this:

# Getting the PDF files...
echo -n "Step"
engine="pdflatex" # pdflatex, xelatex or lualatex
for number in {0..4}; do
  echo -n " "$number
  $engine mal-arrange-$number.tex 1>/dev/null 2>/dev/null
done

Optional. We can clean up the files in Linux/CygWin by executing the following lines:

# Cleaning up files...
rm mal-arrange-{0..4}.{aux,log}  
rm mal-arrange-{0..3}.pdf  

I enclose the TeX files and a preview of the PDF files. The blue rectangles represent pages.

% any LaTeX engine; mal-arrange-0.tex
\def\numberofpages{16} % to be changed from 16, e.g. 48; 
% any number can be used, there will be empty pages upto a multiple of 8, 
% e.g. when 17 pages is used, you will find 7 empty pages...
\documentclass[a4paper]{article}
\pdfpagewidth=\paperwidth
\pdfpageheight=\paperheight
\pagestyle{empty}
\parindent=0pt
\begin{document}
\font\mfont=cmr10 at 250pt \mfont
\newcount\malc
\malc=0
\loop
  \advance\malc by 1
  \newpage\mbox{}
  \vfil\hfil\thepage
\ifnum\malc<\numberofpages\repeat % e.g. 16 or 48, a multiple of 8 is best
\end{document}

mwe, part 0, the initial part

% any LaTeX engine; mal-arrange-1.tex
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages={-},booklet,landscape,frame]{mal-arrange-0.pdf}%frame to be turned off in production
\end{document}

mwe, part 1

% any LaTeX engine; mal-arrange-2.tex
% there is some shift if xelatex engine is run with letterpaper (?)
\documentclass[a4paper]{article}
\usepackage{ifxetex}
\usepackage{pdfpages}
\def\mfile{mal-arrange-1.pdf}
\ifxetex % xelatex
  \def\mlast{\XeTeXpdfpagecount\mfile}
\else % pdflatex+lualatex
  \pdfximage{\mfile}
  \def\mlast{\pdflastximagepages}
\fi
%\pdfpagewidth=\paperwidth
%\pdfpageheight=\paperheight
\begin{document}
\newcount\mcounter \mcounter=0
\loop
\advance\mcounter by 1
\ifodd\mcounter
  \def\mbonus{0}
\else
  \def\mbonus{180}
\fi % End of \ifodd...
\includepdf[pages={\the\mcounter},angle=\mbonus]{\mfile}
\ifnum\mcounter<\mlast\repeat
\end{document}

mwe, part 2

% any LaTeX engine; mal-arrange-3.tex
\documentclass[a4paper,landscape]{article}
\usepackage{pdfpages}
\pdfpagewidth=\paperwidth % for xelatex
\pdfpageheight=\paperheight % for xelatex
\begin{document}
\includepdf[pages={-},angle=-90,nup=2x2]{mal-arrange-2.pdf}
\end{document}

mwe, part 3

% any LaTeX engine; mal-arrange-4.tex
\documentclass[a4paper]{article}
\usepackage{ifxetex}
\usepackage{pdfpages}
\def\mfile{mal-arrange-3.pdf}
\ifxetex % xelatex
  \def\mlast{\XeTeXpdfpagecount\mfile}
\else % pdflatex+lualatex
  \pdfximage{\mfile}
  \def\mlast{\pdflastximagepages}
\fi
\begin{document}
\newcount\mcounter \mcounter=0
\loop
\advance\mcounter by 1
\includepdf[pages={\the\mcounter},viewport=0 0 {0.5\paperheight} {\paperwidth},clip]{\mfile} % left half
\includepdf[pages={\the\mcounter},viewport={0.5\paperheight} 0 {\paperheight} {\paperwidth},clip]{\mfile} % right half
\ifnum\mcounter<\mlast\repeat
\end{document}

mwe, part 4, the final part

  • 2
    Thank thank thank thANKS A LOT! This solved it perfectly! You have saved me a ton of grief. – SupahHakahDaru May 20 '14 at 21:24
  • 3
    This is really impressive stuff. I wish that I had a need to use it! – cfr Jun 1 '14 at 23:01
3

Use makebook:

https://github.com/dgoodmaniii/makebook

This is a bash script which automates all the process of making a new document to compile your document with pdfpages. It has lots of options: paper size, scaling, offsets (for binding corrections, for example), signature size, and so forth. I'm on my phone, so I can't try it; but off the top of my head, the command you'd need is:

makebook -t octavo -H 2.75in -w 2.125in -i mydoc.pdf

This will output mydoc_sigs.pdf, which will be the original document rearranged on octavo signatures (sixteen pages per sheet, eight per side). This assumes that you designed your pages for this small size; if that's not true, you'll need some different options. It also assumes vertical page orientation.

Disclaimer: I wrote and use makebook, so my opinion on its utility is biased.

1

This is not a solution but it is too long for a comment. The reason I'm posting it is in the hopes that somebody else might be able to turn it into a solution. pdfpages can create the signatures. It can also (with a bit of manual config) put the resulting signature pages on the correct physical pages of the final document. However, every other physical page has its logical signature pages upside down and I can't figure out how to prevent this.

I used this code to compile a 16 page PDF in A6 size. Obviously not what you'll have but just for demonstration purposes it should work. This code is actually irrelevant. I just needed a 16 page PDF to experiment with.

\documentclass[a6paper]{book}
\usepackage{geometry}

\makeatletter
\newcommand{\mypages}{%
  \def\mynos{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}%
  \@for \xx:=\mynos\do{%
    \Huge Page \xx
    \newpage
    }}
\makeatother

\begin{document}

\mypages

\end{document}

I renamed the PDF to mypages.pdf. Then this code:

\documentclass[a5paper]{book}
\usepackage{geometry}
\usepackage{pdfpages}

\begin{document}

\includepdf[pages=-,nup=1x2,landscape,signature=16]{mypages}

\end{document}

produces this output:

Signature pages on A5

So if you planned to print the signatures at this point on A5 (or US equivalent), all would by hunky-dory. I renamed the PDF mypages-sig.pdf.

You can use pdfpages again to get things onto the right bits of physical paper but this takes a bit of manual intervention:

\documentclass[a4paper]{book}
\usepackage{geometry}
\usepackage{pdfpages}

\begin{document}

\includepdf[pages={1,3,2,4,5,7,6,8},nup=1x2,landscape]{mypages-sig}

\end{document}

Not very elegant. Worse still, the result is unfortunately not what you want:

Deformed signatures on A4

If it were possible to create a one-sided signature in the first step which did not try to arrange things for two-sided printing, it might work. But I am not sure whether that's possible. pdfpages rotates the pages as if for two-sided printing regardless, it seems. So the results always end up wrong at the final stage.

The other thing to look at might be pgfpages. This is no good for the first stage which creates the signatures. But maybe for the second stage...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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