以下代码\XeTeXinterchartoks
在应用于非 ASCII 字符时会失败。有什么帮助吗?
\documentclass{article}
\usepackage{fontspec}
\usepackage{graphicx}
\usepackage{xcolor}
% \usepackage{bidi}
\setmainfont[Script=Arabic]{Amiri}
\chardef\stretchchar="0640
\newXeTeXintercharclass \charclassAen
\newXeTeXintercharclass \charclassBen
\XeTeXcharclass `\A \charclassAen
\XeTeXcharclass `\C \charclassAen
\XeTeXcharclass `\B \charclassBen
\XeTeXcharclass `\D \charclassBen
\newXeTeXintercharclass \charclassAar
\newXeTeXintercharclass \charclassBar
\chardef\Aar="062A % ت
\chardef\Bar="0641 % ف
\chardef\Car="0647 % ه
\chardef\Dar="0649 % ى
\chardef\Ear="064A % ي
\chardef\Far="06CC % ی
\chardef\Gar="FBFE % ﯾ
\chardef\Har="FBFD % ﯽ
\chardef\Iar="FEF0 % ﻰ
\chardef\Jar="FEF3 % ﻳ
\XeTeXcharclass \Aar \charclassAar
\XeTeXcharclass \Bar \charclassAar
\XeTeXcharclass \Car \charclassAar
\XeTeXcharclass \Dar \charclassAar
\XeTeXcharclass \Ear \charclassAar
\XeTeXcharclass \Far \charclassAar
\XeTeXcharclass \Gar \charclassAar
\XeTeXcharclass \Har \charclassAar
\XeTeXcharclass \Iar \charclassAar
\XeTeXcharclass \Jar \charclassAar
\XeTeXcharclass \Aar \charclassBar
\XeTeXcharclass \Bar \charclassBar
\XeTeXcharclass \Car \charclassBar
\XeTeXcharclass \Dar \charclassBar
\XeTeXcharclass \Ear \charclassBar
\XeTeXcharclass \Far \charclassBar
\XeTeXcharclass \Gar \charclassBar
\XeTeXcharclass \Har \charclassBar
\XeTeXcharclass \Iar \charclassBar
\XeTeXcharclass \Jar \charclassBar
\newcommand \stretchitEN{
\XeTeXinterchartokenstate 1 %
\XeTeXinterchartoks \charclassAen \charclassBen = {{\color{red}\stretchchar\stretchchar\stretchchar}}
}
\newcommand \stretchitAR{
\XeTeXinterchartokenstate 1 %
\XeTeXinterchartoks \charclassAen \charclassBen = {{\color{red}\stretchchar\stretchchar\stretchchar}}
\XeTeXinterchartoks \charclassAar \charclassBar = {{\color{red}\stretchchar\stretchchar\stretchchar}}
}
\pagestyle{empty}
\begin{document}
{
\stretchitEN{}
Test is a test. CDTest is a test. Test is a test. ABTest is a test.
Test is a test. CDTest is a test. Test is a test. ABTest is a test.
Test is a test. CDTest is a test. Test is a test. ABTest is a test.
}
{
\stretchitAR{}
\Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar AB \Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar CD \Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar
\Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar CD \Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar AB \Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar
\Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar CD \Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar CD \Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar
\Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar CD \Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar AB \Far\Dar\Far\Aar\Jar\Iar \Har\Ear\Dar\Ear\Aar
}
\end{document}
其输出为: