# LaTeX package “titling”, titles with hard line breaks, and \MakeUpperCase

I have a document with a title that is spread over several lines using hard line breaks. To configure the title formatting, I use the titling package with code adapted from its documentation:

\documentclass{article}

\usepackage{titling}
\pretitle{\begin{center}\LARGE\sffamily\bfseries}
\posttitle{\par\end{center}\vskip 0.5em}

\title{Higgelty Pigglety Pop! \\ or \\ There Must Be More to Life}

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


…and it works perfectly.

I now want the title additionally to be in all caps and therefore change the \pretitle command:

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


…and I get the following error message:

! Use of \@icentercr doesn't match its definition.
<argument> \def

l.12 \maketitle


This only happens with a title that includes hard line breaks.

What does this error message mean? How can I fix it?

• If that's your actual title then (a) that's awesome, and (b) you might want to be consistent with -elty vs -lety (that is, either Higglety Pigglety or Higgelty Piggelty; I might suggest the latter unless you're trying to invoke images of piglets anyway). – wchargin Feb 2 '15 at 20:39
• @WChargin, no its not, I just like this book. :) And you're right, it's actually Higglety Pigglety. – A. Donda Feb 2 '15 at 21:48

Split the title at \\ and apply \MakeUppercase to each chunk:

\documentclass{article}

