rework generation of grouped theorems

This commit is contained in:
Maximilian Keßler 2022-01-22 15:08:39 +01:00
parent b1b8f59c1b
commit d0939faa5b
2 changed files with 76 additions and 476 deletions

View file

@ -2165,7 +2165,7 @@
% \groupthm_provide_theorem:xVnn
% }
% \begin{syntax}
% \cs{groupthm_new_grouped_theorem:nnnn}\marg{environment name}
% \cs{groupthm_new_theorem:nnnn}\marg{environment name}
% \marg{groups clist}\marg{theorem name}\marg{thmtools keys}
% \end{syntax}
%
@ -2176,20 +2176,22 @@
{ ##1 }
\@@_error:
\@@_define_theorem:nnnn
{ groupthm_#1_theorem_:nnnn }
{ groupthm_#1_theorem:nnnn }
{ { ##1 } { ##2 } { ##3 } { ##4 } }
\cs_generate_variant:Nn \groupthm_new_grouped_theorem:nnnn { n V V V }
\cs_generate_variant:Nn \groupthm_new_theorem:nnnn { n V V V }
\cs_generate_variant:Nn \groupthm_provide_theorem:nnnn { n V V V }
% \end{macrocode}
% We need this extra variant here for the generation of theorem families later:
% \begin{macrocode}
\cs_generate_variant:Nn \groupthm_new_grouped_theorem:nnnn { x V n n }
\cs_generate_variant:Nn \groupthm_new_theorem:nnnn { x V n n }
\cs_generate_variant:Nn \groupthm_provide_theorem:nnnn { x V n n }
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\groupthm_new_theorem:nnnnnn}
% \begin{macro}{\groupthm_new_theorem:nnn, \groupthm_provide_theorem:nnn}
% \begin{syntax}
% \cs{groupthm_new_theorem:nnnnnn}\marg{key=value list}\marg{grouped theorem}
% \cs{groupthm_new_theorem:nnn}\marg{key=value list}\marg{grouped theorem}
% \marg{bool}
% \end{syntax}
%
@ -2198,341 +2200,60 @@
% \texttt{unnumbered} group
%
% \begin{macrocode}
% \end{macrocode}
% \end{macro}
%
%
% The star variants of these that add the \texttt{unnumbered} group
% are straightforward:
%
% \begin{macro}{\groupthm_new_grouped_theorem_star:nnnn}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_new_grouped_theorem_star:nnnn #1 #2 #3 #4
\@@_wrap_multiple:nnn
{ new, provide }
{ groupthm_#1_theorem:nnn }
{
\groupthm_new_grouped_theorem:nnnn
{ #1 } { #2, unnumbered } { #3 } { #4 }
\@@_set_normalized_keys:nnn { ##1 } { grouped ~ theorem } { ##2 }
\bool_if:nT { ##3 }
{
\clist_put_left:Nn \l_@@_group_clist { unnumbered }
}
\use:c { groupthm_#1_theorem:nVVV }
{ ##2 }
\l_@@_group_clist
\l_@@_name_tl
\l_@@_thmtools_clist
\bool_if:NT \l_@@_starred_version_bool
{
\clist_put_left:Nn \l_@@_group_clist { starred }
\use:c { groupthm_#1_theorem:nVVV }
{ ##2* }
\l_@@_group_clist
\l_@@_name_tl
\l_@@_thmtools_clist
}
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\groupthm_provide_grouped_theorem_star:nnnn}
% \begin{syntax}
% \cs{groupthm_provide_grouped_theorem_star:nnnn}\marg{environment name}
% \marg{groups clist}\marg{theorem name}\marg{thmtools keys}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_provide_grouped_theorem_star:nnnn #1 #2 #3 #4
{
\groupthm_provide_grouped_theorem:nnnn
{ #1 } { #2, unnumbered } { #3 } { #4 }
}
% \end{macrocode}
% \end{macro}
%
%
% On top of these, we can provide the shorter versions that will generate
% two theorems each, one with and one without a \enquote{*} in its
% environment name
%
%
%
% \begin{macro}{\groupthm_new_theorem:nnnn,\groupthm_new_theorem:nVVV}
% \begin{syntax}
% \cs{groupthm_new_theorem:nnnn}\marg{environment name}
% \marg{groups clist}\marg{theorem name}\marg{thmtools keys}
% \end{syntax}
%
%
% \begin{macrocode}
\cs_new:Npn \groupthm_new_theorem:nnnn #1 #2 #3 #4
{
\groupthm_new_grouped_theorem:nnnn
{ #1 } { #2 } { #3 } { #4 }
\groupthm_new_grouped_theorem:nnnn
{ #1* } { #2, starred } { #3 } { #4 }
}
\cs_generate_variant:Nn \groupthm_new_theorem:nnnn { n V V V }
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\groupthm_provide_theorem:nnnn,\groupthm_provide_theorem:nVVV}
% \begin{syntax}
% \cs{groupthm_provide_theorem:nnnn}\marg{environment name}
% \marg{groups clist}\marg{theorem name}\marg{thmtools keys}
% \end{syntax}
%
%
% \begin{macrocode}
\cs_new:Npn \groupthm_provide_theorem:nnnn #1 #2 #3 #4
{
\groupthm_provide_grouped_theorem:nnnn
{ #1 } { #2 } { #3 } { #4 }
\groupthm_provide_grouped_theorem:nnnn
{ #1* } { #2, starred } { #3 } { #4 }
}
\cs_generate_variant:Nn \groupthm_provide_theorem:nnnn { n V V V }
% \end{macrocode}
% \end{macro}
%
%
% Combining these is also not difficult:
%
%
%
%
% \begin{macro}{\groupthm_new_theorem_star:nnnn}
% \begin{syntax}
% \cs{groupthm_new_theorem_star:nnnn}\marg{environment name}
% \marg{groups clist}\marg{theorem name}\marg{thmtools keys}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_new_theorem_star:nnnn #1 #2 #3 #4
{
\groupthm_new_theorem:nnnn
{ #1 } { #2, unnumbered } { #3 } { #4 }
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\groupthm_provide_theorem_star:nnnn}
% \begin{syntax}
% \cs{groupthm_provide_theorem_star:nnnn}\marg{environment name}
% \marg{groups clist}\marg{theorem name}\marg{thmtools keys}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_provide_theorem_star:nnnn #1 #2 #3 #4
{
\groupthm_provide_theorem:nnnn
{ #1 } { #2, unnumbered } { #3 } { #4 }
}
% \end{macrocode}
% \end{macro}
%
% We now provide the corresponding key-valued interfaces around these.
% All of these work in the same way:
% We set the normalized keys, and then pass these by value to the
% previously defined macros
%
%
% \begin{macro}{\groupthm_new_grouped_theorem_from_keys:nn}
% \begin{macrocode}
\cs_new:Npn \groupthm_new_grouped_theorem_from_keys:nn #1 #2
{
\@@_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_new_grouped_theorem:nVVV
{ #1 }
\l_@@_key_group_clist
\l_@@_name_tl
\l_@@_key_thmtools_clist
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\groupthm_provide_grouped_theorem_from_keys:nn}
% \begin{macrocode}
\cs_new:Npn \groupthm_provide_grouped_theorem_from_keys:nn #1 #2
{
\@@_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_provide_grouped_theorem:nVVV
{ #1 }
\l_@@_key_group_clist
\l_@@_name_tl
\l_@@_key_thmtools_clist
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\groupthm_new_grouped_theorem_star_from_keys:nn}
% \begin{macrocode}
\cs_new:Npn \groupthm_new_grouped_theorem_star_from_keys:nn #1 #2
{
\@@_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_new_grouped_theorem_star:nVVV
{ #2 }
\l_@@_key_group_clist
\l_@@_name_tl
\l_@@_key_thmtools_clist
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\groupthm_provide_grouped_theorem_star_from_keys:nn}
% \begin{macrocode}
\cs_new:Npn \groupthm_provide_grouped_theorem_star_from_keys:nn #1 #2
{
\@@_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_provide_grouped_theorem_star:nVVV
{ #2 }
\l_@@_key_group_clist
\l_@@_name_tl
\l_@@_key_thmtools_clist
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\groupthm_new_theorem_from_keys:nn}
% \begin{macrocode}
\cs_new:Npn \groupthm_new_theorem_from_keys:nn #1 #2
{
\@@_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_new_theorem:nVVV
{ #2 }
\l_@@_key_group_clist
\l_@@_name_tl
\l_@@_key_thmtools_clist
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\groupthm_provide_theorem_from_keys:nn}
% \begin{macrocode}
\cs_new:Npn \groupthm_provide_theorem_from_keys:nn #1 #2
{
\@@_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_provide_theorem:nVVV
{ #2 }
\l_@@_key_group_clist
\l_@@_name_tl
\l_@@_key_thmtools_clist
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\groupthm_new_theorem_star_from_keys:nn}
% \begin{macrocode}
\cs_new:Npn \groupthm_new_theorem_star_from_keys:nn #1 #2
{
\@@_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_new_theorem_star:nVVV
{ #1 }
\l_@@_key_group_clist
\l_@@_name_tl
\l_@@_key_thmtools_clist
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\groupthm_provide_theorem_star_from_keys:nn}
% \begin{macrocode}
\cs_new:Npn \groupthm_provide_theorem_star_from_keys:nn #1 #2
{
\@@_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_provide_theorem_star:nVVV
{ #1 }
\l_@@_key_group_clist
\l_@@_name_tl
\l_@@_key_thmtools_clist
}
% \end{macrocode}
% \end{macro}
%
%
%
% Now, we can wrap these into document commands
%
%
% \begin{macro}{\NewGroupedTheorem, \NewGroupedTheorem*}
% \begin{macro}
% {
% \NewGroupedTheorem, \NewGroupedTheorem*,
% \ProvideGroupedTheorem, \ProvideGroupedTheorem*
% }
% \begin{syntax}
% \cs{NewGroupedTheorem}\oarg{keys}\marg{theorem name}
% \end{syntax}
%
% \begin{macrocode}
\NewDocumentCommand{\NewGroupedTheorem}{s O{} m}
\@@_wrap_multiple_document:nnnn
{ new, provide }
{ \Declarator GroupedTheorem }
{ s O{} m }
{
\IfBooleanTF{#1}
{
\groupthm_new_grouped_theorem_star_from_keys:nn { #2 } { #3 }
}
{
\groupthm_new_grouped_theorem_from_keys:nn { #2 } { #3 }
}
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\ProvideGroupedTheorem, \ProvideGroupedTheorem*}
% \begin{syntax}
% \cs{ProvideGroupedTheorem}\oarg{keys}\marg{theorem name}
% \end{syntax}
%
% \begin{macrocode}
\ProvideDocumentCommand{\NewGroupedTheorem}{s O{} m}
{
\IfBooleanTF{#1}
{
\groupthm_provide_grouped_theorem_star_from_keys:nn { #2 } { #3 }
}
{
\groupthm_provide_grouped_theorem_from_keys:nn { #2 } { #3 }
}
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\NewTheorem, \NewTheorem*}
% \begin{syntax}
% \cs{NewTheorem}\oarg{keys}\marg{theorem name}
% \end{syntax}
%
% \begin{macrocode}
\NewDocumentCommand{\NewTheorem}{s O{} m}
{
\IfBooleanTF{#1}
{
\groupthm_new_theorem_star_from_keys:nn { #2 } { #3 }
}
{
\groupthm_new_theorem_from_keys:nn { #2 } { #3 }
}
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\ProvideTheorem, \ProvideTheorem*}
% \begin{syntax}
% \cs{ProvideTheorem}\oarg{keys}\marg{theorem name}
% \end{syntax}
%
% \begin{macrocode}
\ProvideDocumentCommand{\NewTheorem}{s O{} m}
{
\IfBooleanTF{#1}
{
\groupthm_provide_theorem_star_from_keys:nn { #2 } { #3 }
}
{
\groupthm_provide_theorem_from_keys:nn { #2 } { #3 }
}
\use:c { groupthm_#1_theorem:nnn }
{ ##2 }
{ ##3 }
{ ##1 }
}
% \end{macrocode}
% \end{macro}

View file

@ -519,166 +519,45 @@
{ ##1 }
\__groupthm_error:
\__groupthm_define_theorem:nnnn
{ groupthm_#1_theorem_:nnnn }
{ groupthm_#1_theorem:nnnn }
{ { ##1 } { ##2 } { ##3 } { ##4 } }
\cs_generate_variant:Nn \groupthm_new_grouped_theorem:nnnn { n V V V }
\cs_generate_variant:Nn \groupthm_new_grouped_theorem:nnnn { x V n n }
\cs_new:Npn \groupthm_new_grouped_theorem_star:nnnn #1 #2 #3 #4
{
\groupthm_new_grouped_theorem:nnnn
{ #1 } { #2, unnumbered } { #3 } { #4 }
}
\cs_new:Npn \groupthm_provide_grouped_theorem_star:nnnn #1 #2 #3 #4
{
\groupthm_provide_grouped_theorem:nnnn
{ #1 } { #2, unnumbered } { #3 } { #4 }
}
\cs_new:Npn \groupthm_new_theorem:nnnn #1 #2 #3 #4
{
\groupthm_new_grouped_theorem:nnnn
{ #1 } { #2 } { #3 } { #4 }
\groupthm_new_grouped_theorem:nnnn
{ #1* } { #2, starred } { #3 } { #4 }
}
\cs_generate_variant:Nn \groupthm_new_theorem:nnnn { n V V V }
\cs_new:Npn \groupthm_provide_theorem:nnnn #1 #2 #3 #4
{
\groupthm_provide_grouped_theorem:nnnn
{ #1 } { #2 } { #3 } { #4 }
\groupthm_provide_grouped_theorem:nnnn
{ #1* } { #2, starred } { #3 } { #4 }
}
\cs_generate_variant:Nn \groupthm_new_theorem:nnnn { n V V V }
\cs_generate_variant:Nn \groupthm_provide_theorem:nnnn { n V V V }
\cs_new:Npn \groupthm_new_theorem_star:nnnn #1 #2 #3 #4
\cs_generate_variant:Nn \groupthm_new_theorem:nnnn { x V n n }
\cs_generate_variant:Nn \groupthm_provide_theorem:nnnn { x V n n }
\__groupthm_wrap_multiple:nnn
{ new, provide }
{ groupthm_#1_theorem:nnn }
{
\groupthm_new_theorem:nnnn
{ #1 } { #2, unnumbered } { #3 } { #4 }
}
\cs_new:Npn \groupthm_provide_theorem_star:nnnn #1 #2 #3 #4
{
\groupthm_provide_theorem:nnnn
{ #1 } { #2, unnumbered } { #3 } { #4 }
}
\cs_new:Npn \groupthm_new_grouped_theorem_from_keys:nn #1 #2
{
\__groupthm_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_new_grouped_theorem:nVVV
{ #1 }
\l__groupthm_key_group_clist
\__groupthm_set_normalized_keys:nnn { ##1 } { grouped ~ theorem } { ##2 }
\bool_if:nT { ##3 }
{
\clist_put_left:Nn \l__groupthm_group_clist { unnumbered }
}
\use:c { groupthm_#1_theorem:nVVV }
{ ##2 }
\l__groupthm_group_clist
\l__groupthm_name_tl
\l__groupthm_key_thmtools_clist
\l__groupthm_thmtools_clist
\bool_if:NT \l__groupthm_starred_version_bool
{
\clist_put_left:Nn \l__groupthm_group_clist { starred }
\use:c { groupthm_#1_theorem:nVVV }
{ ##2* }
\l__groupthm_group_clist
\l__groupthm_name_tl
\l__groupthm_thmtools_clist
}
}
\cs_new:Npn \groupthm_provide_grouped_theorem_from_keys:nn #1 #2
\__groupthm_wrap_multiple_document:nnnn
{ new, provide }
{ \Declarator GroupedTheorem }
{ s O{} m }
{
\__groupthm_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_provide_grouped_theorem:nVVV
{ #1 }
\l__groupthm_key_group_clist
\l__groupthm_name_tl
\l__groupthm_key_thmtools_clist
}
\cs_new:Npn \groupthm_new_grouped_theorem_star_from_keys:nn #1 #2
{
\__groupthm_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_new_grouped_theorem_star:nVVV
{ #2 }
\l__groupthm_key_group_clist
\l__groupthm_name_tl
\l__groupthm_key_thmtools_clist
}
\cs_new:Npn \groupthm_provide_grouped_theorem_star_from_keys:nn #1 #2
{
\__groupthm_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_provide_grouped_theorem_star:nVVV
{ #2 }
\l__groupthm_key_group_clist
\l__groupthm_name_tl
\l__groupthm_key_thmtools_clist
}
\cs_new:Npn \groupthm_new_theorem_from_keys:nn #1 #2
{
\__groupthm_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_new_theorem:nVVV
{ #2 }
\l__groupthm_key_group_clist
\l__groupthm_name_tl
\l__groupthm_key_thmtools_clist
}
\cs_new:Npn \groupthm_provide_theorem_from_keys:nn #1 #2
{
\__groupthm_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_provide_theorem:nVVV
{ #2 }
\l__groupthm_key_group_clist
\l__groupthm_name_tl
\l__groupthm_key_thmtools_clist
}
\cs_new:Npn \groupthm_new_theorem_star_from_keys:nn #1 #2
{
\__groupthm_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_new_theorem_star:nVVV
{ #1 }
\l__groupthm_key_group_clist
\l__groupthm_name_tl
\l__groupthm_key_thmtools_clist
}
\cs_new:Npn \groupthm_provide_theorem_star_from_keys:nn #1 #2
{
\__groupthm_set_normalized_keys:nnn { #1 } { grouped ~ theorem } { #2 }
\groupthm_provide_theorem_star:nVVV
{ #1 }
\l__groupthm_key_group_clist
\l__groupthm_name_tl
\l__groupthm_key_thmtools_clist
}
\NewDocumentCommand{\NewGroupedTheorem}{s O{} m}
{
\IfBooleanTF{#1}
{
\groupthm_new_grouped_theorem_star_from_keys:nn { #2 } { #3 }
}
{
\groupthm_new_grouped_theorem_from_keys:nn { #2 } { #3 }
}
}
\ProvideDocumentCommand{\NewGroupedTheorem}{s O{} m}
{
\IfBooleanTF{#1}
{
\groupthm_provide_grouped_theorem_star_from_keys:nn { #2 } { #3 }
}
{
\groupthm_provide_grouped_theorem_from_keys:nn { #2 } { #3 }
}
}
\NewDocumentCommand{\NewTheorem}{s O{} m}
{
\IfBooleanTF{#1}
{
\groupthm_new_theorem_star_from_keys:nn { #2 } { #3 }
}
{
\groupthm_new_theorem_from_keys:nn { #2 } { #3 }
}
}
\ProvideDocumentCommand{\NewTheorem}{s O{} m}
{
\IfBooleanTF{#1}
{
\groupthm_provide_theorem_star_from_keys:nn { #2 } { #3 }
}
{
\groupthm_provide_theorem_from_keys:nn { #2 } { #3 }
}
\use:c { groupthm_#1_theorem:nnn }
{ ##2 }
{ ##3 }
{ ##1 }
}
\cs_new:Npn \__groupthm_declare_grouped_theorem_family_aux:nnnnnn #1 #2 #3 #4 #5 #6
{