
Я нашел новую команду, написанную ниже, очень полезной. Хотя я хотел бы добавить номер страницы во внешний файл в команде \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}