I am aware of the question below about how to refer, in file1, to labels from file2.

latexmk with external references

However, I must also refer, in file2, to labels from file1.

I am able to do it by using xr and \externaldocument in both files and running latex in the command line of my computer.

I want to run it on overleaf, and imagine that latexmk is the answer, but don't know how.

  • This isn't a full answer, but a general way to handle this sort of situation in make is to create a dummy "master" document which calls up the cross references in all the real documents (and it doesn't need to do anything else apart from that). Then, when you compile the master document, the dependencies mean that all the real documents get compiled first. If any of the references in them have changed, that means the master document needs to be compiled again, which will force another recompile of all the real documents … and repeat, till everything converges.
    – alephzero
    May 23, 2019 at 20:45
  • 1
    (I'm on support staff at Overleaf.) I started with our xr example here: overleaf.com/learn/how-to/… and copied the helper code from File1.tex also into File2.tex. In File2.tex, I used \myexternaldocument{File1} to mark File1.tex as containing external labels to use in File2.tex. With this setup I have references working in both directions: overleaf.com/read/qpsqvqqwshpm . If that's not working for you, could you please write us at support@overleaf.com with your Overleaf project URL, so we can take a closer look? Thanks. May 23, 2019 at 22:26
  • @PaulGessler should be labelled as correct answer - thanks!
    – dsg38
    Dec 8, 2020 at 18:18


Your Answer

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

Browse other questions tagged or ask your own question.