[Tex/LaTex] Unable to link to inserted pages with pdfpages

cross-referencinghyperrefpdfpages

I would like to add labels to pages inserted with the pdfpages package.
It sort of works right now, but it is not possible to link to the labels with \ref and \pageref commands. In spite of that not working, it is possible to link to the page with the hyperlink command from hyperref.

The goal is to compile a list of things to read in a course and then later say 'read from page xx to yy'. The pagenumbers should of course be determined automatically.

In the document below, the pageref expands to ?? while the text Hello links to the correct page.

\documentclass{article}
\usepackage{hyperref}
\usepackage{pdfpages}
\begin{document}
See page \pageref{testing.1}.
\hyperlink{testing.1}{Hello.}
\includepdf[pages=-,link,linkname=testing]{test.pdf}
\end{document}

For reference, the inserted document (test.pdf) can be any valid PDF document.

Best Answer

The inserted link is a hyper-link, not a LaTeX \label. Therefore the \hyperlink macro works but not the \pageref. I don't think you can get the page information from a hyper-link, so I think you need to add \labels manually. This can be done best using the pagecommand key and a custom counter:

\documentclass{article}
\usepackage{hyperref}
\usepackage{pdfpages}
\newcounter{includepdfpage}
\begin{document}
See page \pageref{testing.1} till \pageref{testing.10}.
\hyperlink{testing.1}{Hello.}
\includepdf[pages=-,link,linkname=testing,pagecommand={\refstepcounter{includepdfpage}\label{testing.\theincludepdfpage}}]{test.pdf}
\end{document}
Related Question