3

I am trying to use xr for crossreferences between two documents. I've used it before without a problem for a different project.

Here's the error message I get:

(/usr/local/texlive/2018/texmf-dist/tex/latex/tools/xr.sty))
! Incomplete \ifx; all text was ignored after line 12.
<inserted text> 
            \fi 
<*> main

The call to \externaldocument is on line 12 of the main document. I haven't been able to find any problem like this. Any idea what is going on?

Thanks

Edited:

With just these lines in the main.tex it still fails with the same error:

\documentclass{article}
\usepackage{xr}
\externaldocument{supporting}
\begin{document}
Test
\end{document}

The supporting.aux file contains:

\relax 
\providecommand\zref@newlabel[2]{}
\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{pnas-new}
\babel@aux{english}{}
\newlabel{LastPage}{{}{1}{}{page.1}{}}
\xdef\lastpage@lastpage{1}
\xdef\lastpage@lastpageHy{1}
\expandafter\ifx\csname c@section@totc\endcsname\relax\newcounter{section@totc}\fi\setcounter{section@totc}{0}
\expandafter\ifx\csname c@figure@totc\endcsname\relax\newcounter{figure@totc}\fi\setcounter{figure@totc}{0}
\expandafter\ifx\csname c@table@totc\endcsname\relax\newcounter{table@totc}\fi\setcounter{table@totc}{0}
\expandafter\ifx\csname c@NAT@ctr@totc\endcsname\relax\newcounter{NAT@ctr@totc}\fi\setcounter{NAT@ctr@totc}{0}
\expandafter\ifx\csname c@movie@totc\endcsname\relax\newcounter{movie@totc}\fi\setcounter{movie@totc}{0}
\expandafter\ifx\csname c@dataset@totc\endcsname\relax\newcounter{dataset@totc}\fi\setcounter{dataset@totc}{0}
\expandafter\ifx\csname c@SItext@totc\endcsname\relax\newcounter{SItext@totc}\fi\setcounter{SItext@totc}{0}

The external document is a PNAS template from overleaf.

  • 1
    impossible to guess unless you show some input, try to make a small self contained example that shows this problem (probably at most the first 12 lines of your main document, and the .aux file that is referenced. is needed) – David Carlisle Sep 24 '18 at 16:26
  • I edited the post. Please let me know if there is other information that would help – doubledaffy888 Sep 24 '18 at 18:33
  • Is your external document using hyperref? Then maybe use \usepackage{xr-hyper} – user36296 Sep 24 '18 at 19:24
  • @samcarter xr-hyper is the same :-) (updated answer with fix coming up) – David Carlisle Sep 24 '18 at 19:48
6

Update xr has been updated with this fix in version

[2019/01/05 v5.04 eXternal References (DPC)]

It seems I last edited the code for xr in 1994. It seems like only yesterday...

xr doesn't take kindly to \if tests in the aux file. A fix is relatively simple as shown below, I'll try to get an update into the next release.

\documentclass{article}
\usepackage{xr}
\makeatletter
\long\def\XR@test#1#2#3#4\XR@{%
  \let\XR@next\@gobbletwo
  \ifx#1\newlabel
    \let\XR@next\@firstoftwo%
  \else\ifx#1\@input
     \let\XR@next\@secondoftwo
  \fi\fi
   \XR@next{\newlabel{\XR@prefix#2}{#3}}{\edef\XR@list{\XR@list#2\relax}}%
  \ifeof\@inputcheck\expandafter\XR@aux
  \else\expandafter\XR@read\fi}
\makeatother

\externaldocument{supporting}
\begin{document}
Test
\end{document}

Original answer

Hmm actually it is enough to have

\expandafter\ifx\csname wibble\endcsname\relax\relax\fi

in the referenced aux file.

Possibly xr could be more defensive against weird code in the aux file, I'll look later but meanwhile you can process your document if you reference a copy of the auxfile and in the copy delete the block

\expandafter\ifx\csname c@section@totc\endcsname\relax\newcounter{section@totc}\fi\setcounter{section@totc}{0}
\expandafter\ifx\csname c@figure@totc\endcsname\relax\newcounter{figure@totc}\fi\setcounter{figure@totc}{0}
\expandafter\ifx\csname c@table@totc\endcsname\relax\newcounter{table@totc}\fi\setcounter{table@totc}{0}
\expandafter\ifx\csname c@NAT@ctr@totc\endcsname\relax\newcounter{NAT@ctr@totc}\fi\setcounter{NAT@ctr@totc}{0}
\expandafter\ifx\csname c@movie@totc\endcsname\relax\newcounter{movie@totc}\fi\setcounter{movie@totc}{0}
\expandafter\ifx\csname c@dataset@totc\endcsname\relax\newcounter{dataset@totc}\fi\setcounter{dataset@totc}{0}
\expandafter\ifx\csname c@SItext@totc\endcsname\relax\newcounter{SItext@totc}\fi\setcounter{SItext@totc}{0}
  • Thanks so much! Both seem to work with the full documents. – doubledaffy888 Sep 24 '18 at 20:26
  • @doubledaffy888 OK thanks for the confirmation, I'll try to get an update out before the next 24 years are up. – David Carlisle Sep 25 '18 at 0:22
  • @DavidCarlisle May I urge an update in the next 24 days, please? :P – Kartik Oct 5 '18 at 23:19
  • @DavidCarlisle Thanks so much for your solution! FYI your code above "\makeatletter ... \makeatother" worked like a charm when added to my .tex files, but messing with the \expandafter section of the .aux files didn't. I am using the most recent PNAS templates in TexShop, if that matters. I thought that might be useful info for the planned update. – Andrea Kay Jan 14 at 5:21
  • @AndreaKay this should not be needed now if you have an up to date system [2019/01/05 v5.04 eXternal References (DPC)] version of xr has this change – David Carlisle Jan 14 at 7:46

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