\usepackage{titling}
\pretitle{\begin{center}\LARGE\sffamily\bfseries}
\posttitle{\par\end{center}\vskip 0.5em}
\makeatletter
\renewcommand{\title}[1]{\gdef\@title{\DoUppercase{#1}}}
\DeclareRobustCommand\DoUppercase[1]{\Do@Uppercase#1\\\@nil}
\def\Do@Uppercase#1\\#2\@nil{%
\MakeUppercase{#1}%
\ifx\\#2\\%
\expandafter\@gobble
\else
\\\expandafter\@firstofone
\fi
{\Do@Uppercase#2\@nil}%
}
\makeatother

\title{Higgelty Pigglety Pop! \\ or \\ There Must Be More to Life}

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


This is obtained by redefining \title to store \DoUppercase{<title>} in \@title rather than just the title.

You can't use the vertical spacing optional argument to \\, though.

If you want to support also \$3pt] or whatever, then it is possible with l3regex. \documentclass{article} \usepackage{xparse,l3regex} \usepackage{titling} \pretitle{\begin{center}\LARGE\sffamily\bfseries} \posttitle{\par\end{center}\vskip 0.5em} \makeatletter \renewcommand{\title}[1]{\gdef\@title{\DoUppercase{#1}}} \makeatother \ExplSyntaxOn \NewDocumentCommand{\DoUppercase}{m} { \tl_set:Nn \l_tmpa_tl { #1 } \tl_set:Nn \l_tmpb_tl { \\ } % Add \MakeUppercase{ at the beginning and } at end \regex_replace_once:nnN { (.*) } { \c{MakeUppercase}\cB\{\1\cE\}} \l_tmpa_tl % change \\[...] into }\\[...]\MakeUppercase{ \regex_replace_all:nnN { \u{l_tmpb_tl}\[(.*?)$ }
{ \cE\}\u{l_tmpb_tl}$\1$\c{MakeUppercase}\cB\{ }
\l_tmpa_tl
% change \\ into }\\\MakeUppercase{
\regex_replace_all:nnN
{ \u{l_tmpb_tl}([^\[]) }
{ \cE\}\u{l_tmpb_tl}\c{MakeUppercase}\cB\{\1 }
\l_tmpa_tl
\tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff

\title{Higgelty Pigglety Pop! \\[3pt] or \\ There Must Be More to Life}

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

• Thanks a lot, works perfectly! – Just out of interest: The stuff that "titling" does could all as well be implemented using \makeatletter, correct? Or rather, "titling" uses \makeatletter internally to plug in that pre- and post-code? – A. Donda Feb 2 '15 at 19:01
• @A.Donda Not sure what you mean; \makeatletter is used in order to access to “private macros”. – egreg Feb 2 '15 at 19:12
• OK, this just proves that I have only the most superficial understanding of the inner workings of TeX/LaTeX. :-) – A. Donda Feb 2 '15 at 19:23
• @egreg expl3-based version (essentially \renewcommand{\title}[1]{\xdef\@title{\tl_upper_case:n{#1}}} or similar)? – Joseph Wright Feb 2 '15 at 19:24
• @JosephWright Sorry, no. If I use \'{e} inside the title, the e is not uppercased. How I wished that Knuth had started providing an “all caps” font instead of slanted type. – egreg Feb 2 '15 at 21:07

This problem arises because \\ is redefined in the center environment to something fragile, which \MakeUppercase doesn't like (see also this answer). The simplest way to get this title to work is to \protect the \\:

\title{Higgelty Pigglety Pop! \protect\\ or \protect\\ There Must Be More to Life}

• Will this break the re-defined \\ somehow, or will it work just the same way? – imz -- Ivan Zakharyaschev Nov 8 '15 at 15:42
• BTW, this problem feels a bit weird. What do you think about the possibility of a command like \MakeUppercase which would display all the letters upper-cased, but without such tricky restrictions as \protecting \\ when centering. Perhaps, it's a fault of the definition of center, \centering etc., and a fix there could be imagined ? So that it all works more cleanly. I'm just thinking about the most clean way to solve such problem in theory... – imz -- Ivan Zakharyaschev Nov 8 '15 at 15:55

Here's a solution with stringstrings. The reason it does not work directly with \MakeUppercase is that the argument of the title contains the macro \\. I am presuming that the \MakeUppercase macro works only or regular expressions without macros. In general the stringstrings package has the same limitations, but it does have provisions for limited exceptions.

What the logic does is tell stringstrings to pre-encode each \\ into a ASCII-encoded sequence. It then can operate \caseupper on this sequence using its [e] encoded mode (which does not print out an immediate result, instead storing it in the expanded macro \thestring). The \retokenize macro is needed to process \thestring, reconverting each ASCII-encoded \\ back into the LaTeX macro \\.

In the course of answering this question, a bug was discovered in the stringstrings package which required the following patch.

\usepackage{xpatch}
% BUG FIX
\makeatletter
\xpatchcmd{\@retokenizechar}{{~}}{{\ }}
\makeatother


However...

UPDATE: The stringstrings package was upgraded to V1.23 on 2 FEB 2015, to resolve this bug. Here is the revised MWE, without the need for a patch.

\documentclass{article}
\usepackage{titling,stringstrings}

\pretitle{\begin{center}\LARGE\sffamily\bfseries%
\encodetoken{\\}\caseupper[e]%
}
\posttitle{\retokenize{\thestring}%
\thestring\par\end{center}\vskip 0.5em}

\title{Higgelty Pigglety Pop!\\or\\There Must Be More to Life}

%Now Works for string without \\
%\title{Higgelty Pigglety Pop! or There Must Be More to Life}

\begin{document}
\maketitle

\clearpage
\end{document}


• Perhaps you should also explain why the \MakeUppercase would not work – daleif Feb 2 '15 at 18:30
• @daleif Thanks. I have added some explanation. – Steven B. Segletes Feb 2 '15 at 18:34
• Thank you! – but: this appears to only work well with this specific manually line-broken title. If I remove the \ from the title, I get the title automatically broken like this: 1st line "HIGGELTY PIG-", 2nd line "GLETY POP! OR THERE MUST BE MORE TO LIFE". The second is also no longer properly centered. – A. Donda Feb 2 '15 at 18:39
• @A.Donda I commend the use of egreg's solution, but I wanted to post a repaired version that I think should also work. It required a bug-fix patch to stringstrings. – Steven B. Segletes Feb 2 '15 at 19:13
• @A.Donda The stringstrings package has been updated to V1.23 on 2 FEB 2015 to repair the bug discovered in the course of this answer. – Steven B. Segletes Feb 3 '15 at 10:54

A simple solution is to load David Carlisle textcase package with the option overload. Then you just put the \\-macro into a \NoCaseChange{}, i.e.

\usepackage[overload]{textcase}

...
...

\title{Higglety, Pigglety Pop!\NoCaseChange{\\}or\NoCaseChange{\\}
There must be more to life}

• I didn't say this explicitly, but the idea is not to have to make any changes to the title definition itself, but to have some preamble code that does the styling. Otherwise, I could just write the title in all-caps manually. – A. Donda Feb 3 '15 at 1:19
• @A.Donda OK. But I do not see the big difference between putting in  \\ and \NoCaseChange{\\} in \title{}. The  \\ is added to the \title, isn't it? – Sveinung Feb 3 '15 at 18:07