# How to merge odd and even pages together in a PDF with LaTeX

Submitted by Nicola Rainiero on 2015-06-14

A short post to describe my last LaTeX creation: a template file that allows to merge odd and even pages together, considering also the case of the reversed even pages. As usual there is a little edit area that make the process very fast, without requiring any knowledge of LaTeX and if you have a subscription in an online editor like Overleaf you can execute it in your internet browser.

Recently I have bought a multifunction printer that doesn't support the duplex scanning in the automatic document feeder and so I can only scan a single side of a sheet of paper at a time. At the end I have two PDF files that I will have to merge into one.

The first file contains the odd pages and the second one the reversed even pages (or ordered if I arrange again the order before to give them in the scanner, but I hate doing this). As usual there are many software that can help the merging process (look my article Free software to edit PDF for example) but I decided to use LaTeX in this case because I like complicate things for myself!

## Requirements

• Out of the box with Overleaf1, but a registration is needed in order to upload the PDF files and to edit my template.
• If you want to use it in your computer: LaTeX, an editor and the following packages: mathptmx, moresize, comment, ifthen, and pdfpages (almost standard in a typical LaTeX installation).

## How it works

The entire process can be summarized with the two infographics below and the following piece of code that you have to edit in order to get the final merged PDF.

• reversed{1}

• reversed{0}
% <---------------------- EDIT THIS AREA ONLY ----------------------------->

%%
%% Define the file names and the dimension of your PDF
%% Put the size in mm
%% The typical size of an A4 document is 210x297 mm
%%
\newcommand\units{mm}			% <--- set the units (default mm)
\newcommand\fileOdd{odd.pdf}		% <--- the PDF that contains odd pages
\newcommand\fileEven{even_rev.pdf}	% <--- the PDF that contains even pages
\newcommand\width{210} 			% <--- the width size in mm of your PDF
\newcommand\height{297} 		% <--- the height size in mm of your PDF
%%
%% 			Are reversed the even pages?
\newcommand\reversed{1} 	% <--- "1" YES, "0" NO
%%
%% 			How many pages do you want to process?
\newcommand\numberPages{3} 	% <--- the numbers of pages to process
%%
% <---------------------- EDIT THIS AREA ONLY  ----------------------------->

Editing the area above, you control all the process to merge your two input PDF files.

• 1. Overleaf is the new collaborative writing and publishing system developed by the team behind the popular writeLaTeX editor. Overleaf is designed to make the whole process of writing, editing and producing scientific papers much quicker for both authors and publishers. Overleaf: Real-time Collaborative Writing and Publishing Tools with Integrated PDF Preview. Here is my sign up link to Overleaf.

## Related Content:

### Nicola Rainiero

A civil geotechnical engineer with the ambition to facilitate own work with free software for a knowledge and collective sharing. Also, I deal with green energy and in particular shallow geothermal energy. I have always been involved in web design and 3D modelling.