2

I am using the glossaries package for glossary entries and abbreviations. In the English language that is pretty easy but other languages (e.g. German) inflect words depending on the casus.

I have tried to deal with this in the following way:

% !TeX program = pdflatex

\documentclass[a4paper,ngerman]{article}
\usepackage{babel}
\usepackage{hyperref}

% ------- glossaries preamble -------

% must be loaded after hyperref, babel, polyglossia, inputenc and fontenc
\usepackage[xindy,nogroupskip,nopostdot,numberedsection]{glossaries}
\makeglossaries
\renewcommand*{\glossaryentrynumbers}[1]{{\footnotesize(s.\,S.~#1)}}

\glsaddkey*
    {dativ}% key
    {\PackageError{glossaries}{no dativ form specified}{}}% default value
    {\glsentrydat}% command analogous to \glsentrytext
    {\Glsentrydat}% command analogous to \Glsentrytext
    {\glsdat}% command analogous to \glstext
    {\Glsdat}% command analogous to \Glstext
    {\GLSdat}% command analogous to \GLStext

\renewcommand\glspluralsuffix{\PackageError{glossaries}{no plural form specified}{}}


% ------- definition of abbreviations and glossary entries -------

\newacronym[dativ=Technischen Universität Berlin]{TUB}{TUB}{Technische Universität Berlin}


% ------- main -------

\begin{document}
An der \glsdat{TUB} \ldots\
An der \glsdat{TUB} \ldots\
An der \glsdat{TUB} \ldots

\printglossaries
\end{document}

But \glsdat{TUB} always prints the long form instead of "Technischen Universität Berlin (TUB)" the first time and "TUB" in later uses. This makes sense considering that \glsdat has been defined to be analogous to \glstext.

How do I define a new command analogous to \gls but which uses the dativ field as long form?


I have looked into the documentation of the glossaries-extra package and it sounded very promising saying: "The acronym mechanism implemented by the base glossaries package is insufficiently flexible for some documents. The glossaries-extra package provides a completely different mechanism to deal with abbreviations in a more flexible manner." But I have failed to find anything regarding my question in there.

1
  • 1
    While a different package, acro has good support for this sort of customisation
    – Dai Bowen
    Commented May 8 at 16:54

1 Answer 1

1

EDIT: My original answer worked with acronyms only, with "normal" glossary entries it printed an empty text. Therefore I have added an if statement to check if it is a acronym, if yes I am using the original answer, if no I am using \glsdativ.

% !TeX program = pdflatex

\documentclass[a4paper,ngerman]{article}
\usepackage{babel}
\usepackage{hyperref}

% ------- glossaries preamble -------

% must be loaded after hyperref, babel, polyglossia, inputenc and fontenc
\usepackage[xindy,nogroupskip,nopostdot,numberedsection]{glossaries}
\makeglossaries
\renewcommand*{\glossaryentrynumbers}[1]{{\footnotesize(s.\,S.~#1)}}

\glsaddkey*
    {dativ}% key
    {\PackageError{glossaries}{no dativ form specified}{}}% default value
    {\glsentrydativ}% command analogous to \glsentrytext
    {\Glsentrydativ}% command analogous to \Glsentrytext
    {\glsdativ}% command analogous to \glstext
    {\Glsdativ}% command analogous to \Glstext
    {\GLSdativ}% command analogous to \GLStext

\newcommand\glsdat[1]{%
    \ifglshasfield{long}{#1}{%
        % If the glossary entry has the field "long" it is an acronym.
        % I temporarily replace the long form of the acronym with it's Dativ form and use the usual \gls command which handles whether the short form or both forms should be used.
        \begingroup
            \glsfielddef{#1}{long}{\glsentrydativ{#1}}%
            \gls{#1}%
        \endgroup
    }{%
        % If it is not an acronym I simply use the dativ field.
        \glsdativ{#1}%
    }%
}

\renewcommand\glspluralsuffix{\PackageError{glossaries}{no plural form specified}{}}


% ------- definition of abbreviations and  -------

\newacronym[dativ=Technischen Universität Berlin]{TUB}{TUB}{Technische Universität Berlin}
\newglossaryentry{Lampe}{name=Lampe, description=Ein Leuchtmittel}


% ------- main -------

\begin{document}
An der \glsdat{TUB} \ldots\
An der \glsdat{TUB} \ldots\
An der \glsdat{TUB} \ldots

An der \gls{Lampe} liegt es nicht.

\printglossaries
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .