使用不同的语言来添加词汇表(但一次只能使用一种)

使用不同的语言来添加词汇表(但一次只能使用一种)

是否有可能将多种语言(但一次只能使用一种语言)包含在生成的首字母缩略词中,glossaries-extra如我的 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}

如上所述,在文档的英文部分,首字母缩略词的长形式PV仍使用德语版本的首字母缩略词,但对于首字母缩略词词汇表,如果语言发生变化,它最终会按预期工作(因此它似乎\langde{...}\langbe{...}至少将我的构造传递给了首字母缩略词词汇表,但没有传递给我的文档中的实际用法)。

答案1

\protect在脆弱的命令中使用宏时,您需要。或者您可以使用\protected\def该宏。我在注释中包含了另一种方法,可以仅定义一个宏而不是两个命令。这两种方法都应该可以正常工作。单击以下链接,了解有关“脆弱和强大的命令?我们何时以及为什么需要 \protect?”。希望我没有搞错不同语言的缩写表达,因为我不懂德语。如果我提到的任何内容有误,请纠正我。以下是代码:

% !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}

在此处输入图片描述

相关内容