This is my code:



\newcommand{\myvalue}[1][]{Testvalue #1}


When I try to compile it, I get:

Package hyperref Warning: Token not allowed in a PDF string (Unicode):
(hyperref)                removing `\myvalue' on input line 9.

! Undefined control sequence.
\in@ #1#2->\begingroup \def \in@@
                                  ##1#1{}\toks@ \expandafter {\in@@ #2{}{}#1...
l.9 ...\ui{value={\myvalue[foo]}}]{Text}{2em}{1em}

This even happens if I don't set the optional parameter. The error vanishes when I remove the parameter from the macro or make it a required parameter. Why? And how do I use a macro with an optional parameter here?


You can't. The value is converted to a PDF string and not typeset by TeX. Therefore the stomach of TeX is not available during the conversion. That means, assignments, definitions, non-expandable macros will not work and can even break. Scanning for the optional argument is implemented via \futurelet in LaTeX, an assignment. Therefore \futurelet would be written verbatim to the PDF string as garbage, because PDF viewers do not know TeX commands. And the macro, which should be defined by \futurelet, is left undefined, causing trouble at the next expansion steps.

You have already found a workaround, a required parameter instead of the optional argument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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