# Appending a full version of a document

I have a document written in tex, although it is a shorter version of a larger document. For example, my short document is 10 pages, and once I elaborate on some parts in the shorter document, it will become 15 pages. I would like to create a new document which is essentially 25 pages long, the first 10 pages of which is the short document and the last 15 pages of which is the long version (placed in an appendix). The content of the 15 page part would repeat a lot of content from the first 10 pages.

I have two questions.

1. Is it possible to compile the short version and the long version together in one tex file (i.e., so the content of the entire 25 page document lies in the same tex file)? The only way I know of would involve a lot of work regarding changing label names/references, equations, etc.

2. I guess there is a way to concatenate the short version together with the long version as two separate pdf files (one 10 pages and the other 15 pages), even though I prefer not to do this. Is pdfpages the best way to do this? What if I want the appendix part to begin in the middle of a page at the end of my short document (and not on a new blank page)?

Here is an example. This will result in warnings though, which I want to avoid, and I would have to change the labels individually to fix these warnings (not only are there warnings, but right now both equation references refer to the second equation in the appendix):

\begin{document}

\section{main}

My equation:
$$\label{eqn:addition} 1 + 1$$

\appendix

\section{main}

My equation with some elaboration:
$$\label{eqn:addition} 1 + 1$$

\end{document}

• Welcome to TeX.SE. I would recommended you put it all in one file and use one of the methods for Conditional typesetting / build to select which version to generate. – Peter Grill Oct 23 '14 at 20:45
• Thank you for your reply. I'm not sure I understand what you're suggesting. I only want one version generated all the time. I want a 25 page version, the first 10 pages of which are a short document and the second 15 pages of which are the 10 pages with some elaboration. – Rebbig Oct 23 '14 at 20:57
• Seems as if I am missing something. If you no longer want to be able to generate the short 10 page document, then what is the problem with just adding to the existing document? I suggest that you compose a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. This will go a long way to clarifying any issues. – Peter Grill Oct 23 '14 at 21:02
• This appears to be similar to tex.stackexchange.com/questions/207714/… at least in terms of duplicate labels. – John Kormylo Oct 23 '14 at 21:14
• @JohnKormylo Except that in this case (I think) the OP wants separate labels for the two bits whereas in that question, the OP wanted the labels only defined for one bit even though the second bit's code was identical to the first bit's? So the duplicate-labels bit is similar but how the questioner wants to de-duplicate is different? – cfr Oct 23 '14 at 21:25

If I understand the problem, you are worried about the warnings/errors regarding labels.

LaTeX Warning: Label eqn:addition' multiply defined.

One way to avoid that is to redefine \label and \ref just before your new content with something like:

\let\OrigLabel\label
\let\OrigRef\ref
\renewcommand{\label}[1]{\OrigLabel{NEW##1}}%
\renewcommand{\ref}[1]{\OrigRef{NEW:##1}}%


which automatically changes the any new uses of \label and \ref to refer to the new content. That is any use of \label{foo} and \ref{foo} after the \renewcommands is treated as if you had typed \label{foo-new} and \ref{foo-new}.

Furthermore, with amsmath we also need to redefine \label@in@display as per How to redefine \label command in align environment.

## Code:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newcommand*{\StartNewContent}{%
\let\OrigLabel\label%
\let\OrigRef\ref%
\renewcommand{\label}[1]{\OrigLabel{NEW##1}}%
\renewcommand{\ref}[1]{\OrigRef{NEW:##1}}%
\renewcommand{\label@in@display}[1]{%
\ifx\df@label\@empty\else
\@amsmath@err{Multiple \string\label's:
label '\df@label' will be lost}\@eha
\fi
\gdef\df@label{NEW:##1}%
}%
}
\makeatother

\begin{document}

\section{main}

My equation:
$$\label{eqn:addition} 1 + 1$$

\appendix

\section{main}
\StartNewContent

My equation with some elaboration:
$$\label{eqn:addition} 1 + 1$$

• @Rebbig: Have added a brief explanation. I would recommend you NOT restart the numbering of the equations in the appendix as this can be confusing, unless you are adding a prefix (ie., Equation A-1). If you really want to restart the equation numbering you can use \setcounter{equation}{0}. Seems as if hyperef is fine with this and the links are correct. – Peter Grill Oct 23 '14 at 22:47
• @Rebbig: If you are asking about using a prefix other than -new for different types of labels, you could parse the value of #1 in the \renewcommand` and adjust the prefix based on that, but not sure why that is any better? If you are referring to how the equations are displayed that is a totally different question (and most likely already has been asked and answered on TeX.SE). – Peter Grill Oct 23 '14 at 23:02