I'm working on an article with tons of appendices that we need a cross referencing system for. Since we user hyperref, I gave the xr-hyper package a try. After MANY attempts, I got it to work with three external documents, but the moment I add a fourth, I get the error message "Package xr warning: No file file4.aux LABELS NOT IMPORTED on input line 30".
Here's the thing: We're using Overleaf (and pdflatex). Doing this locally is unfortunately not an option at this point.
I've read every thread I could find, applying all the working examples I could find, but to no avail.
I'm attaching a MWE of the various pages below. Can anyone figure out why on earth it won't accept references to the fourth file?
% the preamble
%\usepackage{xcite}
\usepackage{xr-hyper}
\usepackage{hyperref}
\makeatletter
\newcommand*{\addFileDependency}[1]{% argument=file name and extension
\typeout{(#1)}% latexmk will find this if $recorder=0 (however, in that case, it will ignore #1 if it is a .aux or .pdf file etc and it exists! if it doesn't exist, it will appear in the list of dependents regardless)
\@addtofilelist{#1}% if you want it to appear in \listfiles, not really necessary and latexmk doesn't use this
\IfFileExists{#1}{}{\typeout{No file #1.}}% latexmk will find this message if #1 doesn't exist (yet)
}
\makeatother
\newcommand*{\myexternaldocument}[1]{%
\externaldocument{#1}%
\addFileDependency{#1.tex}%
\addFileDependency{#1.aux}%
}
% put all the external documents here!
\myexternaldocument{file1}
\myexternaldocument{file2}
\myexternaldocument{file3}
\myexternaldocument{file4}
% the latexmkrc file
add_cus_dep( 'tex', 'aux', 0, 'makeexternaldocument' );
sub makeexternaldocument {
# if the dependency isn't one of the files that this latexmk run will consider, process it
# without this test, we would get an infinite loop!
if (!($root_filename eq $_[0]))
{ # PLEASE ENABLE ONLY ONE OF THE FOLLOWING
# DEPENDING ON THE ENGINE YOU'RE USING
# FOR PDFLATEX
system( "latexmk -pdf \"$_[0]\"" );
# FOR LATEX+DVIPDF
# system( "latexmk \"$_[0]\"" );
# FOR XELATEX
# system( "latexmk -xelatex \"$_[0]\"" );
# FOR LUALATEX
# system( "latexmk -lualatex \"$_[0]\"" );
}
}
% File 1
\documentclass[12pt]{article}
\input{preamble}
\begin{document}
\section{section 1 in file 1}
\label{sec1file1}
\section{section 2 in file 1}
\label{sec2file1}
Testing some references: \\
Referencing section one in file one: \ref{sec1file1}\\
Referencing section two in file one: \ref{sec2file1} \\
Referencing section one in file two: \ref{sec1file2} \\
Referencing section two in file two: \ref{sec2file2} \\
Referencing section one in file three: \ref{sec1file3} \\
Referencing section two in file three: \ref{sec2file3} \\
\end{document}
and finally, an example of the rest of the files:
\documentclass[12pt]{article}
\input{preamble}
\begin{document}
\section{section 1 in file 3}
\label{sec1file3}
\section{section 2 in file 3}
\label{sec2file3}
Testing some references: \\
Referencing section one in file one: \ref{sec1file1}\\
Referencing section two in file one: \ref{sec2file1} \\
Referencing section one in file two: \ref{sec1file2} \\
Referencing section two in file two: \ref{sec2file2} \\
Referencing section one in file three: \ref{sec1file3} \\
Referencing section two in file three: \ref{sec2file3} \\
Referencing section two in file four: \ref{sec2file4} \\
\end{document}
UPDATE: I have now downloaded the aux files from Overleaf, which gave me this result:
\relax
\providecommand\hyper@newdestlabel[2]{}
\providecommand\HyperFirstAtBeginDocument{\AtBeginDocument}
\HyperFirstAtBeginDocument{\ifx\hyper@anchor\@undefined
\global\let\oldcontentsline\contentsline
\gdef\contentsline#1#2#3#4{\oldcontentsline{#1}{#2}{#3}}
\global\let\oldnewlabel\newlabel
\gdef\newlabel#1#2{\newlabelxx{#1}#2}
\gdef\newlabelxx#1#2#3#4#5#6{\oldnewlabel{#1}{{#2}{#3}}}
\AtEndDocument{\ifx\hyper@anchor\@undefined
\let\contentsline\oldcontentsline
\let\newlabel\oldnewlabel
\fi}
\fi}
\global\let\hyper@last\relax
\gdef\HyperFirstAtBeginDocument#1{#1}
\providecommand\HyField@AuxAddToFields[1]{}
\providecommand\HyField@AuxAddToCoFields[2]{}
\bibstyle{biblatex}
\bibdata{output-blx,hh_library}
\citation{biblatex-control}
\abx@aux@refcontext{nyt/global//global/global}
\providecommand \oddpage@label [2]{}
\@writefile{toc}{\boolfalse {citerequest}\boolfalse {citetracker}\boolfalse {pagetracker}\boolfalse {backtracker}\relax }
\@writefile{lof}{\boolfalse {citerequest}\boolfalse {citetracker}\boolfalse {pagetracker}\boolfalse {backtracker}\relax }
\@writefile{lot}{\boolfalse {citerequest}\boolfalse {citetracker}\boolfalse {pagetracker}\boolfalse {backtracker}\relax }
\@writefile{toc}{\defcounter {refsection}{0}\relax }\@writefile{toc}{\contentsline {section}{\numberline {1}section 1 in file 1}{1}{section.1}\protected@file@percent }
\newlabel{sec1file1}{{1}{1}{section 1 in file 1}{section.1}{}}
\@writefile{toc}{\defcounter {refsection}{0}\relax }\@writefile{toc}{\contentsline {section}{\numberline {2}section 2 in file 1}{1}{section.2}\protected@file@percent }
\newlabel{sec2file1}{{2}{1}{section 2 in file 1}{section.2}{}}
\newlabel{LastPage}{{}{1}{}{page.1}{}}
\xdef\lastpage@lastpage{1}
\xdef\lastpage@lastpageHy{1}
Does that help at all?
Best Answer
I met the problem too (The tutorial does not work). I found the solution for me is just moving my main and external documents to the root of my overleaf project.