「套件 xr 警告:沒有檔案 file4.aux 標籤未匯入」 – 出了什麼問題?

「套件 xr 警告:沒有檔案 file4.aux 標籤未匯入」 – 出了什麼問題?

我正在寫一篇有大量附錄的文章,我們需要一個交叉引用系統。由於我們使用 hyperref,我嘗試了 xr-hyper 套件。經過多次嘗試,我讓它可以處理三個外部文檔,但當我添加第四個外部文檔時,我收到錯誤訊息「Package xr warning: No file file4.aux LABELS NOT IMPORTED on input line 30」。

事情是這樣的:我們正在使用 Overleaf (和 pdflatex)。不幸的是,目前無法在本地執行此操作。

我已經閱讀了我能找到的所有線程,並應用了我能找到的所有工作範例,但無濟於事。

我附上了下面各個頁面的 MWE。誰能弄清楚為什麼它不接受第四個文件的引用?

% 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}

最後是其餘文件的範例:

\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}

更新:我現在已經從 Overleaf 下載了 aux 文件,這給了我這個結果:

\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}

這些幫助有用?

答案1

看看這個教學:https://www.overleaf.com/learn/how-to/Cross_referencing_with_the_xr_package_in_Overleaf

假設您已經File1.tex並且File2.tex想要在 File1 中引用 File2 中的標籤,您需要的是:

  • 自訂導入程式碼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文件
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]\"" );
   }
}

另請注意,該latexmkrc檔案必須位於根(頂層)資料夾中,而不是子資料夾中。

答案2

我也遇到這個問題了(教學不起作用)。我發現對我來說的解決方案是將我的主要和外部文件移至我的背頁專案的根目錄中。

相關內容