xr 包 + latexmkrc 不能与 includegraphics 命令一起使用?

xr 包 + latexmkrc 不能与 includegraphics 命令一起使用?

我正在尝试实现所描述的技巧这里使用 xr 包让 latex 引用自动跨多个文件工作。该技术效果很好,除了如果引用的文件中有一个 includegraphics 命令。您可以在此处查看我的最小非工作示例: https://www.sharelatex.com/project/594816fa8920e4376fb8d7a6。具体来说,我有

文件1

\documentclass{article}

%%% 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[S]{#1}
    \addFileDependency{#1.tex}
    \addFileDependency{#1.aux}
}
%%% END HELPER CODE

% put all the external documents here!
\myexternaldocument{File2}

% just to see what's happening
\listfiles

\begin{document}

We would like to reference section \ref{Spicture} of file2.tex
\end{document}

文件2

\documentclass{article}
\usepackage{graphicx}

\begin{document}


\section{Label1}
\label{picture}

This section is referenced by File1.

\begin{figure}
    \centering
    \includegraphics{{IMG}.png}
    \caption{Caption}
\end{figure}

\end{document}

.latexmkrc

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]))
    {
        system( "latexmk \"$_[0]\"" );
    }
}

当我注释掉 file2 中的 includegraphics 命令,然后编译 file1 时,引用工作正常。但是当我取消注释 includegraphics 命令时,从 file1 到 file2 的引用就被破坏了。

有什么建议么?

相关内容