Some adjustments for LaTeX glossaries

Tags: latex, howtos

Published on
« Previous post: Fun with unsequenced operations — Next post: Towards Shakespearean Social Network … »

I am using the fine glossaries package to typeset glossaries and acronyms in my dissertation.

While the default settings are not bad, I like to do some custom adjustments to get the glossaries printed just right.

Capitalized descriptions in the glossary

I want entries in the glossary to be capitalized—regardless of the original capitalization. Hence, I prefer minimum spanning tree (MST), but in the glossary, I want it to be written as Minimum spanning tree. To get the package to comply, I find the easiest way to do this is to define a new glossary style. Since I like the long glossary style, I can inherit all features from it and only need to change a small part:

\newglossarystyle{long-br}{%
  \setglossarystyle{long}

  \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \Glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
  }%
}

\setglossarystyle{long-br}

The salient change is the usage of \Glossentrydesc instead of \glossentrydesc, which ensures that the description is printed capitalized.

Non-breaking spaces in the long-short form of an acronym

When glossaries typesets an acronym, I prefer the long-short form. For example, the first use of an acronym should look like minimum spanning tree (MST). Unfortunately, the space between the long form and the short form permits a line-break. This is of course unacceptable and needs to be rectified. The easiest way to solve this is to use

\renewcommand{\acrfullformat}[2]{#1~(#2)}   

in the preamble of the document. This does not work when you use a custom style, though. See below if you want to copy my style.

Printing acronyms always upright in the long-short form

When the long-short form of an acronym is used, I prefer any text decorations only to apply to the long description, but not to the acronym. Consequently, I like minimum spanning tree (MST) better than I like minimum spanning tree (MST). To achieve this, we need to define our own style. Again, I like the long-short style, so I am going to base the custom style upon it:

\newacronymstyle{long-short-br}
{%
  \GlsUseAcrEntryDispStyle{long-short}%
}%
{%
  \GlsUseAcrStyleDefs{long-short}%  
  \renewcommand*{\genacrfullformat}[2]{%
    \glsentrylong{##1}##2~\textup{(\firstacronymfont{\glsentryshort{##1}})}%
  }%
  \renewcommand*{\Genacrfullformat}[2]{%
    \Glsentrylong{##1}##2~\textup{(\firstacronymfont{\glsentryshort{##1}})}%
  }%
  \renewcommand*{\genplacrfullformat}[2]{%
    \glsentrylongpl{##1}##2~\textup{(\firstacronymfont{\glsentryshortpl{##1}})}%
  }%
  \renewcommand*{\Genplacrfullformat}[2]{%
    \Glsentrylongpl{##1}##2~\textup{(\firstacronymfont{\Glsentryshortpl{##1}})}%
  }%
}

\setacronymstyle{long-short-br}

Note that this style also uses a non-breaking space ~ to connect the long form to the short form. If you do not want this, just use \space instead.

That’s it for now—as soon as I have found out more ways to procrastinate when using LaTeX, there will be a new post.