If I define
\newcount\punkt
\def\newpt{\the\punkt\space\advance\punkt by 1}
everything runs fine; but if I do
\newcounter{punkt}
\newcommand\newpt{\the\punkt\space\stepcounter{\punkt}}
I get
You can't use `blank space ' after \the.
Why?
If I define
\newcount\punkt
\def\newpt{\the\punkt\space\advance\punkt by 1}
everything runs fine; but if I do
\newcounter{punkt}
\newcommand\newpt{\the\punkt\space\stepcounter{\punkt}}
I get
You can't use `blank space ' after \the.
Why?
The code you posted, if used, generates a different error to the one you show.
\documentclass{article}
\newcounter{punkt}
\newcommand\newpt{\the\punkt\stepcounter{\punkt}}
\begin{document}
\newpt
\end{document}
! Undefined control sequence.
\newpt ->\the \punkt
\stepcounter {\punkt }
l.9 \newpt
?
The latex command \newcounter does not define \punkt, you can use \thepunkt to get the print form.
\documentclass{article}
\newcounter{punkt}
\newcommand\newpt{\thepunkt\stepcounter{punkt}}
\begin{document}
\newpt
\newpt
\end{document}
You can generate the error shown using a construct such as
\documentclass{article}
\edef\x{\noexpand\the\space}\x
\begin{document}
\end{document}
! You can't use `blank space ' after \the.
\x ->\the
l.3 \edef\x{\noexpand\the\space}\x
?
The analog to Plain's \the\punkt in LaTeX would be
\the\csname c@punkt\endcsname
because when processing \newcounter{punkt} LaTeX does
\newcount\c@punct
Note the big difference: after \newcount (which is borrowed from plain TeX) there should be a control sequence name, whereas the argument to \newcounter is a string of characters that will be used to build different control sequences, namely
\c@punkt
\thepunkt
\p@punkt
The first one is the name of the allocated count register, the second one is the macro for the representation of the counter's value (by default \arabic{punkt}) and the last one is the “prefix” when processing a \label linked to this counter (see source2e for details). In particular, \newcounter{punkt} does not define \punkt.
So with \newcounter{punkt} and \the\punkt you get an error about an undefined control sequence (unless \punkt is independently defined) and if you press return at the error message, or if TeX is run in “nonstop” mode by a front-end, TeX ignores the undefined control sequence and proceeds to apply \the to the next token; since \space is expandable, TeX expands it and tries to apply \the to the resulting token list, but \the<space token> is illegal.
Always look at the first error message. And use \thepunkt instead.
\newcommand\newpt{\the\punkt\space\stepcounter{\punkt}}does give the claimed error in Overleaf as the second error of six. – Teepeemm Feb 22 '23 at 20:45