LaTeX warning "Token not allowed in a PDF string (Unicode)": cause and fix

Warning Token not allowed in a PDF string (Unicode)

hyperref copies every heading into the bookmarks of the PDF, the outline in the side panel of a PDF viewer. A bookmark is plain text, so hyperref removes what plain text cannot hold and names it in the next line of the log: "math shift" is a $, "superscript" a ^, "subscript" a _. The heading on the page is not affected.

Why it happens

How to fix it

A document that produces the message

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\section{The formula $E = mc^2$}
Text.
\end{document}

Open in the editor

The corrected document

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\section{The formula \texorpdfstring{$E = mc^2$}{E = mc2}}
Text.
\end{document}

Open in the editor

Both documents were compiled with pdfLaTeX from TeX Live 2023. The first produces the message, the second compiles without an error.

Finding the line in the editor

The editor lists every error and warning of a compile run with file and line. Select an entry and the cursor jumps to that line. See Error list with jump to the line.

Related pages