generate document commands with helper function

This commit is contained in:
Maximilian Keßler 2022-01-21 13:27:48 +01:00
parent 47e633fefc
commit d005bb4b33
2 changed files with 88 additions and 68 deletions

View file

@ -1682,16 +1682,22 @@
% With the \cs{@@_set_normalized_keys:nnn} macro at hand,
% it is also easy to provide key-value interfaces for these commands:
%
% \begin{macro}{\groupthm_new_group:nn}
% \begin{macro}{\@@_wrap_multiple:nnn}
% \begin{syntax}
% \cs{groupthm_new_group:nn}\marg{keys}\marg{theorem group}
% \cs{@@_wrap_multiple:nnn}\marg{declarator list}\marg{function name}\marg{code}
% \end{syntax}
%
% Defines \meta{function name}, which is assumed to contain \cs{declarator}
% by \meta{code} for each declarator in \meta{declarator list}.
%
% \begin{macrocode}
\cs_new:Npn \@@_wrap_multiple:nnn #1 #2 #3
{
\cs_set:Npn \@@_map_aux:n ##1
{
\def \declarator { ##1 }
\cs_new:cn { #2 }
{
#3
@ -1699,75 +1705,83 @@
}
\clist_map_function:nN { #1 } \@@_map_aux:n
}
\@@_wrap_multiple:nnn
{ new, renew, provide, declare }
{ groupthm_#1_group:nn }
{
\@@_set_normalized_keys:nnn { ##1 } { theoremgroup } { ##2 }
\use:c { groupthm_#1_group:nVVVV }
{ ##2 }
\l_@@_prefix_tl
\l_@@_suffix_tl
\l_@@_mapname_clist
\l_@@_thmtools_clist
}
% \end{macrocode}
% \end{macro}
% \begin{macro}
% {
% \groupthm_new_group:nn,
% \groupthm_renew_group:nn,
% \groupthm_provide_group:nn,
% \groupthm_declare_group:nn
% }
% \begin{syntax}
% \cs{groupthm_new_group:nn}\marg{keys}\marg{theorem group}
% \end{syntax}
%
% \begin{macrocode}
\@@_wrap_multiple:nnn
{ new, renew, provide, declare }
{ groupthm_ \declarator _group:nn }
{
\@@_set_normalized_keys:nnn { ##1 } { theoremgroup } { ##2 }
\use:c { groupthm_#1_group:nVVVV }
{ ##2 }
\l_@@_prefix_tl
\l_@@_suffix_tl
\l_@@_mapname_clist
\l_@@_thmtools_clist
}
% \end{macrocode}
% \end{macro}
%
% \end{macro}
%
%
% Finally, we provide \LaTeX2e wrappers as document commands for these.
%
% \begin{macro}{\@@_wrap_multiple_document:nnnn}
% \begin{syntax}
% \cs{@@_wrap_multiple_document:nnnn}\marg{declarator list}\marg{function name}\marg{arg spec}\marg{code}
% \end{syntax}
%
% \begin{macro}{\NewTheoremGroup}
% This is very similar to \cs{@@_wrap_multiple:nnn}, except that it produces document commands.
% For this reason, \cs{declarator} and \cs{Declarator} are available to refer to the lower
% and upper-case versions of the current declarator.
%
% \begin{macrocode}
\NewDocumentCommand{\NewTheoremGroup}{ O{} m }
\cs_new:Npn \@@_wrap_multiple_document:nnnn #1 #2 #3 #4
{
\groupthm_new_group:nn { #1 } { #2 }
\cs_set:Npn \@@_map_aux:n ##1
{
\def \declarator { ##1 }
\def \Declarator { \text_titlecase_first:n { ##1 } }
\exp_args:Nc \NewDocumentCommand { #2 } { #3 }
{
#4
}
}
\clist_map_function:nN { #1 } \@@_map_aux:n
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NewTheoremGroup, \RenewTheoremGroup, \ProvideTheoremGroup, \DeclareTheoremGroup}
%
%
% \begin{macro}{\RenewTheoremGroup}
% These just wrap the \cs{groupthm_\meta{declarator}_group:nn} macros.
%
% \begin{macrocode}
\NewDocumentCommand{\RenewTheoremGroup}{ O{} m }
\@@_wrap_multiple_document:nnnn
{ new, renew, provide, declare }
{ \Declarator TheoremGroup }
{ O{} m }
{
\groupthm_renew_group:nn { #1 } { #2 }
\use:c { groupthm_ \declarator _group:nn } { ##1 } { ##2 }
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\ProvideTheoremGroup}
%
% \begin{macrocode}
\NewDocumentCommand{\ProvideTheoremGroup}{ O{} m }
{
\groupthm_provide_group:nn { #1 } { #2 }
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\DeclareTheoremGroup}
%
% \begin{macrocode}
\NewDocumentCommand{\DeclareTheoremGroup}{ O{} m }
{
\groupthm_declare_group:nn { #1 } { #2 }
}
% \end{macrocode}
% \end{macro}
%
% We also provide the interface for declaring the precedence rules for theorem groups.
%
%

View file

@ -297,10 +297,12 @@
\cs_generate_variant:Nn \groupthm_renew_group:nnnnn { n V V V V }
\cs_generate_variant:Nn \groupthm_provide_group:nnnnn { n V V V V }
\cs_generate_variant:Nn \groupthm_declare_group:nnnnn { n V V V V }
\cs_new:Npn \__groupthm_wrap_multiple:nnn #1 #2 #3
{
\cs_set:Npn \__groupthm_map_aux:n ##1
{
\def \declarator { ##1 }
\cs_new:cn { #2 }
{
#3
@ -310,32 +312,36 @@
}
\__groupthm_wrap_multiple:nnn
{ new, renew, provide, declare }
{ groupthm_#1_group:nn }
{
\__groupthm_set_normalized_keys:nnn { ##1 } { theoremgroup } { ##2 }
\use:c { groupthm_#1_group:nVVVV }
{ ##2 }
\l__groupthm_prefix_tl
\l__groupthm_suffix_tl
\l__groupthm_mapname_clist
\l__groupthm_thmtools_clist
}
\NewDocumentCommand{\NewTheoremGroup}{ O{} m }
{ new, renew, provide, declare }
{ groupthm_ \declarator _group:nn }
{
\groupthm_new_group:nn { #1 } { #2 }
\__groupthm_set_normalized_keys:nnn { ##1 } { theoremgroup } { ##2 }
\use:c { groupthm_#1_group:nVVVV }
{ ##2 }
\l__groupthm_prefix_tl
\l__groupthm_suffix_tl
\l__groupthm_mapname_clist
\l__groupthm_thmtools_clist
}
\NewDocumentCommand{\RenewTheoremGroup}{ O{} m }
\cs_new:Npn \__groupthm_wrap_multiple_document:nnnn #1 #2 #3 #4
{
\groupthm_renew_group:nn { #1 } { #2 }
\cs_set:Npn \__groupthm_map_aux:n ##1
{
\def \declarator { ##1 }
\def \Declarator { \text_titlecase_first:n { ##1 } }
\exp_args:Nc \NewDocumentCommand { #2 } { #3 }
{
#4
}
}
\clist_map_function:nN { #1 } \__groupthm_map_aux:n
}
\NewDocumentCommand{\ProvideTheoremGroup}{ O{} m }
\__groupthm_wrap_multiple_document:nnnn
{ new, renew, provide, declare }
{ \Declarator TheoremGroup }
{ O{} m }
{
\groupthm_provide_group:nn { #1 } { #2 }
}
\NewDocumentCommand{\DeclareTheoremGroup}{ O{} m }
{
\groupthm_declare_group:nn { #1 } { #2 }
\use:c { groupthm_ \declarator _group:nn } { ##1 } { ##2 }
}
\cs_new:Npn \groupthm_declare_theorem_group_rule:nnnn #1 #2 #3 #4
{