0

I wish to put maths symbol in my Chapter title, but when I run Overleaf, it give warning, but not error.

It said Package hyperref Warning: Token not allowed in a PDF string

enter image description here

My WME:

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

\begin{document}
  \tableofcontents

\chapter{The value of $\boldsymbol{e}$}

\end{document}
aan
  • 2,663
  • @Nasser, I have no idea how to provide a MWE, because the error of compilation is because of my whole thesis code. – aan May 29 '20 at 01:58
  • AN example of MWE: \documentclass{book} \usepackage{amsmath} \begin{document} \chapter{The value of $\boldsymbol{e}$} \end{document}, which works fine ... – Zarko May 29 '20 at 02:01
  • 1
    @Zarko Read the warning message: the warning is produced by hyperref. In addition to my answer, see this: https://tex.stackexchange.com/questions/430876/ways-to-avoid-package-hyperref-warning-token-not-allowed-in-a-pdf-string-warn?rq=1 – Max Xiong May 29 '20 at 02:23
  • 1
    Actually just adding the hyperref package to Zarko's code will produce the issue. – Max Xiong May 29 '20 at 02:35
  • 1
    amsmath and \boldsymbol are not required. They just make the problem worse, because the bookmark actually contains the hidden pmb generated by boldsymbol. – Max Xiong May 29 '20 at 02:58
  • @Nasser, thanks. Now I know is related to hypererlink issue and i edit my question to include MWE. I have no idea how i can create a MWE for a simple – aan May 29 '20 at 09:19

1 Answers1

4

The cause of the warning seems to have to do with the auto-generated bookmarks from the hyperref package. Even just using math mode will cause some warnings in the log. \boldsymbol makes a mess.

The easiest way to fix the problem is

\chapter{\texorpdfstring{The value of $\boldsymbol{e}$}{The value of e}}

The macro \texorpdfstring will use the first argument for the PDF contents, and the second argument for the bookmarks. Read more in section 4.1.2 of the documentation of the hyperref package.

P.S.

  1. You should use \boldmath or \bm instead. The spacing produced by \boldsymbol is bad in some cases. A note of warning that using \bm without \texorpdfstring produces a fatal error.
  2. if you manually specify a different TOC heading in the optional argument to \chapter, \section, etc. (eg. to unbold the math), \texorpdfstring goes in the optional argument, not the main argument.
Max Xiong
  • 281
  • 1
  • 4
  • thanks. Would I able to add \ref in my Chapter/Section heading? I tried \section{\texorpdfstring{Texting {\sffamily x} $/$ {\sffamily x}$^{T}${\sffamily B}{\sffamily x}. A proof of equation \ref{equationforappendix}}} {Texting {x} / {x}^{T}{B}{x}. A proof of equation \ref{equationforappendix}} But it seemed not working. I can post a new question if you need it. – aan May 29 '20 at 08:44