%%
%% This is file `template.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% template.dtx  (with options: `package,trace')
%% 
%% (C) Copyright The LaTeX3 Project and any individual authors
%% listed elsewhere in this file.
%% 
%% This is a generated file.
%% 
%% This file was generated from file(s) of the xbase bundle.
%% ---------------------------------------------------------
%% 
%% This file may only be distributed together with a copy of this bundle.
%% You may however distribute the bundle without such generated files.
%% 
%% ======================================================================
%% 
%% File: template.dtx (C) Copyright 1999-2001 David Carlisle, Frank Mittelbach
%%                    (C) Copyright 2004-2006 Frank Mittelbach, LaTeX3 Project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version.  The latest version
%% of this license is in the file
%%
%%    http://www.latex-project.org/lppl.txt
%%
%% This file is part of the ``xbase bundle'' (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -----------------------------------------------------------------------
%%
%% The development version of the bundle can be found at
%%
%%    http://www.latex-project.org/cgi-bin/cvsweb.cgi/
%%
%% for those people who are interested.
%%
%%%%%%%%%%%
%% NOTE: %%
%%%%%%%%%%%
%%
%%   Snapshots taken from the repository represent work in progress and may
%%   not work or may contain conflicting material!  We therefore ask
%%   people _not_ to put them into distributions, archives, etc. without
%%   prior consultation with the LaTeX Project Team.
%%
%% -----------------------------------------------------------------------
%%
\RequirePackage{l3names}
\GetIdInfo$Id: template.dtx 584 2006-12-12 17:29:34Z morten $
          {template}

\RequirePackage{ldcsetup,xparse}
\RequirePackage{l3toks,l3tlp,l3skip,l3int,l3clist,l3token}
\CodeStart
\toks_new:N\l_TP_KV_assignments_toks
\toks_new:N\l_TP_default_assignments_toks
\def_new:NNn \TP_declare_instance:Nnn 3{
  \group_begin:
    \TP_instdecl_generate_assignments:nn {#2}{#3}
    \gdef:Npx #1 {
      \tlp_if_eq:cNTF { TP>/#2 } \c_TP_doparameterassignments_tlp
         { \toks_use:N \l_TP_KV_assignments_toks }
         {
           \exp_not:N \TP_push_assignments:n
              {\toks_use:N\l_TP_KV_assignments_toks}
            \exp_not:c {TP>/#2}
         }
      }
  \group_end:}
\def_new:Npn \TP_declare_instance:cnn{\exp_args:Nc\TP_declare_instance:Nnn}
\tlp_set:Nn \c_TP_doparameterassignments_tlp {\DoParameterAssignments}
\def_new:NNn \UseTemplate 3{
  \TP_instdecl_generate_assignments:nn {#1/#2}{#3}
  \TP_push_assignments:
  \cs_use:c { TP>/#1/#2 }
}
\def_new:Npn \DoParameterAssignments{
  \exp_after:NN
    \TP_pop_and_execute_assignments:nw
       \toks_use:N \g_TP_assignments_stack_toks \q_stop
}
\def_new:Npn \TP_pop_and_execute_assignments:nw#1#2\q_stop{
  \toks_gset:Nn \g_TP_assignments_stack_toks {#2}
  #1}
\toks_new:N   \g_TP_assignments_stack_toks
\toks_gset:Nn \g_TP_assignments_stack_toks {\scan_stop:}% avoid brace loss
\def_new:Npn \TP_push_assignments:n{
  \tex_afterassignment:D \TP_push_assignments:
  \l_TP_KV_assignments_toks}
\def_new:Npn \TP_push_assignments:{
  \toks_gset:No \g_TP_assignments_stack_toks
    {\exp_after:NN
     {\toks_use:N\exp_after:NN\l_TP_KV_assignments_toks\exp_after:NN}
      \toks_use:N\g_TP_assignments_stack_toks}}
\def_new:NNn \DeclareTemplateType 2{
  \tlp_set:cn {TP@<#1>} {{}#2}}
\def_new:Npn \TP_get_csname_prefix:n#1{
  <\exp_after:NN\exp_after:NN\exp_after:NN
   \use_arg_i:nn
      \cs:w TP@<#1>\cs_end:>#1/
}
\def_new:Npn \TP_get_arg_count:n#1{
  \exp_after:NN\exp_after:NN\exp_after:NN
  \use_arg_ii:nn
    \cs:w TP@<#1>\cs_end:
}
\def_long_new:NNn\DeclareTemplate 5{
  \cs_if_free:cTF{TP@<#1>}
    {\undefinedtype\DeclareTemplateType{#1}#3}
    {
      \int_compare:nNnF{#3}={\TP_get_arg_count:n{#1}}
      { \BadArgCount }
    }
  \let:NN \KV_elt:nn \TP_templdecl_process_KV:nn
  \def:Npn \KV_default_elt:n##1{
    \PackageError{template}{Missing~ =~ after~ ##1}\@ehd}
  \let:NN\KV@elt\KV_elt:nn
  \let:NN\KV@default@elt\KV_default_elt:n
  \tlp_set:Nn \l_TP_curr_name_tlp {#1/#2}
  \toks_clear:N\l_TP_default_assignments_toks
  %\int_compare:nNnTF{\char_value_catcode:n{`\ }}=\c_nine
  %\KV_parse_picky_no_space_removal_no_sanitize:n
  %\KV_parse_picky_space_removal_no_sanitize:n
  \KV@parse{#4}
  \tlp_set:cx { TPD>/\l_TP_curr_name_tlp }
              {\toks_use:N\l_TP_default_assignments_toks}

  \tlp_clear:c {TPR>/\l_TP_curr_name_tlp}

  \tlp_set_eq:cN {TPO>/\l_TP_curr_name_tlp}\l_TP_curr_name_tlp
  \def:cNn  {TP>/\l_TP_curr_name_tlp}{#3}{#5}
}
\def_new:Npn \TP_templdecl_process_KV:nn#1#2{%
  \let:NN \TP_templdecl_add_global_or_nothing: \use_noop:
  \bool_set_false:N\l_TP_global_assignment_bool
  \tlp_set:Nn\l_TP_currkey_tlp{#1}
  \TP_templdecl_parse_KV:N#2\q_stop}
\def_new:Npn \TP_templdecl_parse_KV:N#1{
  \cs_if_free:cTF{TP_use_arg_type_#1:w}
  {\PackageError{template}{Unknown~key~type~ (#1)~for~\l_TP_currkey_tlp}\@eha}
  {\cs_use:c{TP_use_arg_type_#1:w}}
}
\bool_new:N \l_TP_global_assignment_bool
\def_new:cpn{TP_use_arg_type_+:w} {
  \bool_set_true:N\l_TP_global_assignment_bool
  \def:Npn  \TP_templdecl_add_global_or_nothing:
  {\toks_put_right:Nn \l_TP_KV_assignments_toks {\pref_global:D} }
  \TP_templdecl_parse_KV:N
}
\def_new:Npn\TP_use_arg_type_l:w {
  \TP_parse_optional_key_default:nw
  {
    \let:NN \TP_templdecl_add_global_or_nothing: \use_noop:
    \bool_if:NTF \l_TP_global_assignment_bool
    {\TP_templdecl_setup_register_key:Nn\gsetlength}
    {\TP_templdecl_setup_register_key:Nn\setlength}
  }
}
\def_new:Npn\TP_use_arg_type_L:w {
  \TP_parse_optional_key_default:nw
  {\TP_templdecl_setup_fakeregister_key:NNn\setlength\l_tmpa_skip}
}
\def_new:Npn\TP_use_arg_type_c:w {
  \TP_parse_optional_key_default:nw
  {
    \let:NN\TP_templdecl_add_global_or_nothing:\use_noop:
    \bool_if:NTF \l_TP_global_assignment_bool
    {\TP_templdecl_setup_register_key:Nn\GSetInternalCounter}
    {\TP_templdecl_setup_register_key:Nn\SetInternalCounter}
  }
}
\def_new:Npn\TP_use_arg_type_C:w {
  \TP_parse_optional_key_default:nw
  {\TP_templdecl_setup_fakeregister_key:NNn
    \SetInternalCounter\l_tmpa_int}
}
\def_new:Npn\TP_use_arg_type_n:w {
  \TP_parse_optional_key_default:nw
  {\TP_templdecl_setup_n_key:N}
}
\def_new:Npn\TP_use_arg_type_f:w #1{
  %\TP_templdecl_parse_f_arg:nw {#1}
  \TP_parse_optional_key_default:nw{\TP_templdecl_setup_f_key:Nn{#1}}
}
\def_new:Npn \TP_templdecl_parse_f_arg:nw#1#2{
  \TP_parse_optional_key_default:nw{\TP_templdecl_setup_f_key:Nn{#1}{#2}}
}
\def_new:Npn\TP_use_arg_type_b:w {
  \TP_parse_optional_key_default:nw
  {\TP_templdecl_setup_b_key:n}
}
\def_new:Npn \TP_templdecl_setup_b_key:n#1{
  \let:cN { if#1 } \if_true:
  \TP_templdecl_define_key:n
  { \TP_templdecl_eval_b_key_value:nn {#1}{##1} }
}
\def_new:Npn \TP_templdecl_eval_b_key_value:nn#1#2{
  \cs_if_free:cTF {if#2}
    { \PackageError{template}{Bad~boolean~setting~#1=#2}\@eha }
    { \tlp_set_eq:cc {if_#1:}{if_#2:}
      \toks_put_right:Nf \l_TP_KV_assignments_toks
         { \tlp_set_eq:cc {if_#1:}{if_#2:} }
    }
}
\def_new:Npn\TP_use_arg_type_s:w {
  \TP_parse_optional_key_default:nw
  {\TP_templdecl_setup_s_key:n}
}
\def_new:Npn \TP_templdecl_setup_s_key:n #1 {
  \TP_templdecl_define_key:n
    { \TP_templdecl_eval_s_key_value:nnn{##1}#1 }
}
\def_new:Npn\TP_use_arg_type_i:w #1{
  \TP_parse_optional_key_default:nw{\TP_templdecl_setup_i_key:nnn{#1}}
}
\def_new:Npn \TP_templdecl_setup_i_key:nnn#1#2{
  \TP_templdecl_define_key:n
  {
    \TP_templdecl_eval_i_key_value:Nnn #2 {#1}{##1}
  }
}
\def_new:Npn \TP_templdecl_eval_i_key_value:Nnn #1#2#3 {
  \tlist_if_head_eq_meaning:nNTF {#3.}\UseTemplate
  {
    \io_put_term:x{\token_to_string:N\UseTemplate\space seen}
    {\TP_templdecl_declare_tmp_instance:nnnn #3 }
    \toks_put_right:No \l_TP_KV_assignments_toks
          { \exp_after:NN \KV@toks \exp_after:NN {\g_tmpa_tlp} }
    %\TP_templdecl_add_global_or_nothing:
    %\toks_put_right:Nn \l_TP_KV_assignments_toks
    %      { \def:Npx #1{ \toks_use:N \KV@toks} }
    \bool_if:NTF \l_TP_global_assignment_bool
    {\toks_put_right:Nn \l_TP_KV_assignments_toks
      {\gdef:Npx #1 { \toks_use:N \KV@toks}}
    }
    {\toks_put_right:Nn \l_TP_KV_assignments_toks
      {\def:Npx #1 { \toks_use:N \KV@toks}}
    }
  }
  {
    \TP_let_instance:Nnn#1{#2}{#3}
      \toks_put_right:Nf  \l_TP_KV_assignments_toks
        { \TP_let_instance:Nnn#1{#2}{#3} }
  }
}
\def_new:Npn\TP_use_arg_type_x:w {
  \TP_parse_optional_key_default:nw
  {\TP_templdecl_setup_x_key:n}
}
\def_new:Npn \TP_templdecl_setup_x_key:n#1{
  \TP_templdecl_define_key:n
  { \toks_put_right:Nn\l_TP_KV_assignments_toks{#1} }
}
\def_new:Npn\TP_use_arg_type_g:w {
  \TP_parse_optional_key_default:nw
  {\TP_templdecl_setup_g_key:n}
}
\def_new:Npn \TP_templdecl_setup_g_key:n #1 {
  \TP_templdecl_define_key:n{#1}}
\def_new:Npn \TP_templdecl_define_key:n#1{
  \tlp_set:Nx \l_tmpa_tlp {
    \exp_not:N \TP_templdecl_remove_from_default_assignments:N
    \exp_not:c{KV@\l_TP_curr_name_tlp @\l_TP_currkey_tlp}
    \exp_not:o {\TP_templdecl_add_global_or_nothing: }
  }
  \exp_args:NcNo \def:NNn {KV@\l_TP_curr_name_tlp @\l_TP_currkey_tlp} 1
  { \l_tmpa_tlp #1 }
}
\def_long:Npn \TP_ignore_leading_space_in_arg_ii:nn#1#2{
  \exp_args:Nf\TP_ignore_leading_space_in_arg_ii_aux:nn
  {\exp_not:N #2}{#1}
}
\def_long:Npn \TP_ignore_leading_space_in_arg_ii_aux:nn#1#2{#2{#1}}

\DeclareArgumentType t[{meaning}{}{\NoValue}{#1[#2]}{#2}
\DeclareDocumentCommand\TP_parse_optional_key_default:nw{mt}{
  \IfNoValueTF{#2}
    {\TP_templdecl_finish_key_setup:nw{#1}}
    {\TP_templdecl_finish_key_setup_with_default:nnw{#1}{#2}}
}
\def_new:Npn \TP_templdecl_finish_key_setup:nw#1#2\q_stop{
  \TP_ignore_leading_space_in_arg_ii:nn{#1}{#2}
  %%%#1{#2}
}
\def_new:Npn \TP_templdecl_finish_key_setup_with_default:nnw#1#2#3\q_stop{
  \TP_ignore_leading_space_in_arg_ii:nn{#1}{#3}
  %%%  #1 {#3}
  \group_begin:
    \toks_clear:N \l_TP_KV_assignments_toks
    \let:NN \TP_templdecl_remove_from_default_assignments:N \use_none:n
    \cs_use:c{KV@\l_TP_curr_name_tlp @\l_TP_currkey_tlp}{#2}
  \exp_after:NN
  \group_end:
  \exp_after:NN
  \toks_set:Nn
  \exp_after:NN
  \l_TP_default_assignments_toks
  \exp_after:NN
    { \cs:w KV@\l_TP_curr_name_tlp @\l_TP_currkey_tlp \exp_after:NN \cs_end:
  \exp_after:NN
      { \toks_use:N \exp_after:NN \l_TP_KV_assignments_toks
  \exp_after:NN
      }
      \toks_use:N\l_TP_default_assignments_toks
  }
}
\tlp_new:Nn \c_TP_true_tlp {true}
\def_new:Npn \TP_templdecl_eval_s_key_value:nnn#1#2#3 {
  \tlp_set:Nn \l_tmpa_tlp {#1}
  \tlp_if_eq:NNTF \l_tmpa_tlp \c_TP_true_tlp
     { \toks_put_right:Nn \l_TP_KV_assignments_toks {#2} }
     { \toks_put_right:Nn \l_TP_KV_assignments_toks {#3} }
}
\def_new:Npn \TP_templdecl_setup_register_key:Nn #1#2{
  \TP_templdecl_define_key:n{
    \tlist_if_head_eq_meaning:nNTF{##1}\DelayEvaluation
    {
      \toks_put_right:Nn \l_TP_KV_assignments_toks {#1#2{##1}}
      %\toks_set:No\l_tmpa_toks{\use_arg_ii:nn ##1}
      %\toks_put_right:Nx \l_TP_KV_assignments_toks
      %  {\exp_not:n{#1#2}{\toks_use:N \l_tmpa_toks}}
    }
    {
      \tlist_if_head_eq_meaning:nNTF{##1..}\MultiSelection
      {
        \group_begin:
          \TP_multiselection_add:nnnnnn #1#2##1
        \group_end:
        \tlist_if_in:onTF{\toks_use:N\g_TP_multiselection_toks}\DelayEvaluation
        {
          \toks_put_right:No\l_TP_KV_assignments_toks
          {
            \exp_after:NN#1\exp_after:NN#2\exp_after:NN
            {\toks_use:N\g_TP_multiselection_toks}
          }
        }
        {
          \toks_put_right:No\l_TP_KV_assignments_toks
          {
            \exp_after:NN  #2
            \exp_after:NN= \toks_use:N\g_TP_multiselection_toks\scan_stop:
          }
        }
      }
      {
        #1#2{##1}
        \toks_put_right:No\l_TP_KV_assignments_toks {
          \exp_after:NN #2 \exp_after:NN = \tex_the:D #2\scan_stop:
        }
      }
    }
  }
}
\def_new:NNn\DelayEvaluation 1{\use_none:n{\DelayEvaluation}#1}
\def_new:NNn\MultiSelection  1{\use_none:n{\MultiSelection}#1}
\def_new:Npn \TP_templdecl_remove_from_default_assignments:N#1{
  \def:Npn \tmp:w ##1#1##2##3#1##4\q_stop{
    \l_TP_default_assignments_toks{##1##3}
  }
  \exp_after:NN \tmp:w
     \toks_use:N\l_TP_default_assignments_toks #1\scan_stop:#1\q_stop}
\def_new:Npn \TP_templdecl_setup_f_key:Nn#1#2{
  \TP_templdecl_define_key:n
  { \TP_templdecl_define_function:NNn#1#2{##1} }
}
\def_new:Npn \TP_templdecl_define_function:NNn#1#2#3{
  \def:NNn #2 #1 {#3}
  \toks_put_right:Nf \l_TP_KV_assignments_toks  { \def:NNn #2 #1 {#3} }
}
\def_new:Npn \TP_templdecl_setup_n_key:N#1{
  \TP_templdecl_define_key:n{
    \tlist_if_head_eq_meaning:nNTF{##1..}\MultiSelection
    {
      \group_begin:
        \TP_templdecl_multiselection:nnnn ##1
      \group_end:
      \toks_put_right:Nx\l_TP_KV_assignments_toks {
        \exp_not:n{\tlp_set:No #1} { \toks_use:N \g_TP_multiselection_toks}
      }
    }
    {
      \def:Npn #1{##1}                      % setting it?
      \toks_put_right:Nn \l_TP_KV_assignments_toks
                          { \tlp_set:Nn #1{##1} }
    }
  }
}
\def_new:Npn \TP_templdecl_multiselection:nnnn #1#2#3#4{
  \toks_gset:Nn \g_TP_multiselection_toks {\if_case:w #2}
  \clist_map_inline:nn {#3}{ \TP_multiselection_add_or_case:n {##1} }
  \toks_gput_right:Nn\g_TP_multiselection_toks { \else: #4\fi: }
}
\def_new:Npn \DeclareInstance { \DeclareCollectionInstance{} }
\def_long_new:Npn \DeclareCollectionInstance#1#2#3#4{
  \TP_declare_instance:cnn { <#1>#2/#3 }{ #2/#4 }
}
\def_new:Npn \UseCollection#1#2{
  \tlp_set:cx { TP@<#1> }
    { {#2} \TP_get_arg_count:n{#1} }
}
\def_new:Npn \TP_let_instance:Nnn#1#2#3{
  \let:Nc #1
  {
    \cs_if_free:cTF { \TP_get_csname_prefix:n{#2} #3 }
      { <>#2/ }
      { \TP_get_csname_prefix:n{#2} }
    #3
  }
}
\def_new:Npn \UseInstance#1#2{
  \TP_let_instance:Nnn \l_tmpa_tlp {#1}{#2}
  \tlp_if_eq:NNTF \l_tmpa_tlp \scan_stop:
     \INSTANCEundefined
     \l_tmpa_tlp
}
\def_long_new:Npn \TP_templdecl_declare_tmp_instance:nnnn#1#2#3{%
  \TP_declare_instance:Nnn \g_tmpa_tlp {#2/#3} }
\def_new:Npn \ShowTemplate#1#2{
   \io_put_term:x{*******~ Template:~ #1/#2~ *******}
   \io_put_term:x{*}
   \io_put_term:x{*~ Defaults:}
   \io_put_term:x{*}
   \io_put_term:x{\token_to_string:N\TPD>/#1/#2=
      \cs_meaning:c{TPD>/#1/#2}}
   \io_put_term:x{*}
   \io_put_term:x{*~ Restrictions:}
   \io_put_term:x{*}
   \io_put_term:x{\token_to_string:N\TPR>/#1/#2=
      \cs_meaning:c{TPR>/#1/#2}}
   \io_put_term:x{*}
   \io_put_term:x{*~ Body:}
   \io_put_term:x{*}
   \cs_show:c {TP>/#1/#2}}
\def_new:Npn \ShowCollectionInstance#1#2#3{
   \io_put_term:x{*******~ Instance:~ <#1>#2/#3~ *******}
   \io_put_term:x{*}
   \cs_show:c {<#1>#2/#3}}
\def_new:Npn \ShowInstance{\ShowCollectionInstance{}}
\def_new:Npn \TP_templdecl_setup_fakeregister_key:NNn#1#2#3{
  \TP_templdecl_define_key:n{
    \tlist_if_head_eq_meaning:nNTF{##1..}\DelayEvaluation
    {
      \toks_set:No \l_tmpa_toks {\use_arg_ii:nn ##1}
      \toks_put_right:Nx \l_TP_KV_assignments_toks {
        {\exp_not:n{#1#2}{\toks_use:N \l_tmpa_toks}
          \exp_not:n{ \def:Npx #3{\toks_use:N#2} }
        }
      }
    }
    {
      \tlist_if_head_eq_meaning:nNTF{##1..}\MultiSelection
      {
        \group_begin:
          \TP_multiselection_add:nnnnnn#1#2##1
        \group_end:
        \toks_put_right:Nx\l_TP_KV_assignments_toks
          {\exp_not:n{\def:Npn #3} {\toks_use:N\g_TP_multiselection_toks}}
      }
      {
        #1#2{##1}
        \toks_put_right:Nx\l_TP_KV_assignments_toks
                    {\exp_not:n{\def:Npn#3} {\toks_use:N#2}}
      }
    }
  }
}
\toks_new:N \g_TP_multiselection_toks
\def_new:Npn \TP_multiselection_add:nnnnnn #1#2#3#4#5#6{
  \toks_gset:Nn \g_TP_multiselection_toks {\if_case:w #4}
  \clist_map_inline:nn {#5}{
    \tlist_if_head_eq_meaning:nNTF{##1..}\DelayEvaluation
    {
      \TP_multiselection_add_or_case:n {##1}
    }
    {
      #1#2{##1}
      \TP_multiselection_add_or_case:n { \toks_use:N #2 }
    }
  }
  \toks_gput_right:Nn \g_TP_multiselection_toks { \else: #6\fi: }
}
\def_new:Npn \TP_multiselection_add_or_case:n #1 {
     \toks_gput_right:Nn \g_TP_multiselection_toks { \or: #1 }
}
\def_new:Npn \TP_multiselection_add_or_case:o  {
  \exp_args:NNo \TP_multiselection_add_or_case:n
}
\def_new:Npn \IfExistsInstanceTF#1#2{
  \cs_if_exist:cTF{<>#1/#2}
}
\def:Npn \IfExistsInstanceTF#1#2{
  \TP_let_instance:Nnn \l_tmpa_tlp {#1}{#2}
  \if_meaning:NN\l_tmpa_tlp\scan_stop:
    \exp_after:NN\use_arg_ii:nn
  \else:
    \exp_after:NN\use_arg_i:nn
  \fi:}
\def_new:Npn \DeclareRestrictedTemplate#1#2#3#4{
  % CCC do we need a group here??
  \tlp_set_eq:cc { TPD>/#1/#2 } { TPD>/#1/#3 }
  \tlp_set_eq:cc {  TP>/#1/#2 } {  TP>/#1/#3 }

  \toks_set:Nd \l_TP_KV_assignments_toks
           {\cs:w TPR>/#1/#3\cs_end:}

  \setkeys {\cs:w TPO>/#1/#3\cs_end:}{#4}

  \tlp_set:co { TPR>/#1/#2 }
              { \toks_use:N \l_TP_KV_assignments_toks }
  \cs_if_free:cTF { TPO>/#1/#3 }
    { \tlp_set:cn {TPO>/#1/#2}{#1/#3}       }
    { \tlp_set_eq:cc {TPO>/#1/#2}{TPO>/#1/#3}  }
}
\def_new:Npn \TP_instdecl_generate_assignments:nn#1#2 {
                               % Returns to \l_TP_KV_assignments_toks
                               % the restrictions
                               % stored in the TP-structure (at present
                               % in YAM) of the template #1

    \toks_set:Nd \l_TP_default_assignments_toks
                 {\cs:w TPD>/#1\cs_end:\scan_stop:\scan_stop:}

    \toks_set:Nd \l_TP_KV_assignments_toks
                 {\cs:w TPR>/#1\cs_end:}

    \setkeys { \cs:w TPO>/#1 \cs_end: }
             { #2 }            % adds stuff to \l_TP_KV_assignments_toks

    \exp_after:NN\TP_instdecl_add_default_recurse:nn
        \toks_use:N\l_TP_default_assignments_toks

}
\def_new:Npn \TP_instdecl_add_default_recurse:nn#1#2{
  \token_if_eq_meaning:NNF #1\scan_stop:
  {
    \l_tmpa_toks{#2}
    \tlp_set:Nx \l_tmpa_tlp {
      {\toks_use:N \l_tmpa_toks \toks_use:N \l_TP_KV_assignments_toks}
    }
    \l_TP_KV_assignments_toks \l_tmpa_tlp
    \TP_instdecl_add_default_recurse:nn
  }
}
\def_new:Npn \TP_split_finite_skip_value:nnNN #1#2{
  \skip_split_finite_else_action:nnNN {#1} {
    \PackageError{template}{Value~ for~ key~ #2~ contains~ `fil(ll)'}
    {Only~ finite~ minus~ or~ plus~ parts~ are~ allowed~ for~ this~ key.}
  }
}
\endinput
%%
%% End of file `template.sty'.
