1

I am trying to write a large document, and for the sake of organized editing, it makes sense to have each chapter as a standalone document. I am using the standalone package to accomplish this. I have references in the main document that need to be used in subdocuments, and I am trying to use the xr package to accomplish this. However, I have run into the following problem.

A minimal working example is as follows. We have a primary file main.tex, and a secondary file sub/sub.tex in a subfolder. The main.tex file reads:

\documentclass[12pt,twoside]{article}

\usepackage[subpreambles]{standalone}
\usepackage{xr}

\begin{document}
    \section{Test}\label{test}
    \input{sub/sub}

\end{document}

and the sub/sub.tex file reads

\documentclass[12pt,twoside,class=article, crop=false]{standalone}

\usepackage{xr}
\externaldocument[main-]{../main}

\begin{document}
    Referencing the main section: \ref{main-test}
\end{document}

When I compile sub/sub.tex, it works as expected: Correct output of sub/sub.tex

However, when I compile main.tex, the reference cannot be found: Incorrect output of main.tex

How can I get the subfile to reference the main file in such a way that the reference compiles correctly in the main file?

0

Your Answer

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