I have two documents and am trying to use the package xr to create a reference, in the second document, to a \label in the first. But ?? appears in the PDF instead. How do I enable the second to see the first's \labels?

Minimal example:





I am using pdfLaTeX and TeXworks.

The files are in the same directory.

I don't want hyperlinks.

There is very little in the xr package's documentation -- have I used it correctly?

Some similar older questions on the same topic have got answers which say that xr needs to read the .aux file. pdfLaTeX lately runs OK without any .aux files. Does xr still need to read the .aux file nowadays? If so, how do I get TeXworks to get pdfLaTeX to a) keep the .aux file b) revert to the default behaviour of not keeping an .aux file?

  • 2
    I am confused. Surely, the default behaviour is keeping the .aux file? Without it, even internal cross references don't work. Anyhow, the example works for me. Feb 1, 2019 at 11:32
  • If pdfLaTeX runs and makes a .pdf, only the .tex, .synctex.gz and .pdf remain. I might have changed a setting, but nothing in TeXworks's Edit\Preferences menus seem relevant. The default with my installation has been to delete the .aux, since 15 Jun 2018. Behaviour sometimes changes automatically because a new version automatically installs itself. Internal cross-references within a document work fine.
    – Rosie F
    Feb 1, 2019 at 11:43
  • 1
    Just to clarify: It is definitely not the default behaviour of pdfLaTeX (or any other LaTeX engine) to clean up the .aux files after itself. It must be a setting of your editor or your compilation tool (if you use that). The .aux file is required not only to get cross references with xr right, but also to be able to produce proper cross references within the document.
    – moewe
    Feb 1, 2019 at 11:46
  • 2
    latex needs the aux file always whether or not you use xr otherwise no references or table of contents or lists of tables etc will work. Feb 1, 2019 at 11:49
  • Eureka. I will explain in an answer.
    – Rosie F
    Feb 1, 2019 at 12:12

1 Answer 1


As David Carlisle pointed out, TeX engines need to write .aux files. So, XY problem, the Y now being "How do I stop the automatic deletion of the .aux file after a successful run?". I use TeXworks, and the solution in my case is: when using TeXworks to make a document containing \labels to which other documents \refer, select the compilation mode pdfLaTeX (not pdfLaTeX+MakeIndex+BibTeX). I had been using the compilation mode pdfLaTeX+MakeIndex+BibTeX -- presumably MakeIndex or BibTeX cleans up the .aux and .log files if the run succeeded. As moewe says, the pdfLaTeX phase does not delete those files, so it must be one of the later phases.

  • Unless you changed something I cannot imagine that any of those compilation combinations in TeXworks include doing a full cleanup. As these are usually only neededif something goes really wrong
    – daleif
    Feb 1, 2019 at 12:24
  • 1
    If you are using MikTeX pdfLaTeX+MakeIndex+BibTeX runs texify. Usually texify should not delete .aux files after a successful run, but there is an option to enable that (-c). So maybe check your configurations that the -c is not included.
    – moewe
    Feb 1, 2019 at 13:55

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.