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
\newacropair{acr:adc}{ADC}{Analog-Digital-Umsetzer}{Analog to Digital Converter}
% 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.
\newcommand{\glsalt}[2]{\glslink{#1}{#2 (\acrshort*{#1}\glsdesc*{#1})}\glsunset{#1}}
\begin{document}
\section{Problems}
% For the first mention, I'll be using \glsalt, since I need to display the
% German text in genitive.
Die Aufloesung des \glsalt{acr:adc}{Analog-Digital-Umsetzers} beeinflusst\dots
% 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.
Die Aufloesung der \glsalt{acr:adc}{Analog-Digital-Umsetzer} beeinflusst\dots
\section{Normal Cases}
\glsreset{acr:adc}
% These are only to show how it should look like for the 'normal' cases.
\gls{acr:adc} -- \gls{acr:adc}
\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?