# Space oddity: are there spaces that won't end up on the page?

I think the answer to my question is "no," but one could argue that it would be nice if there were. Here's what motivates the question. Define

\def\myloop#1#2{\count11=#1#2%
\ifnum\count11>0{\myloop{\count11}{#2}}\fi}


\myloop{4}{T} then produces T T T T  (notice the extra space at the end). The undesired space at the end of the output is due to the space in the definition that is required to terminate the \advance command. The space has two effects: it acts as both a delimiter in the programming language, and it also appears on the page. What would be nice is a kind of "delimiting but invisible" space.

Of course, it's not clear how one would express such a thing, or how it would be better than

\def\myloop#1#2{\count11=#1#2%
\ifnum\count11>0{\myloop{\count11}{#2}}\fi}


But TeX has so many nooks and crannies that I may have overlooked something.

Apologies for the title, someone else suggested it, and I couldn't resist.

• no, spaces used to terminate a number are absorbed and never produce output Feb 18 at 15:39
• You're inserting a control space \ , that is different from a space. Feb 18 at 15:42
• Also: Ground control to Major Tom! Feb 18 at 15:42
• @RandallFairman but is wrong. Don't use \  to terminate number parsing. If you have to be somewhat explicit use \advance\mycount by -1\@sptoken. Feb 18 at 15:51
• A space token, which \  isn't, will terminate the search for digits and will be ignored. Any other unexpandable token that's not a digit will do as well, but it won't be ignored. I explained it in my answer to your previous question. Feb 18 at 15:54

Quoting from my previous answer to Parsing oddity: when is a space not a space

##### Some more explanations

A space token in the above sense is an explicit character with category code 10. When TeX is looking for digits to perform an assignment, it will do macro expansion (including expandable primitives) and it will stop, as said, when, after expansion, a nondigit is found. If the stop is caused by a space token, it will be ignored; otherwise the token causing the stop is read again after the assignment has been completed.

It follows that \  is not a space token for the purpose of terminating numbers. It does stop the search for further digits, but it is an unexpandable primitive, so it will be reexamined after the number has been used, in this case to make an assignment to \count11. And therefore it will appear in print.

\newcount\loopcount
\def\myloop#1#2{\loopcount=#1\relax
#2% print the second argument
\advance\loopcount by -1 % decrease the counter
\ifnum\loopcount>0
\myloop{\loopcount}{#2}% repeat
\fi
}


You need \relax in the first line, because #1 might be either an explicit number or a register. A space token will not be gobbled if the assignment uses a register's value. In the \advance line, -1 is properly terminated by a space (which won't appear in output). Similarly for the endline following 0 in the next line (it is converted to a space when TeX tokenizes the input).

##### Footnote

You shouldn't be using \count11, to begin with. It's an important register used by TeX to keep track of register allocations: line 194 in plain.tex says

\count11=9 % allocates \dimen registers 10, 11, ...