implement family options

This commit is contained in:
Maximilian Keßler 2022-01-18 15:39:08 +01:00
parent 082c075ebb
commit 61f955c4aa
2 changed files with 441 additions and 3 deletions

View File

@ -1024,7 +1024,18 @@
% \end{macrocode} % \end{macrocode}
% %
% %
% % When the special \cs{AddTheoremToGroup} macro is issued outside a theorem family options
% body.
\begin{syntax}
\cs{msg_error:nn} \{ groupthm \}\{ misuse add theorem to group \}
\end{syntax}
% \begin{macrocode}
\msg_new:nnn { groupthm } { misuse ~ add ~ theorem ~ to ~ group }
{
Bad ~ usage ~ of ~ 'AddTheoremToGroup' ~ macro ~ outside ~ theorem ~
family ~ options ~ \msg_line_context:
}
% \end{macrocode}
% %
% \subsection{Allocation and initialization} % \subsection{Allocation and initialization}
% %
@ -1107,6 +1118,16 @@
% \end{macrocode} % \end{macrocode}
% \end{variable} % \end{variable}
% %
\begin{variable}{\l_@@_in_family_options_environment_bool}
% This variable indicates whether we are in the special environment
% used to parse a set of groups out of options given to a theorem
% family.
%
% This bool toggles the availability of the special \cs{AddTheoremToGroup} macro.
% \begin{macrocode}
\bool_new:N \l_@@_in_family_options_environment_bool
% \end{macrocode}
\end{variable}
% %
% %
% \subsection{Key interface} % \subsection{Key interface}
@ -2799,6 +2820,314 @@
% \end{macro} % \end{macro}
% %
% %
% \subsection{Theorem family options}
%
%
%
% \begin{macro}{\groupthm_add_theorem_to_group:n}
% \begin{syntax}
% \cs{groupthm_add_theorem_to_group:n}\marg{theorem group}
% \end{syntax}
%
%
% \begin{macrocode}
\cs_new:Npn \groupthm_add_theorem_to_group:n #1
{
% \end{macrocode}
% As mentioned earlier, this bool will indicate whether we are
% executing a \meta{selection body} from some family options.
% If used outside, we emit an error message.
% \begin{macrocode}
\bool_if:NTF \l_@@_in_family_options_environment_bool
{
\clist_put_left:Nn \l_@@_group_clist { #1 }
}
{
\msg_error:nn { groupthm } { misuse ~ add ~ theorem ~ to ~ group }
}
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_declare_theorem_family_options_aux:nnnnn}
% \begin{syntax}
% \c{@@_declare_theorem_family_options_aux:nnnnn}\marg{theorem family}
% \marg{argument specification}\marg{selection body}\marg{extra groups}\marg{declaring backend}
% \end{syntax}
%
% This declares a new theorem variant option parser, i.e.~ introduces the environment
% \meta{theorem family} with signature \marg{argument specification}.
%
% The \meta{selection body} will be executed and selects some groups the environment shall have.
% The \meta{extra groups} will be added regardless of the arguments given
% to the \meta{theorem family}
% The \meta{declaring backend} is one of \texttt{New}, \texttt{Renew}, \texttt{Provide}
% and \texttt{Declare} and is given to the \texttt{DocumentEnvironment} command from \pkg{xpars}.
%
% \begin{macrocode}
\cs_new:Npn \__declare_theorem_family_options_aux:nnnnnn #1 #2 #3 #4 #5 #6
{
\use:c{ #5 DocumentEnvironment }
{ #1 }
{ #2 }
{
% \end{macrocode}
% We can now clear the group list and execute the \meta{selection body}
% that populates this list again.
% Additionally, we add the groups that should always be present.
% \begin{macrocode}
\clist_clear:N \l_@@_group_clist
#3
\clist_put_right:NV \l_@@_group_clist { #4 }
% \end{macrocode}
% We now got the list of groups parsed. We sort this and start the corresponding
% environment that has been generated by a \cs{NewGroupedTheoremFamily} command
% or similar.
% \begin{macrocode}
\__sort_group_names:
\begin { __#1__groups_ \clist_use:Nn \l_@@_group_clist { _ } }
}
{
% \end{macrocode}
% At the end of the environment, we have to do the same parsing again.
% \begin{macrocode}
\clist_clear:N \l_@@_group_clist
#3
\clist_put_right:NV \l_@@_group_clist { #4 }
% \end{macrocode}
% End the corresponding environment.
% \begin{macrocode}
\__sort_group_names:
\end { __#1__groups_ \clist_use:Nn \l_@@_group_clist { _ } }
}
}
% \end{macrocode}
% \end{macro}
%
%
% All other macros are now essentially wrappers around this aux macro,
% passing different \meta{extra groups} to them
%
% \begin{macro}{\groupthm_new_grouped_theorem_family_options:nnnn}
% \begin{syntax}
% \cs{groupthm_new_grouped_theorem_family_options:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_new_grouped_theorem_family_options:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { New }
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\groupthm_renew_grouped_theorem_family_options:nnnn}
% \begin{syntax}
% \cs{groupthm_renew_grouped_theorem_family_options:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_renew_grouped_theorem_family_options:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Renew }
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\groupthm_provide_grouped_theorem_family_options:nnnn}
% \begin{syntax}
% \cs{groupthm_provide_grouped_theorem_family_options:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_provide_grouped_theorem_family_options:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Provide }
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\groupthm_declare_grouped_theorem_family_options:nnnn}
% \begin{syntax}
% \cs{groupthm_declare_grouped_theorem_family_options:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_declare_grouped_theorem_family_options:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Declare }
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\groupthm_new_grouped_theorem_family_options_star:nnnn}
% \begin{syntax}
% \cs{groupthm_new_grouped_theorem_family_options_star:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_new_grouped_theorem_family_options_star:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { unnumbered } { New }
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\groupthm_renew_grouped_theorem_family_options_star:nnnn}
% \begin{syntax}
% \cs{groupthm_renew_grouped_theorem_family_options_star:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_renew_grouped_theorem_family_options_star:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { unnumbered } { Renew }
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\groupthm_provide_grouped_theorem_family_options_star:nnnn}
% \begin{syntax}
% \cs{groupthm_provide_grouped_theorem_family_options_star:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_provide_grouped_theorem_family_options_star:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { unnumbered } { Provide }
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\groupthm_declare_grouped_theorem_family_options_star:nnnn}
% \begin{syntax}
% \cs{groupthm_declare_grouped_theorem_family_options_star:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
% \begin{macrocode}
\cs_new:Npn \groupthm_declare_grouped_theorem_family_options_star:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { unnumbered } { Declare }
}
% \end{macrocode}
% \end{macro}
%
%
%
% The variants without \enquote{grouped} in their name will just issue two commands,
% one with and one without the \texttt{starred} group, and add a \enquote{*} to the name.
%
% \begin{macro}{\groupthm_new_theorem_family_options:nnnn}
% \begin{syntax}
% \cs{groupthm_new_theorem_family_options:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
%
% \begin{macrocode}
\cs_new:Npn \groupthm_new_theorem_family_options:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { New }
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1* } { #2 } { #3 } { #4 } { starred } { New }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\groupthm_renew_theorem_family_options:nnnn}
% \begin{syntax}
% \cs{groupthm_renew_theorem_family_options:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
%
% \begin{macrocode}
\cs_new:Npn \groupthm_renew_theorem_family_options:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Renew }
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1* } { #2 } { #3 } { #4 } { starred } { Renew }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\groupthm_provide_theorem_family_options:nnnn}
% \begin{syntax}
% \cs{groupthm_provide_theorem_family_options:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
%
% \begin{macrocode}
\cs_new:Npn \groupthm_provide_theorem_family_options:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Provide }
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1* } { #2 } { #3 } { #4 } { starred } { Provide }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\groupthm_declare_theorem_family_options:nnnn}
% \begin{syntax}
% \cs{groupthm_declare_theorem_family_options:nnnn}\marg{theorem family}
% \marg{signature}\marg{selection body}
% \end{syntax}
%
%
% \begin{macrocode}
\cs_new:Npn \groupthm_declare_theorem_family_options:nnnn #1 #2 #3 #4
{
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Declare }
\@@_declare_theorem_family_options_aux:nnnnnn
{ #1* } { #2 } { #3 } { #4 } { starred } { Declare }
}
% \end{macrocode}
% \end{macro}
%
%
% It remains to wrap these into document commands
%
%
%
%
%
%
% %
% \begin{macrocode} % \begin{macrocode}
%</package> %</package>

View File

@ -50,6 +50,14 @@
{ {
Bad ~ definition ~ of ~ #1 ~ '#2' ~ \msg_line_context:, ~ #1 ~ is ~ #3 ~ defined. Bad ~ definition ~ of ~ #1 ~ '#2' ~ \msg_line_context:, ~ #1 ~ is ~ #3 ~ defined.
} }
\begin{syntax}
\cs{msg_error:nn} \{ groupthm \}\{ misuse add theorem to group \}
\end{syntax}
\msg_new:nnn { groupthm } { misuse ~ add ~ theorem ~ to ~ group }
{
Bad ~ usage ~ of ~ 'AddTheoremToGroup' ~ macro ~ outside ~ theorem ~
family ~ options ~ \msg_line_context:
}
\hook_new:n { __groupthm/prename } \hook_new:n { __groupthm/prename }
\hook_new:n { __groupthm/postname } \hook_new:n { __groupthm/postname }
\hook_new:n { __groupthm/mapname } \hook_new:n { __groupthm/mapname }
@ -69,6 +77,9 @@
\clist_new:N \l__groupthm_thmtools_clist \clist_new:N \l__groupthm_thmtools_clist
\clist_new:N \l__groupthm_group_clist \clist_new:N \l__groupthm_group_clist
\clist_new:N \g__groupthm_defined_theorem_groups_clist \clist_new:N \g__groupthm_defined_theorem_groups_clist
\begin{variable}{\l__groupthm_in_family_options_environment_bool}
\bool_new:N \l__groupthm_in_family_options_environment_bool
\end{variable}
\keys_define:nn { groupthm } \keys_define:nn { groupthm }
{ {
prename .tl_set:N = \l__groupthm_key_prename_tl, prename .tl_set:N = \l__groupthm_key_prename_tl,
@ -756,6 +767,104 @@
\groupthm_provide_theorem_family_from_keys:nn { #2 } { #3 } \groupthm_provide_theorem_family_from_keys:nn { #2 } { #3 }
} }
} }
\cs_new:Npn \groupthm_add_theorem_to_group:n #1
{
\bool_if:NTF \l__groupthm_in_family_options_environment_bool
{
\clist_put_left:Nn \l__groupthm_group_clist { #1 }
}
{
\msg_error:nn { groupthm } { misuse ~ add ~ theorem ~ to ~ group }
}
}
\cs_new:Npn \__declare_theorem_family_options_aux:nnnnnn #1 #2 #3 #4 #5 #6
{
\use:c{ #5 DocumentEnvironment }
{ #1 }
{ #2 }
{
\clist_clear:N \l__groupthm_group_clist
#3
\clist_put_right:NV \l__groupthm_group_clist { #4 }
\__sort_group_names:
\begin { __#1__groups_ \clist_use:Nn \l__groupthm_group_clist { _ } }
}
{
\clist_clear:N \l__groupthm_group_clist
#3
\clist_put_right:NV \l__groupthm_group_clist { #4 }
\__sort_group_names:
\end { __#1__groups_ \clist_use:Nn \l__groupthm_group_clist { _ } }
}
}
\cs_new:Npn \groupthm_new_grouped_theorem_family_options:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { New }
}
\cs_new:Npn \groupthm_renew_grouped_theorem_family_options:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Renew }
}
\cs_new:Npn \groupthm_provide_grouped_theorem_family_options:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Provide }
}
\cs_new:Npn \groupthm_declare_grouped_theorem_family_options:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Declare }
}
\cs_new:Npn \groupthm_new_grouped_theorem_family_options_star:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { unnumbered } { New }
}
\cs_new:Npn \groupthm_renew_grouped_theorem_family_options_star:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { unnumbered } { Renew }
}
\cs_new:Npn \groupthm_provide_grouped_theorem_family_options_star:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { unnumbered } { Provide }
}
\cs_new:Npn \groupthm_declare_grouped_theorem_family_options_star:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { unnumbered } { Declare }
}
\cs_new:Npn \groupthm_new_theorem_family_options:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { New }
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1* } { #2 } { #3 } { #4 } { starred } { New }
}
\cs_new:Npn \groupthm_renew_theorem_family_options:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Renew }
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1* } { #2 } { #3 } { #4 } { starred } { Renew }
}
\cs_new:Npn \groupthm_provide_theorem_family_options:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Provide }
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1* } { #2 } { #3 } { #4 } { starred } { Provide }
}
\cs_new:Npn \groupthm_declare_theorem_family_options:nnnn #1 #2 #3 #4
{
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1 } { #2 } { #3 } { #4 } { } { Declare }
\__groupthm_declare_theorem_family_options_aux:nnnnnn
{ #1* } { #2 } { #3 } { #4 } { starred } { Declare }
}
\endinput \endinput
%% %%
%% End of file `groupthm.sty'. %% End of file `groupthm.sty'.