add providing macro variants

This commit is contained in:
Maximilian Keßler 2022-01-23 17:56:53 +01:00
parent e5b3a7f432
commit 5d103708c2

View File

@ -469,9 +469,31 @@
% \end{macro}
%
%
% \begin{macro}{\@@_wrap_multiple:nnn}
% \begin{syntax}
% \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
{
\cs_new:cn { #2 }
{
#3
}
}
\clist_map_function:nN { #1 } \@@_map_aux:n
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\fancythm_new_theorem:nnnn}
% \begin{macro}{\fancythm_new_theorem:nnnn, \fancythm_provide_theorem:nnnn}
% \begin{syntax}
% \cs{fancythm_new_theorem:nnnn}\marg{fancy theorem}\marg{groups}
% \marg{name}\marg{thmtools keys}
@ -480,25 +502,28 @@
%
%
% \begin{macrocode}
\cs_new:Npn \fancythm_new_theorem:nnnn #1 #2 #3 #4
\@@_wrap_multiple:nnn
{ new, provide }
{ fancythm_#1_theorem:nnnn }
{
\groupthm_new_family:nnnnn { #1 } { dagger, star } { #3 } { #4 } { #2 }
\groupthm_new_family_options:nnnn
{ #1 }
\use:c { groupthm_#1_family:nnnnn } { ##1 } { dagger, star } { ##3 } { ##4 } { ##2 }
\use:c { groupthm_#1_family_options:nnnn }
{ ##1 }
{ !s !t+ }
{
\IfBooleanT { ##1 }
\IfBooleanT { ####1 }
{
\groupthm_add_theorem_to_group:n { star }
}
\IfBooleanT { ##2 }
\IfBooleanT { ####2 }
{
\groupthm_add_theorem_to_group:n { dagger }
}
}
{ #2 }
{ ##2 }
}
\cs_generate_variant:Nn \fancythm_new_theorem:nnnn { n V V V }
\cs_generate_variant:Nn \fancythm_provide_theorem:nnnn { n V V V }
% \end{macrocode}
% \end{macro}
%
@ -512,11 +537,13 @@
%
%
% \begin{macrocode}
\cs_new:Npn \fancythm_new_theorem:nn #1 #2
\@@_wrap_multiple:nnn
{ new, provide }
{ fancythm_#1_theorem:nn }
{
\@@_set_normalized_keys:nn { #1 } { #2 }
\fancythm_new_theorem:nVVV
{ #2 }
\@@_set_normalized_keys:nn { ##1 } { ##2 }
\use:c { fancythm_#1_theorem:nVVV }
{ ##2 }
\l_@@_group_clist
\l_@@_name_tl
\l_@@_thmtools_clist
@ -524,9 +551,50 @@
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_new_document_command:Nnn, \@@_new_document_command:cnn}
%
% Private wrappers around \cs{NewDocumentCommand}.
%
% \begin{macrocode}
\cs_new:Npn \@@_new_document_command:Nnn #1 #2 #3
{
\NewDocumentCommand { #1 } { #2 } { #3 }
}
\cs_generate_variant:Nn \@@_new_document_command:Nnn { c n n }
% \end{macrocode}
% \end{macro}
%
%
%
% \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}
%
% 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}
\cs_new:Npn \@@_wrap_multiple_document:nnnn #1 #2 #3 #4
{
\cs_set:Npn \@@_map_aux:n ##1
{
\cs_set:Nn \@@_Declarator: { \text_titlecase_first:n { ##1 } }
\@@_new_document_command:cnn { #2 } { #3 } { #4 }
}
\clist_map_function:nN { #1 } \@@_map_aux:n
}
% \end{macrocode}
% \end{macro}
%
%
%
%
%
%
% \begin{macro}{\NewFancyTheorem}
% \begin{macro}{\NewFancyTheorem, \ProvideFancyTheorem}
% \begin{syntax}
% \cs{NewFancyTheorem}\marg{key=value list}\marg{fancy theorem}
% \end{syntax}
@ -534,17 +602,62 @@
%
%
% \begin{macrocode}
\NewDocumentCommand { \NewFancyTheorem } { O{} m }
\@@_wrap_multiple_document:nnnn
{ new, provide }
{ \@@_Declarator: FancyTheorem }
{ O{} m }
{
\fancythm_new_theorem:nn { #1 } { #2 }
\use:c { fancythm_#1_theorem:nn } { ##1 } { ##2 }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%
%
% \subsection{Provided resources}
%
%
% We introduce various new theorem groups that help us to organize the document
% in a flexible way.
%
% \begin{variable}{star, dagger, big, small, tiny, custom}
%
%
% \begin{macrocode}
\groupthm_new_group:nnnnn { star } { } { * } { } { }
\groupthm_new_group:nnnnn { dagger } { } { $^{\dagger}$ } { } { }
\groupthm_new_group:nnnnn { big } { } { } { } { sibling = toplevel }
\groupthm_new_group:nnnnn { small } { } { } { } { sibling = sublevel }
\groupthm_new_group:nnnnn { tiny } { } { } { } { numbered = no }
\groupthm_new_group:nnnnn { custom } { } { } { } { sibling = sublevel }
% \end{macrocode}
% \end{variable}
%
%
% \begin{macrocode}
\groupthm_add_parent:nn { star } { custom }
\groupthm_add_parent:nn { dagger } { custom }
% \end{macrocode}
% \begin{macrocode}
\DeclareTheoremGroupRule [ suffix ] { dagger } { higher } { star }
\DeclareTheoremGroupRule { tiny } { higher } { small }
\DeclareTheoremGroupRule { tiny } { higher } { big }
\DeclareTheoremGroupRule { tiny } { higher } { custom }
\DeclareTheoremGroupRule { small } { higher } { big }
\DeclareTheoremGroupRule { custom } { higher } { big }
% \end{macrocode}
%
%
% It remains to provide a list of theorems at the beginning of the document.
%
%
%
%
% \begin{macrocode}
\AddToHook { begindocument / before } [ fancythm ]
{
\ProvideFancyTheorem [ group = big, style = thmgreenmargin ] { example }
}
% \end{macrocode}
%
%