2

I have a large list of symbols and acronyms, which I use with the glossaries package and the makeglossaries program. I write content in more than one language (Portuguese and English, to be more specific) and I wonder if it's possible to write symbol and acronym definitions in more than one language, so that they can be displayed in the glossary and list of acronyms in the same language as the document, or in the language that I choose.

This is an example of what I am looking for

\newglossaryentry{expectation}{type=symbols, name={\ensuremath{\mathbb{E}}}, sort=e, description-en={expectation}, description-pt={expectativa}}
\newacronym{mlp}{MLP}{en={Multi-Layer Perceptron}, pt={Perceptron Multi-Camadas}}

Then I can choose in which language the lists will be printed, e.g. by issuing a command like \printglossaries[en] or \printglossaries[pt].

Are there any packages or programs that are able to manage symbols and acronyms with definitions in multiple languages? Thanks in advance.

1

There is no inbuilt functionality like this in glossaries, but we can patch it in using babel's \languagename.

  1. For normal multilanguage description, I patched \gls@defglossaryentry to use \@mygls@selectdesc in the default value for description. This macro will try to load the description in the current language and issue a warning if there is none. Note that if you explicitly set description in any entry you will overwrite this and the set value will display regardless of \languagename.
  2. For abbreviations/acronyms this does not really make sense, I think, since the acronym is in one language. We can however add translations to the abbreviation and display them if present (no patching of internal commands needed here). For the displaying part, we define a custom glossary style.
\documentclass[spanish]{article}

\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{xparse}
\usepackage{csquotes}
\usepackage[
    abbreviations,
    shortcuts=abbreviations,
    stylemods=longbooktabs,
    nonumberlist,
    ]{glossaries-extra}

\makeglossaries

% Create a custom glossary style for abbreviations, printing a translation if present.
\newglossarystyle{custom-long-booktabs}{%
    \setglossarystyle{long-booktabs}%
    \renewcommand\glossentry[2]{%
        \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
        \glossentrydesc{##1}%
        \glsxtrifhasfield{translation-\languagename}{##1}{%
            \ \small(\enquote{\csname glsentrytrans\languagename\endcsname{##1}})
        }{}%
        \glspostdescription\space ##2\tabularnewline
    }%
}

\makeatletter
    % a macro for selecting the description in the current language
    \def\@mygls@selectdesc#1{%
        \glsxtrifhasfield{description-\languagename}{#1}{%
            \glscurrentfieldvalue
        }{%
            \GenericWarning{}{LaTeX Warning:
                No description for `#1' in language `\languagename'}
        }%
    }
    % replace the default value of description with \@mygls@selectdesc
    \patchcmd\gls@defglossaryentry
        {\let\@glo@desc\@glsnodesc}
        {\def\@glo@desc{\@mygls@selectdesc{#1}}}
        {}{}
    % Add description keys for the different languages.
    \NewDocumentCommand\add@glslangdesckey{m o}{%
        \begingroup
        \edef\@tempa{%
            \endgroup
            \noexpand\glsaddkey*{description-#1}%
                {\IfValueT{#2}{\expandafter\noexpand\csname glsentrydesc#2\endcsname{\noexpand\glslabel}}}%
                \expandafter\noexpand\csname glsentrydesc#1\endcsname
                \expandafter\noexpand\csname Glsentrydesc#1\endcsname
                \expandafter\noexpand\csname glsdesc#1\endcsname
                \expandafter\noexpand\csname Glsdesc#1\endcsname
                \expandafter\noexpand\csname GLSdesc#1\endcsname
        }%
        \@tempa
    }
    \add@glslangdesckey{english}
    \add@glslangdesckey{german}
    \add@glslangdesckey{ngerman}[german]
    \add@glslangdesckey{spanish}
    \add@glslangdesckey{french}
    % Add translation keys for the different languages.
    \NewDocumentCommand\add@glslangtranskey{m o}{%
        \begingroup
        \edef\@tempa{%
            \endgroup
            \noexpand\glsaddkey*{translation-#1}%
                {\IfValueT{#2}{\expandafter\noexpand\csname glsentrytrans#2\endcsname{\noexpand\glslabel}}}%
                \expandafter\noexpand\csname glsentrytrans#1\endcsname
                \expandafter\noexpand\csname Glsentrytrans#1\endcsname
                \expandafter\noexpand\csname glstrans#1\endcsname
                \expandafter\noexpand\csname Glstrans#1\endcsname
                \expandafter\noexpand\csname GLStrans#1\endcsname
        }%
        \@tempa
    }
    \add@glslangtranskey{english}
    \add@glslangtranskey{german}
    \add@glslangtranskey{ngerman}[german]
    \add@glslangtranskey{spanish}
    \add@glslangtranskey{french}
\makeatother

% Define some glossary entries.
\newglossaryentry{one}{
    name=one,
    symbol=1,
    description-english={the number one},
    description-german={die Zahl Eins},
    description-spanish={el número uno},
    description-french={le numéro un},
}
\newglossaryentry{two}{
    name=two,
    symbol=2,
    description-english={the number two},
    description-german={die Zahl Zwei},
    description-spanish={el número dos},
    description-french={le numéro deux},
}
\newglossaryentry{three}{
    name=three,
    symbol=3,
    description-german={die Zahl Drei},
    description-spanish={el número tres},
}

% Define some abbreviations/acronyms.
\newacronym[
        translation-english={union of south american nations},
        translation-german={Union südamerikanischer Nationen},
        translation-french={union des nations sud-américaines},
    ]{unasur}{UNASUR}{Unión de Naciones Suramericanas}
\newacronym[
        translation-german={Nordatlantikpakt-Organisation},
        translation-spanish={organización del tratado del atlántico norte (OTAN)},
        translation-french={organisation du traité de l'Atlantique nord (OTAN)},
    ]{nato}{NATO}{north atlantic treaty organization}
\newabbreviation[
        translation-english={and so forth},
        translation-german={und so weiter},
        translation-spanish={y lo demás},
        translation-french={et les autres choses manquent},
    ]{etc}{etc.}{et cetera}

\begin{document}\makeatletter

\verb|\languagename| is \texttt{\languagename}

\gls{one},
\gls{two},
\gls{three}

\as{unasur},
\as{nato},
\as{etc}

\printglossary[type=main, style=tree]

\printglossary[type=abbreviations, style=custom-long-booktabs]

\end{document}

MWE output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.