`xr` 상호 참조: 외부 참조에 대해서만 색상 변경

`xr` 상호 참조: 외부 참조에 대해서만 색상 변경

Paper1과 Paper2라는 두 파일을 참조하고 싶습니다. hyperref내부 참조를 위해 각 문서에서 사용하고 있습니다 . 어떤 참조가 내부 참조이고 외부 참조인지 명확하게 하기 위해 참조 색상을 변경하고 싶습니다 xr.

에서 hypersetup나는 을 선택했습니다 linkcolor={blue}. 본질적으로는 이렇게 말하고 싶습니다.

if reference is external, then set linkcolor={red}
if reference is internal, then set linkcolor={blue}

Overleaf에 예제를 설정했는데, 여기에서 찾을 수 있습니다:https://www.overleaf.com/4688282852jxtxcsdmnrhs. 파일 사본이 아래에 제공됩니다(너무 길다는 점에 대해 사과드립니다!)

(내 생각으로는 로컬에서 컴파일하는 경우에는 필요하지 않은 추가 '도우미 코드'가 Overleaf에 있습니다.https://www.overleaf.com/learn/how-to/Cross_referencing_with_the_xr_package_in_Overleaf.)

%%File1.tex

\documentclass{article}

\usepackage{hyperref}
\hypersetup{
    colorlinks,
    linkcolor={blue},
    citecolor={blue},
    urlcolor={blue}
}

%%% HELPER CODE FOR DEALING WITH EXTERNAL REFERENCES
\usepackage{xr-hyper}
\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}

\title{\texttt{xr} package example}
\author{Overleaf team}

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

%%%%%%%%%%%%%

%%File2.tex

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\section{Label1}
\label{label1}
This section is referenced by File1.
\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]))
    {   # 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]\"" );
   }
}

답변1

hyperref 전에 xr-hyper를 로드해야 합니다. 이 외에도 xr-hyper를 사용하면 기본적으로 색상이 다르므로 을 linkcolor파란색으로 변경하여 와 매우 유사한 색상으로 변경하면 표시되지 않습니다 filecolor.

\documentclass{article}

\usepackage{xr-hyper}
\usepackage[colorlinks]{hyperref}
\hypersetup{
    colorlinks,
    linkcolor={blue},
    filecolor={red}, %<----
    urlcolor={blue},
    citecolor={blue}
}


\externaldocument[ex:]{external}

\begin{document}

\section{My section}\label{sec:mysection}

Local ref: \ref{sec:mysection}, external ref:  \ref{ex:sec:mytitle} 

\end{document}

여기에 이미지 설명을 입력하세요

%external.tex
\documentclass{article}

\usepackage{xr-hyper}
\usepackage{hyperref}

\begin{document}

\section{MyTitle}\label{sec:mytitle}

\end{document}

관련 정보