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:





and the sub/sub.tex file reads

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


    Referencing the main section: \ref{main-test}

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?


Your Answer

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