# How to reduce the spacing for empty dates in title (when using the titling package)

I am looking for a marco which changes the behaviour of date (while using the titling package) in the case the date is empty.

This MWE A should give a document as normal:

\documentclass{article}
\usepackage{titling}
\title{A date test title}
\date{13 Dec 13}

%
% Here go the tweak macros enhancing the behaviour of \date
% ...
% ...
%

\begin{document}
\maketitle
text text text text text text text text text text text text text text text text text text
\end{document}


But for the following MWE B I want a result with a smaller space between title and text because there is no date printed.

\documentclass{article}
\usepackage{titling}
\title{A date test title}
\date{} % DATE IS NOW EMPTY!

%
% Here go the tweak macros enhancing the behaviour of \date
% ...
% ...
%

\begin{document}
\maketitle
text text text text text text text text text text text text text text text text text text
\end{document}


How can I achieve this with generic tweak macros (changing probably the internal commands of the titling package) so that the same tweak works in both cases, for empty dates and set dates.

The tweak macros somehow have to test whether \@date is empty or not. I tried \ifdefempty (from the etoolbox package) but \@date seems to be never empty, even if no date gets printed (i.e. \date{}).

The titling package (titling.sty) renews the command \maketitle. The printing of the date happens in \maketitle or, if no own page is created (for example article class) in \@maketitle which is invoked by \maketitle. So be sure you know which macro you need to patch. Then you can simply exchange its content with \pathcmd from etoolbox package. (Of course you could write a solution for both cases using \if@titlepage but I think for normal purposes that's not necessary.)

MWE:

\documentclass{article}
\usepackage{titling,etoolbox}
\title{A date test title}
\date{13 Dec 13}
% \date{}

\makeatletter
\ifx\@date\empty
\patchcmd{\@maketitle}{{\@bspredate \@date \@bspostdate} \maketitlehookd \par \vskip 1.5em}{\vskip 0.5em}{}{}
% \patchcmd{\maketitle}{{\@bspredate \@date \@bspostdate} \maketitlehookd \par}{\vskip 0.5em}{}{}%for document classes with extra title pages
\fi
\makeatother

\begin{document}
\maketitle
text text text text text text text text text text text text text text text text text text
\end{document}

• Works perfectly for the date. I didn't know about \patchcmd. Thanks. – halloleo Oct 21 '15 at 4:09
• However it does not work for the author if you don't set \author{}, but just leave it as is. The test has to be different then: \sbox0{\@author}\ifdim\wd0=\z@ (instead of \ifx\@author\empty). – halloleo Oct 21 '15 at 4:13

I use something like this:

\documentclass{article}
\usepackage{titling}
\title{A date test title}
\author{Author}
\makeatletter
\predate{%
\ifx\@empty\thedate\relax
\else\begin{center}\large
\fi}
\postdate{%
\ifx\@empty\thedate\relax
\else\par\end{center}\fi}
\makeatother
\begin{document}
\maketitle
text text text text text text text text text text text text text text text text text text
\date{} % DATE IS NOW EMPTY!
\maketitle
text text text text text text text text text text text text text text text text text text
\end{document}