LaTeX forum ⇒ MakeIndex, Nomenclature, Glossaries and Acronyms ⇒ Combining glossaries and index?

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
eezacque
Posts: 7
Joined: Mon Jan 06, 2020 5:47 pm

Combining glossaries and index?

I am working on a document where glossary entries are referred to from the index. This works, until I add conditional text, indicating whether a description was added or not. It looks like TeX falls into an unbounded recursion, but I cannot seem to wrap my head around this. Without adding an index entry, this works. Any help is appreciated.

\documentclass{article}

\usepackage{imakeidx}
\usepackage{enumitem}
\usepackage[automake]{glossaries}

\makeindex

\makeatletter
\def\ifentry#1#2#3{%
\edef\tmp{#1}%
\ifx\tmp\@empty%
#3%
\else%
#2%
\fi%
}
\makeatother

\newglossarystyle{descriptiontest}{%

\setglossarystyle{indexgroup}

\renewcommand{\glossentry}[2]{
\item \textbf{{\glossentryname{##1}}}
\edef\tmp{\glsentrydesc{##1}}
\ifentry\tmp{Description: '\tmp'}{No description}

}
}

\newglossaryentry{ham}{name={ham}, description={goes with eggs\index{ham}}}
\newglossaryentry{eggs}{name={eggs}, description=}

\makeglossaries

\begin{document}

\printglossary[style=descriptiontest]

\end{document}

eezacque
Posts: 7
Joined: Mon Jan 06, 2020 5:47 pm
Sorted out by Nicola Talbot on usenet group comp.text.tex:
The glossaries package comes with conditional commands for testing if a
key has been set. \ifglshasdesc not only tests for an empty description
but also tests if the description has simply been set to \nopostdesc: