theorem variants generation

add iterating over powerset of clist function
  add sorting hack for theoremgroups
  add declare_theorem_variants macro
This commit is contained in:
Maximilian Keßler 2022-01-16 21:38:19 +01:00
parent 5e141841cb
commit 3630c47b59

View file

@ -11,6 +11,8 @@ __HEADER__(Grouping theorems for easier customization.)
\hook_new:n { groupthm / mapname }
\hook_new:n { groupthm / thmtools }
\hook_new:n { groupthm / groupsort }
\newcounter{indocument}
\newcounter{insection}[section]
@ -25,6 +27,7 @@ __HEADER__(Grouping theorems for easier customization.)
}
\cs_generate_variant:Nn \declaretheorem:nn { n V }
\cs_generate_variant:Nn \hook_gset_rule:nnnn { n n V n }
%%% Messages
@ -56,6 +59,10 @@ __HEADER__(Grouping theorems for easier customization.)
\tl_new:N \l_groupthm_relation_tl
\clist_new:N \l_groupthm_groups_clist
\str_new:N \g_groupthm_last_theorem_group_str
%%% Keys
@ -107,6 +114,12 @@ __HEADER__(Grouping theorems for easier customization.)
\clist_put_right:Nn \l_groupthm_thmtools_clist { #5 }
}
}
\hook_gset_rule:nnnn { groupthm / groupsort }
\g_groupthm_last_theorem_group_str
{ before }
{
#1
}
}
\cs_generate_variant:Nn \new_theorem_group:nnnnn { n V V V V }
@ -150,6 +163,11 @@ __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 }
\tl_clear:N \l_groupthm_postname_tl
@ -183,6 +201,7 @@ __HEADER__(Grouping theorems for easier customization.)
\l_groupthm_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 }
% envname, keys
\cs_new:Npn \new_grouped_theorem_from_keys:nn #1 #2
@ -215,6 +234,9 @@ __HEADER__(Grouping theorems for easier customization.)
}
%% Rules for different theorem groups
\cs_generate_variant:Nn \hook_gset_rule:nnnn { n n V n }
% hook group1 relation group2
@ -241,6 +263,145 @@ __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
\ExplSyntaxOn
\cs_new:Npn \add_to_sort_hook:n #1
{
\hook_gput_code:nnn { groupthm / groupsort }
{ #1 }
{
\clist_put_left:Nn \l_groupthm_groups_clist { #1 }
}
}
\cs_new:Npn \sort_group_names:
{
\hook_gremove_code:nn { groupthm / groupsort }{*}
\clist_map_function:NN \l_groupthm_groups_clist \add_to_sort_hook:n
\clist_clear:N \l_groupthm_groups_clist
\hook_use:n { groupthm / groupsort }
}
% evname, name, thmtools, star?
\cs_new:Npn \declare_theorem_variants_aux: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
{
\sort_group_names:
\new_grouped_theorem:xVnn
{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist {_}}
\l_groupthm_groups_clist
{ #2 }
{ #3 }
}
\NewDocumentEnvironment{#1}{ !s !t+ }
{
\clist_clear:N \l_groupthm_groups_clist
\IfBooleanT{##2}
{
\clist_put_left:Nn \l_groupthm_groups_clist { dagger }
}
\IfBooleanT{##1}
{
\clist_put_left:Nn \l_groupthm_groups_clist { star }
}
\sort_group_names:
\begin{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist{_}}
}
{
\clist_clear:N \l_groupthm_groups_clist
\IfBooleanT{##1}
{
\clist_put_left:Nn \l_groupthm_groups_clist { star }
}
\IfBooleanT{##2}
{
\clist_put_left:Nn \l_groupthm_groups_clist { dagger }
}
\sort_group_names:
\end{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist{_}}
}
}
\DeclareDocumentCommand{\DeclareTheoremVariants}{mmmm}
{
\declare_theorem_variants_aux:nnnn{#1}{#2}{#3}{#4}
}
%%% Default groups available
@ -286,3 +447,5 @@ __HEADER__(Grouping theorems for easier customization.)
\DeclareTheoremGroupRule { starred } { higher } { small }
\DeclareTheoremGroupRule { starred } { higher } { dagger }
\DeclareTheoremGroupRule { starred } { higher } { star }
\DeclareTheoremGroupRule { starred } { higher } { starred}