0

Is there a possibilty to include multiple languages (but only use one language at a time) to acronyms produced with glossaries-extra as shown in my MWE:

% !TeX program = lualatex
\documentclass[british,ngerman]{scrartcl}

\usepackage{iflang} \usepackage{babel} \usepackage[autostyle]{csquotes} \usepackage[acronym]{glossaries-extra}

\newcommand{\langbe}[1]{\IfLanguageName{british}{#1}{}} \newcommand{\langde}[1]{\IfLanguageName{ngerman}{#1}{}}

\makeglossaries

\setabbreviationstyle[acronym]{long-short}

\newacronym{ac:cad}{CAD}{Computer Aided Design} %\newacronym{ac:pv}{PV}{Fotovoltaik} \newacronym{ac:pv}{PV}{\langde{Fotovoltaik}\langbe{Photovoltaic}}

\begin{document}

\selectlanguage{ngerman}

\section{German as document language}

ngerman and british identical: \glsxtrfull{ac:cad}

First regular usage: \gls{ac:cad}

Second regular usage: \gls{ac:cad}

ngerman and british not identical: \glsxtrfull{ac:pv}

First regular usage: \gls{ac:pv}

Second regular usage: \gls{ac:pv}

\selectlanguage{british}

\section{British as document language}

ngerman and british not identical: \glsxtrfull{ac:pv}

Should be: \enquote{Photovoltaic (PV)}

\section{German as document language again}

\selectlanguage{ngerman} %\selectlanguage{british}

\printglossary[style=super, type=\acronymtype]

works as intended for glossary of acronyms, if last selectlanguage gets uncommented

\end{document}

As mentioned, in the English part of the document, the long form of the acronym PV is still using the German version of the acronym, but for the Glossary of Acronyms in the end it works as intended if the language is changed (so it seems to pass my \langde{...}\langbe{...} construct at least to the glossary of acronyms, but not to the actual usage in my document).

Lukas
  • 659

1 Answers1

1

You need \protect when using macros in a fragile command. Or you can \protected\def that macro. I include another method in comments to define only one macro instead of two commands. Both methods should work fine. Click the following link, to understand more concept about "Fragile and Robust commands? When and why do we need \protect?". Hope I didn't mess up the different language acronym expression, because I didn't know german. If Anything I mentioned was wrong, please correct me. Here is the code:

% !TeX program = lualatex
\documentclass[british,ngerman]{scrartcl}

\usepackage{iflang} \usepackage{babel} \usepackage[autostyle]{csquotes} \usepackage[acronym]{glossaries-extra}

\newcommand{\langbe}[1]{\protect\IfLanguageName{british}{#1}{}} \newcommand{\langde}[1]{\protect\IfLanguageName{ngerman}{#1}{}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Another way to define the macro % % for choosing different language % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\protected\def\deorbe#1#2{\IfLanguageName{ngerman}{#1}{#2}} \makeglossaries

\setabbreviationstyle[acronym]{long-short}

\newacronym{ac:cad}{CAD}{Computer Aided Design}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Another way to define the macro % % for choosing different language % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\newacronym{ac:pv}{PV}{\deorbe{Fotovoltaik}{Photovoltaic}}

\newacronym{ac:pv}{PV}{\langde{Fotovoltaik}\langbe{Photovoltaic}}

\begin{document}

\selectlanguage{ngerman}

\section{German as document language}

ngerman and british identical: \glsxtrfull{ac:cad}

First regular usage: \gls{ac:cad}

Second regular usage: \gls{ac:cad}

ngerman and british not identical: \glsxtrfull{ac:pv}

First regular usage: \gls{ac:pv}

Second regular usage: \gls{ac:pv}

\selectlanguage{british}

\section{British as document language}

ngerman and british not identical: \glsxtrfull{ac:pv}

Should be: \enquote{Photovoltaic (PV)}

\section{German as document language again}

\selectlanguage{ngerman} %\selectlanguage{british}

\printglossary[style=super, type=\acronymtype]

works as intended for glossary of acronyms, if last selectlanguage gets uncommented

\end{document}

enter image description here

Lukas
  • 659
Tom
  • 7,318
  • 4
  • 21
  • Thanks for the solution as well as the explanation, it works like a charm! I opted for a macro similar to you deorbe in the beginning but then switched to the two different macros as it was easier for me (visually) to use two separate ones in my code. – Lukas May 16 '22 at 20:18
  • 1
    You are welcome! I guess your method indeed make typing more easier visually. And even better if you have more than two languages. – Tom May 16 '22 at 20:22