[Tex/LaTex] Hyperref package (token not allowed in a PDF string)

bookmarkshyperref

When I start the appendix of the document always gives the problem of hyperref with \uppercase and it always appears:

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing `\uppercase' on input line 504.

How to solve?

\begin{apendicesenv}
% Imprime uma página indicando o início dos apêndices% Imprime uma página indicando o início dos apêndices
\partapendices
% ----------------------------------------------------------
\chapter{Questinários}
% ----------------------------------------------------------
\centering
\includegraphics[trim = 1.9cm 5cm 1.1cm 11mm,clip,width= 16cm]{Selecao.pdf}
% ----------------------------------------------------------
\chapter{Diagnóstico Inicial}
% ----------------------------------------------------------
\centering
\includegraphics[trim = 1.3cm 2cm 1.1cm 8mm,clip,width= 16cm]{diag.pdf}
\includepdf[pages={2-3},trim = 1.3cm 2cm 1.0cm 8mm,clip,width= 16cm]{diag.pdf}
\end{apendicesenv}

Best Answer

\uppercase is a non-expandable command. Therefore, it must be called/executed to do its job, in TeX speech, the place is the stomach. Bookmarks, however, are generated in an expandable context, TeX's mouth. It is similar to writing to a file or to the console. Try:

\typeout{\uppercase{hello}}

As result \uppercase appears in the output and hello remains lowercase:

\uppercase {hello}

The code in hyperref that generates the bookmarks tries hard to avoid that such commands appear in the output and have successfully removed it, see the text of the warning. Of course, the text is not converted to uppercase, thus, the warning is justified.

There are two means to solve the situation without warning:

  • \pdfstringdefDisableCommands can be used to remove unsupported commands:

    \usepackage[...]{hyperref}
    \pdfstringdefDisableCommands{\let\uppercase\@firstofone}
    
  • \texorpdfstring can be used to replace unsupported constructs with replacement texts, e.g.:

    \section{\texorpdfstring{\uppercase{hello}}{HELLO}}