1

I'm trying to lay out the glossary using the glossaries package. I'm using the index style and I'm trying to add a colon after the acronym.

\documentclass{article}
\usepackage[acronyms,nomain]{glossaries}

\makeglossaries
\newacronym{ABC}{ABC}{Alpha Bravo Charlie}
\newacronym{NASA}{NASA}{National Aeronautics and Space Administration}
\newacronym{NSA}{NSA}{National Security Agency}
\newacronym{NATO}{NATO}{North Atlantic Treaty Organization}
\newacronym{EU}{EU}{European Union}
\newacronym{ECDC}{ECDC}{European Centre for Disease Prevention and Control}
\newacronym{EWRS}{EWRS}{Early Warning and Response System}
\newacronym{USA}{USA}{United States of America}

\begin{document}

\gls{ABC}
\gls{NASA}
\gls{NSA}
\gls{NATO}
\gls{EU}
\gls{ECDC}
\gls{EWRS}
\gls{USA}

\setglossarystyle{index}
\renewcommand*{\glsgroupskip}{\vspace{8pt}}
\printglossary[type=\acronymtype,title=Glossary]

\newglossarystyle{mystyle}{%
    \setglossarystyle{index}%
    \renewcommand*{\glsgroupskip}{\vspace{8pt}}%
    \renewcommand*{\glossentry}[2]{%
        \textbf{\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}:}}
        \glossentrydesc{##1}\glspostdescription\space ##2\\
    }%
}
\setglossarystyle{mystyle}
\printglossary[type=\acronymtype,title=Glossary]

\end{document}

Note that the first glossary, which uses the index style alone, properly groups items alphabetically. However, when I use my own style, which appends a colon to the entry name, suddenly the grouping becomes incorrect. What am I doing wrong?

1 Answer 1

1

Using \par rather than \\ seems to give the desired result, but the real problem appears to be that your \glossentry deviates too far from the \glossentry defined in the index style, which uses a list and expects \item.

Instead modifying the \glossentry defined in the index style to insert a colon

\renewcommand*{\glossentry}[2]{%
    \item\glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}%
    \ifglshassymbol{##1}{\space(\glossentrysymbol{##1})}{}%
    \glstreenamefmt{:}%  <== This line added
    \glstreepredesc \glossentrydesc{##1}\glspostdescription\space ##2%
}%

seems more like what you would want.

Compiled code

\documentclass{article}
\usepackage[acronyms,nomain]{glossaries}

\makeglossaries
\newacronym{ABC}{ABC}{Alpha Bravo Charlie}
\newacronym{NASA}{NASA}{National Aeronautics and Space Administration}
\newacronym{NSA}{NSA}{National Security Agency}
\newacronym{NATO}{NATO}{North Atlantic Treaty Organization}
\newacronym{EU}{EU}{European Union}
\newacronym{ECDC}{ECDC}{European Centre for Disease Prevention and Control}
\newacronym{EWRS}{EWRS}{Early Warning and Response System}
\newacronym{USA}{USA}{United States of America}

\begin{document}

\gls{ABC}
\gls{NASA}
\gls{NSA}
\gls{NATO}
\gls{EU}
\gls{ECDC}
\gls{EWRS}
\gls{USA}

\setglossarystyle{index}
\renewcommand*{\glsgroupskip}{\vspace{8pt}}
\printglossary[type=\acronymtype,title=Glossary]

\newglossarystyle{mystyle}{%
    \setglossarystyle{index}%
    \renewcommand*{\glsgroupskip}{\vspace{8pt}}%
    \renewcommand*{\glossentry}[2]{%
        \item\glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}%
        \glstreenamefmt{:}%
        \ifglshassymbol{##1}{\space(\glossentrysymbol{##1})}{}%
        \glstreepredesc \glossentrydesc{##1}\glspostdescription\space ##2%
    }%
}
\setglossarystyle{mystyle}
\printglossary[type=\acronymtype,title=Glossary]

\end{document}
2
  • Oh, I assumed index specifically didn't use a list, since it's not listed in 13.1.1 List Styles in the documentation. Thank you. Commented Aug 19, 2023 at 20:55
  • If you dig into the documented code you can find the exact definitions used by searching for \newglossarystyle{index}.
    – Dai Bowen
    Commented Aug 19, 2023 at 21:26

You must log in to answer this question.

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