Certain sequences of Unicode characters, particularly involving Hebrew yud (י) seem to have strange behavior with \tl_replace_all:Nnn. In the following MWE for XeLaTeX, some of these sequences when used as the search string create unexplained indentation even with no matches while others do not (almost all other Hebrew sequences work as expected). I also saw identical behavior for the same sequences with \regex_replace_all:nnN though I do not include it here. Any thoughts?
\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}
\tl_replace_all:Nnn
though, as it doesn't add typesetting instructions like indentation. That said, you can examine the contents of the token list with\tl_analysis_show:N \l_hebrew_input_text_tl