From 710915271ef3ede68eaa4a9ee07714aa5c7cfc89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 21 Jan 2022 12:25:24 +0100 Subject: [PATCH] simplify some function names --- doc/environments/groupthm/groupthm.dtx | 273 ++++++++++++++++--------- doc/environments/groupthm/groupthm.sty | 123 ++++++----- 2 files changed, 237 insertions(+), 159 deletions(-) diff --git a/doc/environments/groupthm/groupthm.dtx b/doc/environments/groupthm/groupthm.dtx index e83ebb1..6f44a10 100644 --- a/doc/environments/groupthm/groupthm.dtx +++ b/doc/environments/groupthm/groupthm.dtx @@ -732,12 +732,12 @@ % { % \groupthm_new_group:nnnnn, % \groupthm_renew_group:nnnnn, -% \groupthm_provide_theorem_group:nnnnn, -% \groupthm_declare_theorem_group:nnnnn, +% \groupthm_provide_group:nnnnn, +% \groupthm_declare_group:nnnnn, % \groupthm_new_group:nVVVV, % \groupthm_renew_group:nVVVV, -% \groupthm_provide_theorem_group:nVVVV, -% \groupthm_declare_theorem_group:nVVVV +% \groupthm_provide_group:nVVVV, +% \groupthm_declare_group:nVVVV % } % \begin{syntax} % \cs{groupthm_new_group:nnnnn}\marg{theorem group}\marg{prefix tl} @@ -1497,76 +1497,160 @@ % \end{macrocode} % \end{macro} % -% With these two helper functions, we can now easily implement the +% \begin{macro}{\@@_define:nnnNNNn, \@@_define:nnncNNn} +% \begin{syntax} +% \cs{@@_define:nnnNNNn}\marg{declarator}\marg{type}\marg{instance}\marg{existence cs}\marg{undefine function}\marg{define function}\marg{definition args} +% \end{syntax} +% +% A general definition macro that is used to implement the \texttt{new}, +% \texttt{renew}, \texttt{provide} and \texttt{declare} definition variants of \meta{type}s. +% For the purpose of this package, \meta{type} will be one of +% \enquote{theorem group}, \enquote{grouped theorem}, \enquote {theorem family} +% and\enquote{theorem family options}, but could technically be anything. +% +% The \meta{instance} is the actual thing that will be defined by this function. +% The \meta{declarator} is one of \texttt{new}, \texttt{renew}, +% \texttt{provide} and \texttt{declare} and indicates the definition behavior: +% \texttt{new} only defines +% if \meta{instance} does not yet exist and throws an error otherwise, +% \texttt{renew} only (re)defines +% if \meta{instance} does exist yet and throws an error otherwise, +% \texttt{provides} defines if \meta{instance} does not exist yet, +% but does nothing otherwise +% and +% \texttt{declare} defines \meta{instance} in any case, +% possibly by overwriting the old definition. +% +% The \meta{existence cs} is the one whose existence will be checked to +% determine whether the \meta{instance} already exists. +% +% The \meta{undefine function} will be called in case \meta{instance} has to be undefined. +% It is assumed to have argument type \texttt{n} and will be given the \meta{instance} +% as an argument in this case. +% +% The \meta{define function} will be called with the arguments +% given as \meta{definition args} in case no error occurs and \meta{instance} should be defined. +% +% +% \begin{macrocode} +\cs_new:Npn \@@_define:nnnNNNn #1 #2 #3 #4 #5 #6 #7 + { +% \end{macrocode} +% We first check for wrong usage of \texttt{new} +% \begin{macrocode} + \bool_if:nT + { + \str_if_eq_p:nn { #1 } { new } + && + \cs_if_exist_p:N #4 + } + { + \msg_error:nnnn { groupthm } { wrong ~ definition } + { #2 } { #3 } { already } + } +% \end{macrocode} +% Then check for wrong usage of \texttt{renew} +% \begin{macrocode} + \bool_if:nT + { + \str_if_eq_p:nn { #1 } { renew } + && + ! \cs_if_exist_p:N #4 + } + { + \msg_error:nnnn { groupthm } { wrong ~ definition } + { #2 } { #3 } { not } + } +% \end{macrocode} +% Now, remove the old definition if necessary +% \begin{macrocode} + \bool_if:nT + { + ( + \str_if_eq_p:nn { #1 } { declare } || + \str_if_eq_p:nn { #1 } { renew } + ) && + \cs_if_exist_p:N #4 + } + { + #5 { #1 } + } +% \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 + { + #6 #7 + } + } +\cs_generate_variant:Nn \@@_define:nnnNNNn { n n n c N N n } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_define_multiple:nnnNNnn} +% \begin{syntax} +% \cs{@@_define_multiple:nnnNNnn} \marg{declarator list} \marg{type} \marg{existence cs} +% \marg{undefine function}\marg{define function}\marg{function name}\marg{definition args} +% \end{syntax} +% +% This is a wrapper around the \cs{@@_define:nnnNNNn} macro. +% It is intended to wrap the multiple variants of it into a family of macros indicating +% the variant in their name, e.g.~to define \cs{groupthm_new_group}, \cs{groupthm_renew_group}, +% \cs{groupthm_provide_group} and \cs{groupthm_declare_group} in the same way except for their +% indicated declaration behavior, to avoid repetition when defining these. +% +% The first five arguments work the same way as in \cs{@@_define:nnnNNn}, +% except that \meta{declarator list} is now a comma separated list. +% In \meta{existence cs}, \texttt{\#\#1} is used to denote the \meta{instance} +% that has currently been called to define. +% +% The \meta{function name} is expected to contain \texttt{\#1}, +% for which the current \meta{declarator} is inserted. +% These control sequences will then be defined. +% +% The \meta{definition args} denote the arguments passed to the \meta{define function} +% and may contain \texttt{\#\#1}, \texttt{\#\#2}, etc. for the arguments that the +% \meta{function name} received as arguments on expansion. +% +% +% \begin{macrocode} +\cs_new:Npn \@@_define_multiple:nnnNNnn #1 #2 #3 #4 #5 #6 #7 + { + \cs_set:Npn \@@_map_aux:n ##1 + { + \cs_new:cn { #6 } + { + \@@_define:nnncNNn + { ##1 } + { #2 } + { ####1 } + { #3 } + #4 + #5 + { #7 } + } + } + \clist_map_function:nN { #1 } \@@_map_aux:n + } +% \end{macrocode} +% \end{macro} +% +% +% With these helper functions, we can now easily generate the % \texttt{new}, \texttt{renew}, \texttt{provide} and \texttt{declare} variants % of the theorem group macro: % -% \begin{macro}{\groupthm_new_group:nnnnn, \groupthm_new_group:nVVVV} +% \begin{macro} +% { +% \groupthm_new_group:nnnnn, \groupthm_new_group:nVVVV, +% \groupthm_renew_group:nnnnn, \groupthm_renew_group:nVVVV, +% \groupthm_provide_group:nnnnn, \groupthm_provide_group:nVVVV, +% \groupthm_declare_group:nnnnn, \groupthm_declare_group:nVVVV +% } % % \begin{macrocode} -\cs_new:Npn \@@_define_aux:nnnNNNn #1 #2 #3 #4 #5 #6 #7 -{ - \bool_if:nT - { - \str_if_eq_p:nn { #1 } { new } - && - \cs_if_exist_p:N #4 - } - { - \msg_error:nnnn { groupthm } { wrong ~ definition } - { #2 } { #3 } { already } - } - - \bool_if:nT - { - \str_if_eq_p:nn { #1 } { renew } - && - ! \cs_if_exist_p:N #4 - } - { - \msg_error:nnnn { groupthm } { wrong ~ definition } - { #2 } { #3 } { not } - } - - \bool_if:nT - { - ( - \str_if_eq_p:nn { #1 } { declare } || - \str_if_eq_p:nn { #1 } { renew } - ) && - \cs_if_exist_p:N #4 - } - { - #5 { #1 } - } - - #6 #7 -} -\cs_generate_variant:Nn \@@_define_aux:nnnNNNn { n n n c N N n } - -\cs_new:Npn \@@_define_list_aux:nnnNNnn #1 #2 #3 #4 #5 #6 #7 -{ - \cs_set:Npn \@@_map_aux:n ##1 - { - \cs_new:cn { #6 } - { - \@@_define_aux:nnncNNn - { ##1 } - { #2 } - { ####1 } - { #3 } - #4 - #5 - { - #7 - } - } - } - \clist_map_function:nN { #1 } \@@_map_aux:n -} - - -\@@_define_list_aux:nnnNNnn +\@@_define_multiple:nnnNNnn { new, renew, provide, declare } { theorem group } { @@_use_group_##1: } @@ -1576,17 +1660,15 @@ { { ##1 } { ##2 } { ##3 } { ##4 } { ##5 } } % \end{macrocode} % -% Finally, generate some extra variant. +% Finally, generate some extra variants % % \begin{macrocode} -\cs_generate_variant:Nn \groupthm_new_group:nnnnn { n V V V V } +\cs_generate_variant:Nn \groupthm_new_group:nnnnn { n V V V V } +\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 } % \end{macrocode} % \end{macro} -% -% \begin{macrocode} - -% \end{macrocode} -% % % % With the \cs{@@_set_normalized_keys:nnn} macro at hand, @@ -1641,7 +1723,7 @@ \cs_new:Npn \groupthm_provide_theorem_group_from_keys:nn #1#2 { \@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_provide_theorem_group:nVVVV { #2 } + \groupthm_provide_group:nVVVV { #2 } \l_@@_prefix_tl \l_@@_suffix_tl \l_@@_mapname_clist @@ -1661,7 +1743,7 @@ \cs_new:Npn \groupthm_declare_theorem_group_from_keys:nn #1#2 { \@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_declare_theorem_group:nVVVV { #2 } + \groupthm_declare_group:nVVVV { #2 } \l_@@_prefix_tl \l_@@_suffix_tl \l_@@_mapname_clist @@ -1738,24 +1820,21 @@ \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 { @@ / #1 } {#2} \l_tmpa_tl {#4} - } + { + \hook_gset_rule:nnVn {??} {#2} \l_tmpa_tl {#4} + } + { + \hook_gset_rule:nnVn { @@ / #1 } {#2} \l_tmpa_tl {#4} + } } % \end{macrocode} % \end{macro} @@ -1836,9 +1915,9 @@ % \subsection{Grouped Theorems} % % -% \begin{macro}{\@@_use_theorem_group:n} +% \begin{macro}{\@@_use_group:n} % \begin{syntax} -% \cs{@@_use_theorem_group:n}\mymeta{theorem group} +% \cs{@@_use_group:n}\mymeta{theorem group} % \end{syntax} % % Uses this theorem group, i.e.~applies its definition by writing @@ -1846,7 +1925,7 @@ % A proper error message is emitted if the group is not defined. % % \begin{macrocode} -\cs_new:Npn \@@_use_theorem_group:n #1 +\cs_new:Npn \@@_use_group:n #1 { \cs_if_exist_use:cF { @@_use_group_#1: } { @@ -1910,7 +1989,7 @@ % \end{macrocode} % Now, retrieve the group properties, by writing these into the hooks % \begin{macrocode} - \clist_map_function:nN { #2 } \@@_use_theorem_group:n + \clist_map_function:nN { #2 } \@@_use_group:n % \end{macrocode} % Execute the hooks, so that local variables will get modified according to the groups % and in the order that were specified for the hooks. diff --git a/doc/environments/groupthm/groupthm.sty b/doc/environments/groupthm/groupthm.sty index 8484512..16322ed 100644 --- a/doc/environments/groupthm/groupthm.sty +++ b/doc/environments/groupthm/groupthm.sty @@ -220,68 +220,65 @@ { #1 } \__groupthm_remove_from_theorem_group_ordering:n { #1 } } -\cs_new:Npn \__groupthm_define_aux:nnnNNNn #1 #2 #3 #4 #5 #6 #7 -{ - \bool_if:nT - { - \str_if_eq_p:nn { #1 } { new } - && - \cs_if_exist_p:N #4 - } - { - \msg_error:nnnn { groupthm } { wrong ~ definition } - { #2 } { #3 } { already } - } +\cs_new:Npn \__groupthm_define:nnnNNNn #1 #2 #3 #4 #5 #6 #7 + { \bool_if:nT - { - \str_if_eq_p:nn { #1 } { renew } - && - ! \cs_if_exist_p:N #4 - } - { + { + \str_if_eq_p:nn { #1 } { new } + && + \cs_if_exist_p:N #4 + } + { + \msg_error:nnnn { groupthm } { wrong ~ definition } + { #2 } { #3 } { already } + } + \bool_if:nT + { + \str_if_eq_p:nn { #1 } { renew } + && + ! \cs_if_exist_p:N #4 + } + { \msg_error:nnnn { groupthm } { wrong ~ definition } { #2 } { #3 } { not } - } - + } \bool_if:nT - { - ( - \str_if_eq_p:nn { #1 } { declare } || - \str_if_eq_p:nn { #1 } { renew } - ) && - \cs_if_exist_p:N #4 - } - { - #5 { #1 } - } - - #6 #7 -} -\cs_generate_variant:Nn \__groupthm_define_aux:nnnNNNn { n n n c N N n } - -\cs_new:Npn \__groupthm_define_list_aux:nnnNNnn #1 #2 #3 #4 #5 #6 #7 -{ - \cs_set:Npn \__groupthm_map_aux:n ##1 - { - \cs_new:cn { #6 } - { - \__groupthm_define_aux:nnncNNn - { ##1 } - { #2 } - { ####1 } - { #3 } - #4 - #5 - { - #7 - } - } + { + ( + \str_if_eq_p:nn { #1 } { declare } || + \str_if_eq_p:nn { #1 } { renew } + ) && + \cs_if_exist_p:N #4 + } + { + #5 { #1 } + } + \cs_if_exist:NF #4 + { + #6 #7 + } } - \clist_map_function:nN { #1 } \__groupthm_map_aux:n -} - -\__groupthm_define_list_aux:nnnNNnn +\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_set:Npn \__groupthm_map_aux:n ##1 + { + \cs_new:cn { #6 } + { + \__groupthm_define:nnncNNn + { ##1 } + { #2 } + { ####1 } + { #3 } + #4 + #5 + { #7 } + } + } + \clist_map_function:nN { #1 } \__groupthm_map_aux:n + } +\__groupthm_define_multiple_aux:nnnNNnn { new, renew, provide, declare } { theorem group } { __groupthm_use_group_##1: } @@ -289,8 +286,10 @@ \__groupthm_define_group:nnnnn { groupthm_#1_group:nnnnn } { { ##1 } { ##2 } { ##3 } { ##4 } { ##5 } } -\cs_generate_variant:Nn \groupthm_new_group:nnnnn { n V V V V } - +\cs_generate_variant:Nn \groupthm_new_group:nnnnn { n V V V V } +\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 { \__groupthm_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } @@ -312,7 +311,7 @@ \cs_new:Npn \groupthm_provide_theorem_group_from_keys:nn #1#2 { \__groupthm_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_provide_theorem_group:nVVVV { #2 } + \groupthm_provide_group:nVVVV { #2 } \l__groupthm_prefix_tl \l__groupthm_suffix_tl \l__groupthm_mapname_clist @@ -321,7 +320,7 @@ \cs_new:Npn \groupthm_declare_theorem_group_from_keys:nn #1#2 { \__groupthm_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } - \groupthm_declare_theorem_group:nVVVV { #2 } + \groupthm_declare_group:nVVVV { #2 } \l__groupthm_prefix_tl \l__groupthm_suffix_tl \l__groupthm_mapname_clist @@ -406,7 +405,7 @@ \__powerset_clist_foreach_aux:Nn #1 {#2} \clist_set_eq:NN #1 \l__powerset_copied_clist } -\cs_new:Npn \__groupthm_use_theorem_group:n #1 +\cs_new:Npn \__groupthm_use_group:n #1 { \cs_if_exist_use:cF { __groupthm_use_group_#1: } { @@ -431,7 +430,7 @@ \hook_gremove_code:nn { __groupthm/suffix }{*} \hook_gremove_code:nn { __groupthm/mapname }{*} \hook_gremove_code:nn { __groupthm/thmtools }{*} - \clist_map_function:nN { #2 } \__groupthm_use_theorem_group:n + \clist_map_function:nN { #2 } \__groupthm_use_group:n \hook_use:n { __groupthm/prefix } \hook_use:n { __groupthm/suffix } \hook_use:n { __groupthm/mapname }