On TeX.SE (http://tex.stackexchange.com/q/120258/2966), Prof. Enrico
“egreg” Gregorio helped me set up the below code, which sets up an
l3keys definition from a clist.
Note that the property `.generate_choice:V` has to be created; is it
perhaps a useful addition to l3keys?
Note also the way I've set the default value to the first element of
the clist. I would assume that the "idiomatic" way would be
font .initial:o = { \clist_item:Nn \c_jcsfonts_clist {1} },
or something like that, but of course, the property `.initial:o`
doesn't exist. And unlike the rest of Expl3, there is no clean way to
generate variants of l3keys properties; egreg's code needed to call on
`\__`-private functions. Might this, too, be a useful addition to the
package?
Code follows.
—Joel Salomon
% Different choices, depending on the engine
\bool_if:nTF { \xetex_if_engine_p: || \luatex_if_engine_p: }
{ \clist_const:Nn \c_jcsfonts_clist { fontin, constantia, lmodern } }
{ \clist_const:Nn \c_jcsfonts_clist { kpfonts, lmodern } }
% Default to first in the list -- possibly not idiomatic
\clist_get:NN \c_jcsfonts_clist \c_jcsfonts_default_tl
% The property .generate_choice:V doesn't exist, so we create it
\cs_generate_variant:Nn \__keys_choices_generate:n { V }
\cs_new_protected:cpn { \c__keys_props_root_tl .generate_choices:V } #1
{ \__keys_choices_generate:V {#1} }
% Define keys
\keys_define:nn { jcsfonts }
{
font .choice_code:n = \tl_gset:NV \g_jcsfonts_tl \l_keys_choice_tl,
font .generate_choices:V = \c_jcsfonts_clist,
font .initial:V = \c_jcsfonts_default_tl,
font .value_required:,
}
% Define synonyms
\clist_map_inline:Nn \c_jcsfonts_clist
{
\keys_define:nn { jcsres }
{
#1 .meta:n = { format = #1 },
#1 .value_forbidden:
}
}
% Test for key
\prg_new_conditional:Npnn \jcsfonts_if:n #1 { p, T, F, TF }
{
\str_if_eq:nVTF { #1 } \g_jcsfonts_tl
{ \prg_return_true: } { \prg_return_false: }
}
|