如果上一節以其他語言結尾且節標題以其他語言開頭,則無法正確重新選擇主要語言

如果上一節以其他語言結尾且節標題以其他語言開頭,則無法正確重新選擇主要語言

我在使用 XeLaTeX 時遇到問題,該文件包含希伯來語和英語兩種語言。我對希伯來語使用了不同的字體(這裡是 DejaVu Sans,但任何字體都可以)。

問題是,當(1) 某個部分以希伯來語文本結尾並且(2) 下一節標題以希伯來語文本開頭時,文檔的其餘部分以及目錄將以用於希伯來語的字體顯示。由於某種原因,系統不會切換回主字體(請參閱下面的範例)。

我只在一台機器上遇到這個問題(兩台機器)。有問題的機器正在運行 Debian Bookworm,並安裝了 TeX Live 2022這裡xelatex --version給出:

XeTeX 3.141592653-2.6-0.999994 (TeX Live 2022)
kpathsea version 6.3.4
Copyright 2022 SIL International, Jonathan Kew and Khaled Hosny.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the XeTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the XeTeX source.
Primary author of XeTeX: Jonathan Kew.
Compiled with ICU version 70.1; using 70.1
Compiled with zlib version 1.2.11; using 1.2.11
Compiled with FreeType2 version 2.11.1; using 2.11.1
Compiled with Graphite2 version 1.3.14; using 1.3.14
Compiled with HarfBuzz version 3.4.0; using 3.4.0
Compiled with libpng version 1.6.37; using 1.6.37
Compiled with pplib version v2.05 less toxic i hope
Compiled with fontconfig version 2.13.0; using 2.14.1

在我的另一台機器上沒有問題。該機器運行 Debian Bullseye,並從同一源安裝 TeX Live 2022。唯一的區別xelatex --version是:

Compiled with fontconfig version 2.13.0; using 2.13.1

因此,有問題的系統使用較新的字體配置(我不知道如何在較新的系統上使用舊版本來測試是否可以解決問題)。所有軟體包(apttlmgr)在兩個系統上都是最新的。

有什麼想法可以解決這個問題嗎?

\documentclass{article}

\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{hebrew}
\newfontfamily\hebrewfont{DejaVu Sans}
\newcommand{\heb}[1]{\bgroup\normalfont\hebrewfont\RL{#1}\egroup}

\begin{document}

\tableofcontents

\section{First section}
\begin{hebrew}
    This section ends with Hebrew text.
\end{hebrew}
\section{\heb{אב} Section title starts with Hebrew}

\end{document}

在此輸入影像描述

這裡除了「text.Hebrew with結尾部分This」和「אב」之外的所有內容都應該使用預設字體,而不是DejaVu Sans。

答案1

作為烏爾麗克費雪建議, 使用

\newcommand{\heb}[1]{\bgroup\selectlanguage{hebrew}\RL{#1}\egroup}

解決了這個問題。

在此輸入影像描述

相關內容