[Tex/LaTex] LaTeX external document referencing from Main tex file

cross-referencingexternal files

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

Best Answer

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.

Related Question