合并多个文档

合并多个文档

我已经搜索过并且无法弄清楚如何以其他方式做到这一点,所以我在这里询问,看看你们是否有什么想法。

基本上,我试图合并单独的 LaTeX 文件,但有些复杂情况似乎让subfiles和这样的软件包感到沮丧standalone。我正在处理的文件本质上是一份主协议和几份附录。生成后,我希望有一个包含所有内容的单个 PDF。问题如下:

  • 主文件和每个附录都引用单个样式表,因此每个附录都可以独立生成。
  • 样式表中设置了几个重要的变量(日期、名称、价格等),这些变量需要在每个文档中正确包含。
  • 我需要每个文档的页脚来引用文档的版本,并包含“第 X 页,共 Y 页”,其中页数与每个文档相关,而不是与整个文件相关。
  • 每个文档的章节编号都需要从 1 开始(我知道这很容易实现)。

我能够让它工作的唯一方法是独立生成每个文档,然后让最终编译器将它们链接在一起。这不是理想的,因为我真的希望能够调用一次 latex,然后收获单个最终 PDF,希望它尽可能小。我们正在使用 wallpaper 包来包含信头 - 多个文件粘在一起似乎会导致文件大小增加得比文本增加得多。

以下是我所指的实际示例。我已将其精简到基本内容,但希望我已提供足够的细节:

主协议.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}

附录-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}

协议.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}
%

编译文档.tex

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

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

相关内容