# Using Description environment with cleveref

Is there a way to use cleveref to reference the name of an item in a description environment?

For example, if I have

\begin{description}
\item[TEST\label{test}] test
\end{description}


I would like to reference it through \cref{test} and for the text to be TEST.

• Does the solution have to be based on cleveref's machinery? If not, would a solution based on the \hyperlink/\hypertarget mechanism of the hyperref package be acceptable? – Mico May 10 at 5:16
• @Mico does this mean I would not use \cref/\Cref to create the reference? Ideally, for consistency purposes, I would like to stick with using the \cref/\Cref command to create references (whether cleverref is used under the hood I have no strong opinions about. From an outcome perspective, if I had to use a different command but had consistent behaviour for all references throughout the document, I would not mind. – David Poxon May 10 at 5:20
• cleveref works by greatly extending LaTeX's basic \label/\ref mechanism. LaTeX associates the argument of \label with the most recently incremented counter variable. (E.g., each time a \section directive is executive, the section counter is incremented.) Unlike the enumerate list environment, the description list environment does not increment a counter variable when an \item directive is encountered. You'd have to graft some kind of secondary counter mechanism onto the list environment -- and associate the new counters with the description list test items. Ugly... – Mico May 10 at 5:32
• If you can use an enumerate environment, you (more precisely, cleveref) would be all set to go. However, the cross-reference call-out produced by \cref would be a number, not the implicit or explicit label associated with that number. This is why I was thinking about employing the \hyperlink/\hypertarget mechanism. – Mico May 10 at 5:44
• Okay then that sounds good to me :) – David Poxon May 10 at 5:47

Building on the discussion led in the preceding comments, here's a solution that employs the \hypertarget/\hyperlink mechanism of the hyperref package to create cross-references that show text strings rather than numbers.

The commands \hypertarget and \hyperlink both take 2 arguments. \hypertarget creates a target; the first argument becomes the internal name of the target, and the second determines what's shown in the document. \hyperlink creates a link to the target created by \hypertarget. The first arguments of \hypertarget and \hyperlink must coincide, while the second arguments needn't, as is also shown in the following MWE (minimum working example).

\documentclass{article}

\begin{document}
\begin{description}
\item[FOO] \dots
\item[\hypertarget{list:test}{\textbf{TEST}}] \dots
\item[BAR] \dots
\end{description}
As was demonstrated in the \hyperlink{list:test}{TEST} item of the preceding list, \dots
\end{document}


• Hmm, I getting these errors: Undefined control sequence. ...m[\hypertarget{lampstate}{\textbf{State}}] Use of \\smash doesn't match its definition. ...m[\hypertarget{lampstate}{\textbf{State}}] – David Poxon May 10 at 7:13
• @DavidPoxon - Did you load the hyperref package? – Mico May 10 at 7:24
• @DavidPoxon If you also use cleveref, you have to load hyperref and cleveref in correct sequence (cleveref last). – Sveinung May 10 at 7:59
• I load cleveref after hyperref. I created a new document in Overleaf and used the same preamble in my document - this solution works. I'm not sure why it's not working in my document. – David Poxon May 10 at 8:04
• @Mico I think this is the frustrating part - as far as I'm aware, I haven't modified the description` environment in any way (in fact, this is the one and only place I use it in my document.) I have stopped a number of files from being imported, and I have finally got your solution to work! I will reincorporate each document and see which one causes things to fail. :) – David Poxon May 10 at 8:50