# \nameref : how to get counter's label value instead of section name

Hi I build a customer list environment with a counter, and I'd like to be able to reference the name the label associated with the counter. The code below produces an output similar to this:

Requirements

• REQ1 Requirement one
• REQ2 Requirement two

Another Section

• We want read "Requirement One" here : Requirements.
• But instead we get the section name!

Code:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}

\newcounter{reqcount}
\renewcommand{\thereqcount}{\textbf{REQ\arabic{reqcount}}}

\newenvironment{nfrequirements}
{ \begin{list}{\textbf{\thereqcount}}{\usecounter{reqcount}} }
{ \end{list} }

\newcommand{\requirement}[1]{
\item \textbf{#1}
}

\begin{document}
\tableofcontents

\section{Requirements Section}
\begin{requirements}
\requirement{Requirement one} \label{req_one} \\
description
\requirement{Requirement two} \label{req_two} \\
description
\end{requirements}

\section{Another Section}
We want read "Requirement One" here : \nameref{req_one}.
But instead we get the section name.

\end{document}

-
I suspect that zref can do what you want. – Lev Bishop Oct 27 '10 at 5:49
A similar question was asked and answered here: stackoverflow.com/questions/2767389/… might be worth looking at. – Seamus Oct 28 '10 at 10:17

Set \@currentlabelname:

\makeatletter
\newcommand{\requirement}[1]{%
\item
\def\@currentlabelname{#1}%
\textbf{#1}
}
\makeatother

-

It's not quite the same thing, but consider the following:

\newenvironment{requirements}
{ \begin{list}{\textbf{\thereqcount}}{} }
%{ \begin{list}{\textbf{\thereqcount}}{\usecounter{reqcount}} }
{ \end{list} }
\newcommand{\requirement}[1]{
\refstepcounter{reqcount}
\item \textbf{#1}

The inclusion of \refstepcounter means that the value of the reqcount counter becomes the thing that \label now picks up (rather than the argument of \section, which will have been the last thing that invoked \refstepcounter).
After this, \ref{req_one} expands to "REQ1". Getting \nameref to do the same is presumably not far away (ie, exercise for reader territory!)
Responding to Ulrike's suggestion: \refstepcounter ultimately results in setting \@currentlabel (though with hyperref being part of the game, that's a biiig 'ultimately'). I suspect that \@currentlabelname is a hyperref addition, to support \nameref. – Norman Gray Oct 27 '10 at 9:23