# How to allow curly braces in command option

I need to store an URL parameter like &path=weigth:5|color:orange|enc:okydHa}peAXOHi@jANv@A@kJJmFAiDJuAHmDXcBb@cC@gC^_DV}CJaCF{APaBVkBdAyEf@qC@{B\aDSwB with later reencoding to utf8 and passing to a lua script.

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{xkeyval}
\makeatletter
\define@key{testcmd}{arg}[]%
{%
\gdef\testcmdarg{\detokenize{#1}}%
}%
\newcommand*\testcmd[1][]{\setkeys{testcmd}{#1}}%
\makeatother
\begin{document}
\testcmd[arg={&path=weight:5|color:orange|enc:}]
%\testcmd[arg=&path=weight:5|color:orange|enc:okydHa}peAXOHi@jANv@A@kJJmFAiDJuAHmDXcBb@cC@gC^_DV}CJaCF{APaBVkBdAyEf@qC@{B\aDSwB]
Test: \testcmdarg
% in fact, the option is reencoded to utf8 and passed to a lua script! no output!
\end{document}


Most of the problems are solved with \detokenize, but the curly braces are still a problem. I guess it has something to do with the catcodes. So how can i change the catcodes and limit the change to the setting of the option?

Or is there another way to store the option as "text"?

It is not clear what you mean by “reencoded to UTF-8 and passed to a Lua script”, but the issue seems quite clear: you are storing \detokenize, rather than executing it.
\define@key{testcmd}{arg}[]{%

With \xdef the replacement text is expanded; in this case \detokenize performs its duty and the macro will contain all category code 12 characters.
• It's for the getmap package and the arguments are reencoded to UTF8 and passed to getmapdl.lua. If I change \gdef to \xdef, I still get -- instead of | in the first example and ! Argument of \testcmd has an extra }. for the commented second example. So still no braces allowed in options. In getmap I've implemented the pathfile option so that the lua script can read the problematic path with braces directly from a file. But if there would be a solution that works directly with the path option, ... ;-) Jun 5 '16 at 11:11