From 3d8b6f0fdc0ac0cffa71afc22075aea406c6c466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 16 Jan 2022 23:01:52 +0100 Subject: [PATCH] make proper macros for theorem variant parsers --- src/environments/groupthm.pysty3 | 87 ++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/src/environments/groupthm.pysty3 b/src/environments/groupthm.pysty3 index c47dee9..ce68af2 100644 --- a/src/environments/groupthm.pysty3 +++ b/src/environments/groupthm.pysty3 @@ -304,73 +304,82 @@ __HEADER__(Grouping theorems for easier customization.) } } -% evname, star? -\cs_new:Npn \declare_theorem_variants_aux:nn #1 #2 +\cs_new:Npn \add_theorem_to_group:n #1 +{ + \clist_put_left:Nn \l_groupthm_groups_clist { #1 } +} + +\NewDocumentCommand { \AddTheoremToGroup } { m } +{ + \add_theorem_to_group:n { #1 } +} + +\cs_new:Npn \__new_theorem_variant_parser_aux:nnnn #1 #2 #3 #4 { \exp_args:Nx\NewDocumentEnvironment { - #1\IfBooleanT{#2}{*} + #1\IfBooleanT{#4}{*} } - { !s !t+ } + {#2} { \clist_clear:N \l_groupthm_groups_clist - \IfBooleanT{##2} + + #3 + + \IfBooleanT{#4} { - \clist_put_left:Nn \l_groupthm_groups_clist { dagger } - } - \IfBooleanT{##1} - { - \clist_put_left:Nn \l_groupthm_groups_clist { star } - } - \IfBooleanT{#2} - { - \clist_put_left:Nn \l_groupthm_groups_clist { starred } + \add_theorem_to_group:n { starred } } \__sort_group_names: \begin{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist{_}} } { \clist_clear:N \l_groupthm_groups_clist - \IfBooleanT{##1} + + #3 + + \IfBooleanT{#4} { - \clist_put_left:Nn \l_groupthm_groups_clist { star } - } - \IfBooleanT{##2} - { - \clist_put_left:Nn \l_groupthm_groups_clist { dagger } - } - \IfBooleanT{#2} - { - \clist_put_left:Nn \l_groupthm_groups_clist { starred } + \add_theorem_to_group:n { starred } } \__sort_group_names: \end{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist{_}} } } +% envname, signature, definition \cs_new:Npn \new_theorem_variant_parser:nnn #1 #2 #3 { - \NewDocumentEnvironment{#1}{#2} - { - \clist_clear:N \l_groupthm_groups_clist - #3 - \__sort_group_names: - \begin{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist{_}} - } - { - \clist_clear:N \l_groupthm_groups_clist - #3 - \__sort_group_names: - \end{__#1__groups_\clist_use:Nn \l_groupthm_groups_clist{_}} - } + \__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 { \generate_theorem_variants:nnnn { #1 } { #2 } { #3 } { star, dagger, starred } - \declare_theorem_variants_aux:nn { #1 } { \BooleanTrue } - \declare_theorem_variants_aux:nn { #1 } { \BooleanFalse } + \declare_theorem_variants_aux:n { #1 } +} + +% evname, star? +\cs_new:Npn \declare_theorem_variants_aux:n #1 +{ + \new_theorem_variant_parser:xnn + { + #1 + } + { !s !t+ } + { + \IfBooleanT{##2} + { + \add_theorem_to_group:n { dagger } + } + \IfBooleanT{##1} + { + \add_theorem_to_group:n { star } + } + } } % envname, group-determining function