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 thetitlepage
document class option was not set: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 thetwocolumn
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? Inarticle.cls
, one finds the following code: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-columntabular
environment, in\large
(20% larger than\normalsize
); and the argument of\date
(if any) also gets typeset in\large
. Thecenter
environment ends and a vertical skip of 1.5em is inserted. Importantly, no page break is inserted. Thus, if the next document element is theabstract
environment, LaTeX will try to fit the abstract on the page that already contains the title, author, and date elements.