[Tex/LaTex] Why don’t I get any space after \thepage

macrosspacing

The code \thepage of yields the output 3of.

I can fix it by writing \thepage~of, but what causes this in the first place? I can't imagine when it would be useful.

Best Answer

A TeX macro 'eats' the white space after it, so \TeX nician is typeset as TeXnician, and \thepage of is typeset as 3of. You can either type \thepage~of, or \thepage\ of, or \thepage{} of. In the first case the space is unbreakable, in the others it is not.

Update: if you need space after macros for any reason, try xspace package:

\documentclass{standalone}
\usepackage{xspace}
\newcommand{\Thepage}{\thepage\xspace}
\begin{document}
\Thepage of one.  The page is \Thepage.
\end{document}

enter image description here

Related Question