# How come I can redefine \maketitlehooka but not pass the same as an argument to \pretitle in the titling package?

I am attempting to change the font and size of the title through means of the titling package.

In the documentation, it is described that the \maketitle now looks something like this:

\renewcommand{\maketitle}{%
\vspace*{\droptitle}
\maketitlehooka
{\pretitle \title \posttitle}
\maketitlehookb
{\preauthor \author \postauthor}
\maketitlehookc
{\predate \date \postdate}
\maketitlehookd
}


And that the \pre & \post macros can be used to change the typesetting of the title. Also the \maketitlehookX can be used to add stuff or change formatting. I've noticed that the \pre and \post macros only seem to work when I explicitly create a group or an environment within which I do my work (be it changing formatting or adding some extra text to the title). But if I add the text or formatting as arguments to the \pretitle macro I get an error:

LaTeX Error: \begin{titlepage} on input line 9 ended by \end{center}.


However if I \renewcommand\maketitlehooka with the same text/formatting it works fine. I suppose the question is what is different between redefining a macro as described and passing the same code as an argument? or Why do I need to explicitly need to start a group within the {...} which already surrounds the pre/post title-group?

A minimal working example:

\documentclass[12pt,twoside]{report}
\usepackage{titling}    % taking control over the title format
%\renewcommand\maketitlehooka{\sffamily\bfseries} % Works
%\pretitle{\sffamily\bfseries} % Does not work
\pretitle{\begingroup\sffamily\bfseries} % This also works, kind of
\posttitle{\endgroup} % but needs this and will mess up some other formating
\title{The title}
\begin{document}
\maketitle
\end{document}


It is worth noting that redefining \maketitlehooka requires only some small changes to make it look like I want while using \begingroup\endgroup will flush everything right and reset the font size. So \begingroup\endgroup might not be exactly what I'd want to use here.

It's because of the default definitions \pretitle and \posttitle. Their definitions at package load (from titling.dtx are

\pretitle{\begin{center}\LARGE}
\posttitle{\par\end{center}\vskip 2em}


So, updating \pretitle to

\pretitle{\sffamily\bfseries}


leaves an unpaired \end{center} in \posttitle which causes the problem. So, you either need to redefine both, or add your formatting as part of it. Here are some options:

• Appending content to \@bspretitle - the macro holding whatever is passed to \pretitle:

\makeatletter
\makeatother

• Redefining \pretitle entirely but include the original

\pretitle{\begin{center}\LARGE\sffamily\bfseries}

• Updating both \pretitle and \posttitle if you want to remove the center environment and \LARGE formatting:

\pretitle{\sffamily\bfseries}
\posttitle{}


There is no need for a group here, since the group is already established in the definition of \maketitle.

• Updating \maketitlehooka to insert the content in the appropriate location:

\makeatletter
\renewcommand{\maketitlehooka}[1]{{%
\@bspretitle
\sffamily\bfseries
\@title
\@bsposttitle
}}
\makeatother


Note the additional group to limit the scope of the formatting. This is because we've redefined \maketitlehooka to take an argument. This argument removes the original definition scope.