# How do I make a command to display a custom title page?

I followed the advice on the question What do \makeatletter and \makeatother do? to try to make a custom command that displays a custom title page, but it is not working.

./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.


What follows is the simplified code:

\documentclass[12pt]{article}

\newcommand{\makecustomtitle}{
\begin{titlepage}
\makeatletter

\@title by \@author

\makeatother
\end{titlepage}
}

\begin{document}
\author{Andres Riofrio}

\makecustomtitle

Take on me.

\end{document}

-

You need to move the \makeatletter and \makeatother outside of the \newcommand.

\makeatletter
\newcommand{\makecustomtitle}{%
\begin{titlepage}
\@title by \@author
\end{titlepage}
}
\makeatother


The difference is that in the above set-up the category codes are changed at the time of definition; in your set-up they were attempting to change at the time of use.

Note that I've also added % to the end of the first line. Have a look at these links:

-
Actually, those % characters are useless in this particular example: vertical mode, where spaces are ignored, is in force after \begin{titlepage} and \end{titlepage}. It's not necessary after \@author, because spaces are ignored after control sequences. It's not necessary when ending a definition in the preamble. The only sensible place is after the { that starts the definition, but in this particular case it's not needed either, as the command will be given in vertical mode. :) –  egreg Oct 16 '11 at 21:40
That was very useful. Thanks! In the end I also put the code in an .sty file, not needing \makeatletter anymore. –  Andres Riofrio Oct 16 '11 at 21:44
@egreg Thank you for details! Please feel free to edit, or let me know if I should. –  cmhughes Oct 16 '11 at 21:49