0

I want to have the math symbols in section titles automatically be converted into plain text in bookmarks. I find this answer and it does clear the "token not allowed in a pdf string" warning. Automatically add \texorpdfstring for math-mode in section titles

However, as mentioned in the comment by egreg, the math symbols may output some strange Chinese characters in the bookmark. I wonder what cause this and how to avoid this issue?

Stephen
  • 3,826
Gau-Syu
  • 473

1 Answers1

2

Basically you can't avoid it. \detokenize is not a good idea. If you use a catcode 12 backslash in the title, may it be with \detokenize or \string\ or something else, you will break the bookmarks. You get something like \000\040\alp \000h\000a and that is simply rubbish.

I see no easy way to change this. At the place where a substitution could be done, hyperref has already replaced some commands by the internal representation which uses catcode 12 backslash too, and so no simple substitution is possible as it would break other commands like \textbackslash. One would need a regex and that would slow down the compilation quite a lot for a very small gain.

What you naturally can do, is to pass the content of the math to the \fake@math command, and to predefine the set of symbols you use to do something sensible:

\documentclass{article}
\usepackage{hyperref}

\makeatletter \pdfstringdefDisableCommands{\let(\fake@math} \pdfstringdefDisableCommands{\def\alpha{}} \pdfstringdefDisableCommands{\def\beta{}} \newcommand\fake@math{}% just for safety \def\fake@math#1){[math: #1]} \makeatother

\begin{document} \section{(I \alpha \beta ) cast warnings but I wish I wouldnt}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261