LaTeX warning · Packages, files and fonts

Package hyperref Warning: Token not allowed in a PDF string (Unicode): removing `math shift'

Quick answer

hyperref turns every section title into a PDF bookmark, and bookmarks are plain text. When a title contains math ($...$), a superscript, \\ or a formatting command, hyperref cannot convert it, removes the token and warns. The PDF still compiles, but the bookmark reads oddly ("Energy E = mc2"). Give hyperref a plain-text version with \texorpdfstring{$E = mc^2$}{E = mc²}.

The warning in the log

This is how the message appears in the .log file (and in the compile output). The line starting with l. is the line number where TeX noticed the problem; the real mistake is there or just before it.

Package hyperref Warning: Token not allowed in a PDF string (Unicode):
(hyperref)                removing `math shift' on input line 4.

Package hyperref Warning: Token not allowed in a PDF string (Unicode):
(hyperref)                removing `superscript' on input line 4.

Why it happens

  • Inline math in a \section, \subsection, \chapter or \caption title: the math shift token is the $.
  • Superscripts, subscripts or math commands in a title (^, _, \alpha).
  • A line break \\ or a command such as \footnote, \cite or a user macro in the title, reported as removing \\ or removing \cite.

How to fix it

Wrap the part hyperref cannot handle in \texorpdfstring{TeX version}{text version}: the first argument is typeset in the document, the second goes into the bookmark. The text version may contain Unicode such as ² or α.

For a line break in a title, give a short title for the table of contents and bookmarks with \section[Short title]{Long\\title}. Footnotes in titles belong after the optional argument too.

Broken: reproduces the warning

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

Try this in Octree — free LaTeX editor with AI, compiles in your browser

Fixed: compiles cleanly

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

Related errors

Frequently Asked Questions

Is "Token not allowed in a PDF string" an error?

No, it is a warning. The PDF is produced and the section title looks right on the page. Only the PDF bookmark (the outline panel in a PDF viewer) is affected, because hyperref dropped the parts it could not convert.

How do I use math in a section title with hyperref?

Write \section{Results for \texorpdfstring{$\alpha$}{alpha}}. The first argument is used in the document and the table of contents, the second in the bookmark; it can be Unicode, such as α.

How do I turn off the PDF bookmarks instead?

Load hyperref with \usepackage[bookmarks=false]{hyperref}. That removes the warning together with the bookmarks, which most readers use for navigation, so \texorpdfstring is usually the better fix.

Paste your document into Octree — compile errors get a Fix with AI button

When a compile fails, Octree shows the error next to the line that caused it and offers a one-click fix that you can review before applying. Free, nothing to install.

Fix it in Octree →