0

I'm preparing a latex document using the input command. There's a separate file for the appendix called appendix.tex. I wish to add references to theorems in the appendix in the main paper, but I don't want to have the appendix in the final compiled pdf. Is there a way to achieve this (without manually cropping pages from the final pdf)?

To elaborate further: Right now, if I don't include \input{appendix}, I get a lot of ?? (broken references) in my pdf. I wish to replace the ?? with the right theorem numbers without including the appendix.

  • 1
    Well, is it very useful to have references to theorems etc. that can't be looked after then, because you omitted the appendix? – user31729 Aug 2 '17 at 19:23
  • Presumably a journal editor has requested that the body of the paper be submitted separately from an online appendix. – pnj Oct 22 '17 at 11:05
1

Please post a MWE next time.


You can do it with a little trick:

Run your appendix.tex via \input{appendix.tex} in an external document. Then use the xr-hyper package to include the external document with \externaldocument{extfile}. Make sure you run the extfile.tex on its own minimum once.

You will have a three file MWE:

Main document

\documentclass{article} 
\usepackage{xr-hyper}
\usepackage{hyperref} 

\externaldocument{extfile} 

\begin{document}
\autoref{sec:external}

\autoref{sec:local}

\section{Local section}\label{sec:local}
% \input{appendix}
\end{document}

External Document

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\input{appendix.tex}
\end{document} 

Appendix

\section{Appendix}
\label{sec:external}
1

First, I agree with Christian Hupfer. I would be annoyed reading such a document. Second, providing the appendix as an additional PDF may be a good idea, but it's a bit more complicated then goofynos answer suggests, if the page numbers should be continous across both files. And if there are cross references from the appendix to the main part, it get's even more complicated.

But if you really want a PDF file with cross references going nowhere, there are two ways to achieve this. For both you need to compile your PDF with the appendix attached first to get all references right. Then, after some changes to the main file, you need to compile the file one more time to get rid of the appendix.

Solution 1, with \include:

Here you need to add \includeonly{<files>} to the preamble for the last run. <files> is a comma seperated list of all included files with the exception of those for the appendix.

Note that \include always starts a new page.

\documentclass[a4paper]{article}
\usepackage{lipsum}

% uncomment for last run
% comma seperated list of all files except those for appendix
%\includeonly{main}

\begin{document}
\include{main}

\appendix
\include{appendix}

\end{document}

Solution 2, with \input:

Here you need to comment out the files for the appendix and add \nofiles to the preamble. The latter prevents LaTeX from writing auxiliary files, so the informations about the \labels there are not overwritten.

Note: \input does not start a new page.

\documentclass[a4paper]{article}
\usepackage{lipsum}

% uncomment for last run
%\nofiles

\begin{document}
\input{main}

\appendix
% comment out for last run
\input{appendix}

\end{document}

For completeness, main.tex:

\section{Main text}
\lipsum[1]

Reference to appendix: \ref{lia}

\lipsum[2]

and appendix.tex:

\section{Stuff}
\label{lia}
\lipsum[3]

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.