LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
"Joel C. Salomon" <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Thu, 20 Jun 2013 18:39:01 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (61 lines)
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: }
  }

ATOM RSS1 RSS2