2

I am creating a document in LaTeX using TeXworks and I cannot get cross-referencing between separate files working. Every time I use \ref to a label I get two question marks.

I have three separate files: main.tex, background.tex and implementation.tex. The background.tex and implementation.tex files are located in a sub-directory named sections.

I have a label in a section within background.tex which I want to refer to in the implementation.tex file. Here is how they are defined:

background.tex:

\section{MySection}
\label{background:MySection}

to refer to this in implementation.tex I write:

As described in section \ref{background:MySection}

In my main.tex file I use xr as follows:

\usepackage{xr}
\externaldocument{sections/background}

I then compile using pdfLaTeX, then run BiBTeX for my references, then run pdfLaTeX twice. The part where I use \ref appears with two question marks. I get the following console output:

LaTeX Warning: Reference `background:MySection' on page 24 undefined on input line 5.

Anyone know what I am doing wrong?

6

For xr to work you must have run latex on the document that you are referencing and the aux file from that run must be available to TeX when you process the document with the reference. In other words sections/background.aux must exist and have a definition for background:MySection

However if these are sections that are being \input or \included into the main document, you do not want xr at all, just use \label normally.

|improve this answer|||||

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.