# Referencing a text like a hyperreference inside a document

I have a table with many entries and I want to reference the key so another person can quickly look up what the key means.

Here is some pseudocode:

Table
snippet1\label{?key1} & longexplanatory text
snippet2\label{?key2} & longexplanatory text
snippet3\label{?key3} & longexplanatory text

connect \ref{key1} with \ref{key13}


After compilation I want the text to read

connect snippet1 with snippet3


The reader should be able to quickly jump to the table when clicking on snippet-N.

-

The following uses \refstepcounter (instead of the internal \@currentlabel) of a dummy counter to make the text to something that can be referenced. \raisebox moves \refstepcounter a bit to move the anchor position, if package hyperref is used. At the place of \refstepcounter hyperref sets the anchor.

\documentclass{article}
\newcounter{keylabel}
\newcommand*{\keylabel}[2]{%
\leavevmode
\raisebox{2ex}[0pt][0pt]{%
\renewcommand*{\thekeylabel}{#1}%
\refstepcounter{keylabel}%
\label{#2}%
}%
#1%
}

\usepackage{hyperref}

\begin{document}
\begin{tabular}{@{}ll@{}}
\keylabel{snippet1}{key1} & longexplanatory text\\
\keylabel{snippet2}{key2} & longexplanatory text\\
\keylabel{snippet3}{key3} & longexplanatory text\\
\end{tabular}

connect \ref{key1} with \ref{key3}
\end{document}


-