\tl_replace_all:Nnn 会​​破坏某些 Unicode 字符吗?

\tl_replace_all:Nnn 会​​破坏某些 Unicode 字符吗?

某些 Unicode 字符序列,特别是涉及希伯来语 yud (י) 的序列似乎在使用 \tl_replace_all:Nnn 时会出现奇怪的行为。在以下针对 XeLaTeX 的 MWE 中,当将其中一些序列用作搜索字符串时,即使没有匹配项,也会创建无法解释的缩进,而其他序列则不会(几乎所有其他希伯来语序列都按预期工作)。我还看到使用 \regex_replace_all:nnN 的相同序列也出现了相同的行为,尽管我没有将其包括在这里。有什么想法吗?

\documentclass{article}
\usepackage{xparse}
\usepackage{expl3}
\usepackage{polyglossia}
\setdefaultlanguage{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{Taamey Frank CLM}

\ExplSyntaxOn
\NewDocumentCommand{\transliterateA}{m}
 {
  \hebrew_replaceA:n {#1}
 }
 \NewDocumentCommand{\transliterateB}{m}
 {
  \hebrew_replaceB:n {#1}
 }
\tl_new:N \l_hebrew_input_text_tl
\cs_new_protected:Npn \hebrew_replaceA:n #1
 {
  \tl_set:Nn \l_hebrew_input_text_tl { #1 }
  %handle yud-vowel before it accidentally gets turned into an i
  \tl_replace_all:Nnn \l_hebrew_input_text_tl { יְ } { yְ }
  \tl_replace_all:Nnn \l_hebrew_input_text_tl { יֻ } { yֻ }
  %handle yud-dagesh-vowel before it accidentally gets turned into an i
  \tl_replace_all:Nnn \l_hebrew_input_text_tl { יְּ } { yyְ }
  \tl_replace_all:Nnn \l_hebrew_input_text_tl { יֻּ } { yyֻ }
  \tl_use:N \l_hebrew_input_text_tl
 }
 \cs_new_protected:Npn \hebrew_replaceB:n #1
 {
  \tl_set:Nn \l_hebrew_input_text_tl { #1 }
  %handle yud-vowel before it accidentally gets turned into an i
  \tl_replace_all:Nnn \l_hebrew_input_text_tl { יִ } { yִ }
  \tl_replace_all:Nnn \l_hebrew_input_text_tl { יֱ } { yֱ }
  %handle yud-dagesh-vowel before it accidentally gets turned into an i
  \tl_replace_all:Nnn \l_hebrew_input_text_tl { יִּ } { yyִ }
  \tl_replace_all:Nnn \l_hebrew_input_text_tl { יֱּ } { yyֱ }
  \tl_use:N \l_hebrew_input_text_tl
 }
\ExplSyntaxOff

\begin{document}
\transliterateA{שְֿׁ שְֿׁ שְֿׁ שְֿׁ שְֿׁ שְֿׁ שְּֿׁ שְּֿׁ שְּֿׁ שְּֿׁ}

\transliterateB{שְֿׁ שְֿׁ שְֿׁ שְֿׁ שְֿׁ שְֿׁ שְּֿׁ שְּֿׁ שְּֿׁ שְּֿׁ}
\end{document}

在此处输入图片描述

答案1

这实际上是一个 PEBKAC 问题。

有问题的行以两个 U+00A0 开头:NO-BREAK SPACE(事实证明,在某些键盘布局中,可能会通过 alt-shift-space 意外输入)而不是普通空格。切换到普通空格可以解决问题。

此外,Phelype 无法重现该问题的原因是 StackExchange 将 NBSP 清理到普通空间中,因此我发布的 MWE 可以正常工作。谢谢,Phelype。

相关内容