From 619b560e8164b9f0cddb6bb443e921e54904237b Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 13 Dec 2022 21:06:54 +0000 Subject: styledcmd (13dec22) git-svn-id: svn://tug.org/texlive/trunk@65262 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/latex/styledcmd/styledcmd.sty | 369 +++++++++++++++------ 1 file changed, 265 insertions(+), 104 deletions(-) (limited to 'Master/texmf-dist/tex/latex/styledcmd') diff --git a/Master/texmf-dist/tex/latex/styledcmd/styledcmd.sty b/Master/texmf-dist/tex/latex/styledcmd/styledcmd.sty index 5fecba7753f..e259a5dc6c6 100644 --- a/Master/texmf-dist/tex/latex/styledcmd/styledcmd.sty +++ b/Master/texmf-dist/tex/latex/styledcmd/styledcmd.sty @@ -25,198 +25,359 @@ %% along with Styledcmd. If not, see . %% \NeedsTeXFormat{LaTeX2e} -\RequirePackage{expl3}[2018-04-12] -\ProvidesExplPackage{styledcmd}{2021/08/20}{1.1}{Command with different styles} +\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:Nn \c__stycmd_defname_str{ default } -\str_new:N \l__stycmd_cexp_str -\str_new:N \l__stycmd_fexp_str -\cs_new:Npn \__stycmd_cmd:nn #1#2{ __stycmd_command_#1_#2 } -\cs_generate_variant:Nn \__stycmd_cmd:nn { nV } -\cs_generate_variant:Nn \__stycmd_cmd:nn { VV } +\str_const:Nx \c__stycmd_cmdproxy_str { \object_address:nn + { stycmd }{ proxy } } -\cs_new:Nn \__stycmd_cmd: +\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 { - \__stycmd_cmd:VV\l__stycmd_cexp_str\l__stycmd_fexp_str + \object_address:nn{ stycmd }{ entity - #1 } } -\cs_new:Npn \__stycmd_cmddefname:n #1 + +\cs_new_protected:Nn \__stycmd_setdef_aux:nN { - \__stycmd_cmd:nV { #1 } \c__stycmd_defname_str + \object_member_set:nnn + { + \__stycmd_cmd:n{ #1 } + } + { default } + { #2 } } -\msg_new:nnn { stycmd } { noformat } +\cs_generate_variant:Nn \__stycmd_setdef_aux:nN { nc } + +\cs_new_protected:Nn \__stycmd_setdef_style:nn { - Style~#2~not~defined~for~command~#1 + \__stycmd_setdef_aux:nc{ #1 } + { + \object_macro_adr:nn + { + \__stycmd_cmd:n{ #1 } + } + { + style - #2 + } + } } -\cs_new_protected:Npn\__stycmd_erroring:nn #1#2 +\cs_generate_variant:Nn \__stycmd_setdef_style:nn { ff } + +\cs_new_protected:Nn \__stycmd_setdef_strip:Nn { - \cs_if_free:cT { \__stycmd_cmd:nn {#1} {#2} } - { \msg_error:nnnn { stycmd } { noformat } {#1} {#2} } + \__stycmd_setdef_style:ff{ \cs_to_str:N #1 } + { \tl_trim_spaces:n{ #2 } } } -\cs_generate_variant:Nn \__stycmd_erroring:nn { nV, VV } -\msg_new:nnn { stycmd } { deferror } + +\cs_new_protected:Nn \__stycmd_cmd_define_aux_aux:NN { - Cannot~define~a~style~with~name~default + #1 { #2 } } +\cs_generate_variant:Nn \__stycmd_cmd_define_aux_aux:NN { Nc } -\cs_new_protected:Nn\__stycmd_deferr: +\cs_new_protected:Nn \__stycmd_cmd_define_aux:Nnn { - \str_if_eq:NNT \l__stycmd_fexp_str \c__stycmd_defname_str - { \msg_error:nn { stycmd } { deferror } } + \__stycmd_cmd_define_aux_aux:Nc #1 + { + \object_macro_adr:nn + { + \__stycmd_cmd:n{ #2 } + } + { + style - #3 + } + } } -\cs_new_protected:Npn \__stycmd_macro_default:nn #1#2 + +\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 { - \exp_args:Nc \ProvideDocumentCommand { \__stycmd_cmddefname:n { #1 } } - {} + \object_member_use:nn { - \use:c { \__stycmd_cmd:nn { #1 } { #2 } } + \__stycmd_cmd:n{ #1 } + } + { + default } } -\cs_generate_variant:Nn \__stycmd_macro_default:nn { VV } -\cs_new_protected:Npn \__stycmd_macro_overwrite:nn #1#2 +\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_erroring:nn { #1 } { #2 } + \__stycmd_cmd_usesty_aux:ff{ \cs_to_str:N #1 } + { \tl_trim_spaces:n{ #2 } } + } + - \exp_args:Nc \RenewDocumentCommand { \__stycmd_cmddefname:n { #1 } } - {} +\cs_new_protected:Nn \__stycmd_entity_create_aux:nnn + { + \object_if_exist:nF { - \use:c { \__stycmd_cmd:nn { #1 } { #2 } } + \__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_macro_overwrite:nn { VV } -\cs_new_protected:Npn \__stycmd_macro_declaration:n #1 +\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 { - \exp_args:Nc \ProvideDocumentCommand { #1 } {o} + \ProvideDocumentCommand { #1 } { o } { \IfNoValueTF {##1} { - \use:c { \__stycmd_cmddefname:n { #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 } { - \str_set:Nx \l__stycmd_fexp_str {##1} - \__stycmd_erroring:nV { #1 } \l__stycmd_fexp_str - \use:c{ \__stycmd_cmd:nV { #1 } \l__stycmd_fexp_str } + \__stycmd_cmd_usesty_strip:Nn #1 { ##1 } } } } -\cs_generate_variant:Nn \__stycmd_macro_declaration:n { V } -\cs_new_protected:Npn \__stycmd_init_vars:Nn #1#2 + +\NewDocumentCommand{\SetGlobalStyle}{m m} { - \str_set:Nx \l__stycmd_cexp_str { \cs_to_str:N #1 } - \str_set:Nx \l__stycmd_fexp_str {#2} - \__stycmd_deferr: + \__stycmd_setdef_strip:Nn #1 { #2 } } -\cs_new_protected:Npn \stycmd_generate:NN #1#2 + + +\cs_new_protected:Nn \stycmd_generate:NNN { - \NewDocumentCommand #1 {m m} + \cs_new_protected:Npn #1 ##1 ##2 { - \__stycmd_init_vars:Nn { ##1 } { ##2 } - \__stycmd_macro_default:VV \l__stycmd_cexp_str \l__stycmd_fexp_str - \__stycmd_macro_declaration:V \l__stycmd_cexp_str - \exp_args:Nc #2 { \__stycmd_cmd: } + \__stycmd_entity_create_strip:Nnn ##1 { ##2 } + { + #3 ##1 + } + \__stycmd_cmd_define_strip:NNn #2 ##1 { ##2 } } } -\cs_new_protected:Npn \stycmd_generate_renew:NN #1#2 +\cs_new_protected:Nn \stycmd_generate:NN { - \NewDocumentCommand #1 {m m} + \stycmd_generate:NNN #1 #2 \stycmd_xparsecmd:N + } + +\cs_new_protected:Nn \stycmd_generate_renew:NN + { + \cs_new_protected:Npn #1 ##1 ##2 { - \__stycmd_init_vars:Nn { ##1 } { ##2 } - \__stycmd_erroring:VV \l__stycmd_cexp_str \l__stycmd_fexp_str - \exp_args:Nc #2 { \__stycmd_cmd: } + \__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 -\NewDocumentCommand \setGlobalStyle{m m}{ - \__stycmd_init_vars:Nn { #1 } { #2 } +\stycmd_generate:NNN \newstyledcmdExp \newcommand \stycmd_expcmd:N +\stycmd_generate_renew:NN \renewstyledcmdExp \renewcommand +\stycmd_generate:NNN \providestyledcmdExp \providecommand \stycmd_expcmd:N - \__stycmd_macro_overwrite:VV \l__stycmd_cexp_str \l__stycmd_fexp_str -} -\str_new:N \l__stycmd_group_str -\str_new:N \l__stycmd_format_str -\cs_new:Npn \__stycmd_gvar:n #1 { g__stycmd_glist_#1_seq } +\str_new:N \g__stycmd_grproxy_str +\seq_new:N \g__stycmd_tmp_seq +\seq_new:N \g__stycmd_tmpb_seq -\cs_generate_variant:Nn \__stycmd_gvar:n { V } +\proxy_create_gset:NnnN \g__stycmd_grproxy_str { stycmd }{ groups } + \c_object_public_str -\cs_new:Nn \__stycmd_gvar: { \__stycmd_gvar:V \l__stycmd_group_str } -\cs_new_protected:Npn \__stycmd_push_g:Nn #1#2 +\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_gput_left:cn { \__stycmd_gvar:n { #2 } } { #1 } + \seq_gconcat:ccN { #1 }{ #1 } #2 } -\cs_generate_variant:Nn \__stycmd_push_g:Nn { NV } -\msg_new:nnn { stycmd } { gnotclosed } { Group~not~closed } - -\NewDocumentCommand \styBeginGroup { m } +\cs_new_protected:Nn \__stycmd_addgroup:nn { - \str_if_empty:NF \l__stycmd_group_str + \object_if_exist:nF { - \msg_error:nn { stycmd } { gnotclosed } + \object_address:nn{ stycmd }{ group - #1 } + } + { + \object_create:VnnNN \g__stycmd_grproxy_str + { stycmd } + { group - #1 } + \c_object_global_str + \c_object_public_str } - \str_set:Nx \l__stycmd_group_str {#1} + \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 + } - \seq_if_exist:cF { \__stycmd_gvar: } - { \seq_new:c { \__stycmd_gvar: } } + \__stycmd_gconcat:nN + { + \object_member_adr:nnn + { + \object_address:nn + { stycmd } + { group - #1 } + } + { commands } + { seq } + } \g__stycmd_tmpb_seq } -\NewDocumentCommand \styEndGroup {} + +\cs_generate_variant:Nn \__stycmd_addgroup:nn { fn } + +\NewDocumentCommand{\AddCMDToGroup}{m m} { - \str_clear:N \l__stycmd_group_str + \__stycmd_addgroup:fn { \tl_trim_spaces:n{ #1 } } { #2 } } -\msg_new:nnn { stycmd } { fnotclosed } { Format~not~closed } -\NewDocumentCommand \styBeginStyle { m } +\NewDocumentCommand{\SetGroupStyle}{m m} { - \str_if_empty:NF \l__stycmd_format_str + \seq_map_inline:cn { - \msg_error:nn { stycmd } { fnotclosed } + \object_member_adr:nnn + { + \object_address:nn + { stycmd } + { group - #1 } + } + { commands } + { seq } + } + { + \__stycmd_setdef_style:nn{ ##1 }{ #2 } } - \str_set:Nx \l__stycmd_format_str {#1} } -\NewDocumentCommand \styEndStyle {} + +\msg_new:nnnn{ styledcmd }{ stydep }{ Old-fashioned~groups~for~styled~commands~are~deprecated } { - \str_clear:N \l__stycmd_format_str + From~version~2.0~of~styledcmd~you~should~use~new~group~commands~instea~of~old~ones,~see~official~documentation~on~CTAN. } -\NewDocumentCommand \newGstyledcmd { m o +m } + +\str_new:N \g__stycmd_act_group_str +\str_new:N \g__stycmd_act_style_str + +\NewDocumentCommand{\styBeginGroup}{ m } { - \IfNoValueTF {#2} - { - \newstyledcmd {#1} { \l__stycmd_format_str } {#3} - } - { - \newstyledcmd {#1} { \l__stycmd_format_str } [#2] {#3} - } - \__stycmd_push_g:NV {#1} \l__stycmd_group_str + \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 \NewGDocStyledCMD { m m +m } + +\NewDocumentCommand{\styBeginStyle}{ m } { - \NewDocStyledCMD {#1} { \l__stycmd_format_str } {#2} {#3} + \msg_warning:nn{ styledcmd }{ stydep } + \str_gset:Nn \g__stycmd_act_style_str{ #1 } + } - \__stycmd_push_g:NV {#1} \l__stycmd_group_str +\NewDocumentCommand{\styEndStyle}{} + { + \msg_warning:nn{ styledcmd }{ stydep } + \str_gset:Nn \g__stycmd_act_style_str{} } -\NewDocumentCommand \setGroupStyle { m m } + +\cs_generate_variant:Nn \__stycmd_addgroup:nn { Vn } + +\NewDocumentCommand{\newGstyledcmd}{m o m} { - \str_set:Nx \l__stycmd_group_str {#1} - \str_set:Nx \l__stycmd_format_str {#2} - \seq_map_inline:cn { \__stycmd_gvar: } + \msg_warning:nn{ styledcmd }{ stydep } + \__stycmd_addgroup:Vn \g__stycmd_act_group_str { #1 } + \IfNoValueTF{ #2 } { - \setGlobalStyle {##1} { \l__stycmd_format_str } + \exp_args:NNV \newstyledcmd #1 \g__stycmd_act_style_str { #3 } } - \str_clear:N \l__stycmd_format_str - \str_clear:N \l__stycmd_group_str + { + \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'. -- cgit v1.2.3