%%%==============================================================================
%% Copyright 2023-present by Alceu Frigeri
%%
%% This work may be distributed and/or modified under the conditions of
%%
%% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt),
%%   version 1.3c (or later), and/or
%% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html),
%%   version 3 (or later)
%%
%% This work has the LPPL maintenance status *maintained*.
%%
%% The Current Maintainer of this work is Alceu Frigeri
%%
%% This is version {2.3} {2025/11/23}
%%
%% The list of files that compose this work can be found in the README.md file at
%% https://ctan.org/pkg/tikzquests
%%
%%%==============================================================================
\NeedsTeXFormat{LaTeX2e}[2022/06/01]

%%%%%%%
%%%
%%% Just an attempt at having my package's info in a regular way
%%%   \pkginfograb_set:nn {<pkg-name>} { props} sets package info
%%%
%%%   \pkginfograbProvidesExplPackage {<pkg-name>} { props} sets package info
%%%     and calls \ProvidesExplPackage
%%%
%%%%%%%
\RequirePackage{pkginfograb}
\pkginfograbProvidesExplPackage {tikzquests}
  {
     name        = {tikzquests} ,
     prefix      = {tikzquests} ,
     date        = {2025/11/23},
     version     = {2.3} ,
     description = {A Simple Framework for (tikz/text) Parametric Questions}
  }
%%%%%%%
%%% End of cut-n-paste
%%%%%%%


%\newif\iftikzquests@@nodefs
%\tikzquests@@nodefsfalse


\clist_set:Nn \l__tikzquests_keys_clist  {R,L,C,Z,Y,G,H,X,K,T,Q,D,EQ}
\clist_set:Nn \l__tikzquests_skeys_clist  {V,I}
\clist_set:Nn \l__tikzquests_idx_clist {{},a,b}

\keys_define:nn {tikzquests }
  {
    no~ alias  .usage:n = load ,
    no~ alias  .bool_set:N = \l__tikzquests_noalias_bool ,
    no~ alias  .value_forbidden:n  = true ,

    keys~ prefix .usage:n = load ,
    keys~ prefix .tl_set:N = \l__tikzquests_prefix_tl ,
    keys~ prefix .value_required:n  = true ,
    
    
    xtrakeys .usage:n = load ,
    xtrakeys .clist_set:N = \l__tikzquests_xtrakeys_clist ,
    xtrakeys .value_required:n  = true ,
    
    keys .usage:n = load ,
    keys .clist_set:N = \l__tikzquests_keys_clist ,
    keys .value_required:n  = true ,
    
    source~ keys .usage:n = load ,
    source~ keys .clist_set:N = \l__tikzquests_skeys_clist ,
    source~ keys .value_required:n  = true ,

    xtraidx .usage:n = load ,
    xtraidx .clist_set:N = \l__tikzquests_xtraidx_clist ,
    xtraidx .value_required:n  = true ,
   
    idx .usage:n = load ,
    idx .clist_set:N = \l__tikzquests_idx_clist ,
    idx .value_required:n  = true ,
   
    undef~ color .usage:n = load ,
    undef~ color .tl_set:N = \l__tikzquests_undefcolor_tl , 
    undef~ color .value_required:n  = true ,
    undef~ color .initial:n = {red} ,

    in~ review .usage:n = load ,
    in~ review .bool_set:N = \l__tikzquests_inreview_bool ,

    draft .usage:n = load ,
    draft .bool_set:N = \l__tikzquests_inreview_bool ,

    no~ defs  .usage:n = load ,
    no~ defs  .bool_set:N = \l__tikzquests_nodefs_bool ,
    no~ defs  .value_forbidden:n  = true ,
    
    local~ defs  .usage:n = load ,
    local~ defs  .bool_set:N = \l__tikzquests_localdefs_bool ,
    local~ defs  .value_forbidden:n  = true ,

    old~ settings  .usage:n = load ,
    old~ settings  .bool_set:N = \l__tikzquests_oldsettings_bool ,
    old~ settings  .value_forbidden:n  = true ,
    
    keys~ info  .usage:n = load ,
    keys~ info  .bool_set:N = \l__tikzquests_keysinfo_bool ,
    keys~ info  .value_forbidden:n  = true ,
  }
