LATEX-L Archives

Mailing list for the LaTeX3 project

LATEX-L@LISTSERV.UNI-HEIDELBERG.DE

Options: Use Forum View

Use Monospaced 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:
Joseph Wright <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Date:
Mon, 2 Jun 2014 17:32:39 +0100
Content-Type:
text/plain
Parts/Attachments:
text/plain (78 lines)
On 02/06/2014 16:17, Joseph Wright wrote:
> Hello all,
> 
> A reasonably common use case for keyval method is is the situation where
> one or more keys are set to a value implicitly. This is often managed in
> LaTeX using grouping.
> 
>   % Set up keys
>   \keys_define:nn { mymod }
>     {
>       key-a .tl_set:N = \l_mya_tl ,
>      ...
>     }
>   \keys_set:nn { mymod }
>     {
>       key-a = value % Applies unless set otherwise
>     }
>   ...
>   \group_begin:
>     \keys_set:nn { mymod }
>       {
>         key-a = new-value
>       }
>   \group-end:
>   % key-a will be "value" again
>   \group_begin:
>     \keys_set:nn { mymod }
>       {
>         % No key-a set => "value"
>       }
> 
> However, there are cases where you'd like to 'preset' the key every
> time. Currently, that would require
> 
>     \cs_new_protected:Npn \foo #1#2 % #1 = keys
>       {
>         \keys_set:nn { mymod }
>           {
>             key-a = new-value ,
>             #1
>           }
> 
> but that is not that efficient and also not that clear.
> 
> An alternative approach is to provide a method to 'preset' keys from
> within the key system, something like
> 
>   \keys_define:nn { mymod }
>     {
>       key-a .tl_set:N = \l_mya_tl ,
>       key-a .preset:n = value
>      ...
>     }
> 
> where the presetting can avoid having to parse the keys each time it's
> run (cf. what happens in xtemplate).
> 
> The team have some use cases where this makes sense, so I will be
> looking to add it as an experimental idea. Before I do, thought, I'd
> like to know if the name, etc., makes sense. It's distinct from
> ".default:n" (used if a key name is given with no property) and
> ".initial:n" (a 'set up' shortcut).
> 
> I note that xkeyval offers the idea of preset keys, but in a slightly
> more complex fashion as it allows 'tail' keys and does some tests for
> the presence of keys before doing presetting. I don't see a similar
> concept in the pgfkeys manual: I have a feeling there just the 'manual'
> approach is used.
> 
> Thoughts?

Particular questions here as well as the name are whether 'presetting'
depends on what is in the key list (should keys be preset if they are
found in the key list?) and what, if anything, should be done
differently in the key filtering cases.
-- 
Joseph Wright

ATOM RSS1 RSS2