2

I want to use the glossaries package and I want to be able to reference descritpion list items by their name. For the latter problem, I found a solution (Reference name of description list item in LaTeX , the accepted answer). This works fine. It is also no problem to incorporate glossary-entries into the text, however when printing the list of glossaries, this leads to an error.

My solution by now:

\documentclass{article}
\usepackage{hyperref}

%%%
% Macro for description
\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

\usepackage[toc,automake]{glossaries}
\makeglossaries
\newacronym{KG}{KG}{Knowledge Graph}

\begin{document}
\begin{description}
    \item[(A1)\label{desc:A1}] Test
\end{description}
As can be seen in \ref{desc:A1} a \gls{KG} is...
    
\printglossary[type=\acronymtype]
    
\end{document}

This works when either commenting out \printglossary[type=\acronymtype] or everything between makeatletter and makeatother.

The error message is:

Undefined control sequence.
\gls@start@measuring ...else \let \gls@org@target 
                                                  \glstarget \let \gls@org@l...

l.5         \setentrycounter[]{page}\glsnumberformat{1}}}

As I am not an expert on Latex, I would appreciate any help. I am open for all solutions enabling to achieve a combination of labels on items and the glossaries, they need not to be based on this code.

1
  • 1
    Doesn't glossaries by default use the description list to typeset its lists. Thus it does not like your redefinitions
    – daleif
    Sep 4, 2023 at 7:57

1 Answer 1

3

You need to restore the original definition of descriptionlabel before \printglossary.

Meanwhile, I provided better code than yours for suppressing the \label inside the argument.

\documentclass{article}
\usepackage{hyperref}
\usepackage[toc,automake]{glossaries}

%%%
% Macro for description
\makeatletter
\NewCommandCopy{\orgdescriptionlabel}{\descriptionlabel}
\renewcommand*{\descriptionlabel}[1]{%
    \phantomsection
    \begingroup\let\label\@gobble\protected@edef\x{\endgroup
      \def\noexpand\@currentlabel{#1}%
      \def\noexpand\@currentlabelname{#1}%
    }\x
    \orgdescriptionlabel{#1}%
}
\makeatother

\makeglossaries
\newacronym{KG}{KG}{Knowledge Graph}

\begin{document}
\begin{description}
    \item[(A1)\label{desc:A1}] Test
\end{description}
As can be seen in \ref{desc:A1} a \gls{KG} is...

\RenewCommandCopy{\descriptionlabel}{\orgdescriptionlabel}
\printglossary[type=\acronymtype]
    
\end{document}

Note the use of \NewCommandCopy and \RenewCommandCopy that are a lot safer than \let (you need a fairly recent version of LaTeX). Also \protected@edef is better than \edef.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .