我有一份用英语和希伯来语编写的文档。出于某种原因,英文章节标题、编号和名称不是用我为英语文本声明的字体(拉丁现代罗马字体)输入的,而是用为希伯来语设置的字体输入的。
这是为什么?
添加颜色是为了可视化目的。
% !TEX TS-program = xelatex
% !TEX encoding = UTF-8
\documentclass[openany,a5paper]{book}
\usepackage{polyglossia,xcolor}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\englishfont{Latin Modern Roman}[
Script=Latin,
Language=English,
Ligatures=TeX,
Color=red]
\newfontfamily\hebrewfont{Arial}[
Script=Hebrew,
Color=blue]
\begin{document}
\chapter{פרק ראשון}
טקסט טקסט טקסט.
\begin{english}
\chapter{this should be in Latin Modern}
Like this one is.
\end{english}
\end{document}
答案1
这似乎是 的问题polyglossia
。我找到了解决方案这里但它似乎不完整。它将字体切换命令添加到语言切换命令中,但当您结束语言环境时它不会这样做,例如在\end{english}
。我添加了该代码,以便它在环境之外设置语言english
,通常应该是hebrew
。该方案可能不适用于更复杂的嵌套环境。
\documentclass[openany,a5paper]{book}
\usepackage{polyglossia,xcolor}
\setdefaultlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily\englishfont{Latin Modern Roman}[
Script=Latin,
Language=English,
Ligatures=TeX,
Color=red]
\newfontfamily\hebrewfont{Arial}[
Script=Hebrew,
Color=blue]
% Add correction code, inspired by https://tex.stackexchange.com/a/325833/113546
\makeatletter
\def\xpg@set@normalfont#1{%
\letcs{\rmfamily}{#1@font@rm}%
\letcs{\sffamily}{#1@font@sf}%
\letcs{\ttfamily}{#1@font@tt}%
\def\normalfont{\protect\xpg@select@fontfamily{#1}}%def instead of gdef
\def\reset@font{\protect\normalfont}%
}
\addto\inlineextras@english{\xpg@set@normalfont{english}}
\addto\blockextras@english{\xpg@set@normalfont{english}}
% Switch back explicitely to previous language
% This should normally be 'hebrew' outside 'english'.
\addto\endenglish{\selectlanguage{\babelname}}
\addto\inlineextras@hebrew{\xpg@set@normalfont{hebrew}}
\addto\blockextras@hebrew{\xpg@set@normalfont{hebrew}}
\makeatother
\begin{document}
\chapter{פרק ראשון}
טקסט טקסט טקסט.
\begin{english}
\chapter{this should be in Latin Modern}
Like this one is.
\chapter{Another test}
Some other text.
\end{english}
\chapter{פרק ארבע}
טקסט טקסט טקסט.
\end{document}