# Using the glossaries package for English acronyms in German documents

This is a repost of the original message I posted to comp.text.tex in August, which is still unanswered there. I'm sorry for reposting, but I want to spread this to a wider readership.

I found couple of similar questions (along with helpful answers) on StackExchange, however, they are more focused on how to deal with the variety of cases the German language has. This is not my actual problem, since the suggested workarounds for this issue are sufficient. They mostly incorporate the use of \glslink and \glsdisp.

Below is the text of my original post.

I would like to use the glossaries package for German documents including many English based acronyms. For better understanding, let's have a look at a simple example:

• Acronym: PSK
• English long: Phase Shift Keying
• German long: Phasenumtastung

Im most cases, there is not corresponding acronym in German, therefore I would like to use the English acronym in my document. Upon first use, the inserted text shall look like

Phasenumtastung (PSK, Phase Shift Keying)

Upon further use, only

PSK

shall be used.

Finally, in the list of acronyms, it shall look like:

PSK - Phasenumtastung (Phase shift Keying)

I tried to to setup something customized by renewing \CustomAcronymFields, \SetCustomDisplayStyle and \glossaryentryfield following the user documentation. I'm using the current version 3.01 of glossaries.

My approach is basically to put the string ", Phase Shift Keying" into the description field while defining with \newacronym and then use it with customized \defglsdisplayfirst and \glossaryentryfield.

This is to demonstrate how it should look like:

% compile this with
%    pdflatex example.tex
%    makeindex  -s "example.ist" -t "example.alg" -o "example.acr" "example.acn"
%    pdflatex example.tex

\documentclass{scrartcl}

\usepackage[ngerman]{babel}

\usepackage[acronym,nomain,sanitize={description=false,symbol=false}]{glossaries}
\makeglossaries

%% Desired style:
% first: "German long (acronym[, English long])"
% following: "acronym"
\renewcommand*{\CustomAcronymFields}{%
name={\the\glsshorttok},%
symbol={\the\glslongtok},%
text={\the\glsshorttok},%
plural={\the\glsshorttok\noexpand\acrpluralsuffix}%
}

