%%
%% This is file `styledcmd.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% styledcmd.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Styledcmd Handle multiple versions for user-defined macros in LaTeX
%% Copyright (C) 2021  Paolo De Donato <dedonato95@hotmail.it>
%% 
%% Styledcmd is free software: you can redistribute it and/or modify
%% it under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%% 
%% Styledcmd is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%% GNU General Public License for more details.
%% 
%% You should have received a copy of the GNU General Public License
%% along with Styledcmd.  If not, see <https://www.gnu.org/licenses/>.
%% 
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{expl3}[2022-04-10]
\ProvidesExplPackage{styledcmd}{2022/12/13}{2.0}{Command with different styles}
\RequirePackage{lt3rawobjects}[2022-12-12]
\RequirePackage{xparse}


\str_const:Nx \c__stycmd_cmdproxy_str { \object_address:nn
    { stycmd }{ proxy } }

\proxy_create:nnN { stycmd }{ proxy } \c_object_public_str
\proxy_push_member:Vnn \c__stycmd_cmdproxy_str { default }{ tl }


\cs_new:Nn \__stycmd_cmd:n
  {
    \object_address:nn{ stycmd }{ entity - #1 }
  }


\cs_new_protected:Nn \__stycmd_setdef_aux:nN
  {
    \object_member_set:nnn
      {
        \__stycmd_cmd:n{ #1 }
      }
      { default }
      { #2 }
  }
\cs_generate_variant:Nn \__stycmd_setdef_aux:nN { nc }

\cs_new_protected:Nn \__stycmd_setdef_style:nn
  {
    \__stycmd_setdef_aux:nc{ #1 }
      {
        \object_macro_adr:nn
          {
            \__stycmd_cmd:n{ #1 }
          }
          {
            style - #2
          }
      }
  }

\cs_generate_variant:Nn \__stycmd_setdef_style:nn { ff }

\cs_new_protected:Nn \__stycmd_setdef_strip:Nn
  {
    \__stycmd_setdef_style:ff{ \cs_to_str:N #1 }
      { \tl_trim_spaces:n{ #2 } }
  }


\cs_new_protected:Nn \__stycmd_cmd_define_aux_aux:NN
  {
    #1 { #2 }
  }
\cs_generate_variant:Nn \__stycmd_cmd_define_aux_aux:NN { Nc }

\cs_new_protected:Nn \__stycmd_cmd_define_aux:Nnn
  {
    \__stycmd_cmd_define_aux_aux:Nc #1
      {
        \object_macro_adr:nn
          {
            \__stycmd_cmd:n{ #2 }
          }
          {
            style - #3
          }
      }
  }

\cs_generate_variant:Nn \__stycmd_cmd_define_aux:Nnn { Nff }

\cs_new_protected:Nn \__stycmd_cmd_define_strip:NNn
  {
    \__stycmd_cmd_define_aux:Nff #1
      { \cs_to_str:N #2 }{ \tl_trim_spaces:n { #3 } }
  }


\cs_new:Nn \__stycmd_cmd_usedef_aux:n
  {
    \object_member_use:nn
      {
        \__stycmd_cmd:n{ #1 }
      }
      {
        default
      }
  }

\cs_generate_variant:Nn \__stycmd_cmd_usedef_aux:n { f }

\cs_new:Nn \__stycmd_cmd_usedef:N
  {
    \__stycmd_cmd_usedef_aux:f{ \cs_to_str:N #1 }
  }

\cs_new:Nn \__stycmd_cmd_usesty_aux:nn
  {
    \object_macro_use:nn
      {
        \__stycmd_cmd:n{ #1 }
      }
      {
        style - #2
      }
  }

\cs_generate_variant:Nn \__stycmd_cmd_usesty_aux:nn { ff }

\cs_new:Nn \__stycmd_cmd_usesty_strip:Nn
  {
    \__stycmd_cmd_usesty_aux:ff{ \cs_to_str:N #1 }
      { \tl_trim_spaces:n{ #2 } }
  }


\cs_new_protected:Nn \__stycmd_entity_create_aux:nnn
  {
    \object_if_exist:nF
      {
        \__stycmd_cmd:n{ #1 }
      }
      {
        \object_create:VnnNN \c__stycmd_cmdproxy_str
          { stycmd }{ entity - #1 }
          \c_object_global_str
          \c_object_public_str

        \__stycmd_setdef_style:nn{ #1 }{ #2 }

        #3
      }
  }

\cs_generate_variant:Nn \__stycmd_entity_create_aux:nnn { ffn }

\cs_new_protected:Nn \__stycmd_entity_create_strip:Nnn
  {
    \__stycmd_entity_create_aux:ffn
      { \cs_to_str:N #1 }
      { \tl_trim_spaces:n{ #2 } }
      { #3 }
  }


\cs_new_protected:Nn \stycmd_xparsecmd:N
  {
    \ProvideDocumentCommand { #1 } { o }
      {
        \IfNoValueTF {##1}
          {
            \__stycmd_cmd_usedef:N #1
          }
          {
            \__stycmd_cmd_usesty_strip:Nn #1 { ##1 }
          }
      }
  }


\cs_new_protected:Nn \stycmd_expcmd:N
  {
    \providecommand { #1 } [1]
      {
        \tl_if_empty:nTF {##1}
          {
            \__stycmd_cmd_usedef:N #1
          }
          {
            \__stycmd_cmd_usesty_strip:Nn #1 { ##1 }
          }
      }
  }


\NewDocumentCommand{\SetGlobalStyle}{m m}
  {
    \__stycmd_setdef_strip:Nn #1 { #2 }
  }


\cs_new_protected:Nn \stycmd_generate:NNN
  {
    \cs_new_protected:Npn #1 ##1 ##2
      {
        \__stycmd_entity_create_strip:Nnn ##1 { ##2 }
          {
            #3 ##1
          }
        \__stycmd_cmd_define_strip:NNn #2 ##1 { ##2 }
      }
  }

\cs_new_protected:Nn \stycmd_generate:NN
  {
    \stycmd_generate:NNN #1 #2 \stycmd_xparsecmd:N
  }

\cs_new_protected:Nn \stycmd_generate_renew:NN
  {
    \cs_new_protected:Npn #1 ##1 ##2
      {
        \__stycmd_cmd_define_strip:NNn #2 ##1 { ##2 }
      }
  }

\stycmd_generate:NN \newstyledcmd \newcommand
\stycmd_generate_renew:NN \renewstyledcmd \renewcommand
\stycmd_generate:NN \providestyledcmd \providecommand
\stycmd_generate:NN \NewDocStyledCMD \NewDocumentCommand
\stycmd_generate_renew:NN \RenewDocStyledCMD \RenewDocumentCommand
\stycmd_generate:NN \ProvideDocStyledCMD \ProvideDocumentCommand
\stycmd_generate:NNN \newstyledcmdExp \newcommand \stycmd_expcmd:N
\stycmd_generate_renew:NN \renewstyledcmdExp \renewcommand
\stycmd_generate:NNN \providestyledcmdExp \providecommand \stycmd_expcmd:N

\str_new:N \g__stycmd_grproxy_str
\seq_new:N \g__stycmd_tmp_seq
\seq_new:N \g__stycmd_tmpb_seq

\proxy_create_gset:NnnN \g__stycmd_grproxy_str { stycmd }{ groups }
  \c_object_public_str

\proxy_push_member:Vnn \g__stycmd_grproxy_str { commands }{ seq }

\cs_generate_variant:Nn \seq_gconcat:NNN { ccN }

\cs_new_protected:Nn \__stycmd_gconcat:nN
  {
    \seq_gconcat:ccN { #1 }{ #1 } #2
  }

\cs_new_protected:Nn \__stycmd_addgroup:nn
  {
    \object_if_exist:nF
      {
        \object_address:nn{ stycmd }{ group - #1 }
      }
      {
        \object_create:VnnNN \g__stycmd_grproxy_str
          { stycmd }
          { group - #1 }
          \c_object_global_str
          \c_object_public_str
      }

    \seq_gset_from_clist:Nn \g__stycmd_tmp_seq { #2 }
    \seq_gset_map_x:NNn \g__stycmd_tmpb_seq \g__stycmd_tmp_seq
      {
        \cs_to_str:N ##1
      }

    \__stycmd_gconcat:nN
      {
      \object_member_adr:nnn
        {
          \object_address:nn
            { stycmd }
            { group - #1 }
        }
        { commands }
        { seq }
      } \g__stycmd_tmpb_seq
  }

\cs_generate_variant:Nn \__stycmd_addgroup:nn { fn }

\NewDocumentCommand{\AddCMDToGroup}{m m}
  {
    \__stycmd_addgroup:fn { \tl_trim_spaces:n{ #1 } } { #2 }
  }

\NewDocumentCommand{\SetGroupStyle}{m m}
  {
    \seq_map_inline:cn
      {
        \object_member_adr:nnn
          {
            \object_address:nn
              { stycmd }
              { group - #1 }
          }
          { commands }
          { seq }
      }
      {
        \__stycmd_setdef_style:nn{ ##1 }{ #2 }
      }
  }

\msg_new:nnnn{ styledcmd }{ stydep }{ Old-fashioned~groups~for~styled~commands~are~deprecated }
  {
    From~version~2.0~of~styledcmd~you~should~use~new~group~commands~instea~of~old~ones,~see~official~documentation~on~CTAN.
  }

\str_new:N \g__stycmd_act_group_str
\str_new:N \g__stycmd_act_style_str

\NewDocumentCommand{\styBeginGroup}{ m }
  {
    \msg_warning:nn{ styledcmd }{ stydep }
    \str_gset:Nn \g__stycmd_act_group_str{ #1 }
  }

\NewDocumentCommand{\styEndGroup}{}
  {
    \msg_warning:nn{ styledcmd }{ stydep }
    \str_gset:Nn \g__stycmd_act_group_str{}
  }

\NewDocumentCommand{\styBeginStyle}{ m }
  {
    \msg_warning:nn{ styledcmd }{ stydep }
    \str_gset:Nn \g__stycmd_act_style_str{ #1 }
  }

\NewDocumentCommand{\styEndStyle}{}
  {
    \msg_warning:nn{ styledcmd }{ stydep }
    \str_gset:Nn \g__stycmd_act_style_str{}
  }

\cs_generate_variant:Nn \__stycmd_addgroup:nn { Vn }

\NewDocumentCommand{\newGstyledcmd}{m o m}
  {
    \msg_warning:nn{ styledcmd }{ stydep }
    \__stycmd_addgroup:Vn \g__stycmd_act_group_str { #1 }
    \IfNoValueTF{ #2 }
      {
        \exp_args:NNV \newstyledcmd #1 \g__stycmd_act_style_str { #3 }
      }
      {
        \exp_args:NNV \newstyledcmd #1 \g__stycmd_act_style_str [ #2 ] { #3 }
      }
  }

\NewDocumentCommand{\NewGDocStyledCMD}{m m m}
  {
    \msg_warning:nn{ styledcmd }{ stydep }
    \__stycmd_addgroup:Vn \g__stycmd_act_group_str { #1 }
    \exp_args:NNV \NewDocStyledCMD #1 \g__stycmd_act_style_str { #2 } { #3 }
  }

 \NewDocumentCommand{\setGroupStyle}{m m}
   {
     \msg_warning:nn{ styledcmd }{ stydep }
     \SetGroupStyle{ #1 }{ #2 }
   }
\endinput
%%
%% End of file `styledcmd.sty'.
