[Tex/LaTex] Understanding custom definitions of \maketitle

macrosthesis

I've been using some style file to write my thesis and it contains some weird macro definition I don't seem to understand, specifically it contains the following code to make a custom title page:

\let\origin@lmaketitle\maketitle
\def\makethesistitle{
  \def\@titlehead{\centering\st@logo\\\smallskip\large\st@university}
  \def\@title{\st@title}
  \def\@subject{\@fordegree\\\st@subject}
  \def\@author{{\normalsize\@by}\\{\st@author} \\[1.5\bigskipamount]%
    {\normalsize\@undersup}\\{\itshape\st@supervisor}%
    \\[1.5\bigskipamount]}
\def\@date{\ifdefined\st@date\st@date\else\if@Latin\latintoday\else\today\fi\fi}
  \origin@lmaketitle
  \newcommand\date[1]{\def\st@date{##1}}
  \newcommand\title[1]{\def\st@title{##1}}
  \newcommand\author[1]{\def\st@author{##1}}
  \newcommand\subject[1]{\def\st@subject{##1}}}

\renewcommand\date[1]{\def\st@date{#1}}
\renewcommand\title[1]{\def\st@title{#1}}
\renewcommand\author[1]{\def\st@author{#1}}
\renewcommand\subject[1]{\def\st@subject{#1}}
\newcommand\logo[1]{\def\st@logo{#1}}
\newcommand\university[1]{\def\st@university{#1}}
\newcommand\supervisor[1]{\def\st@supervisor{#1}}
\def\@undersup{\if@Latin Supervisor\else استاد راهنما\fi}
\def\@by{\if@Latin By\else نگارش\fi}
\def\@fordegree{\if@Latin B.Sc Thesis\else پایان‌نامه کارشناسی\fi}

These commands are then used as usual to define the content of that page:

\begin{document}
\logo{\includegraphics{logo}}
\date{
today
}
\title{
some title
}
\author{
me
}
\university{%
there
}
\subject{%
that
}
\supervisor{
you
}
\frontmatter \makethesistitle

As the style definition only seems to be defining macros that define new macros, I don't really get what is going on here. There is seemingly no problem with this code as it outputs just what its supposed to. I'd appreciate if someone could enlighten me a little bit.

Best Answer

The various commands defined using the pattern:

\renewcommand\field[1]{\def\st@field{#1}}

simply introduce a way to store a value for a field in a corresponding \st@field macro that can be used later. The effect of writing \field{value} is defining \st@field to be value. At any later point you can use \st@field to typeset value.

The actual typesetting of these values takes place in the \makethesistitle macro.

Specifically, \makethesistitle calls \origin@lmaketitle which at the beginning is let to be \maketitle which, presumably, is where the various elements \st@field are typeset in the final title page.

Consider for example:

\renewcommand\title[1]{\def\st@title{#1}}
\renewcommand\subtitle[1]{\def\st@subtitle{#1}}

\def\maketitle{
   Thesis\vfill
   \begin{center}
      \bfseries
      \complete@title
   \end{center}
   \vfill
}
\def\makethesistitle{
   \def\complete@title{\LARGE\st@title\\\large\st@subtitle}
   \maketitle
}

when in your document you write

\title{Bla}
\subtitle{blabla}
\makethesistitle

you roughly obtain

\def\st@title{Bla}
\def\st@subtitle{#1}
\def\complete@title{\LARGE\st@title\\\large\st@subtitle}
   Thesis\vfill
   \begin{center}
      \bfseries
      \complete@title
   \end{center}
   \vfill

As you can see the definitions of the intermediate macros is just in preparation for the actual typesetting. This is especially useful if you are reusing the same information (for example author names) for setting up other parts of the document as the headings etc.

There is a further aspect here. In the code you provide, the class writers are reusing some default implementation of \maketitle. Since the class you are using introduces non-standard fields that are not known by the default \maketitle (which in the standard classes only uses \@title, \@author and \@date), the \makethesistitle macro is setting up the macros that the default \maketitle uses in terms of the custom \st@ prefixed ones defined by the class. (for example you see \def\@title{\st@title}).

Related Question