如何识别双空格并赋予其含义?

如何识别双空格并赋予其含义?

我想识别两个空格字符并赋予其自己的含义。为什么这不起作用?我该如何修复?

{\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

相关内容