[Tex/LaTex] Ways to avoid ‘Package hyperref Warning: Token not allowed in a PDF string’ warning

hyperref

I know that this question was asked almost 80 times and that the best solution is probably to use \texorpdfstring{...}{...} but I don't want to a mess inside the document so I was thinking of this solution.

\pdfstringdefDisableCommands{%
  \def\${}%
  \def\alpha{alpha}%
}

But this doesn't change the fact that

\section{$\alpha$}

gives the warning

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding): (hyperref) removing `math shift' […]

So the question is: Can I use \pdfstringdefDisableCommands{...} to avoid using \texorpdfstring{...}{...} when handling math in sections?

Best Answer

Here I use \(...\) in lieu of $...$. Warnings avoided.

\documentclass{article}
\usepackage{hyperref}
\pdfstringdefDisableCommands{%
%  \def${}%
  \def\alpha{alpha}%
  \def\({}%
  \def\){}%
  \def\texttt#1{<#1>}%
}
\begin{document}
\section{\texttt{xyz}\(\alpha\)}
\end{document} 

enter image description here

or get a bit more descriptive in the replacement:

\documentclass{article}
\usepackage{hyperref}
\pdfstringdefDisableCommands{%
  \def\alpha{alpha}%
  \def\({Math:[}%
  \def\){]}%
  \def\texttt#1{<#1>}%
}
\begin{document}
\section{\texttt{xyz}\(\alpha\)}
\end{document} 

enter image description here

Related Question