Skip to content

Instantly share code, notes, and snippets.

@michal-h21
Created September 4, 2024 21:59
Show Gist options
  • Save michal-h21/d9dba6a447d8391f62019b41ea963978 to your computer and use it in GitHub Desktop.
Save michal-h21/d9dba6a447d8391f62019b41ea963978 to your computer and use it in GitHub Desktop.
Sample usage of setting zref attributes and hyperref links
\documentclass{article}
\usepackage{zref}
\usepackage{zref-hyperref}
\usepackage{hyperref}
\usepackage{lipsum}
\makeatletter
\zref@newlist{zoo}
\zref@newprop{animal}{\currentanimal}
\zref@addprop{zoo}{animal}
\zref@addprop{zoo}{anchor}
\newcommand\setdest[2]{\edef\@currentHref{zoo:#2}%
\hyper@anchorstart{\@currentHref}\hyper@anchorend\def\currentanimal{#2}\zref@labelbylist{#1}{zoo}}
\newcommand\showref[1]{%
\hyperlink{\zref@extractdefault{#1}{anchor}{}}{\zref@extract{#1}{animal}}}
\makeatother
\begin{document}
\section{My favorite pets}
\setdest{label}{Cat}
Cats
\lipsum[1-5]
See the animal \showref{label}.
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment