Gallery: Abbreviations (With Translations)

If you have a small screen, you may prefer to switch on the small image setting.

This example emulates a set of acronyms where some of the acronyms have an accompanying translation. See Abbreviations With Translations for a simpler alternative that uses the glossaries-extra extension package.

In this example, the translations are specified using the user1 key (internally the useri field). This means that none of the predefined acronym styles are suitable if the first use must also show the translation. Therefore this example defines a custom acronym style (with \newacronymstyle) that will insert the translation on first use (if one has been provided).

\newacronymstyle{acronymslang}%
{%
\GlsUseAcrEntryDispStyle{long-short}%
}
{%
\GlsUseAcrStyleDefs{short-long}%
\renewcommand*{\genacrfullformat}[2]{%
\glsentrylong{##1}##2\space
(\protect\firstacronymfont{\glsentryshort{##1}}%
\ifglshasfield{useri}{##1}%
{, English: \glsentryuseri{##1}}{})%
}%
\renewcommand*{\Genacrfullformat}[2]{%
\Glsentrylong{##1}##2\space
(\protect\firstacronymfont{\glsentryshort{##1}}%
\ifglshasfield{useri}{##1}%
{, English: \glsentryuseri{##1}}{})%
}%
\renewcommand*{\genplacrfullformat}[2]{%
\glsentrylongpl{##1}##2\space
(\protect\firstacronymfont{\glsentryshortpl{##1}}%
\ifglshasfield{useri}{##1}%
{, English: \glsentryuseri{##1}}{})%
}%
\renewcommand*{\Genplacrfullformat}[2]{%
\Glsentrylongpl{##1}##2\space
(\protect\firstacronymfont{\glsentryshortpl{##1}}%
\ifglshasfield{useri}{##1}%
{, English: \glsentryuseri{##1}}{})%
}%
}


A custom glossary style (defined with  \newglossarystyle) is required to ensure the translation also appears in the list of acronyms. The command \ifglshasfield can be used to determine if the field has been set. If it has, the translation is appended in parentheses (prefixed with “English:”) after the description. The style is based on the long style to create a two-column list.

\newglossarystyle{acronymslang}
{%
\setglossarystyle{long}%
\renewcommand*{\glsgroupskip}{}%
\renewcommand{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
\glossentrydesc{##1}\glspostdescription
\ifglshasfield{useri}{##1}{ (English: \glsentryuseri{##1})}{}%
\space ##2\tabularnewline
}%
}


I’ve used the acronym option to define the acronym glossary. Since I’m not using the main glossary, there’s no point defining it, so I’ve used nomain to suppress its creation. Obviously, if you want to adapt this example so that it also uses the main glossary, you should remove the nomain option.

The initial comment lines below are arara directives. You can remove them if you don’t use arara.

% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}

\usepackage[nopostdot,% suppress dot after description
acronym,% create the "acronym" glossary
nomain% don't create the "main" glossary
]{glossaries}

\makeglossaries

% define an acronym style for the acronyms with a translation:

\newacronymstyle{acronymslang}%
{%
\GlsUseAcrEntryDispStyle{long-short}%
}
{%
\GlsUseAcrStyleDefs{short-long}%
\renewcommand*{\genacrfullformat}[2]{%
\glsentrylong{##1}##2\space
(\protect\firstacronymfont{\glsentryshort{##1}}%
\ifglshasfield{useri}{##1}%
{, English: \glsentryuseri{##1}}{})%
}%
\renewcommand*{\Genacrfullformat}[2]{%
\Glsentrylong{##1}##2\space
(\protect\firstacronymfont{\glsentryshort{##1}}%
\ifglshasfield{useri}{##1}%
{, English: \glsentryuseri{##1}}{})%
}%
\renewcommand*{\genplacrfullformat}[2]{%
\glsentrylongpl{##1}##2\space
(\protect\firstacronymfont{\glsentryshortpl{##1}}%
\ifglshasfield{useri}{##1}%
{, English: \glsentryuseri{##1}}{})%
}%
\renewcommand*{\Genplacrfullformat}[2]{%
\Glsentrylongpl{##1}##2\space
(\protect\firstacronymfont{\glsentryshortpl{##1}}%
\ifglshasfield{useri}{##1}%
{, English: \glsentryuseri{##1}}{})%
}%
}

\setacronymstyle{acronymslang}

% glossary style for acronyms with a translation

\newglossarystyle{acronymslang}
{%
\setglossarystyle{long}%
\renewcommand*{\glsgroupskip}{}%
\renewcommand{\glossentry}[2]{%
\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
\glossentrydesc{##1}\glspostdescription
\ifglshasfield{useri}{##1}{ (English: \glsentryuseri{##1})}{}%
\space ##2\tabularnewline
}%
}

\begin{document}

\section{Sample}

First use:

\forglsentries{\thislabel}{\gls{\thislabel}. }

Next use:

\forglsentries{\thislabel}{\gls{\thislabel}. }

\printglossary[type=acronym,style=acronymslang]

\end{document}


This document loads the hyperref package, which creates hyperlinks from the entries in the document (referenced using commands like \gls) to their definition in the glossary. These hyperlinks are displayed in red text. I’ve used \forglsentries for this example to iterate over all the defined entries. In practice, you would typically just use commands like \gls{label} in the text. For example:

Here is a reference to the term \gls{li}.


The entries have all been defined in the file example-glossaries-acronyms-lang.tex, which you should find installed in the same location as the glossaries package (or in a sub-directory called test-entries). The entry definitions look like this:

\newacronym[type=\glsdefaulttype,user1={love itself}]{li}{LI}{lorem
ipsum}

\newacronym[type=\glsdefaulttype,user1={produces
none}]{np}{NP}{nulla pariatur}

\newacronym[type=\glsdefaulttype,user1={blame
belongs}]{sic}{SIC}{sunt in culpa}


Note that I’ve used type=\glsdefaulttype to allow for situations where I might want to load the entries into a different glossary. (For example, I may want to have multiple lists of acronyms for different subject areas.) The target glossary is specified in the optional argument of \loadglsentries.

If you don’t use arara, you need to run the following commands:

pdflatex acronym-lang
makeglossaries acronym-lang
pdflatex acronym-lang


I’ve used the toc option to add the glossary to the table of contents (if one is later required). I’ve also used the nopostdot option to remove the terminating full stop that is placed by default after the description. The entries all have a “1” after the description. This is the page number on which the entry was referenced. In this sample document all the entries were referenced on page 1. If you don’t want these numbers you can use the nonumberlist option.