3

I'd like to recognize two space characters and give my own meaning to it. Why does this not work and how can I fix it?

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

Two things are wrong in your code. Most importantly, when you do your \ifx test you need to remember that \futurelet will have \let your token \peeknexttoken to an active space not to what it expands to. So you need to set up a macro containing \activespacemeaning for comparison. Secondly, you have the primitive syntax for conditional branches wrong. Fixing both of those give us

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.