Latest news 2024-10-15: New blog post: Tales for Our Times Book Launch.

Gallery: Abbreviations With Translations

image of document containing a sample section and abbreviation list including translations in parentheses
This example emulates a set of abbreviations where some of the abbreviations have an accompanying translation. The translations are specified using the user1 key (internally the useri field).

This example document is like the Acronyms (With Translations) example but this uses the glossaries-extra extension package whereas the other example just uses the basic glossaries package.

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}

I’ve used the long-short-user abbreviation style in the document, which was introduced to version 1.04 of glossaries-extra.sty, so this example won’t work with older versions. Note that the sample file uses \newacronym not \newabbreviation. To make the transition from the base package’s acronym mechanism to the extension package’s new abbreviation mechanism, the glossaries-extra package redefines \newacronym to use \newabbreviation with category=acronym. This means that when you set the abbreviation style, you need to specify the acronym category (rather than the default abbreviation category):

\setabbreviationstyle[acronym]{long-short-user}

The style is modified slightly to prefix the parenthetical material with “English:” by redefining \glsxtruserparen:

\renewcommand*{\glsxtruserparen}[2]{%
  \glsxtrfullsep{#2}%
  (#1\ifglshasfield{\glsxtruserfield}{#2}{, English: \glscurrentfieldvalue}{})%
}

This requires at least version 4.23 of glossaries.sty in order to use \glscurrentfieldvalue. To illustrate how to change the font with this abbreviation style, I’ve redefined the associated font commands to use small-caps for the short form:

\renewcommand{\glsabbrvuserfont}[1]{\textsc{\MakeLowercase{#1}}}
\renewcommand*{\glsxtrusersuffix}{\glsxtrscsuffix}

I’ve used the long-booktabs style, provided by the glossary-longbooktabs package, which can easily be loaded with the stylemods=longbooktabs package option. I’ve modified the post-description hook for the abbreviation category to ensure the translation appears in the list of abbreviations:

\renewcommand{\glsxtrpostdescacronym}{%
 \ifglshasfield{\glsxtruserfield}{\glscurrententrylabel}%
 { (English: \glscurrentfieldvalue)}%
 {}%
}

I’ve used the abbreviations package option to create the abbreviations 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.

Note that in the sample file 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:

\loadglsentries[abbreviations]{example-glossaries-acronyms-lang}

The complete document code is shown below. 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[T1]{fontenc}
\usepackage[colorlinks]{hyperref}
\usepackage[abbreviations,% create "abbreviations" glossary
            nomain,% don't create "main" glossary
            stylemods=longbooktabs% do the adjustments for the longbooktabs styles
           ]{glossaries-extra}

\makeglossaries

% The entries in the sample file are all defined using
% \newacronym, which automatically sets the category
% to "acronym". This means that the abbreviation style needs
% to use "acronym" in the optional argument. The glossary
% can be adapted by using the post-description hook for this
% category.

\setglossarystyle{long-booktabs}

% \glscurrentfieldvalue only works with glossaries v4.23 (and above)
\renewcommand{\glsxtrpostdescacronym}{%
 \ifglshasfield{\glsxtruserfield}{\glscurrententrylabel}%
 { (English: \glscurrentfieldvalue)}%
 {}%
}

\setabbreviationstyle[acronym]{long-short-user}

% Translations are stored in the user1 key in the sample file
% (loaded below).
% This is the default for the long-short-user style so
% \glsxtruserfield doesn't need changing, but let's illustrate
% changing the font style for the short form:

\renewcommand{\glsabbrvuserfont}[1]{\textsc{\MakeLowercase{#1}}}
\renewcommand*{\glsxtrusersuffix}{\glsxtrscsuffix}

% This is only a minor modification to the default format to 
% add "English: " in front of the translation. Requires glossaries
% v4.23 (or later)

\renewcommand*{\glsxtruserparen}[2]{%
  \glsxtrfullsep{#2}%
  (#1\ifglshasfield{\glsxtruserfield}{#2}{, English: \glscurrentfieldvalue}{})%
}

% Load the entries from the sample file and put them in the
% "abbreviations" glossary.
\loadglsentries[abbreviations]{example-glossaries-acronyms-lang}

\begin{document}

\section{Sample}

First use:

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

Next use:

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

\printglossaries

\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}.

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

pdflatex abbreviations-lang
makeglossaries abbreviations-lang
pdflatex abbreviations-lang

(See Incorporating makeglossaries or makeglossaries-lite or bib2gls into the document build.)

The glossaries-extra package automatically sets the toc option to add the glossary to the table of contents (if one is later required), and the nopostdot option, which removes 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.

Download: PDF (51.54K), source code (1.93K), sample glossary definitions (647B).