0

I met the error You can't use `\spacefactor' in vertical mode. when using \@whilenum for a loop. Below is a minimum not-working example. Why is this wrong?

\documentclass{article}
\usepackage[utf8]{inputenc}
\title{loop}\author{}
\begin{document}
\maketitle
\@whilenum\value{section}<6\do{\section{more}}
\end{document}

Error Message

You can't use `\spacefactor' in vertical mode.
\@->\spacefactor 
                 \@m {}
l.6 \@
      whilenum\value{section}<6\do{\section{more}}
Sorry, but I'm not programmed to handle this case;
I'll just pretend that you didn't ask for it.
If you're in the wrong mode, you might be able to
return to the right one by typing `I}' or `I$' or `I\par'.

! Missing $ inserted. <inserted text> $ l.6 @ whilenum\value{section}<6\do{\section{more}} I've inserted a begin-math/end-math symbol since I think you left one out. Proceed, with fingers crossed.

youthdoo
  • 861

1 Answers1

1

Following user Lupino's comment, I provide the following community answer. Please refer to What do \makeatletter and \makeatother do? for information regarding \makeatletter and \makeatother.

\documentclass{article}
\usepackage[utf8]{inputenc}
\title{loop}\author{}
\begin{document}
\maketitle
\makeatletter % <-- Added
\@whilenum\value{section}<6\do{\section{more}}
\makeatother % <-- Added
\end{document}

enter image description here