\NewDocumentCommand 中的空控制序列

\NewDocumentCommand 中的空控制序列

在下面的程式碼中,\csname ... \endcsname以及\cs_if_exist_use:c裡面的\NewDocumentCommand行為不符合預期。

在此輸入影像描述

\documentclass{article}
\usepackage{xparse}
\expandafter\def\csname test 1\endcsname{a,$\alpha$,b}
\ExplSyntaxOn
\clist_new:N \l_test_clist
\NewDocumentCommand {\test} {}
  {
    \csname test 1\endcsname
    \cs_if_exist_use:c {test 1}
  }
\ExplSyntaxOff

\begin{document}
show: \test

use: \csname test 1\endcsname
\end{document}

答案1

您定義了一個帶有名稱的命令test 1,但在 Expl3 程式碼中,空格字元被忽略並且不產生任何標記,因此在您測試時test1 使用了test ~ 1 在 test 和 1 之間有一個空格標記。

相關內容