I read how to make a reference that has as a label the label of a description label (Reference name of description list item in LaTeX):
\makeatletter
\let\orgdescriptionlabel\descriptionlabel
\renewcommand*{\descriptionlabel}[1]{%
\let\orglabel\label
\let\label\@gobble
\phantomsection
\edef\@currentlabel{#1}%
%\edef\@currentlabelname{#1}%
\let\label\orglabel
\orgdescriptionlabel{#1}%
}
\makeatother
This works. However, often description labels end with a special character, like :
or ,
, which should not be part of the reference label. How can I remove this character from the reference label?
Edit:
Tried:
\usepackage{xstring}
...
\edef\@currentlabel{\StrGobbleRight{#1}{1}}%
...
But that seems not to work for some reason.
Edit
Here is a full document (from the link above):
\documentclass{article}
\usepackage{hyperref}
\usepackage{nameref}
\makeatletter
\let\orgdescriptionlabel\descriptionlabel
\renewcommand*{\descriptionlabel}[1]{%
\let\orglabel\label
\let\label\@gobble
\phantomsection
\edef\@currentlabel{#1}%
%\edef\@currentlabelname{#1}%
\let\label\orglabel
\orgdescriptionlabel{#1}%
}
\makeatother
\begin{document}
\section{Definitions}
\begin{description}
\item [Vehicle\label{itm:vehicle}] Something
\item [Bus\label{itm:bus}] A type of \ref{itm:vehicle}
\item [Car\label{itm:car}] A type of \ref{itm:vehicle} smaller than a \ref{itm:bus}
\end{description}
The item `\ref{itm:bus}' is listed on page~\pageref{itm:bus} in section~\nameref{itm:bus}.
\end{document}
\orgdescriptionlabel{#1:}
or\orgdescriptionlabel{#1,}
.