The question is about macro \stest, which I found in footnote in the
beginning of the chapter. The macro decides which type of space token
it's parameter represents and returns result in collection of boolean
variables. Here is the code of the macro followed by test code taken
from UKTeX Digest V91 #11:
\def\\{\let\stoken= }\\
\uccode` =`* \uppercase{\uppercase{\def\fspace{ }\let\ftoken= } }
\catcode`\!=\active
\def\\{\let!= }\\
\catcode`|=\active
\let|= \ftoken
% Code from TeXBook begin
\newif\ifspace \newif\iffunny \newif\ifexplicit \newif\ifactive
\def\stest#1{\funnyfalse \expandafter\s\the#1! \stest}
\def\s{\global\explicitfalse \global\activefalse \futurelet\next\ss}
\def\ss{\ifcat\noexpand\next\stoken\let\nxt\sx\else\let\nxt\ns\fi\nxt}
\def\sx{\spacetrue\ifx\next\stoken\let\nxt\sss\else\let\nxt=\ssss\fi
\nxt}
\long\def\sss#1 #2\stest{\def\next{#1}%
\ifx\next\empty \global\explicittrue \else\testactive#1\s\fi}
\long\def\ssss#1#2\stest{\funnytrue{\escapechar=\if*#1`?\else`*\fi
\relax
\if#1\string#1\uccode`#1=`~
\uppercase{\ifcat\noexpand#1}\noexpand~\global\activetrue
\else\global\explicittrue\fi
\else\testactive#1\s\fi}}
\long\def\ns#1\stest{\spacefalse}
\long\def\testactive#1#2\s{\expandafter\tact\string#1\s\tact}
\long\def\tact#1#2\tact{\def\next{#2}\ifx\next\xs\global\activetrue
\else\ifx\next\empty \global\activetrue\fi\fi}
\def\xs{\s}
% Code from TeXBook end
\def\stestex#1{\stest#1
\ifspace
\ifexplicit
\message{explicit}%
\else
\message{implicit}%
\ifactive
\message{active}%
\fi
\fi
\iffunny\message{funny}\else\message{normal}\fi
\message{space |}%
\else
\message{nonspace |}
\fi}
\newtoks\Test
\Test={ } % explicit normal space
\stestex\Test
\Test=\expandafter{\fspace} % explicit funny space
\stestex\Test
\Test={\stoken} % implicit normal space
\stestex\Test
\Test={\ftoken} % implicit funny space
\stestex\Test
\Test={!} % implicit active normal space
\stestex\Test
\Test={|} % implicit active funny space
\stestex\Test
\Test={s} % nonspace
\stestex\Test
\Test={\ } % nonspace
\stestex\Test
According to the digest there are only six types of space tokens. The
code works well but from my point of view it has some useless code.
Firstly, macro \tact could be like that:
\long\def\tact#1#2\tact{\def\next{#2}\ifx\next\xs\global\activetrue
\fi}
instead of
\long\def\tact#1#2\tact{\def\next{#2}\ifx\next\xs\global\activetrue
\else\ifx\next\empty \global\activetrue\fi\fi}
Secondly, macro \ssss can be rewritten:
\long\def\ssss#1#2\stest{\funnytrue{\escapechar=\if*#1`?\else`*\fi
\relax
\if#1\string#1\global\explicittrue%\fi
\else\testactive#1\s\fi}}
original code:
\long\def\ssss#1#2\stest{\funnytrue{\escapechar=\if*#1`?\else`*\fi
\relax
\if#1\string#1\uccode`#1=`~
\uppercase{\ifcat\noexpand#1}\noexpand~\global\activetrue
\else\global\explicittrue\fi
\else\testactive#1\s\fi}}
I've checked my version with test code shown above and it works the
same.
Am I right? Is the code I've deleted meaningful?
Thanks,
Peter.