字形替代符中断连字

字形替代符中断连字

Alan Munn 解释道 仅对某些字形使用风格变化 如何为某些字形子集启用字形替代。

我正在使用他描述的第二种方法(另一种方法对我来说不可行)但它似乎会破坏自动连字功能。

考虑这个例子:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\usepackage[paperwidth =   6 em,right=   1 em,left=    1 em,]{geometry}
\begin{document}
A a h coherence 
\end{document}

这里,连贯性被正确地用连字符连接起来。 正确的

现在,与打开的备用程序相同:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\usepackage[paperwidth =   6 em,right=   1 em,left=    1 em,]{geometry}
% Now the more complicated version:
\XeTeXinterchartokenstate=1 % enable character classes
\newXeTeXintercharclass\myalt % create a new class
\XeTeXcharclass `\h \myalt % add h to the class
% between any character of class 0 and \myalt add the alternate feature
\XeTeXinterchartoks 0 \myalt = {\begingroup\addfontfeature{Alternate=0}}
% between \myalt and any character end the group
\XeTeXinterchartoks  \myalt 0 = {\endgroup}
% between a word boundary and \myalt add the alternate feature
\XeTeXinterchartoks 255 \myalt = {\begingroup\addfontfeature{Alternate=0}}
% between \myalt and the word boundary end the group
\XeTeXinterchartoks  \myalt 255 = {\endgroup}
\begin{document}
A a h coherence 
\end{document}

现在连字符已被破坏。 破碎的

请注意,这不是特定示例的产物,我也用更长的文本尝试过。

这是一个错误吗?

编辑:egreg 解释说这确实不是一个错误。

是否有解决方法?一种明显的可能性是明确标记连字点(例如连贯性),但这在较长的文档中是不切实际的。

答案1

这不是一个错误。在 interchartoks 功能起作用后,排版“coherence”时得到的结果相当于

co\begingroup\addfontfeature{Alternate=0}h\endgroup erence

问题就在这里:XeTeX 不会在字体更改后尝试连字。

你可以用一个卑鄙的手段来“解决”它:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}

\makeatletter
\providecommand{\allowhyphens}{\nobreak\hskip\z@skip}
\makeatother
% Now the more complicated version:
\XeTeXinterchartokenstate=1 % enable character classes
\newXeTeXintercharclass\myalt % create a new class
\XeTeXcharclass `\h \myalt % add h to the class
% between any character of class 0 and \myalt add the alternate feature
\XeTeXinterchartoks 0 \myalt = {\begingroup\addfontfeature{Alternate=0}}
% between \myalt and any character end the group
\XeTeXinterchartoks  \myalt 0 = {\endgroup\allowhyphens}
% between a word boundary and \myalt add the alternate feature
\XeTeXinterchartoks 4095 \myalt = {\begingroup\addfontfeature{Alternate=0}}
% between \myalt and the word boundary end the group
\XeTeXinterchartoks  \myalt 4095 = {\endgroup\allowhyphens}
\begin{document}
\parbox{3pt}{A a h coherence}
\end{document}

我把“solve”放在引号里,因为尝试连字的单词实际上是“erence”,不是“连贯性”,因此结果(对不同的词)可能不正确。

笔记。答案原来是 255,现在是 4095。从 TeX Live 2019 发布开始,这一改变是必要的。

相关内容