[Tex/LaTex] how does ‘\maketitle’ work

documentclass-writinglatex-base

I would like to know how the \maketitle command works since I am creating my own class and I want to use my own commands.
For example, I already create certain commands like \a, \b and \c and I want that with a certain command we say \printabc a new page is created printing such commands.

Thanks in advance

EDIT 1: I try to define

\def\@mycover{%
    \newpage\null
}

but get the error

! Use of \@ doesn't match its definition.

EDIT 2: I have made progress.

\documentclass{myclass}

\makeatletter
\newcommand*{\mytitle}[1]{\gdef\@mytitle{\MakeUppercase{#1}}}
\newcommand*{\myauthors}[5]{\gdef\@myauthors{
    \begin{tabular}{c}
        \MakeUppercase{#1} \\ 
        \MakeUppercase{#2} \\  
        \MakeUppercase{#3} \\
        \MakeUppercase{#4} \\
        \MakeUppercase{#5}
    \end{tabular}
}}
\newcommand*{\myafil}[5]{\gdef\@myafil{
    \begin{tabular}{c}
        \MakeUppercase{#1} \\ 
        \MakeUppercase{#2} \\  
        \MakeUppercase{#3} \\
        \MakeUppercase{#4} \\
        \MakeUppercase{#5}
    \end{tabular}
}}
\newcommand\makecover{\begin{titlepage}%
    \thispagestyle{empty}\centering\bfseries
    \@mytitle
    \vfill
    \@myauthors
    \vfill
    \@myafil
\end{titlepage}
\global\let\makecover\relax
\global\let\@mytitle\@empty
\global\let\@myauthors\@empty
\global\let\@myafil\@empty
\global\let\mytitle\relax
\global\let\myauthors\relax
\global\let\myafil\relax
}
\makeatother

\mytitle{The Title}
\myauthors{Author 1}{}{}{}{}
\myafil{University}{Faculty of exact and natural sciences}{Department of Mathematics}{City}{Year}

\begin{document}
\makecover
\end{document}

This is all right, but when I comment for example

%\myauthors{Author 1}{}{}{}{}

the following error arises

! Undefined control
sequence.

something that does not happen in class book. why does that happen?

Best Answer

Let's assume you're basing your document class on the article document class. The following definition of \maketitle applies if the titlepage document class option was not set:

\newcommand\maketitle{\par
  \begingroup
    \renewcommand\thefootnote{\@fnsymbol\c@footnote}%
    \def\@makefnmark{\rlap{\@textsuperscript{\normalfont\@thefnmark}}}%
    \long\def\@makefntext##1{\parindent 1em\noindent
            \hb@xt@1.8em{%
                \hss\@textsuperscript{\normalfont\@thefnmark}}##1}%
    \if@twocolumn
      \ifnum \col@number=\@ne
        \@maketitle
      \else
        \twocolumn[\@maketitle]%
      \fi
    \else
      \newpage
      \global\@topnum\z@   % Prevents figures from going at top of page.
      \@maketitle
    \fi
    \thispagestyle{plain}\@thanks
  \endgroup
  \setcounter{footnote}{0}%
  \global\let\thanks\relax
  \global\let\maketitle\relax
  \global\let\@maketitle\relax
  \global\let\@thanks\@empty
  \global\let\@author\@empty
  \global\let\@date\@empty
  \global\let\@title\@empty
  \global\let\title\relax
  \global\let\author\relax
  \global\let\date\relax
  \global\let\and\relax
}

What's going on? The macro consists mainly of two parts.

  • In the first part, i.e., the material that's sandwiched between \begingroup and \endgroup, we begin by resetting how footnotes are typeset; mostly, symbolic markers (asterisks, daggers, etc) are used as footnote markers instead of numerals. Next, LaTeX checks if the twocolumn document class was set; if the answer is "no", the \newpage instruction is executed, followed by \@maketitle. (The contents of \@maketitle are examined in more detail below.)

  • In the second part, the footnote counter is (re)set to 0, and then the macros \thanks, \maketitle, \@maketitle, \@thanks, \@author, \@date, \@title, \title, \author, \date, and \and -- which are all defined in the LaTeX kernel -- are all unset. The \global qualifiers are needed, as otherswise the \let\xyz\relax directives would not apply outside of the current group, which was started by the \begingroup directive mentioned above.

The upshot: The macros \title, \author, \date can not be used again once \maketitle has been run. What's the purpose of unsetting these macros, you may ask? If nothing else, this step makes sure that one cannot -- accidentally or intentionally -- run \maketitle more than once in a document.

Finally, how is the macro \@maketitle defined? In article.cls, one finds the following code:

\def\@maketitle{%
  \newpage
  \null
  \vskip 2em%
  \begin{center}%
  \let \footnote \thanks
    {\LARGE \@title \par}%
    \vskip 1.5em%
    {\large
      \lineskip .5em%
      \begin{tabular}[t]{c}%
        \@author
      \end{tabular}\par}%
    \vskip 1em%
    {\large \@date}%
  \end{center}%
  \par
  \vskip 1.5em}

The bulk of the code occurs between \begin{center} and \end{center}: The argument of \title, which gets typeset via \@title, is set at the \LARGE font size (72.7% larger than \normalsize); the argument of \author gets typeset inside a 1-column tabular environment, in \large (20% larger than \normalsize); and the argument of \date (if any) also gets typeset in \large. The center environment ends and a vertical skip of 1.5em is inserted. Importantly, no page break is inserted. Thus, if the next document element is the abstract environment, LaTeX will try to fit the abstract on the page that already contains the title, author, and date elements.