使用lualatex和babel

使用lualatex和babel

有没有办法让 xelatex 遵循标准 bidi 算法?

我正在使用与此类似的设置:

\documentclass[12pt]{article}
\TeXXeTstate=1
\usepackage{polyglossia}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\setdefaultlanguage{english}
\setotherlanguages{russian,hebrew}
\usepackage{bidi}

现在一切都很好,只是我必须使用\begin{hebrew}\end{hebrew}或方向命令来标记希伯来语段落。这相当烦人。

人们期望这\usepackage{bidi}会让 xelatex 在决定文本方向时遵循标准 bidi 算法,但显然这并没有发生。

是否有其他软件包可以启用 bidi 算法,或者提供其他方法让 xelatex 从脚本中推断文本方向?如果没有,也许存在一些我不知道的技术或哲学问题阻碍了这一点?

答案1

使用lualatexbabel

我最近发现babel使用 对此使用的基本支持lualatex。您仍然必须使用\selectlanguage{hebrew}切换到 RTL 段落,但内联 bidi 似乎可以正常工作。

\documentclass{article}
\usepackage[nil,bidi=basic]{babel}
\babelprovide[import=en-AU,main]{australian}
\babelprovide[import=he]{hebrew}
\babelfont{rm}{Linux Libertine O}
\babelfont{sf}{Linux Biolinum O}
\pagestyle{empty}
\begin{document}
In the beginning God created the heavens and the earth. בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת
הַשָּׁמַיִם וְאֵת הָאָרֶץ. (Genesis 1:1)

\selectlanguage{hebrew}
בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת הַשָּׁמַיִם וְאֵת הָאָרֶץ (Genesis 1:1)
\end{document}

在此处输入图片描述

使用xelatexpolyglossia

下面是一个使用与 相同技术的示例unicode-bidi。它不是很强大,并且实际上只适用于内联希伯来语,而不是段落希伯来语。

\documentclass{article}
\usepackage{polyglossia}
\setmainlanguage{english}
\setotherlanguage{hebrew}
\newfontfamily{\hebrewfont}{Linux Libertine O}[Script=Hebrew]
\makeatletter
\newcount\unicode@bidi@hebrew@alphabets
\newXeTeXintercharclass\unicode@bidi@hebrew@alphabets@charclass
\unicode@bidi@hebrew@alphabets=`\^^^^0591 \loop \XeTeXcharclass
\unicode@bidi@hebrew@alphabets \unicode@bidi@hebrew@alphabets@charclass
\ifnum\unicode@bidi@hebrew@alphabets<`\^^^^05f4 \advance\unicode@bidi@hebrew@alphabets \@ne \repeat
\XeTeXinterchartoks \z@ \unicode@bidi@hebrew@alphabets@charclass {\unicode@bidi@starthebrew}
\XeTeXinterchartoks \e@alloc@intercharclass@top \unicode@bidi@hebrew@alphabets@charclass {\unicode@bidi@starthebrew}
\XeTeXinterchartoks \e@alloc@intercharclass@top \z@ {\unicode@bidi@finishhebrew}
\XeTeXinterchartoks \unicode@bidi@hebrew@alphabets@charclass \z@ {\unicode@bidi@finishhebrew}
\newcommand*{\unicode@bidi@starthebrew}{\if@nonlatin\else\bgroup\beginR\hebrewfont\@nonlatintrue\fi}
\newcommand*{\unicode@bidi@finishhebrew}{\if@nonlatin\unskip\endR\egroup{ }\fi}
\makeatother
\setlatin
\pagestyle{empty}
\begin{document}
In the beginning God created the heavens and the earth. בְּרֵאשִׁית בָּרָא אֱלֹהִים אֵת
הַשָּׁמַיִם וְאֵת הָאָרֶץ׃ (Genesis 1:1).
\end{document}

在此处输入图片描述

答案2

XeTeX 逐字处理排版。在每个单词中,它将使用正常的 unicode bidi 算法,但除此之外,它会单独处理每个单词,这意味着将单词放入正在处理的水平列表后,它就变成了一个具有\lastbox尺寸的“框”(但不是可以从 访问的真正框)。

在这种情况下,不可能正确实现双向算法,因为它根据行的内容分配方向性,但是一旦 TeX 进行换行,它就不再知道任何“框”的内容是什么。

就系统而言,这本身实际上相当方便,因为双向算法中的缺陷(至少应用于我所写的希伯来语的特定方言)是我首先切换到 TeX 的(部分)原因。

使用此系统,您永远不会在意想不到的地方出现反向括号,因为您告诉 TeX 它们何时应该是 RTL,何时不是。当用户完全控制方向性时,文本就会按预期显示。

可以使用来制定解决方案\XeTeXinterchartoks,但这将涉及并取决于您的使用情况。

相关内容