2

This question already has an answer here:

How can I silence the hyperref warnings:

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing `\<let>-command' on input line 7.


Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing `\EXD@break' on input line 7.


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

when using the extdash package? I have tried to use pdfstringdefDisableCommands but couldn't find out what to put in there. What I would like to prevent is having to remember to use \texorpdfstring every time I use the extdash commands in sections.

MWE

\documentclass{article}

\usepackage[shortcuts]{extdash}
\usepackage{hyperref}

\begin{document}
    \section{This is a test\-/Thing}
\end{document}

marked as duplicate by Stefan Pinnow, Maarten Dhondt, user31729, gernot, Mico Mar 21 '17 at 14:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @campa I have seen the duplicate, but I was searching for a solution that is not cluttering my section titles with additional commands. No chance to get this working with pdfstringdefDisableCommands? – languitar Mar 21 '17 at 12:34
  • You can do \pdfstringdefDisableCommands{\def\-{-}}, but you'll have to live with the slash in the bookmark. Unless \-/ is the only dash you use in the section titles; in this case \pdfstringdefDisableCommands{\def\-/{-}} would do. Doing a look ahead is not possible. – egreg Mar 21 '17 at 12:38
  • Thanks, both versions work. Please add them as an answer so that I can accept this. I was searching for replacements on a much lower level of tex. – languitar Mar 21 '17 at 12:40
  • 1
    @languitar I added a more complex lookahead. If you also plan to use \=, let me know. – egreg Mar 21 '17 at 13:02
3

The macro \- is redefined by the package to do a look ahead.

Implementing such a look ahead for the bookmarks is not possible in the same way as when typesetting text.

A simple workaround is to add

\pdfstringdefDisableCommands{\def\-{-}}

but this will leave the slash in the bookmark.

If you only plan to use \-/ in sectional titles, you can use

\pdfstringdefDisableCommands{\def\-/{-}}

A more complex look ahead can be obtained with expl3:

\documentclass{article}

\usepackage{expl3}
\usepackage[shortcuts]{extdash}
\usepackage{hyperref}

\ExplSyntaxOn
\cs_new:Nn \languitar_bm_extdash:n
 {
  \str_case:nnF { #1 }
   {
    {/}{-}
    {-}{\__languitar_bm_extdash_aux_i:n}
   }
   {#1}
 }
\cs_new:Nn \__languitar_bm_extdash_aux_i:n
 {
  \str_case:nnF { #1 }
   {
    {-}{\__languitar_bm_extdash_aux_ii:n}
   }
   {\textendash#1}
 }
\cs_new:Nn \__languitar_bm_extdash_aux_ii:n
 {
  \str_case:nnF { #1 }
   {
    {-}{\textemdash}
   }
   {\textemdash#1}
 }
\pdfstringdefDisableCommands
 {
  \cs_set_eq:NN \- \languitar_bm_extdash:n
 }
\ExplSyntaxOff


\begin{document}

\section{This is a test\-/Thing}

\section{This is a test\--Thing}

\section{This is a test\textendash Thing}

\section{This is a test\---Thing}

\section{This is a test\textemdash Thing}

\section{This is a test\-Thing}

\end{document}

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.