상호 참조 명령에 페이지 번호 추가

상호 참조 명령에 페이지 번호 추가

안에 "외부 참조를 눈에 띄게 만들기"

아래에 작성된 새 명령이 매우 유용하다는 것을 알았습니다. \myautoref 명령으로 외부 파일에 페이지 번호를 추가하고 싶은데 포럼에서 어떤 주제도 찾을 수 없는 것 같습니다.

페이지 번호 참조를 추가하는 데 도움을 줄 수 있는 사람이 있나요?

\documentclass{article} 
\usepackage{xcolor}
\usepackage{xr-hyper}

\usepackage{hyperref} 

\externaldocument[A-]{extfile}  %(A)
\makeatletter

\newcommand{\myautoref}[2][A-]{%
  \@ifundefined{r@#1#2}{% Nope A-#2 isn't there
    \@ifundefined{r@#2}{%
    }{%
      \autoref{#2}%
    }%
  }{%
    {\pending{#1#2}}%
  }%
}
\newcommand{\pending}[1]{\color{red}\autoref{#1} from "file.tex"}

\makeatother


\begin{document}
Using \myautoref{sec:vis} and \myautoref{sec:vis}, but \myautoref{localsection}

\section{Local section}\label{localsection}
\end{document}

extfile.tex

\documentclass{article}

\begin{document}
\section{A section} \label{sec:vis}
\end{document}

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

답변1

\pageref의 정의 내에서 매크로를 사용하는 것이 좋습니다 \pending.

\autoref또한 외부에서 컴파일된 파일에 있는 항목을 상호 참조하는 데 사용하려면 hyperref외부 파일을 로드해야 합니다. 따라서 extfile.tex다음과 같아야 합니다.

\documentclass{article}
\usepackage{hyperref}  % <- new
\begin{document}
\section{A section} \label{sec:vis}
\end{document}

그러면 기본 파일은 다음과 같습니다.

\documentclass{article} 

\usepackage{xr-hyper}
\externaldocument[A-]{extfile}

\usepackage{xcolor}
\usepackage[colorlinks,allcolors=red]{hyperref} 

\makeatletter
\newcommand{\myautoref}[2][A-]{%
  \@ifundefined{r@#1#2}{% Nope A-#2 isn't there
    \@ifundefined{r@#2}{}{\autoref{#2}}%
  }{{\pending{#1#2}}}}
\makeatother
\newcommand{\pending}[1]{\color{red}\autoref{#1} on page~\pageref{#1} of ``file.tex''}

\begin{document}
Using \myautoref{sec:vis}, but \autoref{localsection}.

\section{Local section} \label{localsection}
\end{document}

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

답변2

이미 제안한 대로: \pageref또는 확장 가능한 컨텍스트에서: \getpagerefnumber(필요 refcount) 패키지.

\documentclass{article} 
\usepackage{refcount}
\usepackage{xcolor}
\usepackage{xr-hyper}

\externaldocument[A-]{extfile}  %(A)

\usepackage{hyperref} 

\makeatletter

\newcommand{\myautoref}[2][A-]{%
  \@ifundefined{r@#1#2}{% Nope A-#2 isn't there
    \@ifundefined{r@#2}{%
    }{%
      \autoref{#2} on page \pageref{#2}%
    }%
  }{%
    {\pending{#1#2}}%
  }%
}
\newcommand{\pending}[1]{\color{red}\autoref{#1} from "file.tex" on page \getpagerefnumber{#1}}

\makeatother


\begin{document}
Using \myautoref{sec:vis} and \myautoref{sec:vis}, but \myautoref{localsection}

\section{Local section}\label{localsection}
\end{document}

autoref불만을 방지하려면 \usepackage{hyperref}외부 파일에 추가하는 것이 좋습니다.

\documentclass{article}
\usepackage{hyperref}
\usepackage{blindtext}
\begin{document}
\blindtext[5]
\section{A section} \label{sec:vis}
\end{document}

관련 정보