# Hyperref warning - Token not allowed in a PDF string

When compiling a beamer presentation and using the following \author command

\author{Name \\ \texttt{my.email@domain.com}}


I get the following hyperref warning in my logfile

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing \\' on input line 15.

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing \new@ifnextchar' on input line 15.


I understand that this has to do with hyperref setting the PDF metadata, where the linebreak does’t make much sense and should be removed.

Trying to set

\hypersetup{pdfauthor={Name}}


does’t change the situation, seems like hyperref is still looking at the author command.

How do I get the desired display of author name with email and still keep hyperref happy?

There's the aptly, if verbosely, named macro \texorpdfstring, which takes two arguments and uses the first for (La)TeX and the second for pdf, so something like

\author{A.U. Thor\texorpdfstring{\\ foo@bar.baz}{}}


should work.

The command is not defined in the document preamble, so \author{} must be specified after \begin{document} in this case.

(Yes, I've avoided the issue that I don't know off the top of my head if \url is allowed to go inside another argument...)

While Ulrich's answer is correct and works, there is a more general and transparent way to work around the issue.

The \pdfstringdefDisableCommands command from the hyperref package can be used to redefine commands that are usually not supported in PDF bookmark strings.

In the OP example, the offending commands are \\ and \texttt, which can be redefined to do something else in this way:

\pdfstringdefDisableCommands{%
\def\\{}%
\def\texttt#1{<#1>}%
}


Then, the author can be specified in the document without any special care:

\author{Name \\ \texttt{my.email@domain.com}}


and will be formatted as is, but then put as Name <my.email@domain.com> in the PDF info strings.

\PassOptionsToPackage{unicode}{hyperref}

before \documentclass{beamer} to remove many messages generated due to national (non-English) section titles, like
Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing \PD1\cyrn' on input line 33.
`