diff --git a/doc/environments/groupthm/groupthm.dtx b/doc/environments/groupthm/groupthm.dtx index f34bf9d..6230b19 100644 --- a/doc/environments/groupthm/groupthm.dtx +++ b/doc/environments/groupthm/groupthm.dtx @@ -61,6 +61,7 @@ % \begin{documentation} % % \tableofcontents +% \newpage % % A central thing in \LaTeX is the usage of \enquote{theorems}. % With \enquote{theorems} we actually mean \enquote{environments} that typically @@ -1413,15 +1414,21 @@ % \end{macrocode} % \end{macro} % - - - - - +% +% +% +% +% \subsection{Grouped Theorems} +% +% +% +% +% % \begin{macrocode} % % \end{macrocode} % % \end{implementation} % \end{documentation} -% \PrintIndex +% \newpage +% diff --git a/src/environments/groupthm.pysty3 b/src/environments/groupthm.pysty3 index b199a37..cdfe3c9 100644 --- a/src/environments/groupthm.pysty3 +++ b/src/environments/groupthm.pysty3 @@ -7,14 +7,14 @@ __HEADER__(Grouping theorems for easier customization.) \RequirePackage{thmtools} \RequirePackage{mkessler-powerset} -\hook_new:n { groupthm / prename } -\hook_new:n { groupthm / postname } -\hook_new:n { groupthm / mapname } -\hook_new:n { groupthm / thmtools } - -\hook_new:n { groupthm / groupsort } +\hook_new:n { @@/prename } +\hook_new:n { @@/postname } +\hook_new:n { @@/mapname } +\hook_new:n { @@/thmtools } +\hook_new:n { @@/groupsort } +%%TODO move this to fancythm \newcounter{indocument} \newcounter{insection}[section] \newcounter{insubsection}[subsection] @@ -25,12 +25,12 @@ __HEADER__(Grouping theorems for easier customization.) %%% LaTeX3 Wrappers around external commands -\cs_new:Nn \declaretheorem:nn +\cs_new:Nn \@@_declare_theorem:nn { \declaretheorem [ #2 ] { #1 } } -\cs_generate_variant:Nn \declaretheorem:nn { n V } +\cs_generate_variant:Nn \@@_declare_theorem:nn { n V } \cs_generate_variant:Nn \hook_gset_rule:nnnn { n n V n } @@ -48,22 +48,22 @@ __HEADER__(Grouping theorems for easier customization.) %%% Variables -\tl_new:N \l_groupthm_key_prename_tl -\tl_new:N \l_groupthm_key_name_tl -\tl_new:N \l_groupthm_key_postname_tl -\clist_new:N \l_groupthm_key_group_clist -\clist_new:N \l_groupthm_key_mapname_clist -\clist_new:N \l_groupthm_key_thmtools_clist +\tl_new:N \l_@@_key_prename_tl +\tl_new:N \l_@@_key_name_tl +\tl_new:N \l_@@_key_postname_tl +\clist_new:N \l_@@_key_group_clist +\clist_new:N \l_@@_key_mapname_clist +\clist_new:N \l_@@_key_thmtools_clist -\tl_new:N \l_groupthm_prename_tl -\tl_new:N \l_groupthm_name_tl -\tl_new:N \l_groupthm_postname_tl -\tl_new:N \l_groupthm_mapname_clist -\tl_new:N \l_groupthm_thmtools_clist +\tl_new:N \l_@@_prename_tl +\tl_new:N \l_@@_name_tl +\tl_new:N \l_@@_postname_tl +\tl_new:N \l_@@_mapname_clist +\tl_new:N \l_@@_thmtools_clist -\tl_new:N \l_groupthm_relation_tl +\tl_new:N \l_@@_relation_tl -\clist_new:N \l_groupthm_group_clist +\clist_new:N \l_@@_group_clist \clist_new:N \g_groupthm_defined_theorem_groups_clist @@ -71,22 +71,22 @@ __HEADER__(Grouping theorems for easier customization.) \keys_define:nn { groupthm } { - prename .tl_set:N = \l_groupthm_key_prename_tl, + prename .tl_set:N = \l_@@_key_prename_tl, prename .default:n = \c_empty_tl, prename .groups:n = { theoremgroup }, - name .tl_set:N = \l_groupthm_key_name_tl, + name .tl_set:N = \l_@@_key_name_tl, name .default:n = \c_novalue_tl, name .groups:n = { groupedtheorem, theoremvariants }, - postname .tl_set:N = \l_groupthm_key_postname_tl, + postname .tl_set:N = \l_@@_key_postname_tl, postname .default:n = \c_empty_tl, postname .groups:n = { theoremgroup }, - group .clist_set:N = \l_groupthm_key_group_clist, + group .clist_set:N = \l_@@_key_group_clist, group .default:n = {}, group .groups:n = { groupedtheorem, theoremvariants }, - mapname .clist_set:N = \l_groupthm_mapname_clist, + mapname .clist_set:N = \l_@@_mapname_clist, mapname .default:n = {}, mapname .groups:n = { theoremgroup }, - thmtools .clist_set:N = \l_groupthm_key_thmtools_clist, + thmtools .clist_set:N = \l_@@_key_thmtools_clist, thmtools .default:n = {}, thmtools .groups:n = { theoremgroup, groupedtheorem, theoremvariants }, unknown .code:n = \msg_error:nnn { groupthm } { unknown ~ group } { \l_keys_key_str } @@ -98,46 +98,101 @@ __HEADER__(Grouping theorems for easier customization.) { \cs_new:cpn { group_use_#1: } { - \hook_gput_code:nnn { groupthm / prename } { #1 } + \hook_gput_code:nnn { @@/prename } { #1 } { - \tl_put_left:Nx \l_groupthm_prename_tl { #2 } + \tl_put_left:Nx \l_@@_prename_tl { #2 } } - \hook_gput_code:nnn { groupthm / postname } { #1 } + \hook_gput_code:nnn { @@/postname } { #1 } { - \tl_put_right:Nx \l_groupthm_postname_tl { #3 } + \tl_put_right:Nx \l_@@_postname_tl { #3 } } - \hook_gput_code:nnn { groupthm / mapname } { #1 } + \hook_gput_code:nnn { @@/mapname } { #1 } { - \clist_put_right:Nn \l_groupthm_mapname_clist { #4 } + \clist_put_right:Nn \l_@@_mapname_clist { #4 } } - \hook_gput_code:nnn { groupthm / thmtools } { #1 } + \hook_gput_code:nnn { @@/thmtools } { #1 } { - \clist_put_right:Nn \l_groupthm_thmtools_clist { #5 } + \clist_put_right:Nn \l_@@_thmtools_clist { #5 } } } - - \cs_set:Npn \help:n ##1 { - \hook_gset_rule:nnnn { groupthm / groupsort } - { #1 } - { before } - { ##1 } - } - \clist_map_function:NN \g_groupthm_defined_theorem_groups_clist \help:n + \clist_gput_left:Nn \g_groupthm_defined_theorem_groups_clist { #1 } } \cs_generate_variant:Nn \new_theorem_group:nnnnn { n V V V V } + + +\cs_new:Npn \@@_undeclare_theorem_group_aux:n #1 +{ + \cs_undefine:c { @@_use_group_#1: } + \hook_gremove_code:nn { @@/prename } + \hook_gremove_code:nn { @@/postname } + \hook_gremove_code:nn { @@/mapname } + \hook_gremove_code:nn { @@/thmtools } + \clist_remove_all:Nn \g_@@_defined_theorem_groups_clist { #1 } + + \@@_hook_gset_rule_foreach:nNnn + { ?? } + \g_@@_defined_theorem_groups_clist { #1 } + { unrelated } + { #1 } + + \@@_hook_gset_rule_foreach:nNnn + { @@/prename } + \g_@@_defined_theorem_groups_clist { #1 } + { unrelated } + { #1 } + + \@@_hook_gset_rule_foreach:nNnn + { @@/postname } + \g_@@_defined_theorem_groups_clist { #1 } + { unrelated } + { #1 } + + \@@_hook_gset_rule_foreach:nNnn + { @@/mapname } + \g_@@_defined_theorem_groups_clist { #1 } + { unrelated } + { #1 } + + \@@_hook_gset_rule_foreach:nNnn + { @@/thmtools } + \g_@@_defined_theorem_groups_clist { #1 } + { unrelated } + { #1 } +} + + +% hook, list of labels, relation, label +\cs_new:Npn \@@_hook_gset_rule_foreach:nNnn #1 #2 #3 #4 + { + \cs_set:Npn \@@_map_aux:n + { + \hooks_gset_rule:nnnn { #1 } { ##1 } { #3 } { #4 } + } + \clist_map_function:NN #2 \@@_map_aux:n + } + + +\cs_new:Npn \@@_update_ordering:n #1 +{ + \@@_hook_gset_rule_foreach:nNnn + { @@/groupsort } + \g_@@_defined_theorem_groups_clist + { before } + { #1 } +} + \cs_new:Npn \new_theorem_group_by_keys:nn #1#2 { - \keys_set_groups:nnn { groupthm } { theoremgroup } { prename, postname, mapname, thmtools } - \keys_set_groups:nnn { groupthm } { theoremgroup } { #2 } + \@@_set_normalized_keys:nnn { #1 } { theoremgroup } { #2 } \new_theorem_group:nVVVV { #1 } - \l_groupthm_key_prename_tl - \l_groupthm_key_postname_tl - \l_groupthm_key_mapname_clist - \l_groupthm_key_thmtools_clist + \l_@@_prename_tl + \l_@@_postname_tl + \l_@@_mapname_clist + \l_@@_thmtools_clist } \NewDocumentCommand{\NewTheoremGroup}{ O{} m } @@ -146,6 +201,47 @@ __HEADER__(Grouping theorems for easier customization.) } +\cs_new:Npn \groupthm_new_theorem_group:nnnnn #1 #2 #3 #3 #5 + { + \cs_if_exist:cTF { @@_use_group_#1 } + { + \msg_error:nnnn { groupthm } { wrong ~ definition } + { group } { #1 } { already } + } + { + \@@_new_theorem_aux:nnnnn { #1 } { #2 } { #3 } { #4 } { #5 } + } + } + +\cs_new:Npn \groupthm_renew_theorem_group:nnnnn #1 #2 #3 #3 #5 + { + \cs_if_exist:cTF { @@_use_group_#1 } + { + \@@_undeclare_theorem_aux:nnnnn { #1 } + \@@_declare_theorem_aux:nnnnn { #1 } { #2 } { #3 } { #4 } { #5 } + } + { + \msg_error:nnnn { groupthm } { wrong ~ definition } + { group } { #1 } { not } + } + } + +\cs_new:Npn \groupthm_provide_theorem_group:nnnnn #1 #2 #3 #3 #5 + { + \cs_if_exist:cF { @@_use_group_#1 } + { + \@@_new_theorem_aux:nnnnn { #1 } { #2 } { #3 } { #4 } { #5 } + } + } + +\cs_new:Npn \groupthm_declare_theorem_group:nnnnn #1 #2 #3 #3 #5 + { + \cs_if_exist:cT { @@_use_group_#1 } + { + \@@_undeclare_theorem_aux:nnnnn { #1 } + } + \@@_declare_theorem_aux:nnnnn { #1 } { #2 } { #3 } { #4 } { #5 } + } %%% Grouped Theorems @@ -159,9 +255,9 @@ __HEADER__(Grouping theorems for easier customization.) \cs_new:Npn \map_use_on_name:n #1 { - \tl_set:Nx \l_groupthm_name_tl + \tl_set:Nx \l_@@_name_tl { - #1 { \tl_use:N \l_groupthm_name_tl } + #1 { \tl_use:N \l_@@_name_tl } } } @@ -170,64 +266,89 @@ __HEADER__(Grouping theorems for easier customization.) { - \tl_clear:N \l_groupthm_prename_tl - \tl_set:Nn \l_groupthm_name_tl { #3 } - \tl_clear:N \l_groupthm_postname_tl - \clist_clear:N \l_groupthm_mapname_clist - \clist_set:Nn \l_groupthm_thmtools_clist { #4 } + \tl_clear:N \l_@@_prename_tl + \tl_set:Nn \l_@@_name_tl { #3 } + \tl_clear:N \l_@@_postname_tl + \clist_clear:N \l_@@_mapname_clist + \clist_set:Nn \l_@@_thmtools_clist { #4 } - \hook_gremove_code:nn { groupthm / prename }{*} - \hook_gremove_code:nn { groupthm / postname }{*} - \hook_gremove_code:nn { groupthm / mapname }{*} - \hook_gremove_code:nn { groupthm / thmtools }{*} + \hook_gremove_code:nn { @@/prename }{*} + \hook_gremove_code:nn { @@/postname }{*} + \hook_gremove_code:nn { @@/mapname }{*} + \hook_gremove_code:nn { @@/thmtools }{*} \clist_map_function:nN { #2 } \group_use:n -% \ShowHook{ groupthm / postname } - \hook_use:n { groupthm / prename } - \hook_use:n { groupthm / postname } - \hook_use:n { groupthm / mapname } - \hook_use:n { groupthm / thmtools } +% \ShowHook{ @@/postname } + \hook_use:n { @@/prename } + \hook_use:n { @@/postname } + \hook_use:n { @@/mapname } + \hook_use:n { @@/thmtools } - \clist_map_function:NN \l_groupthm_mapname_clist \map_use_on_name:n + \clist_map_function:NN \l_@@_mapname_clist \map_use_on_name:n - \clist_put_right:Nx \l_groupthm_thmtools_clist + \clist_put_right:Nx \l_@@_thmtools_clist { - name = \tl_use:N \l_groupthm_prename_tl - \tl_use:N \l_groupthm_name_tl - \tl_use:N \l_groupthm_postname_tl + name = \tl_use:N \l_@@_prename_tl + \tl_use:N \l_@@_name_tl + \tl_use:N \l_@@_postname_tl } - \declaretheorem:nV + \@@_declare_theorem:nV { #1 } - \l_groupthm_thmtools_clist + \l_@@_thmtools_clist } \cs_generate_variant:Nn \new_grouped_theorem:nnnn { n V V V } \cs_generate_variant:Nn \new_grouped_theorem:nnnn { x V n n } + +% keys, subgroup +\cs_new:Npn \@@_set_normalized_keys:nnn #1 #2 #3 + { + \keys_set:nn { @@ } { prename, name, postname, group, mapname, thmtools } + \keys_set_groups:nnn { @@ } { #2 } { #1 } + + \tl_if_eq:NnTF \l_@@_key_name_tl { \c_novalue_tl } + { + \tl_set:Nx \l_@@_name_tl + { + \text_titlecase_first:n {#3} + } + } + { + \tl_set_eq:NN \l_@@_name_tl \l_@@_key_name_tl + } + + \tl_set_eq:NN \l_@@_prename_tl \l_@@_key_prename_tl + \tl_set_eq:NN \l_@@_postname_tl \l_@@_key_postname_tl + \clist_set_eq:NN \l_@@_group_clist \l_@@_key_group_clist + \clist_set_eq:NN \l_@@_mapname_clist \l_@@_key_mapname_clist + \clist_set_eq:NN \l_@@_thmtools_clist \l_@@_key_group_clist + } + + % envname, keys \cs_new:Npn \new_grouped_theorem_from_keys:nn #1 #2 { - \keys_set_groups:nnn { groupthm } { groupedtheorem } { name, group, thmtools } - \keys_set_groups:nnn { groupthm } { groupedtheorem } { #2 } + \@@_set_normalized_keys { #2 } { groupedtheorem } { #1 } % Construct name - \tl_if_eq:NnTF \l_groupthm_key_name_tl { \c_novalue_tl } + \tl_if_eq:NnTF \l_@@_key_name_tl { \c_novalue_tl } { - \tl_set:Nx \l_groupthm_name_tl + \tl_set:Nx \l_@@_name_tl { \text_titlecase_first:n {#1} } } { - \tl_set_eq:NN \l_groupthm_name_tl \l_groupthm_key_name_tl + \tl_set_eq:NN \l_@@_name_tl \l_@@_key_name_tl } \new_grouped_theorem:nVVV { #1 } - \l_groupthm_key_group_clist - \l_groupthm_name_tl - \l_groupthm_key_thmtools_clist + \l_@@_key_group_clist + \l_@@_name_tl + \l_@@_key_thmtools_clist } \NewDocumentCommand{\NewGroupedTheorem}{O{} m} @@ -243,19 +364,19 @@ __HEADER__(Grouping theorems for easier customization.) % hook group1 relation group2 \cs_new:Npn \declare_theorem_group_rule:nnnn #1 #2 #3 #4 { - \tl_set:Nx \l_groupthm_relation_tl { \tl_trim_spaces:n { #3 } } + \tl_set:Nx \l_@@_relation_tl { \tl_trim_spaces:n { #3 } } \tl_if_eq:nnT { higher } { #3 } { - \tl_set:Nn \l_groupthm_relation_tl { after } + \tl_set:Nn \l_@@_relation_tl { after } } \tl_if_eq:nnT { lower } { #3 } { - \tl_set:Nn \l_groupthm_relation_tl { before } + \tl_set:Nn \l_@@_relation_tl { before } } - \hook_gset_rule:nnVn {#1} {#2} \l_groupthm_relation_tl {#4} + \hook_gset_rule:nnVn {#1} {#2} \l_@@_relation_tl {#4} } % hook, group1, relation, group2 @@ -269,19 +390,19 @@ __HEADER__(Grouping theorems for easier customization.) \cs_new:Npn \__add_to_sort_hook:n #1 { - \hook_gput_code:nnn { groupthm / groupsort } + \hook_gput_code:nnn { @@/groupsort } { #1 } { - \clist_put_left:Nn \l_groupthm_group_clist { #1 } + \clist_put_left:Nn \l_@@_group_clist { #1 } } } \cs_new:Npn \__sort_group_names: { - \hook_gremove_code:nn { groupthm / groupsort }{*} - \clist_map_function:NN \l_groupthm_group_clist \__add_to_sort_hook:n - \clist_clear:N \l_groupthm_group_clist - \hook_use:n { groupthm / groupsort } + \hook_gremove_code:nn { @@/groupsort }{*} + \clist_map_function:NN \l_@@_group_clist \__add_to_sort_hook:n + \clist_clear:N \l_@@_group_clist + \hook_use:n { @@/groupsort } } @@ -292,14 +413,14 @@ __HEADER__(Grouping theorems for easier customization.) % envname, name, thmtools, list of groups \cs_new:Npn \generate_theorem_variants:nnnn #1 #2 #3 #4 { - \clist_set:Nn \l_groupthm_group_clist { #4 } - \powerset_clist_foreach:Nn \l_groupthm_group_clist + \clist_set:Nn \l_@@_group_clist { #4 } + \powerset_clist_foreach:Nn \l_@@_group_clist { \__sort_group_names: \new_grouped_theorem:xVnn - {__#1__groups_\clist_use:Nn \l_groupthm_group_clist {_}} - \l_groupthm_group_clist + {__#1__groups_\clist_use:Nn \l_@@_group_clist {_}} + \l_@@_group_clist { #2 } { #3 } } @@ -313,25 +434,25 @@ __HEADER__(Grouping theorems for easier customization.) \keys_set_groups:nnn { groupthm } { theoremvariants } { name, thmtools, group } \keys_set_groups:nnn { groupthm } { theoremvariants } { #2 } - \tl_if_eq:NnTF \l_groupthm_key_name_tl { \c_novalue_tl } + \tl_if_eq:NnTF \l_@@_key_name_tl { \c_novalue_tl } { - \tl_set:Nx \l_groupthm_name_tl + \tl_set:Nx \l_@@_name_tl { \text_titlecase_first:n {#1} } } { - \tl_set_eq:NN \l_groupthm_name_tl \l_groupthm_key_name_tl + \tl_set_eq:NN \l_@@_name_tl \l_@@_key_name_tl } - \clist_set_eq:NN \l_groupthm_group_clist \l_groupthm_key_group_clist - \clist_put_left:Nn \l_groupthm_group_clist { starred } + \clist_set_eq:NN \l_@@_group_clist \l_@@_key_group_clist + \clist_put_left:Nn \l_@@_group_clist { starred } \generate_theorem_variants:nVVV { #1 } - \l_groupthm_name_tl - \l_groupthm_key_thmtools_clist - \l_groupthm_group_clist + \l_@@_name_tl + \l_@@_key_thmtools_clist + \l_@@_group_clist } \NewDocumentCommand { \GenerateTheoremVariants } { O{} m } @@ -342,7 +463,7 @@ __HEADER__(Grouping theorems for easier customization.) %%% Theorem variants declaration / parsing \cs_new:Npn \add_theorem_to_group:n #1 { - \clist_put_left:Nn \l_groupthm_group_clist { #1 } + \clist_put_left:Nn \l_@@_group_clist { #1 } } % envname, signature, definition, starred? @@ -354,7 +475,7 @@ __HEADER__(Grouping theorems for easier customization.) } {#2} { - \clist_clear:N \l_groupthm_group_clist + \clist_clear:N \l_@@_group_clist #3 @@ -363,10 +484,10 @@ __HEADER__(Grouping theorems for easier customization.) \add_theorem_to_group:n { starred } } \__sort_group_names: - \begin{__#1__groups_\clist_use:Nn \l_groupthm_group_clist{_}} + \begin{__#1__groups_\clist_use:Nn \l_@@_group_clist{_}} } { - \clist_clear:N \l_groupthm_group_clist + \clist_clear:N \l_@@_group_clist #3 @@ -375,7 +496,7 @@ __HEADER__(Grouping theorems for easier customization.) \add_theorem_to_group:n { starred } } \__sort_group_names: - \end{__#1__groups_\clist_use:Nn \l_groupthm_group_clist{_}} + \end{__#1__groups_\clist_use:Nn \l_@@_group_clist{_}} } }