为什么重新定义 \selectlanguage 的尝试会失败?

为什么重新定义 \selectlanguage 的尝试会失败?

我尝试重新定义\selectlanguage如下polyglossia

\LetLtxMacro{\selectlanguage@original}{\selectlanguage}
\renewcommand{\selectlanguage}[2][]{\selectlanguage@original[#1]{#2}}

据我了解,这个新版本的\selectlanguage行为应该与以前完全一样。但是我一直收到错误

Package polyglossia: language * is not loaded. Please load it before using it..

我怎样才能正确应用这个重新定义,即\selectlanguage重建\selectlanguage@original

下面是 MWE。

%! TEX program = xelatex
\documentclass{article}

\usepackage{polyglossia}
\setdefaultlanguage{english}
\setotherlanguage{french}

\makeatletter
\usepackage{letltxmacro}
\LetLtxMacro{\selectlanguage@original}{\selectlanguage}
\renewcommand{\selectlanguage}[2][]{\selectlanguage@original[#1]{#2}}
\makeatother

\begin{document}

\selectlanguage{french}
Text.

\selectlanguage{english}
Text.

\end{document}

答案1

您已删除对*表单的支持,并进行了重新定义

\selectlanguage * {english}

\selectlanguage@original[]{*}{english}

并导致错误

! Package polyglossia Error: language * is not loaded. Please load it before us
ing it..

See the polyglossia package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.2 \selectlanguage *
                     {english}
? 

相关内容