[Tex/LaTex] How to effect line breaks within the title without hardcoding \\’s in \title

hyperrefline-breakingtitles

Although I do need line breaks within my title for my document's title page (I'm using the book class), I'd like to avoid hardcoding line breaks in the argument passed to the \title command, for three reasons:

  1. I always endeavour to separate form and content, for maintainability reasons.
  2. The title may need to be inserted elsewhere in the document, in places where line breaks within it are not warranted.
  3. I pass my title to\hypersetup{pdftitle=...}; hyperref returns a warning,

Token not allowed in a PDF string (PDFDocEnconding):(hyper ref) removing `\\'

if the title contains some \\, and I want to limit the number of compilation warnings to the bare minimum.

How can I effect line breaks at specific places within the title, upon inserting the latter somewhere in my document, without hardcoding \\'s in the \title{...} command? What's the best practice?

\documentclass{book}

\author{Me, me, me}
%\title{Me, myself, and I}      % compiles without mishap; strictly content
\title{Me,\\ myself, \\ and I}  % compilation warnings occur; form and content are mixed

\usepackage{kantlipsum}
\usepackage{hyperref}
\makeatletter
\hypersetup{
    pdftitle = \@title,
}
\makeatother

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

Best Answer

if you always want certain phrases "tied together", use the ~ (tilde = tie) instead of a space between them. sometimes this works to encourage a line break, but sometimes you end up with an overfull box and still have to break the line explicitly.

(this is the same approach recommended in the texbook for keeping things like "Dr.~No" and "Figure~1" from breaking apart at the end of a line.)

the actual result depends on how the \title argument is processed; the stretch has to be defined with sufficient flexibility, which depends on the document class.

Related Question