我试图将希伯来语文本插入公式中,但词序被颠倒了。我只能通过手动颠倒词序和周围的空格来获得正确的输出。
我正在使用 XeLaTeX 和 polyglossia 来处理双向文本。奇怪的是,我记得以前我曾经得到过正确的行为。
这是一个示例文档(素数计数函数的定义):
\documentclass{article}
\usepackage{amsmath}
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\newfontfamily{\hebrewfont}{David CLM}
\begin{document}
$\pi(n) = \#\{p \text{ מספר ראשוני שאינו גדול מ־} n\}$
$\pi(n) = \#\{\text{$p$ מספר ראשוני שאינו גדול מ־$n$}\}$
$\pi(n) = \#\{\text{\texthebrew{$p$ מספר ראשוני שאינו גדול מ־$n$}}\}$
$\pi(n) = \#\{n \text{מ־ גדול שאינו ראשוני מספר } p\}$
\end{document}
这是我编译时得到的结果: 前三个选项展示了编写相同代码的不同方法,但结果相同且错误。只有最后一个看起来符合预期,但其代码完全无意义。
编辑:我得到了更多信息。xetex -version
我的电脑上显示
XeTeX 3.14159265-2.6-0.99996 (TeX Live 2016/Debian)
kpathsea version 6.2.2
Copyright 2016 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 57.1; using 57.1
Compiled with zlib version 1.2.8; using 1.2.8
Compiled with FreeType2 version 2.6.3; using 2.6.3
Compiled with Graphite2 version 1.3.9; using 1.3.9
Compiled with HarfBuzz version 1.4.2; using 1.4.2
Compiled with libpng version 1.6.28; using 1.6.28
Compiled with poppler version 0.48.0
Compiled with fontconfig version 2.11.0; using 2.11.0
我还在另一台机器上编译了上述文件。结果如下:
这里第二行和第三行显示正确。xetex -version
在该机器上运行
XeTeX 3.14159265-2.6-0.99992 (TeX Live 2015/dev/Debian)
kpathsea version 6.2.1dev
Copyright 2014 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 52.1; using 52.1
Compiled with zlib version 1.2.8; using 1.2.8
Compiled with FreeType2 version 2.5.3; using 2.5.3
Compiled with Graphite2 version 1.2.4; using 1.3.6
Compiled with HarfBuzz version 0.9.35; using 0.9.35
Compiled with libpng version 1.6.13; using 1.6.13
Compiled with poppler version 0.26.5
Compiled with fontconfig version 2.11.0; using 2.11.0
所以这确实曾经正常工作,但在某个时候引入了一个错误。我希望问题出在 polyglossia 或 bidi 上,所以我会确保我拥有这些软件包的最新版本,然后再试一次。
答案1
我不确定这是否是bidi
或中的一个错误polyglossia
,但问题在于\textdef@
from的定义amstext-xetex-bidi.def
。
目前的定义如下:
\def\textdef@#1#2#3{\hbox{{%
\everymath{#1}%
\let\f@size#2\selectfont
\if@nonlatin\beginR\fi#3\if@nonlatin\endR\fi}}}
问题\if@nonlatin
是总是无论如何都是 false。由于数学模式设置为 LTR,因此\beginR
永远不会运行,因此即使字体设置正确,您也会得到 LTR 文本。
更好的测试似乎是使用\if@RTL
。
\documentclass{article}
\usepackage{amsmath}
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\setotherlanguage{english}
\newfontfamily{\hebrewfont}{Linux Libertine O}[Script=Hebrew]
\makeatletter
\def\textdef@#1#2#3{\hbox{{%
\everymath{#1}%
\let\f@size#2\selectfont
\if@RTL\beginR\fi#3\if@RTL\endR\fi}}}
\makeatother
\pagestyle{empty}
\begin{document}
$\pi(n) = \#\{\text{$p$ מספר ראשוני שאינו גדול מ־$n$}\}$
\bigskip
% blame google translate if translation is wrong...
\begin{english}
$\pi(n) = \#\{\text{$p$ Primary number not greater than $n$}\}$
\end{english}
\end{document}