simplify some function names

This commit is contained in:
Maximilian Keßler 2022-01-21 12:25:24 +01:00
parent 05bc3d9c60
commit 710915271e
2 changed files with 237 additions and 159 deletions

View file

@ -732,12 +732,12 @@
% { % {
% \groupthm_new_group:nnnnn, % \groupthm_new_group:nnnnn,
% \groupthm_renew_group:nnnnn, % \groupthm_renew_group:nnnnn,
% \groupthm_provide_theorem_group:nnnnn, % \groupthm_provide_group:nnnnn,
% \groupthm_declare_theorem_group:nnnnn, % \groupthm_declare_group:nnnnn,
% \groupthm_new_group:nVVVV, % \groupthm_new_group:nVVVV,
% \groupthm_renew_group:nVVVV, % \groupthm_renew_group:nVVVV,
% \groupthm_provide_theorem_group:nVVVV, % \groupthm_provide_group:nVVVV,
% \groupthm_declare_theorem_group:nVVVV % \groupthm_declare_group:nVVVV
% } % }
% \begin{syntax} % \begin{syntax}
% \cs{groupthm_new_group:nnnnn}\marg{theorem group}\marg{prefix tl} % \cs{groupthm_new_group:nnnnn}\marg{theorem group}\marg{prefix tl}
@ -1497,76 +1497,160 @@
% \end{macrocode} % \end{macrocode}
% \end{macro} % \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 % \texttt{new}, \texttt{renew}, \texttt{provide} and \texttt{declare} variants
% of the theorem group macro: % 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} % \begin{macrocode}
\cs_new:Npn \@@_define_aux:nnnNNNn #1 #2 #3 #4 #5 #6 #7 \@@_define_multiple:nnnNNnn
{
\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
{ new, renew, provide, declare } { new, renew, provide, declare }
{ theorem group } { theorem group }
{ @@_use_group_##1: } { @@_use_group_##1: }
@ -1576,18 +1660,16 @@
{ { ##1 } { ##2 } { ##3 } { ##4 } { ##5 } } { { ##1 } { ##2 } { ##3 } { ##4 } { ##5 } }
% \end{macrocode} % \end{macrocode}
% %
% Finally, generate some extra variant. % Finally, generate some extra variants
% %
% \begin{macrocode} % \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{macrocode}
% \end{macro} % \end{macro}
% %
% \begin{macrocode}
% \end{macrocode}
%
%
% %
% With the \cs{@@_set_normalized_keys:nnn} macro at hand, % With the \cs{@@_set_normalized_keys:nnn} macro at hand,
% it is also easy to provide key-value interfaces for these commands: % it is also easy to provide key-value interfaces for these commands:
@ -1641,7 +1723,7 @@
\cs_new:Npn \groupthm_provide_theorem_group_from_keys:nn #1#2 \cs_new:Npn \groupthm_provide_theorem_group_from_keys:nn #1#2
{ {
\@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } \@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 }
\groupthm_provide_theorem_group:nVVVV { #2 } \groupthm_provide_group:nVVVV { #2 }
\l_@@_prefix_tl \l_@@_prefix_tl
\l_@@_suffix_tl \l_@@_suffix_tl
\l_@@_mapname_clist \l_@@_mapname_clist
@ -1661,7 +1743,7 @@
\cs_new:Npn \groupthm_declare_theorem_group_from_keys:nn #1#2 \cs_new:Npn \groupthm_declare_theorem_group_from_keys:nn #1#2
{ {
\@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } \@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 }
\groupthm_declare_theorem_group:nVVVV { #2 } \groupthm_declare_group:nVVVV { #2 }
\l_@@_prefix_tl \l_@@_prefix_tl
\l_@@_suffix_tl \l_@@_suffix_tl
\l_@@_mapname_clist \l_@@_mapname_clist
@ -1738,24 +1820,21 @@
\cs_new:Npn \groupthm_declare_theorem_group_rule:nnnn #1 #2 #3 #4 \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_set:Nx \l_tmpa_str { \tl_trim_spaces:n { #3 } }
\str_if_eq:VnT \l_tmpa_str { higher } \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_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 } { ?? } \str_if_eq:nnTF { #1 } { ?? }
{ {
\hook_gset_rule:nnVn {??} {#2} \l_tmpa_tl {#4} \hook_gset_rule:nnVn {??} {#2} \l_tmpa_tl {#4}
} }
{ {
\hook_gset_rule:nnVn { @@ / #1 } {#2} \l_tmpa_tl {#4} \hook_gset_rule:nnVn { @@ / #1 } {#2} \l_tmpa_tl {#4}
} }
} }
% \end{macrocode} % \end{macrocode}
% \end{macro} % \end{macro}
@ -1836,9 +1915,9 @@
% \subsection{Grouped Theorems} % \subsection{Grouped Theorems}
% %
% %
% \begin{macro}{\@@_use_theorem_group:n} % \begin{macro}{\@@_use_group:n}
% \begin{syntax} % \begin{syntax}
% \cs{@@_use_theorem_group:n}\mymeta{theorem group} % \cs{@@_use_group:n}\mymeta{theorem group}
% \end{syntax} % \end{syntax}
% %
% Uses this theorem group, i.e.~applies its definition by writing % 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. % A proper error message is emitted if the group is not defined.
% %
% \begin{macrocode} % \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: } \cs_if_exist_use:cF { @@_use_group_#1: }
{ {
@ -1910,7 +1989,7 @@
% \end{macrocode} % \end{macrocode}
% Now, retrieve the group properties, by writing these into the hooks % Now, retrieve the group properties, by writing these into the hooks
% \begin{macrocode} % \begin{macrocode}
\clist_map_function:nN { #2 } \@@_use_theorem_group:n \clist_map_function:nN { #2 } \@@_use_group:n
% \end{macrocode} % \end{macrocode}
% Execute the hooks, so that local variables will get modified according to the groups % Execute the hooks, so that local variables will get modified according to the groups
% and in the order that were specified for the hooks. % and in the order that were specified for the hooks.

View file

@ -220,68 +220,65 @@
{ #1 } { #1 }
\__groupthm_remove_from_theorem_group_ordering:n { #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 \bool_if:nT
{ {
\str_if_eq_p:nn { #1 } { renew } \str_if_eq_p:nn { #1 } { new }
&& &&
! \cs_if_exist_p:N #4 \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 } \msg_error:nnnn { groupthm } { wrong ~ definition }
{ #2 } { #3 } { not } { #2 } { #3 } { not }
} }
\bool_if:nT \bool_if:nT
{ {
( (
\str_if_eq_p:nn { #1 } { declare } || \str_if_eq_p:nn { #1 } { declare } ||
\str_if_eq_p:nn { #1 } { renew } \str_if_eq_p:nn { #1 } { renew }
) && ) &&
\cs_if_exist_p:N #4 \cs_if_exist_p:N #4
} }
{ {
#5 { #1 } #5 { #1 }
} }
\cs_if_exist:NF #4
#6 #7 {
} #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
}
}
} }
\clist_map_function:nN { #1 } \__groupthm_map_aux:n \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
{
\__groupthm_define_list_aux:nnnNNnn \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 } { new, renew, provide, declare }
{ theorem group } { theorem group }
{ __groupthm_use_group_##1: } { __groupthm_use_group_##1: }
@ -289,8 +286,10 @@
\__groupthm_define_group:nnnnn \__groupthm_define_group:nnnnn
{ groupthm_#1_group:nnnnn } { groupthm_#1_group:nnnnn }
{ { ##1 } { ##2 } { ##3 } { ##4 } { ##5 } } { { ##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 \cs_new:Npn \groupthm_new_group_from_keys:nn #1#2
{ {
\__groupthm_set_normalized_keys:nnn { #1 } { theoremgroup } { #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 \cs_new:Npn \groupthm_provide_theorem_group_from_keys:nn #1#2
{ {
\__groupthm_set_normalized_keys:nnn { #1 } { theoremgroup } { #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_prefix_tl
\l__groupthm_suffix_tl \l__groupthm_suffix_tl
\l__groupthm_mapname_clist \l__groupthm_mapname_clist
@ -321,7 +320,7 @@
\cs_new:Npn \groupthm_declare_theorem_group_from_keys:nn #1#2 \cs_new:Npn \groupthm_declare_theorem_group_from_keys:nn #1#2
{ {
\__groupthm_set_normalized_keys:nnn { #1 } { theoremgroup } { #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_prefix_tl
\l__groupthm_suffix_tl \l__groupthm_suffix_tl
\l__groupthm_mapname_clist \l__groupthm_mapname_clist
@ -406,7 +405,7 @@
\__powerset_clist_foreach_aux:Nn #1 {#2} \__powerset_clist_foreach_aux:Nn #1 {#2}
\clist_set_eq:NN #1 \l__powerset_copied_clist \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: } \cs_if_exist_use:cF { __groupthm_use_group_#1: }
{ {
@ -431,7 +430,7 @@
\hook_gremove_code:nn { __groupthm/suffix }{*} \hook_gremove_code:nn { __groupthm/suffix }{*}
\hook_gremove_code:nn { __groupthm/mapname }{*} \hook_gremove_code:nn { __groupthm/mapname }{*}
\hook_gremove_code:nn { __groupthm/thmtools }{*} \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/prefix }
\hook_use:n { __groupthm/suffix } \hook_use:n { __groupthm/suffix }
\hook_use:n { __groupthm/mapname } \hook_use:n { __groupthm/mapname }