\renewcommand*{\SetCustomDisplayStyle}[1]{%
% ##1 corresponds to the 'first' key
% ##2 corresponds to the 'description' key
% ##3 corresponds to the 'symbol' key
% ##4 is the inserted text given by the final optional argument to
% commands like \gls
% The short form can be obtained via \glsentryshort{\glslabel}
% The plural short form can be obtained via
%\glsentryshortpl{\glslabel}
% The long form can be obtained via \glsentrylong{\glslabel}
% The plural long form can be obtained via
%\glsentrylongpl{\glslabel}
\defglsdisplayfirst[#1]{##3 (##1##4##2##4)}%
% ##1 corresponds to the 'text' key
% the rest as above
\defglsdisplay[#1]{##1##4}%
}
\SetCustomStyle

% start the glossary entries with capitals
\newglossarystyle{superuc}{%
\glossarystyle{super}%
\renewcommand*\glossaryentryfield[5]{%
\glstarget{##1}{##2} & \makefirstuc{##4}##3\glspostdescription\space##5\\
}
}

%% acronym definitions
% italic typeset foreign language terms
\newcommand{\foreignlang}[1]{\emph{#1}}
% define acronym with both German and English long
\newcommand{\newacropair}[4]{\newacronym[description={, \foreignlang{#4}}]{#1}{#2}{#3}}
% define acronym with only German long
\newcommand{\newacrogerman}[3]{\newacronym[description={}]{#1}{#2}{#3}}
% define acronym with only English long
\newcommand{\newacroenglish}[3]{\newacronym[description={}]{#1}{#2}{\foreignlang{#3}}}

% sample acronyms
% English acronym along with its common German counterpart
% English acronym without a common German counterpart
\newacroenglish{acr:dect}{DECT}{Digital Enhanced Cordless Telecommunications}
% German acronym
\newacrogerman{acr:din}{DIN}{Deutsches Institut fuer Normung}

% Alternative first - to be used if the first use is not nominative singular.
% Problem: I do not find a way to use glossaries' integrated 'first use' flag.
% This macro is my current dirty implementation. It always displays the full form
% and unsets the 'first use' flag afterwards. Bad things happen if at a later point
% it time, I decide to mention the same acronym earlier. I'll be using \glsalt again
% and end up in a double definition of the acronym, which I would like to avoid.

\begin{document}

\section{Problems}

% For the first mention, I'll be using \glsalt, since I need to display the
% German text in genitive.

% In the example below, I would need a plural form. That means an 's' would
% have to be attached to both the English acronym as well as the English long form.
% I have no clue how to implement that cleanly, due to my changes in
% \SetCustomDisplayStyle in the preamble.

\section{Normal Cases}

% These are only to show how it should look like for the 'normal' cases.

\gls{acr:dect} -- \gls{acr:dect}

\gls{acr:din} -- \gls{acr:din}

\printglossary[type=\acronymtype,style=superuc,nonumberlist=false]

\end{document}


This works for me unless I don't have to use the plural form upon the first occurence. From then on, the concept behind glossaries, so far I can understand, does not really allow my tweak.

The main reason, to my understanding, is the fact that when defining a new acronym by \newacronym, besides the label, only one short form and one long form can be passed and accessed in \CustomAcronymFields. These two can be accessed by \glsshorttok and \glslongtok for storing them under the user-defined keys, such as name, symbol, text, etc. Especially the description key itself cannot be accessed at this stage.

From the conceptual point of view, it would be helpful if all three forms (short, English long, German long) could be passed to \newacronym separately and then concatenated in a customized fashion to be finally stored with their corresponding keys, including firstplural and longplural. Note that for my example, I would e.g. have to append an "s" for the plural forms of the short form as well as to the English long form and provide a used-defined plural form for the German long form in most cases.

For now, my only question is whether you think that my problem can still be solved with what glossaries offers so far. If not, would it make sense to try to redefine a couple of commands? I've had the impression that e.g. \glsentryfull has to be redefined. However, one major problem I fear is that most of these commands only take a subset of keys, such as only short and long (not description) in case of \glsentryfull.

Or is there even another package which would do my task without modifications?

• Your question is lacking (like the orginal question on c.t.t) a complete minimal example that could be used for testing. – Ulrike Fischer Oct 12 '11 at 10:27
• @UlrikeFischer, you are right. My question is more a conceptual one, therefore I did not create one yet. I will add one asap. – Christoph Oct 12 '11 at 11:02
• Well your example actually don't show your problem with the plural. Apart from this: You are writing a german text so I think you should try to translate also "Enhanced Data Rate". At second I think you are putting to much emphasis on the "foreign language" aspect. The main attribute of the text behind the acronym is not that it is in english but that it explains its origin. There could also stand a text like "first used in the novel ...". Also I doubt that you actually need language dependant \newacronym commands. – Ulrike Fischer Oct 12 '11 at 12:28
• Well, this stuff is used in the context of communication technologies. 99% of the acronyms are English, and some of them do not have a common German counterpart. So it is for EDR -- sure I could translate it to erweiterte Datenrate, however, in the context of the document, this is uncommon. Maybe EDR is not the best example, I will replace it by another one. – Christoph Oct 12 '11 at 13:57
• You should put @Ulrike in comments so that I get notified of your answers. I do understand your problem with the multitudity of english technical terms, nevertheless I do think you should make an effort to keep them at bay. But the main point of my comment was that imho you should change your point of view: don't divide your acronyms in "german" and "english" acronyms. Actually you seem to have currently at least 3 types: normal (DIN), commented (ADC), name with additional formating (EDR). – Ulrike Fischer Oct 12 '11 at 15:11

The simplest method is to use the glossaries-extra package. The translation is stored in the user1 key. The long-short-user abbreviation style is designed to include additional information in the parenthetical material on first use. By default it picks up the information from the user1 field.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[acronym,
nomain,% don't create "main" glossary
postdot% put a period after the description
]{glossaries-extra}

\makeglossaries

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

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

\newacronym[user1=Phase Shift Keying]{psk}{PSK}{Phasenumtastung}
\newacronym{aa}{AA}{Another Acronym}

\begin{document}

First use: \gls{psk}. Subsequent use: \gls{psk}.

First use: \gls{aa}. Subsequent use: \gls{aa}.

\printglossaries

\end{document}


The post-description hook (\glsxtrpostdesccategory) appends information after the description in the glossary. This is a convenient way of making a minor adjustment without having to define a new glossary style.

If you prefer to use \newabbreviation instead of \newacronym, you need to redefine \glsxtrpostdescabbreviation instead of \glsxtrpostdescacronym and use \setabbreviationstyle{long-short-user} instead of \setabbreviationstyle[acronym]{long-short-user}. (\newacronym implicitly sets category=acronym and \newabbreviation implicitly sets category=abbreviation.)

If you want to stick with just the base glossaries package, it's slightly more complicated. The translation is still provided in the user1 field:

\documentclass{article}

\usepackage{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}%
{, \glsentryuseri{##1}}{})%
}%
\renewcommand*{\Genacrfullformat}[2]{%
\Glsentrylong{##1}##2\space
(\protect\firstacronymfont{\glsentryshort{##1}}%
\ifglshasfield{useri}{##1}%
{, \glsentryuseri{##1}}{})%
}%
\renewcommand*{\genplacrfullformat}[2]{%
\glsentrylongpl{##1}##2\space
(\protect\firstacronymfont{\glsentryshortpl{##1}}%
\ifglshasfield{useri}{##1}%
{, \glsentryuseri{##1}}{})%
}%
\renewcommand*{\Genplacrfullformat}[2]{%
\Glsentrylongpl{##1}##2\space
(\protect\firstacronymfont{\glsentryshortpl{##1}}%
\ifglshasfield{useri}{##1}%
{, \glsentryuseri{##1}}{})%
}%
}

\setacronymstyle{acronymslang}

\newacronym[user1=Phase Shift Keying]{psk}{PSK}{Phasenumtastung}
\newacronym{aa}{AA}{Another Acronym}

% 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}{ (\glsentryuseri{##1})}{}%
\space ##2\tabularnewline
}%
}

\setglossarystyle{acronymslang}

\begin{document}

First use: \gls{psk}. Subsequent use: \gls{psk}.

First use: \gls{aa}. Subsequent use: \gls{aa}.

\printglossaries
\end{document}


This doesn't have the benefit of the post-description hook so a custom glossary style is required. The difference between the two methods can be seen from the position of the period (full-stop) inserted after the description through the postdot or postpunc=dot (glossaries-extra only) or nopostdot=false package options. With the glossaries-extra post-description hook the terminating punctuation is placed after the hook.

My original answer used an old version of glossaries and had to use internal commands, which isn't desirable. It's better to update to a newer version and use one of the above methods instead. There's no custom glossary style as it uses a hack to append the user1 contents to the description field.

\documentclass{article}

\usepackage{glossaries}
\usepackage{etoolbox}

\newtoks\customtok

\renewcommand*{\newacronymhook}{%
\edef\dosetkeys{\noexpand\setkeys{glossentry}{user1={},\the\glskeylisttok}}%
\dosetkeys
\ifcsempty{@glo@useri}%
{%
\expandafter\customtok\expandafter{\the\glsshorttok}%
}%
{%
\edef\custom{\the\glsshorttok, \csexpandonce{@glo@useri}}%
\expandafter\customtok\expandafter{\custom}%
}%
}

\newcommand*{\custompostdesc}[1]{%
\ifcsempty{glo@#1@useri}{}{ (\glsentryuseri{#1})}%
}

\renewcommand*{\CustomAcronymFields}{%
user1={},%
name={\the\glsshorttok},%
description={\the\glslongtok\noexpand\custompostdesc{\the\glslabeltok}},%
first={\the\glslongtok\space(\the\customtok)},%
firstplural={\the\glslongtok\noexpand\acrpluralsuffix
\space (\the\customtok)}%
text={\the\glsshorttok},%
plural={\the\glsshorttok\noexpand\acrpluralsuffix}%
}

\SetCustomStyle

\makeglossaries

\newacronym[user1=Phase Shift Keying]{psk}{PSK}{Phasenumtastung}
\newacronym{aa}{AA}{Another Acronym}

\begin{document}

First use: \gls{psk}. Subsequent use: \gls{psk}.

First use: \gls{aa}. Subsequent use: \gls{aa}.

\printglossaries
\end{document}


• @egreg could you please help me on modifying the code above so it is: OtherLanguage_long (PSK, EnglishLong). I want to store in user1 the OtherLanguage_long. And if possible to use user2 to set the plural for the OtherLanguage_long. – jlanza Nov 18 '13 at 12:00
• @jlanza I suggest you post a new question with a link back to this one. – Nicola Talbot Nov 18 '13 at 12:15
• I have posted the preliminary solution to my problem at tex.stackexchange.com/questions/136634/… I used 2 custom tokens, on for singular and another for plural. I guess I can tune it a bit more automating the plural from the singular, but Spanish is quite strange on plurals ;) – jlanza Nov 18 '13 at 15:31
• Based on the solution I proposed or yours, do you know how to make the custompostdesc to be capitalized on the Glossaries list? I've tried plenty of things mainly from tex.stackexchange.com/questions/103838/… but I get errors :( Could you please help me on that? – jlanza Nov 18 '13 at 16:51