implement default groups and appending to groups

This commit is contained in:
Maximilian Keßler 2022-01-22 18:31:36 +01:00
parent 7ab693a7cb
commit ef930ed5fa
2 changed files with 98 additions and 17 deletions

View file

@ -63,14 +63,9 @@
% \newpage % \newpage
% %
% \begin{itemize} % \begin{itemize}
% \item Inheritance % \item appending to groups
% \item Appending to groups
% \item default group integration
% \item better error message to avoid low level tex errors in any case
% \item potentially: detection of star / nonstar misuse % \item potentially: detection of star / nonstar misuse
% \item add command to define group rule for all existing groups % \item add command to define group rule for all existing groups
% \item various info commands on defined groups?
% \item debugging information?
% \end{itemize} % \end{itemize}
% A central thing in \LaTeX is the usage of \enquote{theorems}. % A central thing in \LaTeX is the usage of \enquote{theorems}.
% With \enquote{theorems} we actually mean \enquote{environments} that typically % With \enquote{theorems} we actually mean \enquote{environments} that typically
@ -1169,6 +1164,14 @@
\bool_new:N \l_@@_in_family_options_environment_bool \bool_new:N \l_@@_in_family_options_environment_bool
% \end{macrocode} % \end{macrocode}
% \end{variable} % \end{variable}
% \begin{variable}{\g_@@_append_groups_int}
%
% This counts the number of times we appended to a group.
%
% \begin{macrocode}
\int_new:N \g_@@_append_groups_int
% \end{macrocode}
% \end{variable}
% %
% %
% \subsection{Key interface} % \subsection{Key interface}
@ -1450,9 +1453,15 @@
% \end{macrocode} % \end{macrocode}
% \begin{variable}{ \g_@@_parents_group__\meta{theorem group}__clist } % \begin{variable}{ \g_@@_parents_group__\meta{theorem group}__clist }
% %
% This variable will accumulate the parents of this group: % This variable will accumulate the parents of this group.
% \begin{macrocode} % \begin{macrocode}
\clist_new:c { g_@@_parents_group__#1__clist } \clist_new:c { g_@@_parents_group__#1__clist }
% \begin{macrocode}
% This ensures default priorities between groups.
% \end{macrocode}
\hook_gset_rule:nnnn { ?? } { all } { before } { #1 }
\hook_gset_rule:nnnn { ?? } { unnumbered } { after } { #1 }
\hook_gset_rule:nnnn { ?? } { starred } { after } { #1 }
% \end{macrocode} % \end{macrocode}
% \end{variable} % \end{variable}
% Add defined group to corresponding list % Add defined group to corresponding list
@ -1782,6 +1791,7 @@
\l_@@_thmtools_clist \l_@@_thmtools_clist
} }
% \end{macrocode} % \end{macrocode}
\cs_generate_variant:Nn \groupthm_new_group:nn { n x }
% \end{macro} % \end{macro}
% %
% %
@ -1850,20 +1860,21 @@
\str_set:Nx \l_tmpa_str { \tl_trim_spaces:n { #3 } } \str_set:Nx \l_tmpa_str { \tl_trim_spaces:n { #3 } }
\str_if_eq:VnT \l_tmpa_str { higher } \str_if_eq:VnT \l_tmpa_str { higher }
{ {
\str_set:Nn \l_tmpa_tl { after } \str_set:Nn \l_tmpa_str { after }
} }
\str_if_eq:VnT \l_tmpa_str { lower } \str_if_eq:VnT \l_tmpa_str { lower }
{ {
\str_set:Nn \l_tmpa_tl { before } \str_set:Nn \l_tmpa_str { before }
} }
\str_if_eq:nnTF { #1 } { ?? } \str_if_eq:nnTF { #1 } { ?? }
{ {
\hook_gset_rule:nnVn {??} {#2} \l_tmpa_tl {#4} \hook_gset_rule:nnVn {??} {#2} \l_tmpa_str {#4}
} }
{ {
\hook_gset_rule:nnVn { @@ / #1 } {#2} \l_tmpa_tl {#4} \hook_gset_rule:nnVn { @@ / #1 } {#2} \l_tmpa_str {#4}
} }
} }
\cs_generate_variant:Nn \groupthm_declare_group_rule:nnnn { n n n x }
% \end{macrocode} % \end{macrocode}
% \end{macro} % \end{macro}
@ -1897,6 +1908,7 @@
\@@_ensure_group_exists:n { #2 } \@@_ensure_group_exists:n { #2 }
\clist_gput_left:cn { g_@@_parents_group__#1__clist } { #2 } \clist_gput_left:cn { g_@@_parents_group__#1__clist } { #2 }
} }
\cs_generate_variant:Nn \groupthm_add_parent:nn { n x }
% \end{macrocode} % \end{macrocode}
% \end{macro} % \end{macro}
% %
@ -1965,6 +1977,51 @@
% \end{macrocode} % \end{macrocode}
% \end{macro} % \end{macro}
% %
% \begin{macro}{\groupthm_append_to_group:nn}
% \begin{syntax}
% \cs{groupthm_append_to_group:nn}\marg{key=value list}\marg{theorem group}
% \end{syntax}
%
% This works the same as defining a new group, except that we append to the group,
% overwriting the old group in case of conflicts.
%
% \begin{macrocode}
\cs_new:Npn \groupthm_append_to_group:nn #1 #2
{
\groupthm_new_group:nx { #1 } { __append__ \int_use:N \g_@@_append_groups_int }
\groupthm_add_parent:nx { #2 } { __append__ \int_use:N \g_@@_append_groups_int }
\groupthm_declare_group_rule:nnnx
{ ?? } { #2 } { before } { __append__ \int_use:N \g_@@_append_groups_int }
\int_gincr:N \g_@@_append_groups_int
}
% \end{macrocodel}
% \end{macro}
%
% \begin{macro}{\AppendToTheoremGroup}
% \begin{syntax}
% \cs{AppendToTheoremGroup} \marg{key=value list}\marg{theorem group}
% \end{syntax}
%
%
%
% \begin{macrocode}
\NewDocumentCommand { \AppendToTheoremGroup } { O{} m }
{
\groupthm_append_to_group:nn { #1 } { #2 }
}
% \end{macrocode}
% \end{macro}
% We also provide the three default groups:
%
% \begin{macrocode}
\groupthm_new_group:nnnnn { all } { } { } { } { }
\groupthm_new_group:nnnnn { starred } { } { } { } { numbered = no }
\groupthm_new_group:nnnnn { unnumbered } { } { } { } { numbered = no }
% \end{macrocode}
% %
% \subsection{Iterating over powersets} % \subsection{Iterating over powersets}
% For generating the different variants of a theorem family, % For generating the different variants of a theorem family,
@ -2120,7 +2177,7 @@
% \end{macrocode} % \end{macrocode}
% Now, retrieve the group properties, by writing these into the hooks % Now, retrieve the group properties, by writing these into the hooks
% \begin{macrocode} % \begin{macrocode}
\@@_flatten_groups_hierarchy:nN { #2 } \l_@@_group_clist \@@_flatten_groups_hierarchy:nN { #2, all } \l_@@_group_clist
\clist_map_function:NN \l_@@_group_clist \@@_use_group:n \clist_map_function:NN \l_@@_group_clist \@@_use_group:n
\tl_log:x { Flattened ~ groups ~ '#2' ~ to ~ '\clist_use:Nn \l_@@_group_clist {,}' ~ when ~ \tl_log:x { Flattened ~ groups ~ '#2' ~ to ~ '\clist_use:Nn \l_@@_group_clist {,}' ~ when ~
defining ~ theorem ~ '#1' } defining ~ theorem ~ '#1' }

View file

@ -87,6 +87,7 @@
\clist_new:N \l__groupthm_group_clist \clist_new:N \l__groupthm_group_clist
\clist_new:N \g__groupthm_defined_groups_clist \clist_new:N \g__groupthm_defined_groups_clist
\bool_new:N \l__groupthm_in_family_options_environment_bool \bool_new:N \l__groupthm_in_family_options_environment_bool
\int_new:N \g__groupthm_append_groups_int
\keys_define:nn { groupthm / theorem ~ group } \keys_define:nn { groupthm / theorem ~ group }
{ {
prefix .tl_set:N = \l__groupthm_key_prefix_tl, prefix .tl_set:N = \l__groupthm_key_prefix_tl,
@ -215,6 +216,9 @@
} }
\__groupthm_add_to_group_ordering:n { #1 } \__groupthm_add_to_group_ordering:n { #1 }
\clist_new:c { g__groupthm_parents_group__#1__clist } \clist_new:c { g__groupthm_parents_group__#1__clist }
\hook_gset_rule:nnnn { ?? } { all } { before } { #1 }
\hook_gset_rule:nnnn { ?? } { unnumbered } { after } { #1 }
\hook_gset_rule:nnnn { ?? } { starred } { after } { #1 }
\clist_gput_left:Nn \g__groupthm_defined_groups_clist { #1 } \clist_gput_left:Nn \g__groupthm_defined_groups_clist { #1 }
} }
\cs_new:Npn \__groupthm_undefine_group:n #1 \cs_new:Npn \__groupthm_undefine_group:n #1
@ -361,6 +365,7 @@
\l__groupthm_mapname_clist \l__groupthm_mapname_clist
\l__groupthm_thmtools_clist \l__groupthm_thmtools_clist
} }
\cs_generate_variant:Nn \groupthm_new_group:nn { n x }
\cs_new:Npn \__groupthm_new_document_command:Nnn #1 #2 #3 \cs_new:Npn \__groupthm_new_document_command:Nnn #1 #2 #3
{ {
\NewDocumentCommand { #1 } { #2 } { #3 } \NewDocumentCommand { #1 } { #2 } { #3 }
@ -387,20 +392,21 @@
\str_set:Nx \l_tmpa_str { \tl_trim_spaces:n { #3 } } \str_set:Nx \l_tmpa_str { \tl_trim_spaces:n { #3 } }
\str_if_eq:VnT \l_tmpa_str { higher } \str_if_eq:VnT \l_tmpa_str { higher }
{ {
\str_set:Nn \l_tmpa_tl { after } \str_set:Nn \l_tmpa_str { after }
} }
\str_if_eq:VnT \l_tmpa_str { lower } \str_if_eq:VnT \l_tmpa_str { lower }
{ {
\str_set:Nn \l_tmpa_tl { before } \str_set:Nn \l_tmpa_str { before }
} }
\str_if_eq:nnTF { #1 } { ?? } \str_if_eq:nnTF { #1 } { ?? }
{ {
\hook_gset_rule:nnVn {??} {#2} \l_tmpa_tl {#4} \hook_gset_rule:nnVn {??} {#2} \l_tmpa_str {#4}
} }
{ {
\hook_gset_rule:nnVn { __groupthm / #1 } {#2} \l_tmpa_tl {#4} \hook_gset_rule:nnVn { __groupthm / #1 } {#2} \l_tmpa_str {#4}
} }
} }
\cs_generate_variant:Nn \groupthm_declare_group_rule:nnnn { n n n x }
\NewDocumentCommand { \DeclareTheoremGroupRule } { O{??} m m m } \NewDocumentCommand { \DeclareTheoremGroupRule } { O{??} m m m }
{ {
@ -412,6 +418,7 @@
\__groupthm_ensure_group_exists:n { #2 } \__groupthm_ensure_group_exists:n { #2 }
\clist_gput_left:cn { g__groupthm_parents_group__#1__clist } { #2 } \clist_gput_left:cn { g__groupthm_parents_group__#1__clist } { #2 }
} }
\cs_generate_variant:Nn \groupthm_add_parent:nn { n x }
\NewDocumentCommand { \AddTheoremGroupParent } { m m } \NewDocumentCommand { \AddTheoremGroupParent } { m m }
{ {
\groupthm_add_parent:nn { #1 } { #2 } \groupthm_add_parent:nn { #1 } { #2 }
@ -440,6 +447,23 @@
} }
} }
} }
\cs_new:Npn \groupthm_append_to_group:nn #1 #2
{
\groupthm_new_group:nx { #1 } { __append__ \int_use:N \g__groupthm_append_groups_int }
\groupthm_add_parent:nx { #2 } { __append__ \int_use:N \g__groupthm_append_groups_int }
\groupthm_declare_group_rule:nnnx
{ ?? } { #2 } { before } { __append__ \int_use:N \g__groupthm_append_groups_int }
\int_gincr:N \g__groupthm_append_groups_int
}
\NewDocumentCommand { \AppendToTheoremGroup } { O{} m }
{
\groupthm_append_to_group:nn { #1 } { #2 }
}
\groupthm_new_group:nnnnn { all } { } { } { } { }
\groupthm_new_group:nnnnn { starred } { } { } { } { numbered = no }
\groupthm_new_group:nnnnn { unnumbered } { } { } { } { numbered = no }
\clist_new:N \l__powerset_copied_clist \clist_new:N \l__powerset_copied_clist
\seq_new:N \l__powerset_saved_seq \seq_new:N \l__powerset_saved_seq
\cs_generate_variant:Nn \clist_remove_all:Nn { N V } \cs_generate_variant:Nn \clist_remove_all:Nn { N V }
@ -505,7 +529,7 @@
\hook_gremove_code:nn { __groupthm/suffix }{*} \hook_gremove_code:nn { __groupthm/suffix }{*}
\hook_gremove_code:nn { __groupthm/mapname }{*} \hook_gremove_code:nn { __groupthm/mapname }{*}
\hook_gremove_code:nn { __groupthm/thmtools }{*} \hook_gremove_code:nn { __groupthm/thmtools }{*}
\__groupthm_flatten_groups_hierarchy:nN { #2 } \l__groupthm_group_clist \__groupthm_flatten_groups_hierarchy:nN { #2, all } \l__groupthm_group_clist
\clist_map_function:NN \l__groupthm_group_clist \__groupthm_use_group:n \clist_map_function:NN \l__groupthm_group_clist \__groupthm_use_group:n
\tl_log:x { Flattened ~ groups ~ '#2' ~ to ~ '\clist_use:Nn \l__groupthm_group_clist {,}' ~ when ~ \tl_log:x { Flattened ~ groups ~ '#2' ~ to ~ '\clist_use:Nn \l__groupthm_group_clist {,}' ~ when ~
defining ~ theorem ~ '#1' } defining ~ theorem ~ '#1' }