# hyperref token not allowed warning, possible bug?

I currently am using the hyperref package and I'm currently getting a lot of error messages. Currently all of the chapter and section titles give this same error. I decided to try make a minimum example and currently:

\documentclass{amsbook}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[dvipsnames,usenames]{color}

\begin{document}
\pagenumbering{roman}

\chapter{Preface}

\mainmatter
\pagenumbering{arabic}

\part{The}

\end{document}


Is giving me the following warnings:

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                \kern 5.0pt
(hyperref)                replaced by space on input line 18.

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


Is this a bug with the hyperref package or is this just a result of me not setting up things properly? How do I go about either fixing this or silencing the warning messages?

-
\part{The} wouldn't produce those warnings. Please prepare a minimal working example (MWE) that reproduces the messages. –  cgnieder Nov 4 '13 at 17:19
@cgnieder, This is producing exactly those warnings on my setup here. This was a minimal example. –  shuttle87 Nov 4 '13 at 17:20
No. A MWE starts with \documentclass and ends with \end{document}. This doesn't produce said warnings: \documentclass{article} \usepackage{hyperref} \begin{document} \tableofcontents \part{The} \end{document} –  cgnieder Nov 4 '13 at 17:23
@cgnieder, edited as per request to include the entire example file I ran this from. –  shuttle87 Nov 4 '13 at 17:31
It seems to be a bug related to amsbook, as discussed in this link. You may want to ignore the warning, if it is not affecting the desired output. –  Pedro Nov 4 '13 at 18:05

It's not really a bug, but an innocuous “feature”. You can cure it by disabling the offending commands during bookmark preparation:

\documentclass{amsbook}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[dvipsnames,usenames]{color}
\usepackage{hyperref}

\pdfstringdefDisableCommands{%
\let\enspace\empty  % this causes the warning for \kern
\let\noindent\empty % this causes the warning for \indent
}

\begin{document}
\frontmatter

\chapter{Preface}

\mainmatter

\part{The}

\end{document}


The macro \pdfstringdefDisableCommand has precisely this purpose: to add definitions for commands that make no sense in bookmarks. Several commands are already redefined to safe version (for instance \<space>), but it would slow down compilation if all commands one can think of were included. So only the most common ones are redefined, others can be added when needed.

As an aside, note that \frontmatter should be preferred to \pagenumbering{roman} for the front matter of the document. There's no need of \pagenumbering{arabic} after \mainmatter.

-