summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2024-10-05 19:36:34 +0000
committerKarl Berry <karl@freefriends.org>2024-10-05 19:36:34 +0000
commit1348801ecf56dfcae71868ed3f77bb14b648fea8 (patch)
treee9ae7b0b09328e47e3542f0d3aaf325041e7b169 /Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty
parentd177e698d4d64891fa1a04c97b8909b78f359825 (diff)
keytheorems (5oct24)
git-svn-id: svn://tug.org/texlive/trunk@72470 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty')
-rw-r--r--Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty205
1 files changed, 138 insertions, 67 deletions
diff --git a/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty b/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty
index 7059d951a0a..00781a8e143 100644
--- a/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty
+++ b/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty
@@ -2,7 +2,7 @@
% Please report all issues and feature requests at https://github.com/mbertucci47/keytheorems
% This work is licensed under the LPPL version 1.3c or later: https://www.latex-project.org/lppl.txt
\NeedsTeXFormat{LaTeX2e}[2023-06-01]
-\ProvidesExplPackage{keytheorems}{2024-09-30}{0.1.5}{l3keys interface to amsthm}
+\ProvidesExplPackage{keytheorems}{2024-10-05}{0.1.6}{l3keys interface to amsthm}
\IfFormatAtLeastTF { 2024-06-01 } { }
{
@@ -18,6 +18,8 @@
{ \IfPackageLoadedTF{#1}{ }{#2} }
\ProvideDocumentCommand \IfClassLoadedT { m m }
{ \IfClassLoadedTF{#1}{#2}{ } }
+ \ProvideDocumentCommand \IfClassLoadedWithOptionsT { m m m }
+ { \IfClassLoadedWithOptionsTF{#1}{#2}{#3}{ } }
}
\RequirePackage{aliascnt}
\RequirePackage{amsthm} % ams classes have way of ignoring this
@@ -91,6 +93,11 @@
Theorem~style~'#1'~already~defined.~
Use~\protect\renewkeytheoremstyle\space instead.
}
+\msg_new:nnn { keytheorems } { thm-undefined }
+ {
+ Command~\c_backslash_str #1~undefined.~
+ Use~\protect\newkeytheorem\space instead.
+ }
\msg_new:nnn { keytheorems } { title-code-with-AMS }
{
The~'title-code'~key~has~no~effect~with~an~AMS~class.
@@ -154,7 +161,7 @@
{ unnumbered.\arabic{keythms_unnumbered_dummyctr} }
\cs_gset:Npn \thekeythms_unnumbered_dummyctr { }
-\cs_generate_variant:Nn \hook_gput_code:nnn { nnV }
+\cs_generate_variant:Nn \hook_gput_code:nnn { nnv }
\cs_generate_variant:Nn \keys_precompile:nnN { nv, nVc, nnc, ne }
%%%%%%%%%%%%%%
@@ -197,11 +204,12 @@
headstyle / margin .code:n =
{
\cs_set:Nn \keythms_thmstyle_headcmd:nnn
- { \makebox[0pt][r]{\NUMBER\ }\NAME\NOTE }
+ { \makebox[0pt][r]{\thmnumber{ ##2 ~ }}\NAME\NOTE }
},
headstyle / swapnumber .code:n =
{
- \cs_set:Nn \keythms_thmstyle_headcmd:nnn { \NUMBER\ \NAME\NOTE }
+ \cs_set:Nn \keythms_thmstyle_headcmd:nnn
+ { \thmnumber{ ##2 ~ }\NAME\NOTE }
},
headstyle / unknown .cs_set:Np = \keythms_thmstyle_headcmd:nnn #1#2#3,
inherit-style .choice:,
@@ -504,7 +512,25 @@
\clist_map_inline:nn { #1 } % define multiple theorems at once
{ \keythms_thm_newkeythm:nn { ##1 } { #2 } }
}
+\NewDocumentCommand \renewkeytheorem { m O{} }
+ { % #1 = name, #2 = keys
+ \clist_map_inline:nn { #1 }
+ { \keythms_thm_renewkeythm:nn { ##1 } { #2 } }
+ }
+\NewDocumentCommand \providekeytheorem { m O{} }
+ { % #1 = name, #2 = keys
+ \clist_map_inline:nn { #1 }
+ { \keythms_thm_providekeythm:nn { ##1 } { #2 } }
+ }
+\NewDocumentCommand \declarekeytheorem { m O{} }
+ { % #1 = name, #2 = keys
+ \clist_map_inline:nn { #1 }
+ { \keythms_thm_declarekeythm:nn { ##1 } { #2 } }
+ }
\@onlypreamble \newkeytheorem
+\@onlypreamble \renewkeytheorem
+\@onlypreamble \providekeytheorem
+\@onlypreamble \declarekeytheorem
% to prevent error when plain, remark, or definition style used
\tl_new:N \l__keythms_thmstyle_plain_savedthmkeys_tl
@@ -515,6 +541,12 @@
{ % #1 = name, #2 = keys
% Store envname
\tl_set:Nn \l__keythms_thm_envname_tl { #1 }
+ % Set up tl's for hooks; hooks will be created and added to at begindocument
+ \tl_gclear_new:c { g__keythms_thm_preheadfromkeys_#1_tl }
+ \tl_gclear_new:c { g__keythms_thm_postheadfromkeys_#1_tl }
+ \tl_gclear_new:c { g__keythms_thm_prefootfromkeys_#1_tl }
+ \tl_gclear_new:c { g__keythms_thm_postfootfromkeys_#1_tl }
+ \tl_gclear_new:c { g__keythms_thm_tcbpatch_#1_tl }
% Make unless-unique false by default (can't precompile this)
\bool_set_false:N \l__keythms_thm_unlessunique_bool
% Set default keys
@@ -538,30 +570,11 @@
}
% Set env-specific keys
\keys_set:nn { keytheorems/thm } { #2 }
- % Set up env-specific hooks
- \__keythms_thm_makethmhooks:n { #1 }
- % Add to env-specific hooks (use label so code given in keys is outermost)
- % NOTE: faster to check if empty than add empty code to hook
- \tl_if_empty:NF \l__keythms_thm_preheadhook_tl
- {
- \hook_gput_code:nnV { keytheorems/#1/prehead }
- { keythms_hook_keys } \l__keythms_thm_preheadhook_tl
- }
- \tl_if_empty:NF \l__keythms_thm_postheadhook_tl
- {
- \hook_gput_code:nnV { keytheorems/#1/posthead }
- { keythms_hook_keys } \l__keythms_thm_postheadhook_tl
- }
- \tl_if_empty:NF \l__keythms_thm_prefoothook_tl
- {
- \hook_gput_code:nnV { keytheorems/#1/prefoot }
- { keythms_hook_keys } \l__keythms_thm_prefoothook_tl
- }
- \tl_if_empty:NF \l__keythms_thm_postfoothook_tl
- {
- \hook_gput_code:nnV { keytheorems/#1/postfoot }
- { keythms_hook_keys } \l__keythms_thm_postfoothook_tl
- }
+ % Build tl for env-specific hooks; will be added to hooks at begindocument
+ \tl_gput_right:cV { g__keythms_thm_preheadfromkeys_#1_tl } \l__keythms_thm_preheadhook_tl
+ \tl_gput_right:cV { g__keythms_thm_postheadfromkeys_#1_tl } \l__keythms_thm_postheadhook_tl
+ \tl_gput_right:cV { g__keythms_thm_prefootfromkeys_#1_tl } \l__keythms_thm_prefoothook_tl
+ \tl_gput_right:cV { g__keythms_thm_postfootfromkeys_#1_tl } \l__keythms_thm_postfoothook_tl
% Set name if none given
\quark_if_no_value:NT \l__keythms_thm_name_tl % use quark so name={} is valid
{
@@ -580,8 +593,8 @@
\RequirePackage[unq]{unique}
\tl_if_empty:NTF \l__keythms_thm_parent_tl
{
- \hook_gput_code:nnn { keytheorems/#1/prehead }
- { keythms_hook_keys } { \setuniqmark { #1 } }
+ \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_#1_tl }
+ { \setuniqmark { #1 } }
\ifuniq{ #1 }
{ \bool_set_false:N \l__keythms_thm_numbered_bool }
{ \bool_set_true:N \l__keythms_thm_numbered_bool }
@@ -600,7 +613,7 @@
}
{
\__keythms_thm_new_unnumbered:nV { #1 } \l__keythms_thm_name_tl
- \hook_gput_code:nnn { keytheorems/#1/prehead } { keythms_hook_keys }
+ \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_#1_tl }
{
\keythms_if_restating:F
{ \refstepcounter{ keythms_unnumbered_dummyctr } }
@@ -635,7 +648,7 @@
}
{
\__keythms_thm_new_unnumbered:nV { #1 } \l__keythms_thm_name_tl
- \hook_gput_code:nnn { keytheorems/#1/prehead } { keythms_hook_keys }
+ \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_#1_tl }
{
\keythms_if_restating:F
{ \refstepcounter{ keythms_unnumbered_dummyctr } }
@@ -672,11 +685,27 @@
{ \__keythms_theoremstyle:V \l__keythms_thm_currentthmstyle_tl }
}
-\cs_new_protected:Npn \__keythms_thm_tcboxcode:nn #1#2
+\hook_gput_code:nnn { begindocument } { . }
{
+ \prop_map_inline:Nn \g__keythms_thmnames_prop
+ {
+ \__keythms_thm_makethmhooks:n { #1 }
+ \clist_map_inline:nn { prehead, posthead, prefoot, postfoot }
+ {
+ \tl_if_empty:cF { g__keythms_thm_##1fromkeys_#1_tl }
+ {
+ \hook_gput_code:nnv { keytheorems/#1/##1 } { keythms_hook_keys }
+ { g__keythms_thm_##1fromkeys_#1_tl }
+ }
+ }
+ \tl_use:c { g__keythms_thm_tcbpatch_#1_tl }
+ }
+ }
+
+\cs_new_protected:Npn \__keythms_thm_tcboxcode:nn #1#2
+ { % #1 = name, #2 = tcolorbox keys
\RequirePackage{tcolorbox}
- \hook_gput_code:nnn { keytheorems/#1/prehead }
- { keythms_tcbox }
+ \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_#1_tl }
{
\cs_set_eq:NN \deferred@thm@head \__keythms_thm_storedeferredthmhead:n
\cs_set_eq:NN \Hy@theorem@makelinktarget \use_none:n
@@ -686,23 +715,18 @@
\cs_set_protected:Npn \thm@space@setup { \thm@preskip=0pt \thm@postskip=0pt }
% ^ to match tcolorbox defaults; shouldn't interfere with user styles
}
- \hook_gset_rule:nnnn { keytheorems/#1/posthead }
- { keythms_tcbox } { before } { keythms_hook_keys }
- \hook_gset_rule:nnnn { keytheorems/#1/prefoot }
- { keythms_tcbox } { after } { keythms_hook_keys }
- \hook_gset_rule:nnnn { keytheorems/#1/prefoot }
- { keythms_tcbox } { after } { keythms_qed }
\tcbset
{
keythms_tcbox_#1/.style =
{
savedelimiter=#1,
title={ \__keythms_thm_tcboxtemphead: },
+ #2
}
}
\bool_if:NT \l__keythms_thm_numbered_bool
{
- \hook_gput_code:nnn { begindocument } { . }
+ \tl_gset:cn { g__keythms_thm_tcbpatch_#1_tl }
{
\IfPackageLoadedF{cleveref}
{ % hyperref doesn't patch \@thm if cleveref loaded
@@ -714,27 +738,69 @@
}
}
}
- \hook_gput_code:nnn { keytheorems/#1/posthead } { keythms_tcbox }
- { \begin{tcolorbox}[keythms_tcbox_#1,#2] }
- \hook_gput_code:nnn { keytheorems/#1/prefoot } { keythms_tcbox }
+ \tl_gput_left:cn { g__keythms_thm_postheadfromkeys_#1_tl }
+ { \begin{tcolorbox}[keythms_tcbox_#1] }
+ \tl_gput_right:cn { g__keythms_thm_prefootfromkeys_#1_tl }
{ \end{tcolorbox} }
}
\cs_new_protected:Npn \__keythms_thm_qedcode:nn #1#2
- {
- \hook_gput_code:nnn { keytheorems/#1/posthead }
- { keythms_qed }
+ { % #1 = name, #2 = symbol
+ \tl_gput_right:cn { g__keythms_thm_postheadfromkeys_#1_tl }
{
\exp_args:No \tl_if_novalue:nF { #2 } { \protected@edef\qedsymbol{#2} }
\pushQED{\qed}
}
- \hook_gput_code:nnn { keytheorems/#1/prefoot }
- { keythms_qed }
+ \tl_gput_left:cn { g__keythms_thm_prefootfromkeys_#1_tl }
{
\exp_args:No \tl_if_novalue:nF { #2 } { \protected@edef\qedsymbol{#2} }
\popQED
}
}
+\cs_new_protected:Npn \__keythms_nocheck_removefromreset:nn #1#2
+ { % need to fake @ckpt counter
+ \group_begin:
+ \cs_if_exist:cF { c@#2 } { \cs_set:cpn { c@#2 } { } }
+ \@removefromreset{#1}{#2}
+ \group_end:
+ }
+
+\cs_new_protected:Npn \keythms_thm_renewkeythm:nn #1#2
+ { % #1 = name, #2 = keys
+ \cs_if_exist:cTF { #1 }
+ {
+ \cs_undefine:c { #1 }
+ \cs_undefine:c { c@ #1 }
+ \cs_undefine:c { the #1 }
+ \tl_if_exist:cT { g__keythms_thm_#1_parent_tl }
+ { % remove parent counter binding
+ \exp_args:Nnv \@removefromreset { #1 } { g__keythms_thm_#1_parent_tl }
+ }
+ \__keythms_nocheck_removefromreset:nn { #1 } { @ckpt }
+ \keythms_thm_newkeythm:nn { #1 } { #2 }
+ }
+ { \msg_error:nnn { keytheorems } { thm-undefined} { #1 } }
+ }
+\cs_new_protected:Npn \keythms_thm_providekeythm:nn #1#2
+ { % #1 = name, #2 = keys
+ \cs_if_free:cT { #1 }
+ {
+ \keythms_thm_newkeythm:nn { #1 } { #2 }
+ }
+ }
+\cs_new_protected:Npn \keythms_thm_declarekeythm:nn #1#2
+ { % #1 = name, #2 = keys
+ \cs_undefine:c { #1 }
+ \cs_undefine:c { c@ #1 }
+ \cs_undefine:c { the #1 }
+ \tl_if_exist:cT { g__keythms_thm_#1_parent_tl }
+ { % remove parent counter binding
+ \exp_args:Nnv \@removefromreset { #1 } { g__keythms_thm_#1_parent_tl }
+ }
+ \__keythms_nocheck_removefromreset:nn { #1 } { @ckpt }
+ \keythms_thm_newkeythm:nn { #1 } { #2 }
+ }
+
\cs_new_eq:NN \__keythms_theoremstyle:n \theoremstyle
\cs_generate_variant:Nn \__keythms_theoremstyle:n { V }
@@ -749,7 +815,12 @@
\cs_generate_variant:Nn \__keythms_thm_new_unnumbered:nn { nV }
\cs_new_protected:Npn \__keythms_thm_new_parent:nnn #1#2#3
- { \__keythms_thm_new:w { #1 } { #2 } [ #3 ] }
+ {
+ % for \renewkeytheorem need to know parent key if set
+ \tl_gclear_new:c { g__keythms_thm_#1_parent_tl }
+ \tl_gset:cn { g__keythms_thm_#1_parent_tl } { #3 }
+ \__keythms_thm_new:w { #1 } { #2 } [ #3 ]
+ }
\cs_generate_variant:Nn \__keythms_thm_new_parent:nnn { nVV }
\cs_new_protected:Npn \__keythms_thm_new_sibling:nnn #1#2#3
@@ -769,6 +840,9 @@
{
\keythms_if_restating:F
{ \refstepcounter{ keythms_unnumbered_dummyctr } }
+ \IfPackageLoadedT { tcolorbox }
+ { \tcbset{keythms_tcbox_#1/.append~style=nophantom} }
+ % ^ otherwise we try to set two identical anchors
\begin{keythms_orig_nonumber_#1}
}
{
@@ -1000,7 +1074,7 @@
{ #1 }
}
}
- }
+ }
}
}
\cs_new:Npn \__keythms_use_iii_v_braced:nnnnn #1#2#3#4#5 { {#3}{#5} }
@@ -1110,7 +1184,7 @@
}
}
\cs_new_protected:Npn \__keythms_thm_addstoredreverseddata:nnn #1#2#3
- {
+ { % #1 = theorem name, #2 = keys, #3 = body
\iow_shipout:Ne \@auxout
{
\exp_not:N \@writefile { thlist }
@@ -1927,7 +2001,7 @@
\ProvideDocumentEnvironment { restatable } { O{} m m }
{ % need to redefine this to add store to thlist since we set it outside env
\cs_set_protected:Npn \__keythms_thm_addcontentsdata:nnnn ####1####2####3####4
- { % #1 = theorem name, #2 = stored counters, #3 = keys, #4 = body
+ { % ####1 = theorem name, ####2 = stored counters, ####3 = keys, ####4 = body
\keythms_listof_chaptervspacehack:
\iow_shipout:Ne \@auxout
{
@@ -1959,7 +2033,7 @@
\ProvideDocumentEnvironment { restatable* } { O{} m m }
{ % need to redefine this to add store* to thlist since we set it outside env
\cs_set_protected:Npn \__keythms_thm_addstoredreverseddata:nnn ####1####2####3
- {
+ { % ####1 = theorem name, ####2 = keys, ####3 = body
\iow_shipout:Ne \@auxout
{
\exp_not:N \@writefile { thlist }
@@ -2063,32 +2137,27 @@
nocut .meta:n = { cut=false },
thickness .code:n =
{ % could also add keys to clist with changed dimens; which is better?
- \hook_gput_code:nnn { keytheorems/\l__keythms_thm_envname_tl/prehead }
- { keythms_tcbox }
+ \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_ \l__keythms_thm_envname_tl _tl }
{ \dim_set:Nn \l_keythms_tcbthmbox_thickness_dim { ##1 } }
},
leftmargin .code:n =
{
- \hook_gput_code:nnn { keytheorems/\l__keythms_thm_envname_tl/prehead }
- { keythms_tcbox }
+ \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_ \l__keythms_thm_envname_tl _tl }
{ \dim_set:Nn \l_keythms_tcbthmbox_leftmargin_dim { ##1 } }
},
rightmargin .code:n =
{
- \hook_gput_code:nnn { keytheorems/\l__keythms_thm_envname_tl/prehead }
- { keythms_tcbox }
+ \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_ \l__keythms_thm_envname_tl _tl }
{ \dim_set:Nn \l_keythms_tcbthmbox_rightmargin_dim { ##1 } }
},
hskip .code:n =
{
- \hook_gput_code:nnn { keytheorems/\l__keythms_thm_envname_tl/prehead }
- { keythms_tcbox }
+ \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_ \l__keythms_thm_envname_tl _tl }
{ \dim_set:Nn \l_keythms_tcbthmbox_hskip_dim { ##1 } }
},
vskip .code:n =
{
- \hook_gput_code:nnn { keytheorems/\l__keythms_thm_envname_tl/prehead }
- { keythms_tcbox }
+ \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_ \l__keythms_thm_envname_tl _tl }
{ \dim_set:Nn \l_keythms_tcbthmbox_vskip_dim { ##1 } }
},
}
@@ -2297,8 +2366,9 @@
}
\keys_define:nn { keytheorems/thmstyle }
{
- shaded .code:n = \keythms_thmstyle_savethmkey_optval:n { ##1 },
- thmbox .code:n = \keythms_thmstyle_savethmkey_optval:n { ##1 },
+ shaded .code:n = \keythms_thmstyle_savethmkey_optval:n { ##1 },
+ thmbox .code:n = \keythms_thmstyle_savethmkey_optval:n { ##1 },
+ mdframed .code:n = \msg_error:nn { keytheorems } { mdframed-undefined },
}
}
@@ -2390,6 +2460,7 @@
\keythms_support_check:n { amsart }
\keythms_support_check:n { amsbook }
\keythms_support_check:n { amsproc }
+\keythms_support_check:n { beamer }
\keythms_support_check:n { memoir }
\file_input_stop: \ No newline at end of file