我听从了这个问题的建议\makeatletter 和 \makeatother 起什么作用?尝试制作一个显示自定义标题页的自定义命令,但它不起作用。
./article.tex:17: You can't use `\spacefactor' in vertical mode.\@ ->\spacefactor
\@m
l.17 \makecustomtitle
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'.
./article.tex:17: Missing $ inserted.<inserted text>
$
l.17 \makecustomtitle
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
./example.tex:17: You can't use `\spacefactor' in math mode.\@ ->\spacefactor
\@m
l.17 \makecustomtitle
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'.
./example.tex:17: Missing $ inserted.<inserted text>
$
l.17 \makecustomtitle
I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
以下是简化的代码:
\documentclass[12pt]{article}
\newcommand{\makecustomtitle}{
\begin{titlepage}
\makeatletter
\@title by \@author
\makeatother
\end{titlepage}
}
\begin{document}
\title{Please, be my title}
\author{Andres Riofrio}
\makecustomtitle
Take on me.
\end{document}
答案1
您需要将\makeatletter
和\makeatother
移到 之外\newcommand
。
\makeatletter
\newcommand{\makecustomtitle}{%
\begin{titlepage}
\@title by \@author
\end{titlepage}
}
\makeatother
区别在于,在上述设置中,类别代码在定义时发生更改;而在您的设置中,它们试图在使用时发生更改。
请注意,我还在%
第一行末尾添加了内容。请查看以下链接: