From 61f955c4aad84a2ddcaaa2d029e449698ae5b0e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Tue, 18 Jan 2022 15:39:08 +0100 Subject: [PATCH] implement family options --- doc/environments/groupthm/groupthm.dtx | 335 ++++++++++++++++++++++++- doc/environments/groupthm/groupthm.sty | 109 ++++++++ 2 files changed, 441 insertions(+), 3 deletions(-) diff --git a/doc/environments/groupthm/groupthm.dtx b/doc/environments/groupthm/groupthm.dtx index 83e250e..551ae97 100644 --- a/doc/environments/groupthm/groupthm.dtx +++ b/doc/environments/groupthm/groupthm.dtx @@ -1023,8 +1023,19 @@ } % \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} % @@ -1106,7 +1117,17 @@ \clist_new:N \g_@@_defined_theorem_groups_clist % \end{macrocode} % \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} @@ -2799,7 +2820,315 @@ % \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} % % \end{macrocode} diff --git a/doc/environments/groupthm/groupthm.sty b/doc/environments/groupthm/groupthm.sty index 0de90f2..60076d4 100644 --- a/doc/environments/groupthm/groupthm.sty +++ b/doc/environments/groupthm/groupthm.sty @@ -50,6 +50,14 @@ { 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/postname } \hook_new:n { __groupthm/mapname } @@ -69,6 +77,9 @@ \clist_new:N \l__groupthm_thmtools_clist \clist_new:N \l__groupthm_group_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 } { prename .tl_set:N = \l__groupthm_key_prename_tl, @@ -756,6 +767,104 @@ \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 %% %% End of file `groupthm.sty'.