12

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?

  • 1
    \part{The} wouldn't produce those warnings. Please prepare a minimal working example (MWE) that reproduces the messages. – clemens 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
  • 3
    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} – clemens 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
  • 1
    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
14

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.

  • With \quad in a Section title, hyperref throws a "Warning: Token not allowed in a PDF string", which is suppressed by, in the preamble after invoking hyperref, \pdfstringdefDisableCommands{\let\hskip\empty}. – JosephHarriott Oct 5 '16 at 21:13
  • @JosephHarriott I'd prefer \let\quad\space – egreg Oct 5 '16 at 21:17
  • 1
    \pdfstringdefDisableCommands{\let\quad\space} doesn't suppress the "Warning: Token not allowed in a PDF string". – JosephHarriott Oct 5 '16 at 21:24
  • @JosephHarriott Doh! – egreg Oct 5 '16 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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