[Tex/LaTex] Math symbol in section heading

best practiceshyperrefmath-mode

I have a section heading which includes an epsilon. Furthermore I am using the "hyperref" package to create links in my PDF document.

When compiling I get a strange warning that a math symbol is not allowed in a PDF string, e.g. Token not allowed in a PDF string (PDFDocEncoding): (hyperref) removing \varepsilon on input line 6.

However, if I open the compiled PDF there are no obvious errors and all links are clickable. Am I missing something, or can I just ignore this warning? Are there any alternatives to achieve the same result?

\documentclass{article}
\usepackage{hyperref}

\begin{document}
\tableofcontents
\section{$\varepsilon$SOA}

Text about $\varepsilon$SOA.

\end{document}

Screenshot of the compiled example

Thanks in advance!

Best Answer

  • Option pdfencoding=auto or unicode enables bookmarks in Unicode with more symbols.

  • Option psdextra defines lots of math symbols, however it misses \varepsilon.

  • Then \pdfstringdefDisableCommands can be used to define a bookmark replacement string for commands.

Full example:

\documentclass{article}
\usepackage[pdfencoding=auto, psdextra]{hyperref}
\pdfstringdefDisableCommands{\def\varepsilon{\textepsilon}}
\usepackage{bookmark}% faster updated bookmarks

\begin{document}
\tableofcontents
\section{$\varepsilon$SOA}

Text about $\varepsilon$SOA.

\end{document}

If the warnings about math shift should also be removed, then \texorpdfstring helps:

\section{\texorpdfstring{$\varepsilon$}{\textepsilon}SOA}