scantoken 增加了不必要的空间

scantoken 增加了不必要的空间

我的目标是评估 LaTeX3 字符串的内容。不幸的是,它在末尾添加了一些不必要的空格。你知道如何避免这种情况吗?

在此处输入图片描述

\documentclass{article}
\ExplSyntaxOn

\NewDocumentCommand{\setMe}{m}{
  \str_set:Nn \l_test_a_str {#1}
}

\NewDocumentCommand{\printMe}{m}{
  \exp_args:Nx \scantokens {\use:c{l_test_#1_str}}
}

\ExplSyntaxOff

\begin{document}
\setMe{Hello $\delta$.}

This should display some math, without any space before or after the quote symbols: ``\printMe{a}''.
\end{document}

答案1

在此处输入图片描述

\scantokens是一个棘手的野兽,有几种可能性:

\documentclass{article}
\ExplSyntaxOn

\NewDocumentCommand{\setMe}{m}{
  \str_set:Nn \l_test_a_str {#1}
}

\NewDocumentCommand{\printMe}{m}{
  \exp_args:Nx \scantokens {\use:c{l_test_#1_str}
                             \noexpand\noexpand}
}

\cs_generate_variant:Nn\tl_rescan:nn {nv}
\NewDocumentCommand{\printMeB}{m}{
  \tl_rescan:nv {}{l_test_#1_str}
}

\ExplSyntaxOff

\begin{document}
\setMe{Hello $\delta$.}

This should display some math, without any space before or after the quote symbols: ``\printMe{a}''.

This should display some math, without any space before or after the quote symbols: ``\printMeB{a}''.
\end{document}

相关内容