1

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?

13
  • [Disclaimer: I'm a support personnel at Overleaf.] When you compile file4.tex as the main document, are there any compile errors?
    – imnothere
    Mar 25, 2020 at 1:56
  • 1
    you need the aux files. presumably the first three are already in your project copy the fourth one to the same project. you only need the aux not the tex source Mar 25, 2020 at 7:43
  • 1
    In that case it may be best to contact support@overleaf.com with your project's URL, so that support personnel can have a look. .aux files on Overleaf can be accessed (that is, if they had been generated successfully) using the steps here: overleaf.com/learn/how-to/View_generated_files
    – imnothere
    Mar 25, 2020 at 11:53
  • 2
    I've just received your request-for-support email to Overleaf, and have looked at your projec. So there are several issue: (1) You actually have all your file1.tex, file2.tex, file3.tex and file4.tex in a folder. You will therefore need to use the -cd flag in your latexmkrc file, for the pdflatex command. (2) Your latexmkrc file must be on the project's root level, not inside any folder. (3) You must give the full path to your files, e.g. \myexternaldocument{_Appendices/file2}.
    – imnothere
    Mar 25, 2020 at 12:27
  • 2
    (4) You have other compile errors in your project; namely a wrongly-named option to a package. Once these are corrected, xr will work in your project.
    – imnothere
    Mar 25, 2020 at 12:27

2 Answers 2

1

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.

0

Check out this tutorial: https://www.overleaf.com/learn/how-to/Cross_referencing_with_the_xr_package_in_Overleaf

Lets say you have File1.tex and File2.tex and want to cite a label from File2 in File1, what you need are:

  • customized importing code in File1.tex
%%% HELPER CODE FOR DEALING WITH EXTERNAL REFERENCES
\usepackage{xr}
\makeatletter
\newcommand*{\addFileDependency}[1]{
  \typeout{(#1)}
  \@addtofilelist{#1}
  \IfFileExists{#1}{}{\typeout{No file #1.}}
}
\makeatother

\newcommand*{\myexternaldocument}[1]{
    \externaldocument{#1}
    \addFileDependency{#1.tex}
    \addFileDependency{#1.aux}
}
%%% END HELPER CODE

% put all the external documents here!
\myexternaldocument{File2}
  • latexmkrc file
add_cus_dep( 'tex', 'aux', 0, 'makeexternaldocument' );

sub makeexternaldocument {
    if (!($root_filename eq $_[0]))
    {
        # FOR PDFLATEX
        system( "latexmk -cd -pdf \"$_[0]\"" );

        # FOR LATEX+DVIPDF
        # system( "latexmk -cd \"$_[0]\"" );

        # FOR XELATEX
        # system( "latexmk -cd -xelatex \"$_[0]\"" );
        
        # FOR LUALATEX
        # system( "latexmk -cd -lualatex \"$_[0]\"" );
   }
}

Also note that the latexmkrc file must be in the root (top) level folder, not inside sub-folder.

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.