\@whilenum 的问题

\@whilenum 的问题

You can't use `\spacefactor' in vertical mode.我在使用\@whilenumfor 循环时遇到了错误。下面是一个不工作的小例子。为什么会出现这个错误?

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

错误信息

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.

答案1

根据用户 Lupino 的评论,我提供了以下社区答案。请参阅\makeatletter 和 \makeatother 起什么作用?有关\makeatletter和 的信息\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}

在此处输入图片描述

相关内容