# Combining multiple documents

I've searched and have not been able to figure out how to do this any other way, so I'm asking here to see if any of you have any ideas.

Basically, I'm trying to combine separate LaTeX files, but there are complications that seem to frustrate packages like subfiles and standalone. The documents I'm working on are essentially a master-agreement, and several addenda. When generated, I want there to be a single PDF with everything. Here's the problem:

• The Master file and each addendum reference a single style sheet, so that each can be generated independently.
• There are several important variables that are set in the style sheet (dates, names, prices, etc) that need to be included properly in each document.
• I need the footers of each document to reference the document's version, and include "Page X of Y", where the page counts are relative to each document, and NOT to the entirety of the file.
• Each document needs to have the section numbering start at 1 (this is easy to accomplish, I know).

The only way I've been able to get this to work is to generate each document independently, and then have a final compiler link them together. This isn't ideal, as I'd really prefer to be able to call latex one time and then harvest the single final PDF, which hopefully is as small as possible. We're using the wallpaper package to include letterhead - multiple files stuck together seem to cause the file size to increase much more than the text would cause.

Here are working examples of what I mean. I've stripped it down to the essentials, but hopefully I've provided enough detail:

Master-Agreement.tex

\documentclass[letterpaper,10pt]{article}
\usepackage{Agreement} % Include the Contracts style, for all header & other material

\newcommand{\DocumentDescription} {Master Agreement v1.0}

\begin{document}
\huge \noindent Master Agreement \normalsize\par

\lipsum[1-5]

\pagebreak
\begin{multicols}{2}
\lipsum[4]
\lipsum[5]
\lipsum[6]

\lipsum[7]

\lipsum[8]

\lipsum[4]
\lipsum[5]
\lipsum[6]

\lipsum[7]

\lipsum[8]

\end{multicols}

\end{document}


\documentclass[letterpaper,10pt]{article}
\usepackage{Agreement} % Include the Contracts style, for all header & other material

\begin{document}

\huge \noindent First Addendum \normalsize\par
\lipsum[1-4]

\lipsum[4]
\lipsum[5]
\lipsum[6]

\lipsum[7]

\lipsum[8]

\lipsum[4]
\lipsum[5]
\lipsum[6]
\end{document}


Agreement.sty

% Contracts.sty
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{Agreement}[2015/02/11 v1.0 LaTeX package for contracts]
\RequirePackage[top=1.85in,left=0.6in,right=0.6in,bottom=1.25in,includefoot,heightrounded]{geometry}
\RequirePackage{fancyhdr}
\RequirePackage{lipsum}
\RequirePackage{wallpaper}
\RequirePackage{lastpage}
\RequirePackage{multicol}

%% Setup pagenumbers
\fancyhf{} % clear all header and footers
\rfoot{\DocumentDescription\ Page \thepage\ of \pageref{LastPage}}
%
%lfoot{\thepage} % puts it on the left side instead
%
% or if your document is 2 sided, and you want even and odd placement of the number
%\fancyfoot[LE,RO]{\thepage} % Left side on Even pages; Right side on Odd pages
%
\pagestyle{fancy}
%


Compile-Documents.tex

\documentclass[letterpaper,10pt]{article}
\usepackage{pdfpages}

\begin{document}
\includepdf[pages={-}]{Master-Agreement.pdf}