![如何识别双空格并赋予其含义?](https://linux22.com/image/314978/%E5%A6%82%E4%BD%95%E8%AF%86%E5%88%AB%E5%8F%8C%E7%A9%BA%E6%A0%BC%E5%B9%B6%E8%B5%8B%E4%BA%88%E5%85%B6%E5%90%AB%E4%B9%89%EF%BC%9F.png)
我想识别两个空格字符并赋予其自己的含义。为什么这不起作用?我该如何修复?
{\catcode`\ =13%make space active
\gdef\activespacetoken{ }%
\gdef {\activespacemeaning}}
\def\activespacemeaning{\futurelet\peeknexttoken\activespacewithnexttokenmeaning}
\def\activespacewithnexttokenmeaning{\ifx\peeknexttoken\activespacetoken{T}{F}\fi}
\catcode`\ =13%
Lorem Ipsum is simply dummy text.
\catcode`\ =10%make space space
\bye
答案1
您的代码中有两处错误。最重要的是,当您进行测试时,\ifx
您需要记住,这\futurelet
会将\let
您的标记\peeknexttoken
置于活动空间而不是其扩展的位置。因此,您需要设置一个包含的宏\activespacemeaning
以供比较。其次,您的条件分支的原始语法是错误的。修复这两个问题会给我们
{\catcode`\ =\active
\gdef\activespacetoken{ }%
\gdef {\activespacemeaning}}
\def\activespacemeaning{\futurelet\peeknexttoken\activespacewithnexttokenmeaning}
\def\activespacetest{\activespacemeaning}
\def\activespacewithnexttokenmeaning{\ifx\peeknexttoken\activespacetest T\else F\fi}
\catcode`\ =\active
Lorem Ipsum is simply dummy text.
\catcode`\ =10 %make space space
\bye