Produce multiple pdfs in LaTeX with automated cross-references

For some time I looked for a way to simplify the process of linking LaTeX files of my manuscripts with the replies to editors and referees. In particular, I was looking for a way to automatically update cross-references (i.e. to put a \ref in the replies and link it to a \label in the mansuctipt – for example for a table), and also to put direct quotes of the from the main text into a report (e.g. if you want to tell the editor/referee if you have a specific sentence, paragraph or even table added to the revised manuscript).

There are two issues involved here: first, to get cross-references between the separate paper and reply files right, you need to compile all documents in one go. Second, we will need to find a way to split the output in different output pdf files (paper, reply to editor, reply to referee 1/2/3). In the following, I will describe one way to do these two steps. You can find a simple example of the code on our GitHub repo.

The basic idea

The basic idea is that all files (paper, several replies to editor and referees) are compiled together so that cross-references work (with \label{} and \ref{}). To achieve this, we simply save the code for the separate files in separate files, excluding the header. These files will be included with \include in a main file

\documentclass[11pt,fleqn]{article}
% Load hyperref
\usepackage{hyperref}

\begin{document}
\include{text_paper}
\include{text_ed}
\include{text_r1}
\end{document}

With this code, the pdf output will contain all three files (paper, editor, referee 1) in one document. Cross-references in replies to editor and referee, e.g. to a Table or Section will be correctly shown and, importantly, updated if the numbering changes.

How can we make direct quotes between the documents?

If we want to copy a part of the text (a new sentence, a new paragraph or a new table) into the reply to editor/referee, we can make use of the use package clipboard. This allows us simple copy and paste that automatically updates when text is changed. We first must load the package with

\usepackage{clipboard}

and can then specify the text that is supposed to be copied (e.g. in the manuscript) by typing

\Copy{MyKey}{Hello, here is some text without a meaning. This text should show what a printed text will look like at this place.}

You can refer to this text anywhere in the linked files that are included in the main .tex file by typing

\Paste{MyKey}

That’s it!

Splitting up PDFs

Now, the other question is how to split up the pdf output into separate files for (1) revised manuscript, (2) reply to editor, and (3) reply to referees. One way is to simply split up the resulting pdf file with a web-based solution (e.g. this one), your pdf viewer (eg with preview on OS X or with the full version of Acrobat).

An alternative way is to use the command \includeonly. This is not perfect either, but works ok. Basically you first need to compile the whole document with all inlcude-files. Then, one by one, you need to specify

\includeonly{text_paper}

then

\includeonly{text_ed}

and finally

\includeonly{text_r1}

In between, you need to save the files with a new name. These will only contain the respective output AND working cross references and quotes.

There might be other, more sophisticated ways. If you have any ideas to improve the code, just drop a line in the comments section.

Leave a Reply