make proper macros for theorem variant parsers

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

View File

@ -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