0

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}
\section{Section Head}
\lipsum[4]
\subsection{Subsection Head}
\lipsum[5]
\subsection{Subsection Head}
\lipsum[6]

\section{Section Head}
\subsection{Subsection Head}
\lipsum[7]

\subsection{Subsection Head}
\lipsum[8]

\section{Section Head}
\lipsum[4]
\subsection{Subsection Head}
\lipsum[5]
\subsection{Subsection Head}
\lipsum[6]

\section{Section Head}
\subsection{Subsection Head}
\lipsum[7]

\subsection{Subsection Head}
\lipsum[8]

\end{multicols}

\end{document}

Addendum-1.tex

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

\newcommand{\DocumentDescription} {Addendum 1}

\begin{document}

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

\section{Section Head}
\lipsum[4]
\subsection{Subsection Head}
\lipsum[5]
\subsection{Subsection Head}
\lipsum[6]

\section{Section Head}
\subsection{Subsection Head}
\lipsum[7]

\subsection{Subsection Head}
\lipsum[8]

\section{Section Head}
\lipsum[4]
\subsection{Subsection Head}
\lipsum[5]
\subsection{Subsection Head}
\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
\renewcommand{\headrulewidth}{0pt} % remove the header rule
\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}
\includepdf[pages={-}]{Addendum-1.pdf}
\end{document}
  • This seems to be a duplicate really and I'd repeat the comment that I made on earlier versions: – David Carlisle Feb 12 '15 at 19:43
  • @David Carlisle, I did see your comment when looking. However it doesn't seem to apply to what I'm doing. First of all, unlike the thesis in the other example, I'm intending on regenerating this (with multiple addenda that are optional each time) many times a week - with different values for the input vars each time. Also, we need to track the specific versions of the addenda that are used, to ensure that the proper ones have been executed. Finally, there are no cross-refs between the addenda, so accounting for that is not important. – crc32 Feb 12 '15 at 19:48
  • 1
    @crc32 yes well it's a bit different and slightly more reasonable in your case to use separate documents, but if so the logical conclusion is to just run latex separately and use pdftools to concatenate the pdf. – David Carlisle Feb 12 '15 at 19:52
  • @David Carlisle, well, if that's the answer, then it'll have to do. I was just hoping I could do it all in Tex, but I'm building the preliminary files with Perl, so I can just have that trigger everything. – crc32 Feb 12 '15 at 22:46

Your Answer

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

Browse other questions tagged or ask your own question.