add code for theorem variants generation in document

This commit is contained in:
Maximilian Keßler 2022-01-16 23:28:43 +01:00
parent 3d8b6f0fdc
commit 9d5a257aed

View file

@ -60,7 +60,7 @@ __HEADER__(Grouping theorems for easier customization.)
\tl_new:N \l_groupthm_relation_tl \tl_new:N \l_groupthm_relation_tl
\clist_new:N \l_groupthm_groups_clist \clist_new:N \l_groupthm_group_clist
\str_new:N \g_groupthm_last_theorem_group_str \str_new:N \g_groupthm_last_theorem_group_str
@ -272,46 +272,77 @@ __HEADER__(Grouping theorems for easier customization.)
\hook_gput_code:nnn { groupthm / groupsort } \hook_gput_code:nnn { groupthm / groupsort }
{ #1 } { #1 }
{ {
\clist_put_left:Nn \l_groupthm_groups_clist { #1 } \clist_put_left:Nn \l_groupthm_group_clist { #1 }
} }
} }
\cs_new:Npn \__sort_group_names: \cs_new:Npn \__sort_group_names:
{ {
\hook_gremove_code:nn { groupthm / groupsort }{*} \hook_gremove_code:nn { groupthm / groupsort }{*}
\clist_map_function:NN \l_groupthm_groups_clist \__add_to_sort_hook:n \clist_map_function:NN \l_groupthm_group_clist \__add_to_sort_hook:n
\clist_clear:N \l_groupthm_groups_clist \clist_clear:N \l_groupthm_group_clist
\hook_use:n { groupthm / groupsort } \hook_use:n { groupthm / groupsort }
} }
%%% Theorem variants declaration %%% Theorem variants generation
\ExplSyntaxOn \ExplSyntaxOn
% envname, name, thmtools, list of groups % envname, name, thmtools, list of groups
\cs_new:Npn \generate_theorem_variants:nnnn #1 #2 #3 #4 \cs_new:Npn \generate_theorem_variants:nnnn #1 #2 #3 #4
{ {
\clist_set:Nn \l_groupthm_groups_clist { #4 } \clist_set:Nn \l_groupthm_group_clist { #4 }
\powerset_clist_foreach:Nn \l_groupthm_groups_clist \powerset_clist_foreach:Nn \l_groupthm_group_clist
{ {
\__sort_group_names: \__sort_group_names:
\new_grouped_theorem:xVnn \new_grouped_theorem:xVnn
{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist {_}} {__#1__groups_\clist_use:Nn \l_groupthm_group_clist {_}}
\l_groupthm_groups_clist \l_groupthm_group_clist
{ #2 } { #2 }
{ #3 } { #3 }
} }
} }
\cs_generate_variant:Nn \generate_theorem_variants:nnnn { n V V V }
\cs_new:Npn \add_theorem_to_group:n #1
% envname, keys
\cs_new:Npn \generate_theorem_variants_from_keys:nn #1 #2
{ {
\clist_put_left:Nn \l_groupthm_groups_clist { #1 } \keys_set_groups:nnn { groupthm } { theoremvariants } { name, thmtools }
\keys_set_groups:nnn { groupthm } { theoremvariants } { #2 }
\tl_if_eq:NnTF \l_groupthm_key_name_tl { \c_novalue_tl }
{
\tl_set:Nx \l_groupthm_name_tl
{
\text_titlecase_first:n {#1}
}
}
{
\tl_set_eq:NN \l_groupthm_name_tl \l_groupthm_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 }
\generate_theorem_variants:nVVV
{ #1 }
\l_groupthm_name_tl
\l_groupthm_key_thmtools_clist
\l_groupthm_group_clist
} }
\NewDocumentCommand { \AddTheoremToGroup } { m } \NewDocumentCommand { \GenerateTheoremVariants } { O{} m }
{ {
\add_theorem_to_group:n { #1 } \generate_theorem_variants_from_keys:nn { #2 } { #1 }
}
%%% Theorem variants declaration / parsing
\cs_new:Npn \add_theorem_to_group:n #1
{
\clist_put_left:Nn \l_groupthm_group_clist { #1 }
} }
\cs_new:Npn \__new_theorem_variant_parser_aux:nnnn #1 #2 #3 #4 \cs_new:Npn \__new_theorem_variant_parser_aux:nnnn #1 #2 #3 #4
@ -322,7 +353,7 @@ __HEADER__(Grouping theorems for easier customization.)
} }
{#2} {#2}
{ {
\clist_clear:N \l_groupthm_groups_clist \clist_clear:N \l_groupthm_group_clist
#3 #3
@ -331,10 +362,10 @@ __HEADER__(Grouping theorems for easier customization.)
\add_theorem_to_group:n { starred } \add_theorem_to_group:n { starred }
} }
\__sort_group_names: \__sort_group_names:
\begin{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist{_}} \begin{__#1__groups_\clist_use:Nn \l_groupthm_group_clist{_}}
} }
{ {
\clist_clear:N \l_groupthm_groups_clist \clist_clear:N \l_groupthm_group_clist
#3 #3
@ -343,7 +374,7 @@ __HEADER__(Grouping theorems for easier customization.)
\add_theorem_to_group:n { starred } \add_theorem_to_group:n { starred }
} }
\__sort_group_names: \__sort_group_names:
\end{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist{_}} \end{__#1__groups_\clist_use:Nn \l_groupthm_group_clist{_}}
} }
} }
@ -353,44 +384,55 @@ __HEADER__(Grouping theorems for easier customization.)
\__new_theorem_variant_parser_aux:nnnn { #1 } { #2 } { #3 } { \BooleanTrue } \__new_theorem_variant_parser_aux:nnnn { #1 } { #2 } { #3 } { \BooleanTrue }
\__new_theorem_variant_parser_aux:nnnn { #1 } { #2 } { #3 } { \BooleanFalse } \__new_theorem_variant_parser_aux:nnnn { #1 } { #2 } { #3 } { \BooleanFalse }
} }
\cs_generate_variant:Nn \new_theorem_variant_parser:nnn { x n n }
% envname, name, thmtools %% Exposing clean interface for parsing theorem variants
\cs_new:Npn \declare_theorem_variants:nnn #1 #2 #3
\NewDocumentCommand { \AddTheoremToGroup } { m }
{ {
\generate_theorem_variants:nnnn { #1 } { #2 } { #3 } { star, dagger, starred } \add_theorem_to_group:n { #1 }
\declare_theorem_variants_aux:n { #1 }
} }
\DeclareDocumentCommand{ \DeclareTheoremVariants }{ m m m }
{
\new_theorem_variant_parser:nnn { #1 } { #2 } { #3 }
}
%%%%% Convenience macros for usage of this package
% evname, star? % evname, star?
\cs_new:Npn \declare_theorem_variants_aux:n #1 \cs_new:Npn \declare_standard_theorem_variants:n #1
{ {
\new_theorem_variant_parser:xnn \DeclareTheoremVariants { #1 } { !s !t+ }
{ {
#1
}
{ !s !t+ }
{
\IfBooleanT{##2}
{
\add_theorem_to_group:n { dagger }
}
\IfBooleanT{##1} \IfBooleanT{##1}
{ {
\add_theorem_to_group:n { star } \AddTheoremToGroup { star }
}
\IfBooleanT{##2}
{
\AddTheoremToGroup { dagger }
} }
} }
} }
% envname, group-determining function % envname, name, thmtools
%\cs_new:Nn \toggle_variable_environment \cs_new:Npn \generate_standard_theorem_variants:nnn #1 #2 #3
\DeclareDocumentCommand{\DeclareTheoremVariants}{mmm}
{ {
\declare_theorem_variants:nnn{#1}{#2}{#3} \generate_theorem_variants:nnnn { #1 } { #2 } { #3 } { star, dagger, starred }
} }
% envname, keys
\cs_new:Npn \generate_standard_theorem_variants_from_keys:nn
{
% TODO
}
\DeclareDocumentCommand{\GenerateDefaultTheoremVariants}{ O{} m }
{
\generate_standard_theorem_variants_from_keys:nn { #2 } { #1 }
}
%%% Default groups available %%% Default groups available