1

With the two following documents, I get a correct result: in the second document, the first chapter page from first document is included and the external link opens the correct page in the first document.

enter image description here

First document (xr-ext.tex):

\documentclass{book}
\usepackage{hyperref}

\begin{document}
%\frontmatter
\chapter*{Introduction}
Text of introduction....

%\mainmatter
\chapter{First chapter}
\label{myextref}
Text of first chapter...
\end{document}

Second document:

\documentclass{book}
\usepackage{graphicx}
\usepackage{xr-hyper}
\usepackage{hyperref}
\usepackage{pdfpages}

\externaldocument{xr-ext}

\begin{document}
\framebox{\includegraphics[width=5cm,page=\getpagerefnumber{myextref}]{xr-ext}}

Here, my reference to chapter \ref{myextref}.
\end{document}

But, if I use \frontmatter and \mainmatter (the corresponding lines are commented in my first document), the \getpagerefnumber macro gives the logical page (1) and not the physical page (3) and the \includegraphics macro includes the "Introduction page" instead of the "First chapter" page (but the external links via \ref works).

enter image description here

Which macro of the xr-hyper package can I use to get the physical page of an external reference?

2

You can use the zref-package. It stores absolute page numbers:

External document (test-utf8.tex):

\documentclass{book}
\usepackage{zref-user,zref-abspage}
\usepackage{hyperref}

\begin{document}
\frontmatter
\chapter*{Introduction}
Text of introduction....

\mainmatter
\chapter{First chapter}
\zlabel{myextref}
Text of first chapter...
\end{document}

Second document:

\documentclass{book}
\usepackage{graphicx}
\usepackage{zref-user,zref-xr}
\makeatletter\let\zrefextractdefault\zref@extractdefault\makeatother 
\zexternaldocument{test-utf8}
\usepackage{hyperref}
\usepackage{pdfpages}

\begin{document}
\framebox{\includegraphics[width=5cm,
    page=\zrefextractdefault{myextref}{abspage}{1}]{test-utf8}}

Here, my reference to chapter \zref{myextref}.
\end{document}

enter image description here

  • Thanks for this solution but, here, the external document must be modified to use \zlabel.... – Paul Gaborit Jan 22 at 9:14
  • Another problem: the 1 in second document is no longer a link to the external document. – Paul Gaborit Jan 22 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.