LaTeX forum ⇒ MakeIndex, Nomenclature, Glossaries and AcronymsCombining 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?

Postby eezacque » Mon Feb 10, 2020 2:39 pm

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.

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2.  
  3. \usepackage{imakeidx}
  4. \usepackage{enumitem}
  5. \usepackage[automake]{glossaries}
  6.  
  7. \makeindex
  8.  
  9. \makeatletter
  10. \def\ifentry#1#2#3{%
  11. \edef\tmp{#1}%
  12. \ifx\tmp\@empty%
  13. #3%
  14. \else%
  15. #2%
  16. \fi%
  17. }
  18. \makeatother
  19.  
  20. \newglossarystyle{descriptiontest}{%
  21.  
  22. \setglossarystyle{indexgroup}
  23.  
  24. \renewcommand{\glossentry}[2]{
  25. \item \textbf{{\glossentryname{##1}}}
  26. \edef\tmp{\glsentrydesc{##1}}
  27. \ifentry\tmp{Description: '\tmp'}{No description}
  28.  
  29. }
  30. }
  31.  
  32. \newglossaryentry{ham}{name={ham}, description={goes with eggs\index{ham}}}
  33. \newglossaryentry{eggs}{name={eggs}, description=}
  34.  
  35. \makeglossaries
  36.  
  37.  
  38.  
  39. \begin{document}
  40.  
  41. \glsaddall
  42.  
  43. \printglossary[style=descriptiontest]
  44.  
  45. \end{document}

eezacque
Posts: 7
Joined: Mon Jan 06, 2020 5:47 pm

Postby eezacque » Thu Feb 13, 2020 2:28 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:


Return to “MakeIndex, Nomenclature, Glossaries and Acronyms”

Who is online

Users browsing this forum: No registered users and 2 guests