The hyperref
package provides the pair of commands
\hypertarget{<name>}{<text>}
\hyperlink{<name>}{<text>}
for the creation of cross-references that are independent from counters. They are analogues of \label
and \ref
, respectively. Here's an example:
\documentclass{article}
\usepackage[breaklinks=true]{hyperref}
\begin{document}
Go to the \hyperlink{lip}{second}, or \hyperlink{lipsys}{third} paragraph.
\newpage
The first hyperlink brings you \hypertarget{lip}{here.}
\newpage
The second hyperlink brings you \hypertarget{lipsys}{here.}
\end{document}
On the other hand, if you wish associate cross-references to a counter, you can try using the following declarations:
\documentclass{article}
\usepackage{etoolbox}
\usepackage[breaklinks=true,colorlinks=true,linkcolor=red]{hyperref}
\newrobustcmd*{\foo}[1]{{\refstepcounter{bar}\label{#1}\thebar}}
\newcounter{bar}
\renewcommand{\thebar}{\textcolor{black}{[}\arabic{bar}\textcolor{black}{]}}
\begin{document}
Go to \ref{lipsys}, and \ref{lip}.
\newpage
The second hyperlink brings you \foo{lip} here.
\newpage
The first hyperlink brings you \foo{lipsys} here.
\end{document}
In the example above, \foo{<key>}
(1) globally increments the counter bar
, (2) maps the key to the current reference string, and (3) prints the value of bar
. \textcolor{black}{...}
is used to override the formatting applied by the hyperref
package (otherwise it's typeset in the same colour as the counter).
