Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
MWE?........... –  Andrew Swann Aug 9 '13 at 12:17
    
@AndrewSwann I didn't think the question warranted an MWE, but sure; it's on the way. –  Jubobs Aug 9 '13 at 12:19
    
@Jubobs, I think Andrew Swann may have had the same though as me, I'd like to figure out why you need a forced line break in the title, rather than a subtitle –  Chris H Aug 9 '13 at 12:21
2  
Well for one thing, the title macro depends on the documentclass, and may or may not take an optional argument that could be used. Then there is \textorpdfstring for hyperref... –  Andrew Swann Aug 9 '13 at 12:23
    
@ChrisH I can sympathisze with the general thought. Title layout on the page and its line breaks is quite critical with regard to emphasing/deemphasing certain words etc. –  Andrew Swann Aug 9 '13 at 12:25
show 5 more comments

2 Answers 2

up vote 9 down vote accepted

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.

share|improve this answer
add comment

The easiest way is using option pdfusetitle and without spaces around \\ in \title:

\documentclass{book}

\usepackage{kantlipsum}
\usepackage[pdfusetitle]{hyperref}

\author{Me, me, me}
\title{Me,\\myself,\\and I}

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

Result of pdfinfo:

Title:          Me, myself, and I
Author:         Me, me, me

Otherwise, there is \texorpdfstring:

\title{My,\texorpdfstring{\\}{ }myself,\texorpdfstring{\\}{ }and I}

Or \pdfstringdefDisableCommands can be used, e.g.:

\pdfstringdefDisableCommands{\def\\#1{ #1}}

That is the definition that is used for the title with option pdfusetitle, it supports the following forms:

\title{Me,\\myself,\\and I}
\title{Me,\\ myself,\\ and I}

If you prefer more spaces:

\pdfstringdefDisableCommands{\let\\\@firstofone}
\title{Me, \\ myself, \\ and I}

The trick with the argument is, that TeX does not accept a space as undelimited argument. Thus the space after \\ is gobbled.

The spaces are one of the reasons, that \\ is not provided by hyperref and a warning is given. The usual tricks (\unskip, \ignorespaces, ...) are not working inside the generation of PDF strings.

share|improve this answer
    
Such a great answer! Thanks. I guess I can also use \texorpdfstring to include nonbreaking spaces in the title as recommended by Barbara. –  Jubobs Aug 9 '13 at 13:33
1  
@Jubobs: ~ is supported by hyperref, no need for \texorpdfstring. –  Heiko Oberdiek Aug 9 '13 at 13:34
    
Great. Even better. Thanks again. –  Jubobs Aug 9 '13 at 13:35
    
@HeikoOberdiek As a substitute for \ignorespaces inside the generation of PDF strings, you could use \romannumeral-^^ \q. Of couse, that leaves a preceeding space: this could be a problem. Alternatively, one could implement \unskip by adding a step after the full expansion and after stripping braces which would strip all occurrences of <space>\unskip. –  Bruno Le Floch Aug 9 '13 at 18:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.