I want to define a command with an optional star argument and be able to use it inside pdf strings, e.g. via \section
. With the MWE below, I get a Token not allowed in a PDF string
warning and \foo
is just removed.
I can't think of a safe expandable way to replace \@ifstar
in order to do this. For my application, it would be okay to default to \s@foo
inside a pdf string, but the *
should be removed if present.
Is there any way to achieve this?
\documentclass{article}\usepackage{hyperref}\makeatletter \protected\def\foo{% \@ifstar\s@foo\@foo } \def\@foo#1{one #1 one} \def\s@foo#1{two #1 two}\makeatother\begin{document}\section{\foo{bar}}\end{document}