I have multiple documents which require cross-referencing from one another (I am the author of all of them). Each document lies in a separate folder.

As an example, everything lives in a directory named "main-folder". Within this directory, I have two directories: "folder-1" and "folder-2". Within each directory (folder-1 and folder-2) lives a TeX document, say file-1.tex is in folder-1 and file-2.tex is in folder-2.

I am using the xr package, and when two TeX documents needing cross-referencing are within the same directory (say, both in folder-1), I enter the following two lines in the preamble of file-1.tex:


and this allows me to cross-reference labels from file-2.tex in file-1.tex via the usual \label and \ref commands, using someprefix- to distinguish between the labels in file-1.tex and those in file-2.tex.

I am wondering what the syntax should be if file-2.tex is in folder-2 instead of folder-1. I have already tried:


but nothing works. What am I doing wrong?

  • 3
    I'd expect ../folder2/file-2 to work, ~ would also work if you use \string~/... to prevent ~ expanding to non-breakable space Dec 29, 2016 at 21:25
  • 2
    "nothing works" isn't a description that anyone can debug. If it gives the wrong output, show the output, if it gives an error message or warning, show the text from the log file. Dec 29, 2016 at 21:43
  • have you tried the subfile package already? This also allows you to compile parts separate from each other while writing and all together for the finish. Dec 29, 2016 at 21:45
  • @David Carlisle: yes, you're right. What happens is that the file compiles (there is syntaxically nothing wrong of course) but the references appear as wrong (i.e. as ?? instead of 3.7 or something). I know that the error must be there however, since the same file-2.tex is in both folders, and when I change that \externaldocument line to work within folder-1 (i.e. if I write "file-2" as an argument instead like in my first example), everything works fine. Dec 30, 2016 at 2:35
  • 1
    You need the same path that you would need to input the file. So if you compile in folder-1 ../folder-2/file-2 should work. Dec 30, 2016 at 9:38

1 Answer 1


This should work:


Notice: Do not include the .tex extension.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .