# [texhax] Multiple documents within a document.

Stephen Hicks sdh33 at cornell.edu
Wed Mar 31 04:00:28 CEST 2010

I dunno if there's something already out there for you to use, but I
can imagine the basic algorithm you want is as follows:

1. Load both documents into separate vboxes (i.e. galleys)
\setbox\left at box\vbox\bgroup\input left\egroup
\setbox\right at box\vbox\bgroup\input right\egroup
This might lead to difficulties if anything in the documents have,
say, \eject or anything else weird re: page handling, or it might just
work if the whatsits behave well inside boxes.

2. Alternately \vsplit off \textheight from each box and \unvbox it
into the current page, followed by a \clearpage.

I'm not sure if there's a maximum box size in TeX, but as long as you
don't run into that problem, this will get the job done:

\makeatletter
\newbox\left at box
\newbox\right at box
\newenvironment{leftpage}{\global\setbox\left at box\vbox\bgroup}{\egroup}
\newenvironment{rightpage}{\global\setbox\right at box\vbox\bgroup}{\egroup}
\def\alternate{\cleardoublepage\let\@next\@alternate
\ifdim\ht\left at box=\z@\ifdim\ht\right at box=\z@\let\@next\relax\fi\fi
\@next}
\def\@unvsplit#1{\ifdim\ht#1=\z@\vbox{}\else
\setbox\z@\vsplit#1 to\textheight\unvbox\z@\fi}
\def\@alternate{\@unvsplit\left at box\eject\@unvsplit\right at box\eject\alternate}
\makeatother

You can use it with

\begin{leftpage}
\input left
\end{leftpage}
\begin{rightpage}
\input right
\end{rightpage}
\alternate

Cheers,
steve

On Tue, Mar 30, 2010 at 5:52 PM, Ramamoorthi Bhaskar
> For a few pages (about 20, all told) I would like one piece of text to
> appear on even pages, and another to appear on odd pages.  One of the
> documents has linenumbers which are referred to with the \linelabel command
> in the facing page document.
> The two pieces of text are not the same length so one of them would spill
> over, and in that case I want to both (a) reserve the option of having it
> just spillover like a regular document and (b) arrange for a series of blank
> pages on one side till the longer document is completely printed.
> I though some version of columns or minipages would work, but what I'm able
> to imagine seems unwieldy/unworkable.
> Will really appreciate any ideas.
> Thanks.
>
> 106 Larchwood Drive
> Cambridge, MA 02138
> 617-501-2110
>
>
> _______________________________________________
> TeX FAQ: http://www.tex.ac.uk/faq
> Mailing list archives: http://tug.org/pipermail/texhax/