215

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

\author{Name \\ \texttt{[email protected]}}

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?

0

4 Answers 4

221

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{\\ [email protected]}{}} 

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...)

2
  • 1
    It's nice. There ought to exist an option in hyperref to automatically replace all non-allowed tokens by {} for the pdf string. Doing this for all my section titles is a hassle.
    – Arnaud
    Commented Sep 3, 2022 at 19:20
  • 1
    I used it in \author, before \begin{document}, and it worked. I also used a shorter syntax - \texorpdfstring{\\}
    – Zvika
    Commented Jan 16, 2023 at 12:13
110

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{[email protected]}}

and will be formatted as is, but then put as Name <[email protected]> in the PDF info strings.

3
  • 2
    Best answer. For me, the offender was glossaries. I had to do \pdfstringdefDisableCommands{% \def\Glsxtrshort{}% \def\glsxtrshort{}}
    – Marcel
    Commented Jun 1, 2022 at 17:29
  • What would be the syntax for the "math" command, e.g. \section{Local $d$-Privacy}? Commented Sep 28, 2023 at 9:51
  • In this case you can use the LaTeX way of inline math, i.e. \(d\). Then you can redefine \( and \) inside the command to expand to nothing Commented Sep 28, 2023 at 20:35
45

One can also add

\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{naturalnames}{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.

P.S. Usually one may get up to few thousands of those even for a simple presentation, and parsing of them takes few extra seconds for many IDEs even on a modern box.

1

There is an option to disable automatic generation of title and author entries in the pdf document information, if you don't care about it.

\documentclass[usepdftitle=false]{beamer}

This is suggested at the end of section 10.1 in the user guide.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .