From 9d5a257aedf693ad093d1e80f34b1931e427f7ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 16 Jan 2022 23:28:43 +0100 Subject: [PATCH] add code for theorem variants generation in document --- src/environments/groupthm.pysty3 | 118 +++++++++++++++++++++---------- 1 file changed, 80 insertions(+), 38 deletions(-) diff --git a/src/environments/groupthm.pysty3 b/src/environments/groupthm.pysty3 index ce68af2..ec728ab 100644 --- a/src/environments/groupthm.pysty3 +++ b/src/environments/groupthm.pysty3 @@ -60,7 +60,7 @@ __HEADER__(Grouping theorems for easier customization.) \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 @@ -272,46 +272,77 @@ __HEADER__(Grouping theorems for easier customization.) \hook_gput_code:nnn { groupthm / groupsort } { #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: { \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 + \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 } } -%%% Theorem variants declaration +%%% Theorem variants generation \ExplSyntaxOn % envname, name, thmtools, list of groups \cs_new:Npn \generate_theorem_variants:nnnn #1 #2 #3 #4 { - \clist_set:Nn \l_groupthm_groups_clist { #4 } - \powerset_clist_foreach:Nn \l_groupthm_groups_clist + \clist_set:Nn \l_groupthm_group_clist { #4 } + \powerset_clist_foreach:Nn \l_groupthm_group_clist { \__sort_group_names: \new_grouped_theorem:xVnn - {__#1__groups_\clist_use:Nn \l_groupthm_groups_clist {_}} - \l_groupthm_groups_clist + {__#1__groups_\clist_use:Nn \l_groupthm_group_clist {_}} + \l_groupthm_group_clist { #2 } { #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 @@ -322,7 +353,7 @@ __HEADER__(Grouping theorems for easier customization.) } {#2} { - \clist_clear:N \l_groupthm_groups_clist + \clist_clear:N \l_groupthm_group_clist #3 @@ -331,10 +362,10 @@ __HEADER__(Grouping theorems for easier customization.) \add_theorem_to_group:n { starred } } \__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 @@ -343,7 +374,7 @@ __HEADER__(Grouping theorems for easier customization.) \add_theorem_to_group:n { starred } } \__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 } { \BooleanFalse } } -\cs_generate_variant:Nn \new_theorem_variant_parser:nnn { x n n } -% envname, name, thmtools -\cs_new:Npn \declare_theorem_variants:nnn #1 #2 #3 +%% Exposing clean interface for parsing theorem variants + +\NewDocumentCommand { \AddTheoremToGroup } { m } { - \generate_theorem_variants:nnnn { #1 } { #2 } { #3 } { star, dagger, starred } - \declare_theorem_variants_aux:n { #1 } + \add_theorem_to_group:n { #1 } } +\DeclareDocumentCommand{ \DeclareTheoremVariants }{ m m m } +{ + \new_theorem_variant_parser:nnn { #1 } { #2 } { #3 } +} + + +%%%%% Convenience macros for usage of this package + % 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} { - \add_theorem_to_group:n { star } + \AddTheoremToGroup { star } + } + \IfBooleanT{##2} + { + \AddTheoremToGroup { dagger } } } } -% envname, group-determining function -%\cs_new:Nn \toggle_variable_environment - -\DeclareDocumentCommand{\DeclareTheoremVariants}{mmm} +% envname, name, thmtools +\cs_new:Npn \generate_standard_theorem_variants:nnn #1 #2 #3 { - \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