0

I am using zref for crossreferencing from one file to another. But my Hyperreferencing is not working. Here's the code

Main.tex

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}


\usepackage{zref-xr,zref-user}
\usepackage{hyperref}
\zexternaldocument*{trail2}



\begin{document}
Hi, \zref{S1}
\end{document}

trail2.tex

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}


\usepackage{zref-xr,zref-user}
\usepackage{hyperref}


\renewcommand{\thefigure}{S\arabic{figure}}


\begin{document}

\newpage

\begin{figure}[htp!]
\centering \Large

\bigskip

\includegraphics[width=1.1\linewidth]{trail_picture}

\caption{\label{S1} trail-picture }
\end{figure}

\end{document}

1 Answer 1

0

zref is not really prepared for hyperlinking (or hyperref not really prepared for zref).

So either you should use the normal \ref command which hyperref redefines, or you will have to build your own ref command with the infos provided by zref. E.g.

(this is only a draft, I didn't really try to check if all special chars are handled correctly).

\documentclass[10pt,a4paper]{article}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}

\usepackage{hyperref}
\usepackage{nameref} %needed by zref-xr

\usepackage{zref-xr,zref-hyperref,zref-user}

\zxrsetup{toltxlabel=true}

\zexternaldocument*{trail2}

{\catcode`\#=12 \gdef\hashchar{#1}}
\makeatletter
\newcommand\hzref[1]{\edef\next{%
    \noexpand\href{%
      \zref@extractdefault{#1}{url}{}%
      \zref@ifrefcontainsprop{#1}{anchor}{%
      \hashchar\zref@extract{#1}{anchor}}{}}%
      {\noexpand\zref{#1}}}\next}
\makeatother

\begin{document}

\ref{S1}, \zref{S1}, \hzref{S1}

\end{document} 

enter image description here

3
  • Thank you. It works like a charm. Thank you Commented Apr 15, 2020 at 15:46
  • I didn't think that zref and hyperref were incompatible. I typically use both and don't seem to have an issue. Just double checked, and section/figure hyperlinks work fine while still pulling labels from another document.
    – Sterling
    Commented Mar 6, 2021 at 8:03
  • @Sterling: I didn't wrote incompatible, only that some functions are not supported, and the question here is one example. Commented Mar 6, 2021 at 9:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .