# LaTeX external document referencing from Main tex file

I have a file structure like this

• Main.tex
• chapters (folder)
• Chapter_1 (folder)
• chap1.tex
• Chapter_2 (folder)
• chap2.tex

To refence diagrams and equations from chap1.tex in chap2.tex, I have used

  \usepackage{xr}
\externaldocument[I-]{../Chapter_1/chap1}


as mentioned in this_question and it works when I compile chap2.tex separately.

However, in Main.tex, I have added all the chapters using

 \cfchapter{Chapter 1}{chapters/Chapter_1}{chap1.tex}
\cfchapter{Chapter 2}{chapters/Chapter_2}{chap2.tex}


Now when I compile main.tex, the cross chapter references are not happening as I am getting Latex errors that externaldocument command needs to be declared in the preamble. Adding the externaldocument commands (with corrected paths) in Main.tex does not work. Can someone provide me with a fix ? Thanks

• What is wrong with plain \include{...} or \input{...}? Jan 24, 2016 at 22:37

I just found out the answer. I need to remove the reference specifier within chap2.tex and using plain reference name. Example: instead of specifying

   \ref{I-figure1}


I need to just use

   \ref{figure1}


without the need for \externaldocument and when I compile Main.tex, the correct reference is shown! But I think I need to make sure that label names are unique to prevent clashes.

• I havent used those packages, I just use \input{chapters/chapter_1/chap1.tex} in main.tex. What this does (and I think your commands work the same way) is to read that section as if it was written in the main.tex document. And referencing other files or things is done as if you are in the working directory of the main file. Hope that helps! Jul 28, 2015 at 13:42
• You might prefer \ref{fig:descriptive_name} if you aren't doing that already en.wikibooks.org/wiki/LaTeX/Labels_and_Cross-referencing Jul 28, 2015 at 13:45
• Thanks guys but I found the solution. As I have mentioned, the \externaldocument command is only required to link between unrelated tex files. Since I use a main.tex file to add all the chapters (which are individual tex files) there is no need to use \externaldocument` command .. Jul 29, 2015 at 16:11