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:
- I always endeavour to separate form and content, for maintainability reasons.
- The title may need to be inserted elsewhere in the document, in places where line breaks within it are not warranted.
- I pass my title to
\hypersetup{pdftitle=...};hyperrefreturns 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}
\textorpdfstringfor hyperref... – Andrew Swann Aug 09 '13 at 12:23\texorpdfstringwould obviate the warning. However, what about my 2nd point? What if I need to format my title in a different way, somewhere else than on the title page? – jub0bs Aug 09 '13 at 12:30\titlecrthat is initially\\, but is\letto\relaxjust after\maketitle(assuming you have saved\@title), or redefined to something more appropriate in other applications. – Andrew Swann Aug 09 '13 at 12:44~(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 have to break the line explicitly. depends on how the\titleargument is processed; the stretch has to be defined with sufficient flexibility, which depends on the document class. – barbara beeton Aug 09 '13 at 12:53