# macro with optional argument in eforms textField

This is my code:

\documentclass{article}

\usepackage{polyglossia}
\usepackage[useui]{eforms}

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

\begin{document}
\textField[\ui{value={\myvalue[foo]}}]{Text}{2em}{1em}
\end{document}


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.

(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/se-ascii-print.def)
! 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.