# Package hyperref Warning: Token not allowed in a PDF string [duplicate]

My document contains section titles that are formatted by the listings package. (The section names are names of configure script switches.)

\subsection{\lstinline!--enable-so-version!}\label{enable-so-version}


I am getting the following warning when processing the LaTeX source:

Package hyperref Warning: Token not allowed in a PDF string (Unicode):
(hyperref)                removing \lstinline' on input line 231.


Can I avoid it anyhow? I would be willing to duplicate the title string without the listings formatting decoration if there were a directive to set the PDF TOC entry string manually (instead of automatically).

## marked as duplicate by jub0bs, Jesse, Peter Jansson, Guido, Svend TveskægFeb 9 '14 at 14:09

Many commands that works via unexpandable stuff (assignments, catcode changes, ...) do not work in bookmarks. A PDF viewer is not TeX and does not understand the TeX language.

Package hyperref provides \texorpdfstring to provide different code for the normal case and the bookmark case:

\documentclass{article}
\usepackage{listings}
\usepackage{hyperref}
\usepackage{bookmark}

\begin{document}
\tableofcontents
\section{%
\texorpdfstring{\lstinline!--enable-so-version!}%
{-{}-enable-so-version}}
\end{document}


Remarks:

• The curly braces inside -{}-enable prevent that the bookmark code makes a ligature and converts the two single hyphens to an en dash.
• Package bookmark` is recommended, the bookmarks are faster up to date and the package provides more features.