TeX does not save character strings in its memory but tokens. When the parameter of \toot
in the line of your example
\toot{\textsc{1}}
is scanned, the tokenizer creates the tokens "textsc", "{", "1" and "}". When TeX is asked to print the tokens (using \meaning
in your example) then it must solve the question how tokens of control-sequence type are printed. If the printed token control sequence name consists of letters then TeX prints a backslash in front of and a space after such token. This is decision of TeX’s author. The reason: the tokens "relax", "a" are printed as \relax a
which is better than \relaxa
.
Edit If you want to elaborate with catcodes, then an example follows. The parameter of the \toot
macro is read (and tokenized) when catcodes of backslash and space are 12 (normal). So you can detect duplicate spaces and there are no control sequences. As soon as the parameter is read, the standard catcodes are set back (at \egroup
). Then a second "normal" variant of the parameter is prepared using \scantokens
because we expect that macro programmer needs to manipulate with both variants: "normal" and "space-respected". Finally the macro \tootB
is started. It gets two parameters, first is "normal" variant of parameter and second is "space-respected" variant (where no control sequences are).
\def\toot{\bgroup \catcode`\\=12 \catcode`\ =12 \tootA}
\long\def\tootA#1{\egroup
\scantokens{\def\tmp{#1}}%
\expandafter\tootB\expandafter{\tmp}{#1}%
}
\long\def\tootB#1#2{%
\def\tmp{#1}%
\message{normal: "\meaning\tmp"}
\def\tmp{#2}%
\message{space-respected: "\meaning\tmp"}
}
\toot{\textsc{1}}
\toot{\textsc{ a b c \par a\par1 \textbf {a}a}}
\toot{\textsc{ a b c \hskip1em a\space 1 \textbf {a}a}}
\bye
\meaning\toot
instead of\meaning\toto
? – Solomon Ucko Mar 17 '18 at 12:24\textsc{1}
to an external file (rather than using it at that point in the document)? In which case, are you able to just do\string\textsc
? – Nicola Talbot Mar 17 '18 at 13:38