This is an extremely minimal example of what I'm trying to do.
\documentclass{article}
\usepackage{pgfkeys}
\pgfkeys
{
/ae/example/set/parameters/.cd,
keya/.code = { \def\mykeya{#1} },
keyb/.code = { \def\mykeyb{#1} },
/ae/example/use/parameters/.cd,
keya/.code = { \mykeya },
keyb/.code = { \mykeyb },
}
\newcommand{\setkeys}[1]{\pgfkeys{ /ae/example/set/parameters/.cd, #1}}
\newcommand{\usekeys}[1]{\pgfkeys{ /ae/example/use/parameters/.cd, #1}}
\pagestyle{empty}
\begin{document}
\setkeys{keya={{\bfseries hello}},keyb={world!}}
\usekeys{keya,keyb}
This following text should not be \textbf{bold.}
\end{document}
The general idea is that I have setter and getter keys defined. Generally, the macro call is more complicated than just assigning a value to a command name. But the above example illustrates the problem I've run into. My inner braces are getting completely stripped out.
I don't want to assume that key values are to define subgroups. That is, I don't necessarily want to define the key as
/ae/example/set/parameters/.cd,
keya/.code = { \def\mykeya{{#1}} },
I would like the user to be able to specify the grouping by using inner braces like I have in the MWE:
\setkeys{keya={{\bfseries hello}}
I know for the above example I could write
\setkeys{keya={\textbf{hello}}
and everything would be fine. But such an approach won't work for other commands like \footnotesize and other kindred commands. Also, I know I could wrap things up in boxes
\setkeys{keya=\mbox{\bfseries hello}}}
But this prevents the innards of the box from seeing mark-up that's being called from the outside.
Any ideas on how to get pgfkeys to be a bit less greedy in how it strips away braces?
UPDATE
I've considered doing something like:
\setkeys{keya="\bfseries hello"}
and use some preprocessor to convert the " to the appropriate braces.
I also considered defining a variant key like
/ae/example/set/parameters/.cd,
keya*/.code = { \def\mykeya{{#1}} },
But I'm wondering whether someone else has a better approach.
pgfkeys: other key-value packages are very careful about this sort of thing. (Try the same inl3keysand you should see exactly one set of braces stripped.) – Joseph Wright Jul 06 '13 at 19:49l3keysworks very nicely and generally does what I want it to do. Where I'm getting stuck withl3keysis creating keys to be processed with private packages. For example, I don't know how to usel3keysto process keys in something like\usepackage[keys={{\bfseries ....}}]{myprivatepackage}I keep getting errors around the use of the equal sign. Perhaps I should post that as its own question? – A.Ellett Jul 06 '13 at 19:53l3keys2efor option parsing, but there is an issue with any keyval processing in package options. The LaTeX2e kernel expands options before passing them on, so things like command names are 'unsafe'. For that reason I've recommended against using load-time options insiunitxand instead promote using\sisetup, even though the 'back-end' is the same. – Joseph Wright Jul 06 '13 at 19:55