group generation and theorem generation working. not all keys implemented yet

This commit is contained in:
Maximilian Keßler 2022-01-16 13:48:25 +01:00
parent 274ce257d6
commit e92f1da165

View file

@ -6,75 +6,124 @@ __HEADER__(Grouping theorems for easier customization.)
\RequirePackage{amsthm}
\RequirePackage{thmtools}
\NewHook { groupthm / prename }
\NewHook { groupthm / postname }
\cs_new:Nn \declaretheorem:nn
{
\tl_show:n { #1 }
\declaretheorem [ #1 ] { #2 }
}
\cs_generate_variant:Nn \declaretheorem:nn {V V}
\cs_generate_variant:Nn \declaretheorem:nn {V V, V n}
\cs_new:Npn \store_group:nnnnn #1#2#3#4#5
{
\cs_new:cpn { retrieve_group_#1: }
{
\AddToHook { groupthm / prename } [ #1 ]
{
\tl_put_right:Nx \__name_str { #2 }
}
\AddToHook { groupthm / postname } [ #1 ]
{
\tl_put_right:Nx \__name_str { #3 }
}
% TODO: handle thmtools and mapname
}
}
\cs_new:Npn \retrieve_group:n #1
{
\use:c { retrieve_group_#1: }
}
\cs_generate_variant:Nn \store_group:nnnnn { n V V V V }
\keys_define:nn { groupthm / theoremgroup }
{
postname .tl_set:N = \l_groupthm_postname_tl,
prename .tl_set:N = \l_groupthm_prename_tl,
mapname .tl_set:N = \l_groupthm_mapname_tl,
thmtools .tl_set:N = \l_groupthm_thmtools_tl
prename .tl_set:N = \l_groupthm_prename_tl,
prename .default:n = \c_empty_tl,
postname .tl_set:N = \l_groupthm_postname_tl,
postname .default:n = \c_empty_tl,
mapname .clist_set:N = \l_groupthm_mapname_clist,
mapname .default:n = \c_empty_clist,
thmtools .clist_set:N = \l_groupthm_thmtools_clist,
thmtools .default:n = \c_empty_clist
}
\clist_new:N __PACKAGE_MACRO__(thmtools_args)
\NewDocumentCommand{\NewTheoremGroup}{ m o }
{
\keys_set:nn { groupthm / theoremgroup } { postname, prename, mapname, thmtools }
\IfValueT {#2}
{
\keys_set:nn { groupthm / theoremgroup } { #2 }
}
\store_group:nVVVV { #1 }
\l_groupthm_prename_tl
\l_groupthm_postname_tl
\l_groupthm_mapname_clist
\l_groupthm_thmtools_clist
}
\keys_define:nn { groupthm / groupedtheorem }
{
thmtools .clist_set:N = __PACKAGE_MACRO__(thmtools_args_clist),
thmtools .default:n = {},
group .clist_set:N = __PACKAGE_MACRO__(groups_clist),
group .default:n = {},
name .tl_set:N = __PACKAGE_MACRO__(theorem_name_tl),
name .default:n = \q_no_value
name .default:n = \c_novalue_tl
}
\NewDocumentCommand{\NewGroupedTheorem}{o m}
{
\keys_set:nn { groupthm / groupedtheorem } { #1 }
\RemoveFromHook
\UseHook
\keys_set:nn { groupthm / groupedtheorem } { name, group, thmtools }
\IfValueT {#1}
{
\keys_set:nn { groupthm / groupedtheorem } { #1 }
}
% Construct name
\str_new:N \__name_str
\str_set:Nx \__name_str
\tl_if_eq:NnTF __PACKAGE_MACRO__(theorem_name_tl) { \c_novalue_tl }
{
\quark_if_no_value:NTF __PACKAGE_MACRO__(theorem_name_tl)
\str_set:Nx \__name_str
{
\text_titlecase_first:n {#2}
}
}
{
\str_set:Nx \__name_str
{
\tl_use:N __PACKAGE_MACRO__(theorem_name_tl)
}
}
\tl_new:N \__name_tl
\tl_set:NV \__name_tl \__name_str
% Process groups here, adding to the hooks for prename, postname, mapname, thmtools
% mapname currently not implemented
\clist_map_function:NN __PACKAGE_MACRO__(groups_clist) \retrieve_group:n
% \clist_new:N __PACKAGE_MACRO__(mapname_clist)
% \clist_set:N
\str_put_left:Nx \__name_str
{
\UseHook { groupthm / prename }
}
\str_put_right:Nx \__name_str
{
\UseHook { groupthm / postname }
}
\hook_use:n { groupthm / prename }
\hook_use:n { groupthm / postname }
\declaretheorem:VV
\clist_put_right:Nx __PACKAGE_MACRO__(thmtools_args_clist)
{
__PACKAGE_MACRO__(thmtools_args_clist)
name = \str_use:N \__name_str
}
{ \__name_str }
\declaretheorem:Vn
{
__PACKAGE_MACRO__(thmtools_args_clist)
}
{ #2 }
}
\cs_new: