[Tex/LaTex] Cross-referencing between different files

cross-referencingexternal files

I want to cross-reference between different .tex files, just because I want to put every chapters separately.

Let's say in file chapterI.tex I have \label{a} and I want to access this in file chapterII.tex using something like \ref{a}. How to do this exactly in LaTeX, moreover if LEd have an easy feature to cover this, it will be better (I have put those both files in the same project).

I found another question with similar title, but I just didn't really understand. It's here: Cross-reference between LaTeX files.

Best Answer

You can use the xr package to reference to other LaTeX document.

So in chapterII.tex you say:

\usepackage{xr}
\externaldocument{chapterI}

And then can use \ref{a} like normal. You can also add a prefix:

\externaldocument[I-]{chapterI}

then you can reference it as \ref{I-a} which is useful if you have identical label names in different chapters.

Note that the normal xr doesn't add hyperlinks. It only adds the label text. The zref package can be used for this. It provides the zref-xr subpackage which gives you the same functionality and should work fine with hyperref (after all both packages are from the same author). You only need to replace \externaldocument with \zexternaldocument as well as \ref with \zref.

Note that the xr package reads the aux file, e.g. in this case, it checks chapterI.aux for references.