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, % With the \cs{@@_set_normalized_keys:nnn} macro at hand,
% it is also easy to provide key-value interfaces for these commands: % 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} % \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} % \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} % \begin{macrocode}
\cs_new:Npn \@@_wrap_multiple:nnn #1 #2 #3 \cs_new:Npn \@@_wrap_multiple:nnn #1 #2 #3
{ {
\cs_set:Npn \@@_map_aux:n ##1 \cs_set:Npn \@@_map_aux:n ##1
{ {
\def \declarator { ##1 }
\cs_new:cn { #2 } \cs_new:cn { #2 }
{ {
#3 #3
@ -1699,10 +1705,24 @@
} }
\clist_map_function:nN { #1 } \@@_map_aux:n \clist_map_function:nN { #1 } \@@_map_aux:n
} }
% \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 \@@_wrap_multiple:nnn
{ new, renew, provide, declare } { new, renew, provide, declare }
{ groupthm_#1_group:nn } { groupthm_ \declarator _group:nn }
{ {
\@@_set_normalized_keys:nnn { ##1 } { theoremgroup } { ##2 } \@@_set_normalized_keys:nnn { ##1 } { theoremgroup } { ##2 }
\use:c { groupthm_#1_group:nVVVV } \use:c { groupthm_#1_group:nVVVV }
@ -1715,59 +1735,53 @@
% \end{macrocode} % \end{macrocode}
% \end{macro} % \end{macro}
% %
%
% \end{macro} % \end{macro}
% %
% %
% Finally, we provide \LaTeX2e wrappers as document commands for these. % 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} % \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{macrocode}
% \end{macro} % \end{macro}
% %
% \begin{macro}{\NewTheoremGroup, \RenewTheoremGroup, \ProvideTheoremGroup, \DeclareTheoremGroup}
% %
% % These just wrap the \cs{groupthm_\meta{declarator}_group:nn} macros.
% \begin{macro}{\RenewTheoremGroup}
% %
% \begin{macrocode} % \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{macrocode}
% \end{macro} % \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. % 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_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_provide_group:nnnnn { n V V V V }
\cs_generate_variant:Nn \groupthm_declare_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_new:Npn \__groupthm_wrap_multiple:nnn #1 #2 #3
{ {
\cs_set:Npn \__groupthm_map_aux:n ##1 \cs_set:Npn \__groupthm_map_aux:n ##1
{ {
\def \declarator { ##1 }
\cs_new:cn { #2 } \cs_new:cn { #2 }
{ {
#3 #3
@ -311,7 +313,7 @@
\__groupthm_wrap_multiple:nnn \__groupthm_wrap_multiple:nnn
{ new, renew, provide, declare } { new, renew, provide, declare }
{ groupthm_#1_group:nn } { groupthm_ \declarator _group:nn }
{ {
\__groupthm_set_normalized_keys:nnn { ##1 } { theoremgroup } { ##2 } \__groupthm_set_normalized_keys:nnn { ##1 } { theoremgroup } { ##2 }
\use:c { groupthm_#1_group:nVVVV } \use:c { groupthm_#1_group:nVVVV }
@ -321,21 +323,25 @@
\l__groupthm_mapname_clist \l__groupthm_mapname_clist
\l__groupthm_thmtools_clist \l__groupthm_thmtools_clist
} }
\NewDocumentCommand{\NewTheoremGroup}{ O{} m } \cs_new:Npn \__groupthm_wrap_multiple_document:nnnn #1 #2 #3 #4
{ {
\groupthm_new_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
} }
\NewDocumentCommand{\RenewTheoremGroup}{ O{} m }
{
\groupthm_renew_group:nn { #1 } { #2 }
} }
\NewDocumentCommand{\ProvideTheoremGroup}{ O{} m } \clist_map_function:nN { #1 } \__groupthm_map_aux:n
{
\groupthm_provide_group:nn { #1 } { #2 }
} }
\NewDocumentCommand{\DeclareTheoremGroup}{ O{} m } \__groupthm_wrap_multiple_document:nnnn
{ new, renew, provide, declare }
{ \Declarator TheoremGroup }
{ 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 \cs_new:Npn \groupthm_declare_theorem_group_rule:nnnn #1 #2 #3 #4
{ {