# distribute contents of two input-files to left and right pages

Is it possible to import two tex files with \input and to have the content of the one file be always on the left page facing the content of the other file being always on the right? The page numbers should go on continuously 1, 2, 3, 4, ...

(Actually I guess that this is not so easy to be achieved.)

I imagine something like this:

%!TEX TS-program = lualatexmk
\documentclass{scrbook}
\begin{document}

\input[left]{file_A.tex}
\input[right]{file_B.tex}

\end{document}


Both files would just consist of simple data such as

\chapter{Chapter}
Text.
\section{Section}
Text. ...


Nonetheless both files will be long and contain several pages worth of text. In other words, I would have two long files file_A.tex and file_B.tex and latex fills me the left page consecutively with the contents of A and the right pages consecutively with the contents of B.

This being said, I don't mind (and in fact would prefer!) to cut the contents of the two files in page-size chunks by manually using \pagebreak several times at appropriate places within each file.

• I guess you could typeset them both on their own and increment the page counter by 2 on each page, then splice the pdfs together? – Juri Robl Jan 27 '15 at 7:52
• Yes, I thought of this. This is one -- potentially laborious -- way to do it. – ClintEastwood Jan 27 '15 at 7:54
• why not using eledpar? – Maïeul Jan 28 '15 at 16:42
• actually, because I am looking for an alternative to eledmac/eledpar, as I have been unable to overcome my problems with these packages for three years. – ClintEastwood Jan 28 '15 at 19:11
• it's work like explained in this handbook. See this MWE pastebin.fr/38373 – Maïeul Jan 31 '15 at 10:20

You can probably arrange to store each page in a box instead of shipping it out, and then sorting the boxes at the end, something like this:

\documentclass[openany]{scrbook}

\newcount\zzz
\newif\ifdone
\let\zzshipout\shipout
\makeatletter
\def\shipout\vbox#1{%
\edef\x{\noexpand\typeout{page \thepage\space is box \the\zzz}}\x
\global\setbox\zzz\vbox{#1}%
\stepcounter{page}%
}

\begin{document}

\clearpage
\zzz=5001\setcounter{page}{1}
\input{file_A.tex}

\clearpage
\zzz=6001\setcounter{page}{2}
\input{file_B.tex}
\clearpage

\typeout{===========}

\makeatletter
\begingroup
\let \protect \noexpand
\@resetactivechars
\@parboxrestore
\global\c@page=1
\loop
\ifvoid\numexpr5000+\c@page\relax
\ifvoid\numexpr6000+\c@page\relax
\donetrue
\else
\zzshipout\vbox{\hbox{blank A}}%
\zzshipout\box\numexpr6000+\c@page
\fi
\else
\zzshipout\box\numexpr5000+\c@page
\ifvoid\numexpr6000+\c@page\relax
\zzshipout\vbox{\hbox{blank B}}%
\else
\zzshipout\box\numexpr6000+\c@page
\fi
\fi
\ifdone\else