diff --git a/src/environments/groupthm.pysty3 b/src/environments/groupthm.pysty3 index a84d141..0e8c392 100644 --- a/src/environments/groupthm.pysty3 +++ b/src/environments/groupthm.pysty3 @@ -5,6 +5,7 @@ __HEADER__(Grouping theorems for easier customization.) \RequirePackage{amsthm} \RequirePackage{thmtools} +\RequirePackage{mkessler-powerset} \hook_new:n { groupthm / prename } \hook_new:n { groupthm / postname } @@ -120,6 +121,7 @@ __HEADER__(Grouping theorems for easier customization.) { #1 } + \str_gset:Nn \g_groupthm_last_theorem_group_str { #1 } } \cs_generate_variant:Nn \new_theorem_group:nnnnn { n V V V V } @@ -163,10 +165,6 @@ __HEADER__(Grouping theorems for easier customization.) \cs_new:Npn \new_grouped_theorem:nnnn #1 #2 #3 #4 { -% \tl_show:n { #1 } -% \tl_show:n { #2 } -% \tl_show:n { #3 } -% \tl_show:n { #4 } \tl_clear:N \l_groupthm_prename_tl \tl_set:Nn \l_groupthm_name_tl { #3 } @@ -263,57 +261,7 @@ __HEADER__(Grouping theorems for easier customization.) \declare_theorem_group_rule:nnnn {#1} {#2} {#3} {#4} } -%%% Iterate over powerset of claist -\clist_new:N \copied_clist -\seq_new:N \saved_seq - -%remove left -> push on stack -% call recursive -% add left to 'extra' -% call recursive -% remove left from 'extra' -% add from stack to left - - -\cs_generate_variant:Nn \clist_remove_all:Nn { N V } - -\cs_new:Npn \clist_use_powerset_aux:Nn #1 #2 -{ - \clist_if_empty:NTF \copied_clist - { - #2 - } - { - - \clist_get:NN \copied_clist \l_tmpa_tl % gets first element of copied list into local - \seq_push:NV \saved_seq \l_tmpa_tl % pushes local value onto stack - \clist_pop:NN \copied_clist { \l_tmpa_tl } % removes from copied list - - \clist_use_powerset_aux:Nn #1 {#2} - - \seq_get:NN \saved_seq \l_tmpa_tl - \clist_put_left:NV #1 \l_tmpa_tl - - \clist_use_powerset_aux:Nn #1 {#2} - - \seq_get:NN \saved_seq \l_tmpa_tl - \clist_remove_all:NV #1 \l_tmpa_tl - \clist_push:NV \copied_clist \l_tmpa_tl - \seq_pop:NN \saved_seq \l_tmpa_tl - } -} - -\cs_new:Npn \clist_use_powerset:Nn #1 #2 -{ - \clist_set_eq:NN \copied_clist #1 - \clist_clear:N #1 - \clist_remove_duplicates:N \copied_clist - - \clist_use_powerset_aux:Nn #1 {#2} - - \clist_set_eq:NN #1 \copied_clist -} %%% Theorem variants declaration @@ -338,24 +286,11 @@ __HEADER__(Grouping theorems for easier customization.) \hook_use:n { groupthm / groupsort } } - -% evname, name, thmtools, star? -\cs_new:Npn \declare_theorem_variants_aux:nnnn #1 #2 #3 #4 +% envname, name, thmtools, list of groups +\cs_new:Npn \generate_theorem_variants:nnnn #1 #2 #3 #4 { - - \clist_set:Nn \l_groupthm_groups_clist { dagger, star } -% \clist_set:Nn \l_groupthm_thmtools_clist {#3} -% \IfBooleanT{#4} - - % envname, groups, name, thmtools -% \clist_sort:Nn \l_groupthm_groups_clist -% { -% \str_compare:nNnTF { #1 } > { #2 } -% { \sort_return_swapped: } -% { \sort_return_same: } -% } - - \clist_use_powerset:Nn \l_groupthm_groups_clist + \clist_set:Nn \l_groupthm_groups_clist { #4 } + \powerset_clist_foreach:Nn \l_groupthm_groups_clist { \sort_group_names: \new_grouped_theorem:xVnn @@ -364,18 +299,29 @@ __HEADER__(Grouping theorems for easier customization.) { #2 } { #3 } } +} - - \NewDocumentEnvironment{#1}{ !s !t+ } +% evname, star? +\cs_new:Npn \declare_theorem_variants_aux:nn #1 #2 +{ + \exp_args:Nx\NewDocumentEnvironment + { + #1\IfBooleanT{#2}{*} + } + { !s !t+ } { \clist_clear:N \l_groupthm_groups_clist \IfBooleanT{##2} { - \clist_put_left:Nn \l_groupthm_groups_clist { dagger } + \clist_put_left:Nn \l_groupthm_groups_clist { dagger } } \IfBooleanT{##1} { - \clist_put_left:Nn \l_groupthm_groups_clist { star } + \clist_put_left:Nn \l_groupthm_groups_clist { star } + } + \IfBooleanT{#2} + { + \clist_put_left:Nn \l_groupthm_groups_clist { starred } } \sort_group_names: \begin{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist{_}} @@ -390,15 +336,29 @@ __HEADER__(Grouping theorems for easier customization.) { \clist_put_left:Nn \l_groupthm_groups_clist { dagger } } + \IfBooleanT{#2} + { + \clist_put_left:Nn \l_groupthm_groups_clist { starred } + } \sort_group_names: \end{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist{_}} } - } -\DeclareDocumentCommand{\DeclareTheoremVariants}{mmmm} +% envname, name, thmtools +\cs_new:Npn \declare_theorem_variants:nnn #1 #2 #3 { - \declare_theorem_variants_aux:nnnn{#1}{#2}{#3}{#4} + \generate_theorem_variants:nnnn { #1 } { #2 } { #3 } { star, dagger, starred } + \declare_theorem_variants_aux:nn { #1 } { \BooleanTrue } + \declare_theorem_variants_aux:nn { #1 } { \BooleanFalse } +} + +% envname, group-determining function +%\cs_new:Nn \toggle_variable_environment + +\DeclareDocumentCommand{\DeclareTheoremVariants}{mmm} +{ + \declare_theorem_variants:nnn{#1}{#2}{#3} } diff --git a/src/utils/powerset.pysty3 b/src/utils/powerset.pysty3 new file mode 100644 index 0000000..7fe325a --- /dev/null +++ b/src/utils/powerset.pysty3 @@ -0,0 +1,62 @@ +__HEADER__(Iterate over powerset of clist) + +\ExplSyntaxOn + +%%% Iterate over powerset of claist + +\clist_new:N \l_powerset_copied_clist +\seq_new:N \l_powerset_saved_seq + + + +\cs_generate_variant:Nn \clist_remove_all:Nn { N V } + +% Pseudocode of this macro +% remove left -> push on stack +% call recursive +% add left to 'extra' +% call recursive +% remove left from 'extra' +% add from stack to left + +\cs_new:Npn \__powerset_clist_foreach_aux:Nn #1 #2 +{ + \clist_if_empty:NTF \l_powerset_copied_clist + { + #2 + } + { + \clist_get:NN \l_powerset_copied_clist \l_tmpa_tl + \seq_push:NV \l_powerset_saved_seq \l_tmpa_tl + \clist_pop:NN \l_powerset_copied_clist { \l_tmpa_tl } + + \__powerset_clist_foreach_aux:Nn #1 {#2} + + \seq_get:NN \l_powerset_saved_seq \l_tmpa_tl + \clist_put_left:NV #1 \l_tmpa_tl + + \__powerset_clist_foreach_aux:Nn #1 {#2} + + \seq_get:NN \l_powerset_saved_seq \l_tmpa_tl + \clist_remove_all:NV #1 \l_tmpa_tl + \clist_push:NV \l_powerset_copied_clist \l_tmpa_tl + \seq_pop:NN \l_powerset_saved_seq \l_tmpa_tl + } +} + + +% Usage: +% \clist_use_powerset:Nn {clist variable name}{code for each subset} +% This will execute #2 for each subset of the listname given as #1 +% In #2, the name given as #1 can be used for the current subset +% After execution, the value of #1 is restored +\cs_new:Npn \powerset_clist_foreach:Nn #1 #2 +{ + \clist_set_eq:NN \l_powerset_copied_clist #1 + \clist_clear:N #1 + \clist_remove_duplicates:N \l_powerset_copied_clist + + \__powerset_clist_foreach_aux:Nn #1 {#2} + + \clist_set_eq:NN #1 \l_powerset_copied_clist +}