下面的 MNWE 无法编译 XeLaTeX。由于环境\MakeUppercase
中未定义,因此编译以错误结束english
。
取消注释注释的代码允许编译。
然而,为了使用由基础 LaTeX 格式提供的格式化命令,这肯定不是必需的。
应如何设置语言/字体以便希伯来语成为默认文档语言但\MakeUppercase
在环境中有效english
?
\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\hebrewfont[Script=Hebrew]{Noto Sans Hebrew}
\newfontfamily\hebrewfontsf[Script=Hebrew]{Noto Sans Hebrew}
\newfontfamily\hebrewfonttt[Script=Hebrew]{Noto Sans Hebrew}
\newfontfamily\englishfont[Ligatures=TeX]{Latin Modern Roman}
\setmainfont{Latin Modern Roman}
\setmonofont{Latin Modern Mono}
\setsansfont{Latin Modern Sans}
% \makeatletter
% \newcommand*\restoreuppercase{%
% \DeclareRobustCommand{\MakeUppercase}[1]{{% from base/latex.ltx
% \def\i{I}\def\j{J}%
% \def\reserved@a####1####2{\let####1####2\reserved@a}%
% \expandafter\reserved@a\@uclclist\reserved@b{\reserved@b\@gobble}%
% \protected@edef\reserved@a{\uppercase{##1}}%
% \reserved@a
% }%
% }%
% \protected@edef\MakeUppercase##1{\MakeUppercase{##1}}%
% }
% \makeatother
\begin{document}
\begin{english}
% \restoreuppercase
\MakeUppercase{english}
\end{english}
\end{document}
答案1
这是 gloss-hebrew.ldf 中的一个错误。它\noextras@hebrew
尝试恢复\MakeUppercase
而不确保或检查\MakeUppercase
之前是否已存储 - 并且正如\noextras@hebrew
在 \begin{document} 的安装命令中第一次调用时所显示的那样,它失败了。
\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\hebrewfont[Script=Hebrew]{FreeSerif}
\newfontfamily\hebrewfontsf[Script=Hebrew]{FreeSans}
\newfontfamily\hebrewfonttt[Script=Hebrew]{FreeMono}
\newfontfamily\englishfont[Ligatures=TeX]{Latin Modern Roman}
\setmainfont{Latin Modern Roman}
\setmonofont{Latin Modern Mono}
\setsansfont{Latin Modern Sans}
\makeatletter
\def\noextras@hebrew{%
\ifcsname @@MakeUppercase\endcsname
\let\MakeUppercase\@@MakeUppercase%
\fi
}
\makeatother
\begin{document}
\begin{english}
\MakeUppercase{english}
\end{english}
\MakeUppercase{ירושלים}
\end{document}
答案2
我会这样做letltxmacro
:
\documentclass{article}
\usepackage{polyglossia}
\usepackage{letltxmacro}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\hebrewfont[Script=Hebrew]{FreeSerif}
\newfontfamily\hebrewfontsf[Script=Hebrew]{FreeSans}
\newfontfamily\hebrewfonttt[Script=Hebrew]{FreeMono}
\newfontfamily\englishfont[Ligatures=TeX]{Latin Modern Roman}
\setmainfont{Latin Modern Roman}
\setmonofont{Latin Modern Mono}
\setsansfont{Latin Modern Sans}
\makeatletter
\LetLtxMacro\latex@MakeUppercase\MakeUppercase
\newcommand*\restore@uppercase{%
\LetLtxMacro\MakeUppercase\latex@MakeUppercase
}
\appto\blockextras@english{\restore@uppercase}
\appto\inlineextras@english{\restore@uppercase}
\makeatother
\begin{document}
\begin{english}
\MakeUppercase{english}
\end{english}
\MakeUppercase{ירושלים}
\end{document}