From 47e633fefc395ee291c13e3ca33d94439e15c470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 21 Jan 2022 13:03:34 +0100 Subject: [PATCH] wrap new group methods into key methods. fix some bugs --- doc/environments/groupthm/groupthm.dtx | 124 +++++++++---------------- doc/environments/groupthm/groupthm.sty | 104 ++++++++++----------- 2 files changed, 93 insertions(+), 135 deletions(-) diff --git a/doc/environments/groupthm/groupthm.dtx b/doc/environments/groupthm/groupthm.dtx index 6f44a10..52ebcac 100644 --- a/doc/environments/groupthm/groupthm.dtx +++ b/doc/environments/groupthm/groupthm.dtx @@ -712,13 +712,13 @@ % % \begin{function} % { -% \groupthm_new_group_from_keys:nn, -% \groupthm_renew_group_from_keys:nn, -% \groupthm_provide_theorem_group_from_keys:nn, -% \groupthm_declare_theorem_group_from_keys:nn +% \groupthm_new_group:nn, +% \groupthm_renew_group:nn, +% \groupthm_provide_theorem_group:nn, +% \groupthm_declare_theorem_group:nn % } % \begin{syntax} -% \cs{groupthm_new_group_from_keys:nn}\marg{keys}\marg{theorem group} +% \cs{groupthm_new_group:nn}\marg{keys}\marg{theorem group} % \end{syntax} % % \LaTeX3 versions of \cs{NewTheoremGroup}, \cs{RenewTheoremGroup}, @@ -745,11 +745,11 @@ % \end{syntax} % % Non-keyval versions of -% \cs{groupthm_new_group_from_keys:nn}, -% \cs{groupthm_renew_group_from_keys:nn}, -% \cs{groupthm_provide_theorem_group_from_keys:nn} +% \cs{groupthm_new_group:nn}, +% \cs{groupthm_renew_group:nn}, +% \cs{groupthm_provide_theorem_group:nn} % and -% \cs{groupthm_declare_theorem_group_from_keys:nn} +% \cs{groupthm_declare_theorem_group:nn} % % These take the individual values of the keyval keys directly, in the order % indicated by the syntax specification. @@ -1441,6 +1441,7 @@ % \begin{macrocode} \cs_new:Npn \@@_undefine_group:n #1 { + \tl_log:n { Undefining ~ theorem ~ group ~ '#1' } \cs_undefine:c { @@_use_group_#1: } % \end{macrocode} % @@ -1545,7 +1546,8 @@ \cs_if_exist_p:N #4 } { - \msg_error:nnnn { groupthm } { wrong ~ definition } + \tl_log:n { Wrong ~ 'new' ~ definition ~ of ~ #2 ~ '#3' ~ detected. } + \msg_error:nnnnn { groupthm } { wrong ~ definition } { #2 } { #3 } { already } } % \end{macrocode} @@ -1558,7 +1560,8 @@ ! \cs_if_exist_p:N #4 } { - \msg_error:nnnn { groupthm } { wrong ~ definition } + \tl_log:n { Wrong ~ 'renew' ~ definition ~ of ~ #2 ~ '#3' ~ detected. } + \msg_error:nnnnn { groupthm } { wrong ~ definition } { #2 } { #3 } { not } } % \end{macrocode} @@ -1573,14 +1576,19 @@ \cs_if_exist_p:N #4 } { - #5 { #1 } + \tl_log:n { Removing ~ definition ~ of ~ #2 ~ '#3'. } + #5 { #3 } } % \end{macrocode} % Finally, define new version if not already defined % (this check is necessary for the provide version.) % \begin{macrocode} - \cs_if_exist:NF #4 + \cs_if_exist:NTF #4 { + \tl_log:n { Providing ~ #2 ~ '#3' ~ skipped: ~ '#3' ~ already ~ defined. } + } + { + \tl_log:n { Defining ~ #2 ~ '#3'. } #6 #7 } } @@ -1674,16 +1682,31 @@ % With the \cs{@@_set_normalized_keys:nnn} macro at hand, % it is also easy to provide key-value interfaces for these commands: % -% \begin{macro}{\groupthm_new_group_from_keys:nn} +% \begin{macro}{\groupthm_new_group:nn} % \begin{syntax} -% \cs{groupthm_new_group_from_keys:nn}\marg{keys}\marg{theorem group} +% \cs{groupthm_new_group:nn}\marg{keys}\marg{theorem group} % \end{syntax} % % \begin{macrocode} -\cs_new:Npn \groupthm_new_group_from_keys:nn #1#2 +\cs_new:Npn \@@_wrap_multiple:nnn #1 #2 #3 + { + \cs_set:Npn \@@_map_aux:n ##1 + { + \cs_new:cn { #2 } + { + #3 + } + } + \clist_map_function:nN { #1 } \@@_map_aux:n + } + +\@@_wrap_multiple:nnn +{ new, renew, provide, declare } +{ groupthm_#1_group:nn } { - \@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_new_group:nVVVV { #2 } + \@@_set_normalized_keys:nnn { ##1 } { theoremgroup } { ##2 } + \use:c { groupthm_#1_group:nVVVV } + { ##2 } \l_@@_prefix_tl \l_@@_suffix_tl \l_@@_mapname_clist @@ -1693,63 +1716,6 @@ % \end{macro} % % -% -% \begin{macro}{\groupthm_renew_group_from_keys:nn} -% \begin{syntax} -% \cs{groupthm_renew_group_from_keys:nn}\marg{keys}\marg{theorem group} -% \end{syntax} -% -% \begin{macrocode} -\cs_new:Npn \groupthm_renew_group_from_keys:nn #1#2 -{ - \@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_renew_group:nVVVV { #2 } - \l_@@_prefix_tl - \l_@@_suffix_tl - \l_@@_mapname_clist - \l_@@_thmtools_clist -} -% \end{macrocode} -% \end{macro} -% -% -% -% \begin{macro}{\groupthm_provide_theorem_group_from_keys:nn} -% \begin{syntax} -% \cs{groupthm_provide_theorem_group_from_keys:nn}\marg{keys}\marg{theorem group} -% \end{syntax} -% -% \begin{macrocode} -\cs_new:Npn \groupthm_provide_theorem_group_from_keys:nn #1#2 -{ - \@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_provide_group:nVVVV { #2 } - \l_@@_prefix_tl - \l_@@_suffix_tl - \l_@@_mapname_clist - \l_@@_thmtools_clist -} -% \end{macrocode} -% \end{macro} -% -% -% -% \begin{macro}{\groupthm_declare_theorem_group_from_keys:nn} -% \begin{syntax} -% \cs{groupthm_declare_theorem_group_from_keys:nn}\marg{keys}\marg{theorem group} -% \end{syntax} -% -% \begin{macrocode} -\cs_new:Npn \groupthm_declare_theorem_group_from_keys:nn #1#2 -{ - \@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_declare_group:nVVVV { #2 } - \l_@@_prefix_tl - \l_@@_suffix_tl - \l_@@_mapname_clist - \l_@@_thmtools_clist -} -% \end{macrocode} % \end{macro} % % @@ -1761,7 +1727,7 @@ % \begin{macrocode} \NewDocumentCommand{\NewTheoremGroup}{ O{} m } { - \groupthm_new_group_from_keys:nn { #1 } { #2 } + \groupthm_new_group:nn { #1 } { #2 } } % \end{macrocode} % \end{macro} @@ -1773,7 +1739,7 @@ % \begin{macrocode} \NewDocumentCommand{\RenewTheoremGroup}{ O{} m } { - \groupthm_renew_group_from_keys:nn { #1 } { #2 } + \groupthm_renew_group:nn { #1 } { #2 } } % \end{macrocode} % \end{macro} @@ -1785,7 +1751,7 @@ % \begin{macrocode} \NewDocumentCommand{\ProvideTheoremGroup}{ O{} m } { - \groupthm_provide_theorem_group_from_keys:nn { #1 } { #2 } + \groupthm_provide_group:nn { #1 } { #2 } } % \end{macrocode} % \end{macro} @@ -1797,7 +1763,7 @@ % \begin{macrocode} \NewDocumentCommand{\DeclareTheoremGroup}{ O{} m } { - \groupthm_declare_theorem_group_from_keys:nn { #1 } { #2 } + \groupthm_declare_group:nn { #1 } { #2 } } % \end{macrocode} % \end{macro} diff --git a/doc/environments/groupthm/groupthm.sty b/doc/environments/groupthm/groupthm.sty index 16322ed..ed60126 100644 --- a/doc/environments/groupthm/groupthm.sty +++ b/doc/environments/groupthm/groupthm.sty @@ -187,6 +187,7 @@ } \cs_new:Npn \__groupthm_undefine_group:n #1 { + \tl_log:n { Undefining ~ theorem ~ group ~ '#1' } \cs_undefine:c { __groupthm_use_group_#1: } \hook_gremove_code:nn { __groupthm/prefix } { #1 } \hook_gremove_code:nn { __groupthm/suffix } { #1 } @@ -220,7 +221,6 @@ { #1 } \__groupthm_remove_from_theorem_group_ordering:n { #1 } } - \cs_new:Npn \__groupthm_define:nnnNNNn #1 #2 #3 #4 #5 #6 #7 { \bool_if:nT @@ -230,7 +230,8 @@ \cs_if_exist_p:N #4 } { - \msg_error:nnnn { groupthm } { wrong ~ definition } + \tl_log:n { Wrong ~ 'new' ~ definition ~ of ~ #2 ~ '#3' ~ detected. } + \msg_error:nnnnn { groupthm } { wrong ~ definition } { #2 } { #3 } { already } } \bool_if:nT @@ -240,7 +241,8 @@ ! \cs_if_exist_p:N #4 } { - \msg_error:nnnn { groupthm } { wrong ~ definition } + \tl_log:n { Wrong ~ 'renew' ~ definition ~ of ~ #2 ~ '#3' ~ detected. } + \msg_error:nnnnn { groupthm } { wrong ~ definition } { #2 } { #3 } { not } } \bool_if:nT @@ -252,15 +254,20 @@ \cs_if_exist_p:N #4 } { - #5 { #1 } + \tl_log:n { Removing ~ definition ~ of ~ #2 ~ '#3'. } + #5 { #3 } } - \cs_if_exist:NF #4 + \cs_if_exist:NTF #4 { + \tl_log:n { Providing ~ #2 ~ '#3' ~ skipped: ~ '#3' ~ already ~ defined. } + } + { + \tl_log:n { Defining ~ #2 ~ '#3'. } #6 #7 } } \cs_generate_variant:Nn \__groupthm_define:nnnNNNn { n n n c N N n } -\cs_new:Npn \__groupthm_define_multiple_aux:nnnNNnn #1 #2 #3 #4 #5 #6 #7 +\cs_new:Npn \__groupthm_define_multiple:nnnNNnn #1 #2 #3 #4 #5 #6 #7 { \cs_set:Npn \__groupthm_map_aux:n ##1 { @@ -278,7 +285,7 @@ } \clist_map_function:nN { #1 } \__groupthm_map_aux:n } -\__groupthm_define_multiple_aux:nnnNNnn +\__groupthm_define_multiple:nnnNNnn { new, renew, provide, declare } { theorem group } { __groupthm_use_group_##1: } @@ -290,37 +297,25 @@ \cs_generate_variant:Nn \groupthm_renew_group:nnnnn { n V V V V } \cs_generate_variant:Nn \groupthm_provide_group:nnnnn { n V V V V } \cs_generate_variant:Nn \groupthm_declare_group:nnnnn { n V V V V } -\cs_new:Npn \groupthm_new_group_from_keys:nn #1#2 +\cs_new:Npn \__groupthm_wrap_multiple:nnn #1 #2 #3 + { + \cs_set:Npn \__groupthm_map_aux:n ##1 + { + \cs_new:cn { #2 } + { + #3 + } + } + \clist_map_function:nN { #1 } \__groupthm_map_aux:n + } + +\__groupthm_wrap_multiple:nnn +{ new, renew, provide, declare } +{ groupthm_#1_group:nn } { - \__groupthm_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_new_group:nVVVV { #2 } - \l__groupthm_prefix_tl - \l__groupthm_suffix_tl - \l__groupthm_mapname_clist - \l__groupthm_thmtools_clist -} -\cs_new:Npn \groupthm_renew_group_from_keys:nn #1#2 -{ - \__groupthm_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_renew_group:nVVVV { #2 } - \l__groupthm_prefix_tl - \l__groupthm_suffix_tl - \l__groupthm_mapname_clist - \l__groupthm_thmtools_clist -} -\cs_new:Npn \groupthm_provide_theorem_group_from_keys:nn #1#2 -{ - \__groupthm_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_provide_group:nVVVV { #2 } - \l__groupthm_prefix_tl - \l__groupthm_suffix_tl - \l__groupthm_mapname_clist - \l__groupthm_thmtools_clist -} -\cs_new:Npn \groupthm_declare_theorem_group_from_keys:nn #1#2 -{ - \__groupthm_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_declare_group:nVVVV { #2 } + \__groupthm_set_normalized_keys:nnn { ##1 } { theoremgroup } { ##2 } + \use:c { groupthm_#1_group:nVVVV } + { ##2 } \l__groupthm_prefix_tl \l__groupthm_suffix_tl \l__groupthm_mapname_clist @@ -328,41 +323,38 @@ } \NewDocumentCommand{\NewTheoremGroup}{ O{} m } { - \groupthm_new_group_from_keys:nn { #1 } { #2 } + \groupthm_new_group:nn { #1 } { #2 } } \NewDocumentCommand{\RenewTheoremGroup}{ O{} m } { - \groupthm_renew_group_from_keys:nn { #1 } { #2 } + \groupthm_renew_group:nn { #1 } { #2 } } \NewDocumentCommand{\ProvideTheoremGroup}{ O{} m } { - \groupthm_provide_theorem_group_from_keys:nn { #1 } { #2 } + \groupthm_provide_group:nn { #1 } { #2 } } \NewDocumentCommand{\DeclareTheoremGroup}{ O{} m } { - \groupthm_declare_theorem_group_from_keys:nn { #1 } { #2 } + \groupthm_declare_group:nn { #1 } { #2 } } \cs_new:Npn \groupthm_declare_theorem_group_rule:nnnn #1 #2 #3 #4 { \str_set:Nx \l_tmpa_str { \tl_trim_spaces:n { #3 } } - \str_if_eq:VnT \l_tmpa_str { higher } - { - \str_set:Nn \l_tmpa_tl { after } - } - + { + \str_set:Nn \l_tmpa_tl { after } + } \str_if_eq:VnT \l_tmpa_str { lower } - { - \str_set:Nn \l_tmpa_tl { before } - } - + { + \str_set:Nn \l_tmpa_tl { before } + } \str_if_eq:nnTF { #1 } { ?? } - { - \hook_gset_rule:nnVn {??} {#2} \l_tmpa_tl {#4} - } - { - \hook_gset_rule:nnVn { __groupthm / #1 } {#2} \l_tmpa_tl {#4} - } + { + \hook_gset_rule:nnVn {??} {#2} \l_tmpa_tl {#4} + } + { + \hook_gset_rule:nnVn { __groupthm / #1 } {#2} \l_tmpa_tl {#4} + } } \NewDocumentCommand { \DeclareTheoremGroupRule } { O{??} m m m }