\ProcessKeyOptions [ tikzquests ]


%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%
%%
%%
%%
%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%

\msg_new:nnnn {tikzquests} {repository already defined}
  {
    (ID:#1)~Repository~ '#2'~already~defined!
  }
  {
    You~tried~to~create~an~already~defined~Repository:~'#2'.
    ~Error~Code~ ID:<#1>.
  }

\msg_new:nnnn {tikzquests} {invalid repository}
  {
    (ID:#1)~Invalid~Repository:~ '#2'
  }
  {
    You~tried~to~use~an~invalid~Repository:~'#2'.
    ~Error~Code~ ID:<#1>.
  }

\msg_new:nnnn {tikzquests} {invalid question}
  {
    (ID:#1)~Invalid~Question:~ '#2'
  }
  {
    You~tried~to~use~an~invalid~Question:~'#2'.
    ~Error~Code~ ID:<#1>.
  }


\msg_new:nnnn {tikzquests} {deprecated}
  {
    (ID:#1)~#2 ~ is ~ deprecated.~ use~ '#3' ~ instead
  }
  {
    You~tried~to~use~a~deprecated~command:~#2. Use~'#3'~ instead.
    ~Error~Code~ ID:<#1>.
  }


\msg_new:nnnn {tikzquests} {info}
  {
    #1:~ #2
  }
  {
    #1:~ #2.
  }


\seq_new:N  \l__tikzquests_repositories_seq
\tl_new:N   \l__tikzquests_active_repository_tl
\seq_new:N  \l__tikzquests_tmpa_seq
\seq_new:N  \l__tikzquests_tmpb_seq

\tl_new:N   \l__tikzquests_repo_tl    
\tl_new:N   \l__tikzquests_tmp_tl  
\tl_new:N   \l__tikzquests_tmpa_tl  
\tl_new:N   \l__tikzquests_tmpb_tl  
\tl_new:N   \l__tikzquests_tmpc_tl  
\tl_new:N   \l__tikzquests_tmpd_tl  

\cs_new_protected:Npn \__tikzquests_select_repository:n #1
  {
    \prop_if_exist:cTF {l__tikzquests_ #1 _tikzrepo_prop}
    { \tl_set:Nn \l__tikzquests_active_repository_tl {#1} }
    { \msg_error:nnne {tikzquests}{invalid repository}{select~01}{#1} }
  }

\cs_new_protected:Npn \__tikzquests_new_repository:nn #1#2
  {
    \prop_if_exist:cTF {l__tikzquests_ #2 _tikzrepo_prop}
      {
        \msg_warning:nnne {tikzquests}{repository already defined}{new~01}{#2}
      }
      { 
        \prop_new_linked:c {l__tikzquests_ #2 _tikzrepo_prop}
        \prop_new_linked:c {l__tikzquests_ #2 _textrepo_prop}
        \seq_put_right:Nn \l__tikzquests_repositories_seq {#2}
      }
    \bool_if:nT {#1}
      { \__tikzquests_select_repository:n {#2} }
  }  

\__tikzquests_new_repository:nn {\c_true_bool}{default}

\NewDocumentCommand{\SelectRepository}{m}
  { \__tikzquests_select_repository:n {#1} }
  
\NewDocumentCommand{\defRepository}{sm}
  { \__tikzquests_new_repository:nn {#1}{#2} }  

\NewDocumentCommand\defNewRepository{sm}
  {
    \msg_warning:nnnnn {tikzquests}{deprecated}{dep~03}{\defNewRepository}{\defRepository}
    \__tikzquests_new_repository:nn {#1}{#2}
  }


\NewDocumentCommand{\defQuestion}{sO{\l__tikzquests_active_repository_tl}m+mO{}}
  {
    \prop_if_exist:cTF {l__tikzquests_ #2 _tikzrepo_prop}
    {
      \bool_if:nTF {#1}
        { \prop_put:cnn {l__tikzquests_ #2 _textrepo_prop}{#3}{{#4}{#5}} }
        { \prop_put:cnn {l__tikzquests_ #2 _tikzrepo_prop}{#3}{{#4}{#5}} }    
    }
    { \msg_error:nnne {tikzquests}{invalid repository}{def~quest~01}{#2} }
  }
  
  
\NewDocumentCommand{\defQuestionAlias}{sO{\l__tikzquests_active_repository_tl}mO{}m}
  {
    \tl_if_blank:nTF {#4}
      { \tl_set:Nn \l__tikzquests_tmpa_tl {#2} }
      { \tl_set:Nn \l__tikzquests_tmpa_tl {#4} }
    \bool_lazy_and:nnTF { \prop_if_exist_p:c {l__tikzquests_ #2 _tikzrepo_prop} } { \prop_if_exist_p:c {l__tikzquests_ \l__tikzquests_tmpa_tl _tikzrepo_prop} }
    {
      \bool_if:NF \l__tikzquests_noalias_bool
        {
          \bool_if:nTF {#1}
            { 
              \prop_get:cnNTF {l__tikzquests_ \l__tikzquests_tmpa_tl _textrepo_prop}{#5} \l__tikzquests_tmpb_tl
                { \prop_put:cnV {l__tikzquests_ #2 _textrepo_prop}{#3} \l__tikzquests_tmpb_tl }
                { \msg_error:nnnn {tikzquests}{invalid question}{alias~01}{#5}  }
            }
            { 
              \prop_get:cnNTF {l__tikzquests_ \l__tikzquests_tmpa_tl _tikzrepo_prop}{#5} \l__tikzquests_tmpb_tl
                { \prop_put:cnV {l__tikzquests_ #2 _tikzrepo_prop}{#3} \l__tikzquests_tmpb_tl  }
                { \msg_error:nnnn {tikzquests}{invalid question}{alias~02}{#5}  }
            }
        }
    }
    {
      \tl_if_blank:nTF {#4}
        { \msg_error:nnne {tikzquests}{invalid repository}{alias~04}{<#2>} }
        { \msg_error:nnne {tikzquests}{invalid repository}{alias~04}{<#2> - <#4>} }
    }
  }
  
  
\cs_new_protected:Npn \__tikzquests_annot:nnn #1#2#3
  {
    \bool_if:nT {#1}
      {
        {
          \scriptsize
          \tl_if_blank:nF {#2}
            { \par\textbf{Remarks:~}{\color{\l__tikzquests_undefcolor_tl}#2} }
          \tl_if_blank:nF {#3}
            { \par\textbf{Annotation:~}{\color{\l__tikzquests_undefcolor_tl}#3} }
        }
      }
  }
\cs_generate_variant:Nn   \__tikzquests_annot:nnn {Vnn, VVn, nVn}

\cs_new_protected:Npn \__tikzquests_pgfkeys:n #1
  { \pgfkeys{tikz , #1} }
  
\cs_new_protected:Npn \__tiqzquests_tikzpicture:nn #1#2
  {
		\begin{tikzpicture}
      \__tikzquests_keys_set:n{#2}
      \exp_args:NV \__tikzquests_pgfkeys:n \l__tikzquests_tikz_keys_tl
			#1
		\end{tikzpicture}  
  }  
\cs_generate_variant:Nn   \__tiqzquests_tikzpicture:nn {Vn}

\cs_new_protected:Npn \__tikzquests_prop_split:nnNN #1#2#3#4
  {
    \tl_set:Nn #3 {#1}
    \tl_set:Nn #4 {#2}
  }

\cs_new_protected:Npn \__tikzquests_tikzquestion:nnnnnn #1#2#3#4#5#6
  {
    \bool_if:nTF {#1}
      { \tl_set:Nn \l__tikzquests_repo_tl {textrepo} }
      { \tl_set:Nn \l__tikzquests_repo_tl {tikzrepo} }
    \prop_if_exist:cTF {l__tikzquests_ #3 _ \l__tikzquests_repo_tl _prop}
    {
      \prop_get:cnNTF {l__tikzquests_ #3 _ \l__tikzquests_repo_tl _prop} {#4} \l__tikzquests_tmp_tl
        {
          \exp_last_unbraced:NV \__tikzquests_prop_split:nnNN \l__tikzquests_tmp_tl \l__tikzquests_tmpa_tl \l__tikzquests_tmpb_tl

          \tl_if_blank:nTF {#2}
            {
              \__tiqzquests_tikzpicture:Vn \l__tikzquests_tmpa_tl {#5} 
            }
            {
      				\resizebox{#2\textwidth}{!}{
              \__tiqzquests_tikzpicture:Vn \l__tikzquests_tmpa_tl {#5}  }
            }
          \__tikzquests_annot:nnn 
            \l__tikzquests_inreview_bool
            {\l__tikzquests_tmpb_tl}{#6}          
        }
        {
          Invalid~Question:~#4
          \msg_error:nnnn {tikzquests}{invalid question}{quest~01}{#4}
        }
    }
    {
      Invalid~Repository:~#3
      \msg_error:nnne {tikzquests}{invalid repository}{quest~01}{#3}
    }
  }


\NewDocumentCommand{\tikzQuestion}{sD(){}O{\l__tikzquests_active_repository_tl}mO{}D<>{}}
  { \__tikzquests_tikzquestion:nnnnnn {#1}{#2}{#3}{#4}{#5}{#6} }  

  
\NewDocumentCommand{\ftikzQuestion}{sD(){}O{\l__tikzquests_active_repository_tl}mO{}D<>{}}
  {
    \begin{center}
      \__tikzquests_tikzquestion:nnnnnn {#1}{#2}{#3}{#4}{#5}{#6}
    \end{center}
  }  

\cs_new_protected:Npn \__tikzquests_rawquestion:nnnnn #1#2#3#4#5
  {
    \prop_if_exist:cTF {l__tikzquests_ #1 _ #2 _prop}
    {
      \prop_get:cnNTF {l__tikzquests_ #1 _ #2 _prop} {#3} \l__tikzquests_tmp_tl
        {
         \exp_last_unbraced:NV \__tikzquests_prop_split:nnNN \l__tikzquests_tmp_tl \l__tikzquests_tmpa_tl \l__tikzquests_tmpb_tl
        
          \begingroup
            \__tikzquests_keys_set:n{#4}
            \l__tikzquests_tmpa_tl
          \endgroup
          \__tikzquests_annot:nnn 
            \l__tikzquests_inreview_bool
            {\l__tikzquests_tmpb_tl}{#5}
        }
        {
          Invalid~Question:~#3
          \msg_error:nnnn {tikzquests}{invalid question}{quest~02}{#3}
        }
    }
    {
      Invalid~Repository:~#1
      \msg_error:nnne {tikzquests}{invalid repository}{quest~02}{#1}
    }
  }  

  
\NewDocumentCommand{\rawtikzQuestion}{O{\l__tikzquests_active_repository_tl}mO{}D<>{}}
  {
    \msg_warning:nnnnn {tikzquests}{deprecated}{dep~01}{\rawtikzQuestion}{\Question}
    \__tikzquests_rawquestion:nnnnn {#1}{tikzrepo}{#2}{#3}{#4}
  }

  
\NewDocumentCommand{\textQuestion}{O{\l__tikzquests_active_repository_tl}mO{}D<>{}}
  {
    \msg_warning:nnnnn {tikzquests}{deprecated}{dep~02}{\textQuestion}{\Question*}
    \__tikzquests_rawquestion:nnnnn {#1}{textrepo}{#2}{#3}{#4}
  }

\NewDocumentCommand{\Question}{sO{\l__tikzquests_active_repository_tl}mO{}D<>{}}
  {
    \bool_if:nTF {#1}
      { \__tikzquests_rawquestion:nnnnn {#2}{textrepo}{#3}{#4}{#5} }
      { \__tikzquests_rawquestion:nnnnn {#2}{tikzrepo}{#3}{#4}{#5} }
  }


%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%

\coffin_new:N \l__tikzquests_tmpa_coffin
\coffin_new:N \l__tikzquests_tmpb_coffin

\cs_new_protected:Npn \__tikzquests_sorted_list:nnn #1#2#3
  {
      \prop_if_empty:cF {l__tikzquests_ #1 _ #2 _prop}
        {
            \seq_gclear_new:N \l__tikzquests_questions_seq
            \prop_map_inline:cn {l__tikzquests_ #1 _ #2 _prop}
              {
                \seq_put_right:Nn \l__tikzquests_questions_seq {##1}
              }
            \seq_sort:Nn \l__tikzquests_questions_seq
              {
                \str_compare:eNeTF { ##1 } > { ##2 }
                  { \sort_return_swapped: }
                  { \sort_return_same: }
              }
              
              \seq_map_inline:Nn \l__tikzquests_questions_seq
                {                  
                  \vcoffin_set:Nnn \l__tikzquests_tmpa_coffin {0.2\textwidth}
                    {
                      \noindent \textbf{##1}
                    }
                  \vcoffin_set:Nnn \l__tikzquests_tmpb_coffin {0.8\textwidth}
                    {
                      \noindent #3[#1]{##1}
                      \bool_if:nF {\l__tikzquests_inreview_bool}
                        {
                          \prop_get:cnN {l__tikzquests_ #1 _ #2 _prop} {##1}
                            \l__tikzquests_tmpc_tl
                            
                            %%% dubious, at best...the remark is the 2nd {} from the property item
                          \exp_last_unbraced:NNNV \use_i_ii:nnn \tl_set:Nn \l__tikzquests_tmpd_tl \l__tikzquests_tmpc_tl

                          \__tikzquests_annot:nVn
                            \c_true_bool
                            \l__tikzquests_tmpd_tl
                            {}
                        }
                    }
                  \coffin_join:NnnNnnnn
                    \l__tikzquests_tmpa_coffin {r}{vc}
                    \l__tikzquests_tmpb_coffin {l}{vc}
                    {0pt}{0pt}
                  \noindent \coffin_typeset:Nnnnn \l__tikzquests_tmpa_coffin {l}{t}{0pt}{0pt}
                  \skip_vertical:n{0.35ex}  
                  {
                    \color{white!20!gray}\hrule\relax
                  }
                  \skip_vertical:n{1ex}                 
                }    
        }
  }


\NewDocumentCommand{\QuestionsFmtList}{O{}mm}
  {
    \tl_if_blank:nTF {#1}
      { 
        \seq_set_eq:NN \l__tikzquests_tmpb_seq \l__tikzquests_repositories_seq
      }
      {
        \seq_set_from_clist:Nn \l__tikzquests_tmpb_seq {#1}
      }
      
    \seq_map_inline:Nn \l__tikzquests_tmpb_seq
      {
        \regex_match:nnTF {/$}{##1}
          {
            \tl_set:Nn \l__tikzquests_tmpa_tl {##1}
            \regex_replace_once:nnN {/$}{} \l__tikzquests_tmpa_tl
            \seq_put_right:Nn \l__tikzquests_tmpa_seq {\l__tikzquests_tmpa_tl}
            \seq_map_inline:Nn \l__tikzquests_repositories_seq
              {
                \regex_match:nnTF {##1}{####1}
                  {
                    \seq_put_right:Nn \l__tikzquests_tmpa_seq {####1}
                  }
                  {}
              }
          }
          {
            \seq_put_right:Nn \l__tikzquests_tmpa_seq {##1}
          }
      }      
      
    \seq_remove_duplicates:N \l__tikzquests_tmpa_seq
    \seq_sort:Nn \l__tikzquests_tmpa_seq
      {
        \str_compare:eNeTF { ##1 } > { ##2 }
          { \sort_return_swapped: }
          { \sort_return_same: }
      }
    \seq_map_inline:Nn \l__tikzquests_tmpa_seq
      {
        \prop_if_exist:cTF {l__tikzquests_ ##1 _tikzrepo_prop}
        {    
          \skip_vertical:n{0.35ex}  
          \hrule\relax\hrule\relax
          
          \skip_vertical:n{1ex}  
          {Repository:~ \large\textbf{##1}}
          \skip_vertical:n{0.35ex}  
          \hrule
          
          \skip_vertical:n{1ex}  
          ~\hfill\emph{\underline{ non~ starred~ ones~ -~ TikZ~ graphics}}
          \skip_vertical:n{0.35ex}  
          
          \__tikzquests_sorted_list:nnn {##1}{tikzrepo}{#3}
          
          \skip_vertical:n{1ex}  
          ~\hfill\emph{\underline{starred~ ones~ -~ text/\TeX}}
          \skip_vertical:n{0.35ex}  

          \__tikzquests_sorted_list:nnn {##1}{textrepo}{#2}
        }
        {
          \msg_error:nnne {tikzquests}{invalid repository}{Qlist~01}{##1}
        }
      }
  }

\NewDocumentCommand{\QuestionsList}{O{}}
  { \QuestionsFmtList[#1]{\Question*}{\tikzQuestion(0.35)} }


%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%

\cs_new:Npn \__tikzquests_keys_set:n #1
  { 
    \__tikzquests_lkeys_set:
    \keys_set:nn { tikzquests / vars }
      {#1}
  }

\NewDocumentCommand {\QuestVal} {m}
  {
    \tl_if_exist:cTF {l__tikzquests_ #1 _key_tl}
      { \use:c {l__tikzquests_ #1 _key_tl} }
      { 
        \textbf { \emph{ \color{ \l__tikzquests_undefcolor_tl } #1  } }
      }
  }

\cs_new_protected:Npn \__tikzquests_keydef:nnnN #1#2#3#4
  {
    \tl_set:cn {#2} {#3}
    \keys_define:nn { tikzquests / vars }
      {
        #1 .code:n = 
          { \tl_set:cn {#2} {#4{##1}} } ,
        #1 .value_required:n = true ,
        
        #1* .code:n = 
          { \tl_set:cn {#2} {\ensuremath{##1}} } ,                      
        #1* .value_required:n = true ,
        
        #1 ~ raw .code:n = 
          { \tl_set:cn {#2} {##1} } ,                      
        #1 ~ raw .value_required:n = true ,
      }
  }

\seq_const_from_clist:Nn \c__tikzquests_abc_seq {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}

\cs_new_protected:Npn \__tikzquests_keys:nNNn #1#2#3#4
  {

    \seq_map_inline:Nn #2
      {
        \seq_map_inline:Nn #3
          {
            \seq_map_inline:Nn \c__tikzquests_abc_seq
              {
                \exp_args:Ncc \tl_set:Nn {l__tikzquests_ #1##1####1########1 _key_tl} {##1####1########1}
                \__tikzquests_keydef:nnnN 
                  { #1##1####1########1 }
                  { #1##1####1########1 }
                  {\ensuremath{#1##1 \c_math_subscript_token {#4{####1########1}}}}
                  \ensuremath
              }
          }
      }   
  }
\cs_generate_variant:Nn  \__tikzquests_keys:nNNn {V}


\cs_new_protected:Npn \__tikzquests_keys_nodefs:nNNn #1#2#3#4
  {
    \bool_if:NTF \l__tikzquests_oldsettings_bool
      { \cs_set_eq:NN \__tikzquests_auxi: \relax  }
      { \cs_set_eq:NN \__tikzquests_auxi: \ensuremath  }

    \seq_map_inline:Nn #2
      {
        \seq_map_inline:Nn #3
          {
            \seq_map_inline:Nn \c__tikzquests_abc_seq            
              {
                \__tikzquests_keydef:nnnN
                  { #1##1####1########1 }
                  { l__tikzquests_ #1##1####1########1 _key_tl }
                  {\ensuremath{#1##1 \c_math_subscript_token {#4{####1########1}}}}
                  \__tikzquests_auxi:
              }
          }
      }   
  }
\cs_generate_variant:Nn  \__tikzquests_keys_nodefs:nNNn {V}

\cs_new_protected:Npn \__tikzquests_newkey:Nnn #1#2#3
  {
    \tl_if_empty:nTF {#3}
      {
        \tl_set:Nn #1
          { \textbf { \emph{ \color{ \l__tikzquests_undefcolor_tl } #2  } } }        
      }
      {
        \tl_set:Nn #1
          { #3 }        
      }
    \keys_define:nn { tikzquests / vars }
      {
        #2 .tl_set:N = #1 , 
        #2 .value_required:n = true
      }    
  }
\cs_generate_variant:Nn \__tikzquests_newkey:Nnn {cV}

\cs_generate_variant:Nn \msg_note:nnnn {nnne}

\cs_new_protected:Npn \__tikzquests_keys_set: 
  {
    \keys_define:nn { tikzquests / vars }
      {
        unknown .code:n = 
          {
            \__tikzquests_newkey:cVn 
              {l__tikzquests_ \l_keys_key_str _key_tl} 
              \l_keys_key_str 
              {##1}          
          } ,
        tikz ~ keys .tl_set:N = \l__tikzquests_tikz_keys_tl
      }

    \clist_concat:NNN \l__tikzquests_keys_clist \l__tikzquests_keys_clist \l__tikzquests_xtrakeys_clist
    \seq_set_from_clist:NN \l__tikzquests_keys_seq \l__tikzquests_keys_clist
    \seq_remove_duplicates:N \l__tikzquests_keys_seq

    \clist_concat:NNN \l__tikzquests_idx_clist \l__tikzquests_idx_clist \l__tikzquests_xtraidx_clist
    \seq_set_from_clist:NN \l__tikzquests_idx_seq \l__tikzquests_idx_clist
    \seq_remove_duplicates:N \l__tikzquests_idx_seq
         
    \seq_set_from_clist:NN \l__tikzquests_skeys_seq \l__tikzquests_skeys_clist
    \seq_remove_duplicates:N \l__tikzquests_skeys_seq
      
    \bool_if:NTF \l__tikzquests_keysinfo_bool
      {
        \tl_if_empty:VTF \l__tikzquests_prefix_tl
          {
            \msg_note:nnnn {tikzquests}{info}
              {keys ~ prefix}
              {  -no~ key~ prefix- ~ (default) }
          }
          {
            \msg_note:nnne {tikzquests}{info}
              {keys ~ prefix}
              { \l__tikzquests_prefix_tl }
          }
        \msg_note:nnne {tikzquests}{info}
          {Processed ~ keys}
          { \seq_use:Nn \l__tikzquests_keys_seq {,} }
        \msg_note:nnne {tikzquests}{info}
          {Processed ~ source ~ keys}
          { \seq_use:Nn \l__tikzquests_skeys_seq {,} }
        \msg_note:nnne {tikzquests}{info}
          {Processed ~ indexes} 
          { \seq_use:Nn \l__tikzquests_idx_seq {,} }
      }
      {}
    
    \bool_if:NTF \l__tikzquests_nodefs_bool
      { \cs_gset_eq:NN \__tikzquests_map:VNNn \__tikzquests_keys_nodefs:VNNn }
      { \cs_gset_eq:NN \__tikzquests_map:VNNn \__tikzquests_keys:VNNn }
            
    \__tikzquests_map:VNNn 
      \l__tikzquests_prefix_tl
      \l__tikzquests_keys_seq
      \l__tikzquests_idx_seq
      {}

    \__tikzquests_map:VNNn 
      \l__tikzquests_prefix_tl
      \l__tikzquests_skeys_seq
      \l__tikzquests_idx_seq
      { f \c_math_subscript_token }

  }


\bool_if:NTF \l__tikzquests_localdefs_bool
  {
    \cs_set_eq:NN \__tikzquests_gkeys_set: \relax
    \cs_set_eq:NN \__tikzquests_lkeys_set: \__tikzquests_keys_set:
  }
  {
    \cs_set_eq:NN \__tikzquests_gkeys_set: \__tikzquests_keys_set:
    \cs_set_eq:NN \__tikzquests_lkeys_set: \relax
  }


\AtBeginDocument{\__tikzquests_gkeys_set:}


