texlive[72780] Master/texmf-dist: keytheorems (6nov24)

commits+karl at tug.org commits+karl at tug.org
Wed Nov 6 22:22:42 CET 2024


Revision: 72780
          https://tug.org/svn/texlive?view=revision&revision=72780
Author:   karl
Date:     2024-11-06 22:22:42 +0100 (Wed, 06 Nov 2024)
Log Message:
-----------
keytheorems (6nov24)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/keytheorems/CHANGELOG.md
    trunk/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.pdf
    trunk/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.tex
    trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsart-support.tex
    trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsbook-support.tex
    trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsproc-support.tex
    trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-beamer-support.tex
    trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-memoir-support.tex
    trunk/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty

Modified: trunk/Master/texmf-dist/doc/latex/keytheorems/CHANGELOG.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/keytheorems/CHANGELOG.md	2024-11-06 21:22:32 UTC (rev 72779)
+++ trunk/Master/texmf-dist/doc/latex/keytheorems/CHANGELOG.md	2024-11-06 21:22:42 UTC (rev 72780)
@@ -1,5 +1,10 @@
 # Changelog for keytheorems package
 
+## [v0.2.1]
+- make several commands "long" so keyvals can contain `\par` tokens
+- add `leftmargin` and `rightmargin` keys
+- improve implementation of tcolorbox theorems
+
 ## [v0.1.8]
 - add support for tagged PDF ([\#4](https://github.com/mbertucci47/keytheorems/issues/4))
 - add tagged example file tagged-keytheorems-amsthmtest.tex
@@ -44,6 +49,7 @@
 ## 0.1.0 - 2024-09-04
 - First release
 
+[v0.2.1]: https://github.com/mbertucci47/keytheorems/compare/v0.1.8...v0.2.1
 [v0.1.8]: https://github.com/mbertucci47/keytheorems/compare/v0.1.7...v0.1.8
 [v0.1.7]: https://github.com/mbertucci47/keytheorems/compare/v0.1.6...v0.1.7
 [v0.1.6]: https://github.com/mbertucci47/keytheorems/compare/v0.1.5...v0.1.6

Modified: trunk/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.tex	2024-11-06 21:22:32 UTC (rev 72779)
+++ trunk/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.tex	2024-11-06 21:22:42 UTC (rev 72780)
@@ -22,7 +22,19 @@
 \usepackage{keytheorems}
 \usepackage{cleveref}
 
+%%% TEMPORARY (https://tex.stackexchange.com/q/730126/208544)
+\RemoveFromHook{label}[firstaid/cleveref]
 \makeatletter
+\AddToHook{label}[firstaid/cleveref]
+         {\ifx
+           \@currentcounter\@empty
+          \else
+           \firstaid at cref@updatelabeldata{\@currentcounter}%<--- was missing
+          \fi} 
+\makeatother
+%%% END TEMPORARY
+
+\makeatletter
 \newcommand\keythmsversion{\@keythms at version}
 \makeatother
 
@@ -78,6 +90,8 @@
   sibling=corollary,
   ]
 \newkeytheorem{observation}[style=breaksty]
+\newkeytheorem{quotethm}[name=Quote Theorem,leftmargin=1cm,rightmargin=1cm]
+\newkeytheorem{indentedthm}[name=Indented Theorem,leftmargin=1cm]
 
 \MakeShortVerb{\|}
 \newcommand{\env}{\texttt}
@@ -86,7 +100,9 @@
 \newcommand{\bracks}[1]{\texttt{[#1]}}
 \newcommand{\ttbraces}[1]{\braces{\texttt{#1}}}
 %\tcbset{index gather commands=false}
-\colorlet{ExampleBack}{yellow!10}
+\usepackage{xcolor-solarized}
+\colorlet{ExampleBack}{solarized-base3!50}
+\colorlet{ExampleBackLower}{solarized-base3}
 \tcbset{
   color command=BrickRed,
   color key=Fuchsia,
@@ -102,8 +118,8 @@
     before upper = {%
       {\ttfamily\itshape \% preamble}%
       \vspace{-0.7\baselineskip}%
-      \tcbusetemplisting%
-      {\ttfamily\itshape \% document}%
+      \tcbusetemplisting
+      \noindent{\ttfamily\itshape \% document}%
       \vspace{-0.7\baselineskip}%
       }
     }
@@ -117,8 +133,9 @@
 %    listing side text,
 %    lower separated=false,
     skin=bicolor,
-    colbacklower=yellow!25,
+    colbacklower=ExampleBackLower,
     breakable,
+    parbox=false, % so examples match document with indent, etc.
 %    enhanced,
 %    segmentation engine=path,
 %    segmentation style={solid,gray},
@@ -164,7 +181,7 @@
 
 \section{Dependencies}
 
-The package depends on the \pkg{aliascnt}, \pkg{amsthm}, \pkg{refcount}, \pkg{translations} packages.
+The package depends on the \pkg{aliascnt}, \pkg{amsthm}, \pkg{etoolbox}, \pkg{refcount}, \pkg{translations} packages.
 The \refKey{tcolorbox} and \refKey{tcolorbox-no-titlebar} keys require \pkg{tcolorbox}, and the \refKey[numbered=unless-unique]{numbered} key requires the \pkg{unique} package.
 A \LaTeX{} kernel no older than 2023-06-01 is required; if older than 2024-06-01, \pkg{nameref} is required.
     
@@ -630,6 +647,43 @@
 
 \subsection{Keys added by \pkg{keytheorems}} \label{thm-added-keys}
 
+\begin{docKeys}[doc parameter={=\meta{length}}]
+  {
+    { doc name=leftmargin },
+    { doc name=rightmargin },
+  }
+Sets the left (respectively, right) margin of the theorem relative to the text width.
+This sets the theorem apart from the text, similar to a block quote. Code adapted from Enrico Gregorio's \TeX{} Stack Exchange answers:
+\begin{itemize}
+	\item \href{https://tex.stackexchange.com/a/67251/208544}{How to change margins in enunciation (theorem-like environment)?}
+	\item \href{https://tex.stackexchange.com/a/236407/208544}{A theoremstyle with complete indentation using amsthm}
+\end{itemize}
+\begin{tcbwritetemp}
+\newcommand{\marginthmtext}{%
+  We need some text to show off theorems with margins. }
+\newkeytheorem{quotethm}[
+  name=Quote Theorem,
+  leftmargin=1cm, rightmargin=1cm]
+\newkeytheorem{indentedthm}[name=Indented Theorem, leftmargin=1cm]
+\end{tcbwritetemp}
+
+\newcommand{\marginthmtext}{We need some text to show off theorems with margins. }
+\begin{keythmscode}[withpreamble]
+\marginthmtext\marginthmtext\marginthmtext
+
+\begin{quotethm}
+\marginthmtext\marginthmtext\marginthmtext
+\end{quotethm}
+
+\marginthmtext\marginthmtext\marginthmtext
+
+\begin{indentedthm}
+\marginthmtext\marginthmtext\marginthmtext
+\end{indentedthm}
+\end{keythmscode}
+
+\end{docKeys}
+
 \begin{docKey}{tcolorbox}
   {\colOpt{=\marg{tcolorbox options}}}
   {initially unset}
@@ -799,6 +853,10 @@
 
 \end{docKey}
 
+\begin{notebox}
+With \refKey{tcolorbox} and \refKey{tcolorbox-no-titlebar}, the \refKey{spaceabove} and \refKey{spacebelow} keys are internally passed to \pkg{tcolorbox}'s \texttt{before skip} and \texttt{after skip}. When no explicit \texttt{spaceabove} or \texttt{spacebelow} values are given, \pkg{tcolorbox} defaults are used instead of \cs{topsep}.
+\end{notebox}
+
 \subsection{Keys added by \pkg{keytheorems}}
 
 \begin{docKey}{inherit-style}
@@ -978,7 +1036,7 @@
 \end{docKey}
 
 \begin{docKey}{chapter-skip-length}
-  {=\meta{dimension}}
+  {=\meta{length}}
   {initially |10pt|}
 Controls the amount of space inserted between chunks.
 \end{docKey}
@@ -1157,7 +1215,8 @@
 The \LaTeX{} team has been working hard to support the creation of tagged PDFs (see \url{https://latex3.github.io/tagging-project/}).
 The current |dev| formats make \pkg{amsthm} compatible with the kernel tagging code.
 Most of \pkg{keytheorems} is supported too, and anything that doesn't work should be reported.
-The only things explicitly not supported are the \refKey{tcolorbox} and \refKey{tcolorbox-no-titlebar} keys.
+Explicitly not supported are the \refKey{tcolorbox} and \refKey{tcolorbox-no-titlebar} keys.
+There is only partial support for \refKey{leftmargin} and \refKey{rightmargin}, namely only the latter works.
 
 To produce a tagged PDF, add \cs{DocumentMetadata} in the first line of your document (additional instructions are found on the Tagging Project \href{https://latex3.github.io/tagging-project/documentation/prototype-usage-instructions.html}{website}).
 An example invocation might look like
@@ -1177,12 +1236,25 @@
 
 \subsection{Public coding interfaces}
 
-\begin{itemize}
-	\item |\l_keythms_thmuse_envname_tl|
-	
-	Inside theorem environments and in all theorem hooks, you have access to the theorem's environment and counter name in this token list variable.
-\end{itemize}
+\begin{docCommand}{l_keythms_thmuse_envname_tl}{}
+Inside theorem environments and in all theorem hooks, you have access to the theorem's environment and counter name in this token list variable.
+\end{docCommand}
 
+\begin{docKeys}[doc no index,color key=black]
+  {
+    {
+      doc name=keytheorems/allthms/\textmd{\meta{hook name}},
+      doc label=allthms-hook,
+    },
+    {
+      doc name=keytheorems/\textmd{\meta{envname}}/\textmd{\meta{hook name}},
+      doc label=envname-hook,
+    }
+  }
+These are the ``real'' names for the hooks described in \autoref{keythms-hooks}.
+They can be useful with \cs{AddToHookNext} or the kernel's label mechanism for hooks.
+\end{docKeys}
+
 \section{Further examples}
 
 More examples will be added soon -- rather, eventually\dots{}

Modified: trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsart-support.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsart-support.tex	2024-11-06 21:22:32 UTC (rev 72779)
+++ trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsart-support.tex	2024-11-06 21:22:42 UTC (rev 72780)
@@ -27,10 +27,6 @@
             headindent    = \@acmplainindent,
             notefont      = \@acmplainnotefont,
             postheadspace = .5em,
-            spaceabove    =
-              .5\baselineskip plus .2\baselineskip minus .2\baselineskip,
-            spacebelow    =
-              .5\baselineskip plus .2\baselineskip minus .2\baselineskip,
           }
         \keys_define:nn { keytheorems/thmstyle }
           {
@@ -81,12 +77,5 @@
           }
       }
   }
-  { % the amsart defaults
-    \prop_gput_from_keyval:Nn \g__keythms_thmstyle_defaultkeys_prop
-      {
-        spaceabove = .5\baselineskip plus .2\baselineskip minus .2\baselineskip,
-        spacebelow = .5\baselineskip plus .2\baselineskip minus .2\baselineskip,
-      }
-  }
 
 \file_input_stop:
\ No newline at end of file

Modified: trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsbook-support.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsbook-support.tex	2024-11-06 21:22:32 UTC (rev 72779)
+++ trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsbook-support.tex	2024-11-06 21:22:42 UTC (rev 72780)
@@ -10,8 +10,6 @@
   {
     headfont   = \scshape,
     headindent = \parindent,
-    spaceabove = .5\baselineskip plus .2\baselineskip minus .2\baselineskip,
-    spacebelow = .5\baselineskip plus .2\baselineskip minus .2\baselineskip,
   }
 
 \keys_define:nn { keytheorems/thmstyle }

Modified: trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsproc-support.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsproc-support.tex	2024-11-06 21:22:32 UTC (rev 72779)
+++ trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsproc-support.tex	2024-11-06 21:22:42 UTC (rev 72780)
@@ -10,8 +10,6 @@
   {
     headfont   = \scshape,
     headindent = \parindent,
-    spaceabove = .5\baselineskip plus .2\baselineskip minus .2\baselineskip,
-    spacebelow = .5\baselineskip plus .2\baselineskip minus .2\baselineskip,
   }
 
 \keys_define:nn { keytheorems/thmstyle }

Modified: trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-beamer-support.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-beamer-support.tex	2024-11-06 21:22:32 UTC (rev 72779)
+++ trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-beamer-support.tex	2024-11-06 21:22:42 UTC (rev 72780)
@@ -9,7 +9,7 @@
   {
     \protect\listofkeytheorems\space not~supported~with~beamer
   }
-\RenewDocumentCommand \listofkeytheorems { o }
+\RenewDocumentCommand \listofkeytheorems { +o }
   {
     \msg_warning:nn { keytheorems } { beamer-listof }
   }
@@ -25,53 +25,101 @@
         preheadhook = \def\inserttheoremblockenv{exampleblock},
       }
   }
-\keys_define:nn { keytheorems/thm }
-  { % redefine key to include \thm at headsep
-    tcolorbox-no-titlebar .meta:n =
+
+\cs_set_protected:Npn \__keythms_thm_tcbcode:nn #1#2
+  { % #1 = name, #2 = tcolorbox keys
+    \__keythms_thm_tcbshared:nn { #1 } { #2 }
+    \tl_gput_left:cn { g__keythms_thm_preheadfromkeys_#1_tl }
       {
-        tcolorbox={
-          notitle,
-          before~upper={
-            \group_begin:
-            \usebeamerfont*{block title}
-            \__keythms_thm_tcboxtemphead:
-            \hskip\thm at headsep
-            \group_end:
-            },
-          #1
-          }
-      },
+        \cs_set:Npn \inserttheoremblockenv { keythms_beamer_tcb }
+      }
   }
-\cs_set_protected:Npn \__keythms_thm_tcboxcode:nn #1#2
+\cs_set_protected:Npn \__keythms_thm_tcbnotitlebarcode:nn #1#2
   { % #1 = name, #2 = tcolorbox keys
+    \__keythms_thm_tcbshared:nn { #1 } { #2 }
+    \tl_gput_left:cn { g__keythms_thm_preheadfromkeys_#1_tl }
+      {
+        \cs_set:Npn \inserttheoremblockenv { keythms_beamer_tcbnotitlebar }
+      }
+  }
+\cs_set_protected:Npn \__keythms_thm_tcbshared:nn #1#2
+  {
     \RequirePackage{tcolorbox}
+    \AddToHook{env/#1/begin}
+      { % fix labels adding extra space
+        \keys_define:nn { keytheorems/thmuse }
+          { label .code:n = \tcbset{ phantom = { \label{##1} } } }
+      }
     \tcbset
       {
-        keythms_tcbox_#1/.style =
+        keythms_tcb_#1/.style =
           {
             savedelimiter=#1,
             #2
           }
       }
-    \tl_gput_left:cn { g__keythms_thm_preheadfromkeys_#1_tl }
-      {
-        \cs_set_protected:Npn \thm at space@setup { \thm at preskip=0pt \thm at postskip=0pt }
-        \cs_set:Npn \inserttheoremblockenv { keythms_beamer_tcbox }
-      }
+      \tl_if_empty:NTF \l__keythms_thm_style_tl
+        {
+          \tl_set_eq:NN \l__keythms_thm_tempstyle_tl
+            \l__keythms_thm_currentthmstyle_tl
+        }
+        { \tl_set_eq:NN \l__keythms_thm_tempstyle_tl \l__keythms_thm_style_tl }
+      \tl_gput_right:ce { g__keythms_thm_preheadfromkeys_#1_tl }
+        { % don't mess with tcolorbox defaults unless explicitly asked to in style
+          \exp_not:N \tl_put_right:cn { th@ \l__keythms_thm_tempstyle_tl }
+            { \thm at preskip=0pt \thm at postskip=0pt }
+        }
+      \tl_if_exist:cT
+        { g__keythms_thmstyle_ \l__keythms_thm_tempstyle_tl _tcbspaceabove_skip }
+        {
+          \exp_args:Ne \tcbset
+            {
+              keythms_tcb_#1/.prefix~style =
+                {
+                  before~skip =
+                    \skip_use:c { g__keythms_thmstyle_ \l__keythms_thm_tempstyle_tl _tcbspaceabove_skip }
+                }
+            }
+        }
+      \tl_if_exist:cT
+        { g__keythms_thmstyle_ \l__keythms_thm_tempstyle_tl _tcbspacebelow_skip }
+        {
+          \exp_args:Ne \tcbset
+            {
+              keythms_tcb_#1/.prefix~style =
+                {
+                  after~skip =
+                    \skip_use:c { g__keythms_thmstyle_ \l__keythms_thm_tempstyle_tl _tcbspacebelow_skip }
+                }
+            }
+        }
   }
-\NewDocumentEnvironment{ keythms_beamer_tcbox }{ m d<> }
+\NewDocumentEnvironment{ keythms_beamer_tcb }{ m d<> }
   {
-    \cs_set:Npn \__keythms_thm_tcboxtemphead: { #1 } % for tcolorbox-no-titlebar
-    \tl_if_novalue:nF { #2 } { \begin{onlyenv}<#2> }
+    \tl_if_novalue:nF { #2 } { \begin{actionenv}<#2> }
     \begin{tcolorbox}[
       title={\usebeamerfont*{block title} #1},
-      keythms_tcbox_\l_keythms_thmuse_envname_tl
+      keythms_tcb_\l_keythms_thmuse_envname_tl
       ]
   }
   {
     \end{tcolorbox}
-    \tl_if_novalue:nF { #2 } { \end{onlyenv} }
+    \tl_if_novalue:nF { #2 } { \end{actionenv} }
   }
+\NewDocumentEnvironment{ keythms_beamer_tcbnotitlebar }{ m d<> }
+  {
+    \tl_if_novalue:nF { #2 } { \begin{actionenv}<#2> }
+    \begin{tcolorbox}[ keythms_tcb_\l_keythms_thmuse_envname_tl ]
+      \group_begin:
+      \usebeamerfont*{block title} #1
+      \thmheadnl
+      \hskip\thm at headsep
+      \group_end:
+  }
+  {
+    \end{tcolorbox}
+    \tl_if_novalue:nF { #2 } { \end{actionenv} }
+  }
 
 \cs_set_protected:Npn \keythms_keyify_theorem:n #1
   { % #1 = theorem name
@@ -78,6 +126,7 @@
     \DeclareEnvironmentCopy { keythms_orig_#1 } { #1 }
     \DeclareDocumentEnvironment { keythms_beamer_grab_#1 } { m m m +b }
       { % ##1 = keys, ##2 = note, ##3 = action spec, ##4 = theorem body
+        \__keythms_thm_prehead_code:n { #1 }
         \tl_if_empty:nTF { ##3 }
           { \begin{keythms_orig_#1}[{##2}] }
           { \begin{keythms_orig_#1}[{##2}]<##3> }
@@ -136,6 +185,7 @@
              \msg_warning:nnV { keytheorems } { store-reversed-not-got }
                \l__keythms_thmuse_storereversed_tl
            }
+        \__keythms_thm_prehead_code:n { #1 }
         \hook_use:n { keytheorems/#1/restated }
         \hook_use:n { keytheorems/allthms/restated }
         \tl_if_empty:nTF { ##3 }
@@ -164,19 +214,21 @@
         {
           \tl_set:Nn \l_keythms_thmuse_envname_tl { #1 }
           \keys_set:nn { keytheorems/thmuse } { ##2 }
-          \tl_if_empty:NF \l__keythms_thmuse_store_tl
+          \tl_if_empty:NTF \l__keythms_thmuse_store_tl
             {
+              \tl_if_empty:NTF \l__keythms_thmuse_storereversed_tl
+                { \__keythms_thm_prehead_code:n { #1 } }
+                {
+                  % \bool_gset_true:N \g__keythms_listof_writefile_bool % disable writing to file
+                  \cs_set_eq:NN \__keythms_beamer_withhooks_begin:nnnn \__keythms_beamer_grabreversed_begin:nnnn
+                  \cs_set_eq:NN \__keythms_beamer_withhooks_end:n \__keythms_beamer_grabreversed_end:n
+                }
+            }
+            {
               % \bool_gset_true:N \g__keythms_listof_writefile_bool % disable writing to file
               \cs_set_eq:NN \__keythms_beamer_withhooks_begin:nnnn \__keythms_beamer_grab_begin:nnnn
               \cs_set_eq:NN \__keythms_beamer_withhooks_end:n \__keythms_beamer_grab_end:n
             }
-          \tl_if_empty:NF \l__keythms_thmuse_storereversed_tl
-            {
-              % \bool_gset_true:N \g__keythms_listof_writefile_bool % disable writing to file
-              \cs_set_eq:NN \__keythms_beamer_withhooks_begin:nnnn \__keythms_beamer_grabreversed_begin:nnnn
-              \cs_set_eq:NN \__keythms_beamer_withhooks_end:n \__keythms_beamer_grabreversed_end:n
-            }
-          \__keythms_thm_prehead_code:n { #1 }
           \tl_if_empty:nTF { ##3 }
             { % if ##3 empty, just pass ##1 and withhooks_begin will check if empty
               \__keythms_beamer_withhooks_begin:nnVn { #1 } { ##2 }
@@ -270,7 +322,7 @@
   {
     \iow_shipout:Ne \@auxout
       {
-        \KeyThmsBeamerReversedData { \l__keythms_thmuse_storereversed_tl }
+        \token_to_str:N \KeyThmsBeamerReversedData { \l__keythms_thmuse_storereversed_tl }
           { \@currentlabel }
           { #2 }
       }

Modified: trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-memoir-support.tex
===================================================================
--- trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-memoir-support.tex	2024-11-06 21:22:32 UTC (rev 72779)
+++ trunk/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-memoir-support.tex	2024-11-06 21:22:42 UTC (rev 72780)
@@ -20,7 +20,7 @@
 \newlistof{ keythms_support_memoir_listof:w }{ thlist }
   { \l__keythms_listof_title_tl }
 
-\RenewDocumentCommand \listofkeytheorems { O{} }
+\RenewDocumentCommand \listofkeytheorems { +O{} }
   {
     \bool_gset_true:N \g__keythms_listof_writefile_bool
     \group_begin:

Modified: trunk/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty	2024-11-06 21:22:32 UTC (rev 72779)
+++ trunk/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty	2024-11-06 21:22:42 UTC (rev 72780)
@@ -2,8 +2,8 @@
 % 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]
-\def\@keythms at date{2024-10-21}
-\def\@keythms at version{0.1.8}
+\def\@keythms at date{2024-11-05}
+\def\@keythms at version{0.2.1}
 \ProvidesExplPackage{keytheorems}{\@keythms at date}{\@keythms at version}
   {l3keys interface to amsthm}
 
@@ -15,15 +15,15 @@
     \cs_generate_variant:Nn \keys_set:nn { ne }
     \cs_generate_variant:Nn \msg_warning:nnn { nne }
     \cs_generate_variant:Nn \tl_put_right:Nn { Ne }
-    \ProvideDocumentCommand \IfPackageLoadedT { m m }
+    \ProvideDocumentCommand \IfPackageLoadedT { m +m }
       { \IfPackageLoadedTF{#1}{#2}{ } }
-    \ProvideDocumentCommand \IfPackageLoadedF { m m }
+    \ProvideDocumentCommand \IfPackageLoadedF { m +m }
       { \IfPackageLoadedTF{#1}{ }{#2} }
-    \ProvideDocumentCommand \IfClassLoadedT { m m }
+    \ProvideDocumentCommand \IfClassLoadedT { m +m }
       { \IfClassLoadedTF{#1}{#2}{ } }
-    \ProvideDocumentCommand \IfClassLoadedWithOptionsT { m m m }
+    \ProvideDocumentCommand \IfClassLoadedWithOptionsT { m m +m }
       { \IfClassLoadedWithOptionsTF{#1}{#2}{#3}{ } }
-    \ProvideDocumentCommand \IfPackageLoadedWithOptionsT { m m m }
+    \ProvideDocumentCommand \IfPackageLoadedWithOptionsT { m m +m }
       { \IfPackageLoadedWithOptionsTF{#1}{#2}{#3}{ } }
   }
 \RequirePackage{aliascnt}
@@ -125,6 +125,7 @@
 %%% Declare Variables %%%
 %%%%%%%%%%%%%%%%%%%%%%%%%
 
+\dim_new:N \l__keythms_tmpa_dim
 \iow_new:N \g__keythms_tmpa_iow
 \tl_new:N \l__keythms_tmpa_tl
 
@@ -139,6 +140,9 @@
 \bool_new:N \l__keythms_thmuse_restating_bool
 \clist_new:N \g__keythms_restatecounters_clist
 \clist_new:N \l__keythms_thmstyle_savedkeys_clist
+\dim_new:N \l__keythms_thm_currparindent_dim
+\dim_new:N \l__keythms_thm_currparskip_dim
+\int_new:N \l__keythms_thm_tcbstate_int
 \prop_new:N \g__keythms_thmnames_prop
 \prop_new:N \g__keythms_thmstyle_defaultkeys_prop
 \prop_new:N \g__keythms_thmuse_othercounters_prop
@@ -146,6 +150,8 @@
 \tl_new:N \l__keythms_thm_currentthmstyle_tl
 \tl_new:N \l__keythms_thm_defaultkeys_tl
 \tl_new:N \l__keythms_thm_envname_tl
+\tl_new:N \l__keythms_thm_tcbkeys_tl
+\tl_new:N \l__keythms_thm_tempstyle_tl
 \tl_new:N \l__keythms_thmstyle_defaultkeys_tl
 \tl_new:N \l__keythms_thmstyle_lnotebrace_tl
 \tl_new:N \l__keythms_thmstyle_rnotebrace_tl
@@ -167,9 +173,8 @@
 \cs_gset:Npn \thekeythms_unnumbered_dummyctr { }
 
 \cs_generate_variant:Nn \hook_gput_code:nnn { nnv }
-\cs_generate_variant:Nn \keys_precompile:nnN { nv, nVc, nnc, ne }
+\cs_generate_variant:Nn \keys_precompile:nnN { ne, nv, nnc, nVc }
 \cs_generate_variant:Nn \prop_set_from_keyval:Nn { Ne }
-\prg_generate_conditional_variant:Nnn \tl_if_novalue:n { o } { T, F, TF }
 
 %%%%%%%%%%%%%%
 %%% Styles %%%
@@ -249,6 +254,7 @@
     spaceabove    .tl_set:N = \l__keythms_thmstyle_spaceabove_tl,
     spacebelow    .tl_set:N = \l__keythms_thmstyle_spacebelow_tl,
     % thm keys that are saved for later
+    leftmargin            .code:n = \keythms_thmstyle_savethmkey_reqval:n { #1 },
     numbered              .code:n = \keythms_thmstyle_savethmkey_optval:n { #1 },
     numberlike            .code:n = \keythms_thmstyle_savethmkey_reqval:n { #1 },
     numberwithin          .code:n = \keythms_thmstyle_savethmkey_reqval:n { #1 },
@@ -259,7 +265,7 @@
     preheadhook           .code:n = \keythms_thmstyle_savethmkey_reqval:n { #1 },
     qed                   .code:n =
       { % qed needs special treatment to distinguish qed from qed={}
-        \tl_if_novalue:oTF { #1 }
+        \tl_if_novalue:nTF { #1 }
           {
             \clist_put_right:No \l__keythms_thmstyle_savedkeys_clist
               { \l_keys_key_str }
@@ -269,7 +275,8 @@
               { \l_keys_key_str = { #1 } }
           }
       },
-    qed                   .default:n = \c_novalue_tl,
+    qed                   .default:o = \c_novalue_tl,
+    rightmargin           .code:n = \keythms_thmstyle_savethmkey_reqval:n { #1 },
     sharenumber           .code:n = \keythms_thmstyle_savethmkey_reqval:n { #1 },
     sibling               .code:n = \keythms_thmstyle_savethmkey_reqval:n { #1 },
     tcolorbox             .code:n = \keythms_thmstyle_savethmkey_optval:n { #1 },
@@ -312,8 +319,8 @@
     noteseparator = {~},
     numberfont    = \upshape,
     postheadspace = 5pt plus 1pt minus 1pt,
-    spaceabove    = \topsep,
-    spacebelow    = \topsep,
+    spaceabove    = {}, % empty means default (works for AMS classes too)
+    spacebelow    = {}, % empty means default (works for AMS classes too)
   }
 \hook_gput_code:nnn { package/keytheorems/after } { . }
   { % need to defer to wait for support files
@@ -322,24 +329,24 @@
       \l__keythms_thmstyle_defaultkeys_tl
   }
 
-\NewDocumentCommand \newkeytheoremstyle { m m }
+\NewDocumentCommand \newkeytheoremstyle { m +m }
   {
     \cs_if_free:cTF { th@ #1 }
       { \keythms_thmstyle_declarestyle:nn { #1 } { #2 } }
       { \msg_error:nnn { keytheorems } { thmstyle-defined } { #1 } }
   }
-\NewDocumentCommand \renewkeytheoremstyle { m m }
+\NewDocumentCommand \renewkeytheoremstyle { m +m }
   {
     \cs_if_free:cTF { th@ #1 }
       { \msg_error:nnn { keytheorems } { thmstyle-undefined } { #1 } }
       { \keythms_thmstyle_declarestyle:nn { #1 } { #2 } }
   }
-\NewDocumentCommand \providekeytheoremstyle { m m }
+\NewDocumentCommand \providekeytheoremstyle { m +m }
   {
     \cs_if_free:cT { th@ #1 }
       { \keythms_thmstyle_declarestyle:nn { #1 } { #2 } }
   }
-\NewDocumentCommand \declarekeytheoremstyle { m m }
+\NewDocumentCommand \declarekeytheoremstyle { m +m }
   {
     \keythms_thmstyle_declarestyle:nn { #1 } { #2 }
   }
@@ -390,17 +397,27 @@
       \l__keythms_thmstyle_postheadspace_tl
       { \text_expand:n { \keythms_thmstyle_headcmd:nnn{##1}{##2}{##3} } }
     % Define inherit-style key
-    \tl_if_exist:cF { l__keythms_thmstyle_#1_metakeys_tl }
-      { \tl_new:c { l__keythms_thmstyle_#1_metakeys_tl } }
+    \tl_clear_new:c { l__keythms_thmstyle_#1_metakeys_tl }
     \keys_precompile:nnc { keytheorems/thmstyle } { #2 } % use precompile instead of meta key
       { l__keythms_thmstyle_#1_metakeys_tl }           % because that's sensitive to hashes
     \keys_define:nn { keytheorems/thmstyle }             % and we want to allow both # and ##
       { inherit-style / #1 .code:n = \tl_use:c { l__keythms_thmstyle_#1_metakeys_tl } }
-    \tl_if_exist:cF { l__keythms_thmstyle_#1_savedthmkeys_tl }
-      { \tl_new:c { l__keythms_thmstyle_#1_savedthmkeys_tl } }
+    \tl_clear_new:c { l__keythms_thmstyle_#1_savedthmkeys_tl }
     \keys_precompile:nVc { keytheorems/thm }
       \l__keythms_thmstyle_savedkeys_clist
       { l__keythms_thmstyle_#1_savedthmkeys_tl }
+    \tl_if_empty:NF \l__keythms_thmstyle_spaceabove_tl
+      {
+        \skip_zero_new:c { g__keythms_thmstyle_#1_tcbspaceabove_skip }
+        \skip_set_eq:cN { g__keythms_thmstyle_#1_tcbspaceabove_skip }
+          \l__keythms_thmstyle_spaceabove_tl
+      }
+    \tl_if_empty:NF \l__keythms_thmstyle_spacebelow_tl
+      {
+        \skip_zero_new:c { g__keythms_thmstyle_#1_tcbspacebelow_skip }
+        \skip_set_eq:cN { g__keythms_thmstyle_#1_tcbspacebelow_skip }
+          \l__keythms_thmstyle_spacebelow_tl
+      }
     \cs_undefine:N \NAME % undefine to prevent conflicts
     \cs_undefine:N \NUMBER
     \cs_undefine:N \NOTE
@@ -444,6 +461,7 @@
 \keys_define:nn { keytheorems/thm }
   {
     heading        .meta:n    = { name = {#1} },
+    leftmargin     .dim_set:N = \l__keythms_thm_leftmargin_dim,
     name           .tl_set:N  = \l__keythms_thm_name_tl,
     numbered       .choice:,
     numbered       .default:n = true,
@@ -464,27 +482,25 @@
     prefoothook    .tl_set:N  = \l__keythms_thm_prefoothook_tl,
     preheadhook    .tl_set:N  = \l__keythms_thm_preheadhook_tl,
     qed            .tl_set:N  = \l__keythms_thm_qed_tl,
-    qed            .default:n = \c_novalue_tl,
+    qed            .default:o = \c_novalue_tl,
     % ^ distinguish between 'qed' and 'qed={}'
     refname        .tl_set:N  = \l__keythms_thm_refname_tl,
     Refname        .tl_set:N  = \l__keythms_thm_Refname_tl,
+    rightmargin    .dim_set:N = \l__keythms_thm_rightmargin_dim,
     sharenumber    .meta:n    = { sibling = {#1} },
     sibling        .tl_set:N  = \l__keythms_thm_sibling_tl,
     style          .tl_set:N  = \l__keythms_thm_style_tl,
     style          .groups:n  = { style-comes-first },
-    tcolorbox      .tl_set:N  = \l__keythms_thm_tcbkeys_tl,
+    tcolorbox      .code:n    =
+      {
+        \int_set:Nn \l__keythms_thm_tcbstate_int { 1 }
+        \tl_set:Nn \l__keythms_thm_tcbkeys_tl { #1 }
+      },
     tcolorbox      .default:n = {},
-    tcolorbox-no-titlebar .meta:n =
+    tcolorbox-no-titlebar .code:n =
       {
-        tcolorbox={
-          notitle,
-          before~upper={
-            \group_begin:
-            \__keythms_thm_tcboxtemphead:
-            \group_end:
-            },
-          #1
-          }
+        \int_set:Nn \l__keythms_thm_tcbstate_int { 2 }
+        \tl_set:Nn \l__keythms_thm_tcbkeys_tl { #1 }
       },
     tcolorbox-no-titlebar .default:n = {},
     title          .meta:n    = { name = {#1} },
@@ -491,25 +507,9 @@
     within         .meta:n    = { parent = {#1} },
   }
 
-% what below is unnecessary? I really don't understand this code.
-\cs_new_protected:Npn \__keythms_thm_storedeferredthmhead:n #1
-  {
-    \if at inlabel \indent \par \fi % eject a section head if one is pending
-    \if at nobreak
-      \adjust at parskip@nobreak
-    \else
-    \addpenalty\@beginparpenalty
-    \addvspace\@topsep
-    \addvspace{-\parskip}
-    \fi
-    % \global\@inlabeltrue % MB: if this is uncommented then spacing after sections is wrong
-    \everypar\dth at everypar
-    \cs_set:Npn \__keythms_thm_tcboxtemphead: { \normalfont #1 }
-    \ignorespaces
-  }
-
 \keys_precompile:nnN { keytheorems/thm }
   {
+    leftmargin   = 0pt,
     name         = \q_no_value,
     numbered     = true,
     parent       = {},
@@ -520,18 +520,16 @@
     qed          = \q_no_value,
     refname      = \q_no_value,
     Refname      = \q_no_value,
+    rightmargin  = 0pt,
     sibling      = {},
     style        = {},
-    tcolorbox    = \q_no_value,
   }
   \l__keythms_thm_defaultkeys_tl
 
 \cs_new_protected:Npn \__keythms_thm_makethmhooks:n #1
   {
-    \hook_new:n { keytheorems/#1/prehead }
-    \hook_new:n { keytheorems/#1/posthead }
-    \hook_new_reversed:n { keytheorems/#1/prefoot }
-    \hook_new_reversed:n { keytheorems/#1/postfoot }
+    \hook_new_pair:nn { keytheorems/#1/prehead } { keytheorems/#1/postfoot }
+    \hook_new_pair:nn { keytheorems/#1/posthead } { keytheorems/#1/prefoot }
     \hook_new:n { keytheorems/#1/restated }
   }
 
@@ -538,22 +536,22 @@
 % Make generic theorem hooks
 \__keythms_thm_makethmhooks:n { allthms }
 
-\NewDocumentCommand \newkeytheorem { m O{} }
+\NewDocumentCommand \newkeytheorem { m +O{} }
   { % #1 = name, #2 = keys
     \clist_map_inline:nn { #1 } % define multiple theorems at once
       { \keythms_thm_newkeythm:nn { ##1 } { #2 } }
   }
-\NewDocumentCommand \renewkeytheorem { m O{} }
+\NewDocumentCommand \renewkeytheorem { m +O{} }
   { % #1 = name, #2 = keys
     \clist_map_inline:nn { #1 }
       { \keythms_thm_renewkeythm:nn { ##1 } { #2 } }
   }
-\NewDocumentCommand \providekeytheorem { m O{} }
+\NewDocumentCommand \providekeytheorem { m +O{} }
   { % #1 = name, #2 = keys
     \clist_map_inline:nn { #1 }
       { \keythms_thm_providekeythm:nn { ##1 } { #2 } }
   }
-\NewDocumentCommand \declarekeytheorem { m O{} }
+\NewDocumentCommand \declarekeytheorem { m +O{} }
   { % #1 = name, #2 = keys
     \clist_map_inline:nn { #1 }
       { \keythms_thm_declarekeythm:nn { ##1 } { #2 } }
@@ -582,6 +580,8 @@
     \bool_set_false:N \l__keythms_thm_unlessunique_bool
     % Set default keys
     \tl_use:N \l__keythms_thm_defaultkeys_tl
+    % Initialize tcb state to zero (1 is with title bar, 2 is without title bar)
+    \int_zero:N \l__keythms_thm_tcbstate_int
     % First set style so we can pick up additional thm keys, then overwrite if necessary
     \keys_set_groups:nnn { keytheorems/thm } { style-comes-first } { #2 }
     % Store theorem style
@@ -696,6 +696,14 @@
       { \keythms_thm_setrefnames:nV { #1 } \l__keythms_thm_refname_tl }
     \quark_if_no_value:NF \l__keythms_thm_Refname_tl 
       { \keythms_thm_setRefnames:nV { #1 } \l__keythms_thm_Refname_tl }
+    % Set margins if needed
+    \bool_lazy_or:nnT
+      { ! \dim_compare_p:nNn { \l__keythms_thm_leftmargin_dim } = { 0pt } }
+      { ! \dim_compare_p:nNn { \l__keythms_thm_rightmargin_dim } = { 0pt } }
+      {
+        \exp_args:NnVV \__keythms_thm_margincode:nnn { #1 }
+          \l__keythms_thm_leftmargin_dim \l__keythms_thm_rightmargin_dim
+      }
     % Set up qed if needed
     \quark_if_no_value:NF \l__keythms_thm_qed_tl
       {
@@ -702,11 +710,18 @@
         \exp_args:Nno \__keythms_thm_qedcode:nn { #1 } { \l__keythms_thm_qed_tl }
       }
     % Set up tcolorbox if needed
-    \quark_if_no_value:NF \l__keythms_thm_tcbkeys_tl
+    \int_compare:nNnTF { \l__keythms_thm_tcbstate_int } = { 1 }
       {
-        \exp_args:Nno \__keythms_thm_tcboxcode:nn { #1 }
+        \exp_args:Nno \__keythms_thm_tcbcode:nn { #1 }
           { \l__keythms_thm_tcbkeys_tl }
       }
+      {
+        \int_compare:nNnT { \l__keythms_thm_tcbstate_int } = { 2 }
+          {
+            \exp_args:Nno \__keythms_thm_tcbnotitlebarcode:nn { #1 }
+              { \l__keythms_thm_tcbkeys_tl }
+          }
+      }
     % Set up list-of definition
     \cs_set_eq:cN { l@ #1 } \keythms_listof_tocline:
     % Set default list-of display command
@@ -731,39 +746,57 @@
           }
         \tl_use:c { g__keythms_thm_tcbpatch_#1_tl }
       }
+    \cs_set_eq:NN \__keythms_thm_origtrivlist: \trivlist % for margin code below
   }
 
-\cs_new_protected:Npn \__keythms_thm_tcboxcode:nn #1#2
+\cs_new_protected:Npn \__keythms_thm_margincode:nnn #1#2#3
+  {
+    \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_#1_tl }
+      {
+        \dim_set_eq:NN \l__keythms_thm_currparindent_dim \parindent
+        \dim_set_eq:NN \l__keythms_thm_currparskip_dim \parskip
+        \cs_set_protected:Npn \trivlist
+          {
+            \list{ }
+              {
+                \dim_set:Nn \leftmargin { #2 }
+                \dim_set:Nn \rightmargin { #3 }
+                \dim_zero:N \labelwidth % trivlist does this; important for tcb-no-title
+                % need to revert some adjustments \list makes (any more?)
+                \int_gdecr:N \@listdepth % avoid changing format of inner lists
+                \dim_set_eq:NN \listparindent \l__keythms_thm_currparindent_dim
+                \dim_set_eq:NN \parsep \l__keythms_thm_currparskip_dim  
+              }
+          }
+      }
+    \tl_gput_right:cn { g__keythms_thm_postheadfromkeys_#1_tl }
+      { \cs_set_eq:NN \trivlist \__keythms_thm_origtrivlist: }
+  }
+
+\cs_new_protected:Npn \__keythms_thm_tcbcode:nn #1#2
   { % #1 = name, #2 = tcolorbox keys
-    \RequirePackage{tcolorbox}
     \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_#1_tl }
       {
-        \cs_set_eq:NN \deferred at thm@head \__keythms_thm_storedeferredthmhead:n
+        \cs_set_eq:NN \deferred at thm@head \__keythms_thm_storedeferred at thm@head:n
         \cs_set_eq:NN \Hy at theorem@makelinktarget \use_none:n
-        % ^ don't like playing with hyperref internals... but don't see around
-        %   it because hyperref tries to add to para hook which doesn't work
-        %   when title set up the way we do it
-        \cs_set_protected:Npn \thm at space@setup { \thm at preskip=0pt \thm at postskip=0pt }
-        % ^ to match tcolorbox defaults; shouldn't interfere with user styles
+        % % ^ don't like playing with hyperref internals... but don't see around
+        % %   it because hyperref tries to add to para hook which doesn't work
+        % %   when title set up the way we do it
       }
-    \tcbset
+    \__keythms_thm_tcbshared:nn { #1 }
       {
-        keythms_tcbox_#1/.style =
-          {
-            savedelimiter=#1,
-            title={ \__keythms_thm_tcboxtemphead: },
-            #2
-          }
+        title={ \__keythms_thm_tcbtemphead: },
+        #2
       }
     \bool_if:NT \l__keythms_thm_numbered_bool
       {
         \tl_gset:cn { g__keythms_thm_tcbpatch_#1_tl }
           {
-            \IfPackageLoadedF{cleveref}
+            \IfPackageLoadedF { cleveref }
               { % hyperref doesn't patch \@thm if cleveref loaded
                 \tcbset
                   {
-                    keythms_tcbox_#1/.append~style = % fix hyperlinking
+                    keythms_tcb_#1/.append~style = % fix hyperlinking
                       { phantom={ \MakeLinkTarget*{\@currentHref} } }
                   }
               }
@@ -770,20 +803,93 @@
           }
       }
     \tl_gput_left:cn { g__keythms_thm_postheadfromkeys_#1_tl }
-      { \begin{tcolorbox}[keythms_tcbox_#1] }
+      { \begin{tcolorbox}[keythms_tcb_#1] }
     \tl_gput_right:cn { g__keythms_thm_prefootfromkeys_#1_tl }
       { \end{tcolorbox} }
   }
+\cs_new_protected:Npn \__keythms_thm_tcbnotitlebarcode:nn #1#2
+  { % #1 = name, #2 = tcolorbox keys
+    \__keythms_thm_tcbshared:nn { #1 } { #2 }
+    \tl_gclear_new:c { g__keythms_thm_#1_tcbprehead_tl }
+    \tl_gset:cn { g__keythms_thm_#1_tcbprehead_tl }
+      { \begin{tcolorbox}[keythms_tcb_#1] }
+    \tl_gclear_new:c { g__keythms_thm_#1_tcbpostfoot_tl }
+    \tl_gset:cn { g__keythms_thm_#1_tcbpostfoot_tl }
+      { \end{tcolorbox} }
+  }
+\cs_new_protected:Npn \__keythms_thm_tcbshared:nn #1#2
+  {
+    \RequirePackage{tcolorbox}
+    \tcbset
+      {
+        keythms_tcb_#1/.style =
+          {
+            savedelimiter=#1,
+            #2
+          }
+      }
+    \tl_if_empty:NTF \l__keythms_thm_style_tl
+      {
+        \tl_set_eq:NN \l__keythms_thm_tempstyle_tl
+          \l__keythms_thm_currentthmstyle_tl
+      }
+      { \tl_set_eq:NN \l__keythms_thm_tempstyle_tl \l__keythms_thm_style_tl }
+    \tl_gput_right:ce { g__keythms_thm_preheadfromkeys_#1_tl }
+      { % don't mess with tcolorbox defaults unless explicitly asked to in style
+        \exp_not:N \tl_put_right:cn { th@ \l__keythms_thm_tempstyle_tl }
+          { \thm at preskip=0pt \thm at postskip=0pt }
+      }
+    \tl_if_exist:cT
+      { g__keythms_thmstyle_ \l__keythms_thm_tempstyle_tl _tcbspaceabove_skip }
+      {
+        \exp_args:Ne \tcbset
+          {
+            keythms_tcb_#1/.prefix~style =
+              {
+                before~skip =
+                  \skip_use:c { g__keythms_thmstyle_ \l__keythms_thm_tempstyle_tl _tcbspaceabove_skip }
+              }
+          }
+      }
+    \tl_if_exist:cT
+      { g__keythms_thmstyle_ \l__keythms_thm_tempstyle_tl _tcbspacebelow_skip }
+      {
+        \exp_args:Ne \tcbset
+          {
+            keythms_tcb_#1/.prefix~style =
+              {
+                after~skip =
+                  \skip_use:c { g__keythms_thmstyle_ \l__keythms_thm_tempstyle_tl _tcbspacebelow_skip }
+              }
+          }
+      }
+  }
+% what below is unnecessary? I really don't understand this code.
+\cs_new_protected:Npn \__keythms_thm_storedeferred at thm@head:n #1
+  {
+    \if at inlabel \indent \par \fi % eject a section head if one is pending
+    \if at nobreak
+      \adjust at parskip@nobreak
+    \else
+    \addpenalty\@beginparpenalty
+    \addvspace\@topsep
+    \addvspace{-\parskip}
+    \fi
+    % \global\@inlabeltrue % MB: if this is uncommented then spacing after sections is wrong
+    \everypar\dth at everypar
+    \cs_set:Npn \__keythms_thm_tcbtemphead: { \normalfont #1 }
+    \ignorespaces
+  }
 \cs_new_protected:Npn \__keythms_thm_qedcode:nn #1#2
   { % #1 = name, #2 = symbol
     \tl_gput_right:cn { g__keythms_thm_postheadfromkeys_#1_tl }
       {
-        \tl_if_novalue:oF { #2 } { \protected at edef\qedsymbol{#2} }
+        \tl_if_novalue:nF { #2 } { \protected at edef\qedsymbol{#2} }
         \pushQED{\qed}
       }
     \tl_gput_left:cn { g__keythms_thm_prefootfromkeys_#1_tl }
       {
-        \tl_if_novalue:oF { #2 } { \protected at edef\qedsymbol{#2} }
+        \tl_if_novalue:nF { #2 } { \protected at edef\qedsymbol{#2} }
         \popQED
       }
   }
@@ -872,7 +978,7 @@
             \keythms_if_restating:F
               { \refstepcounter{ keythms_unnumbered_dummyctr } }
             \IfPackageLoadedT { tcolorbox }
-              { \tcbset{keythms_tcbox_#1/.append~style=nophantom} }
+              { \tcbset{keythms_tcb_#1/.append~style=nophantom} }
             % ^ otherwise we try to set two identical anchors
             \begin{keythms_orig_nonumber_#1}
           }
@@ -902,11 +1008,6 @@
       {
         \property_new:nnnn { keytheorems/recordednote } { now } { }
           { \l__keythms_thmuse_note_tl }
-        \cs_new:Npn \__keythms_getrecordednote:n #1
-          {
-            \property_ref:nn { keythms_recordednote_#1 }
-              { keytheorems/recordednote }
-          }
         \cs_new:Npn \__keythms_thmuse_recordnote:
           {
             \tl_if_empty:NF \l__keythms_thmuse_note_tl
@@ -916,6 +1017,11 @@
                   { keytheorems/recordednote }
               }
           }
+        \cs_new:Npn \__keythms_getrecordednote:n #1
+          {
+            \property_ref:nn { keythms_recordednote_#1 }
+              { keytheorems/recordednote }
+          }
       }
   }
 
@@ -956,6 +1062,7 @@
     \DeclareEnvironmentCopy { keythms_orig_#1 } { #1 }
     \DeclareDocumentEnvironment { keythms_grab_#1 } { m m +b }
       { % ##1 = keys, ##2 = note, ##3 = theorem body
+        \__keythms_thm_prehead_code:n { #1 }
         \begin{keythms_orig_#1}[{##2}]
         \clist_map_inline:Nn \g__keythms_restatecounters_clist
           {
@@ -1012,6 +1119,7 @@
              \msg_warning:nnV { keytheorems } { store-reversed-not-got }
                \l__keythms_thmuse_storereversed_tl
            }
+        \__keythms_thm_prehead_code:n { #1 }
         \hook_use:n { keytheorems/#1/restated }
         \hook_use:n { keytheorems/allthms/restated }
         \begin{keythms_orig_#1}[{##2}]
@@ -1038,19 +1146,21 @@
         {
           \tl_set:Nn \l_keythms_thmuse_envname_tl { #1 }
           \keys_set:nn { keytheorems/thmuse } { ##1 }
-          \tl_if_empty:NF \l__keythms_thmuse_store_tl
+          \tl_if_empty:NTF \l__keythms_thmuse_store_tl
             {
+              \tl_if_empty:NTF \l__keythms_thmuse_storereversed_tl
+                { \__keythms_thm_prehead_code:n { #1 } }
+                {
+                  \bool_gset_true:N \g__keythms_listof_writefile_bool
+                  \cs_set_eq:NN \__keythms_withhooks_begin:nnn \__keythms_grabreversed_begin:nnn
+                  \cs_set_eq:NN \__keythms_withhooks_end:n \__keythms_grabreversed_end:n
+                }
+            }
+            {
               \bool_gset_true:N \g__keythms_listof_writefile_bool
               \cs_set_eq:NN \__keythms_withhooks_begin:nnn \__keythms_grab_begin:nnn
               \cs_set_eq:NN \__keythms_withhooks_end:n \__keythms_grab_end:n
             }
-          \tl_if_empty:NF \l__keythms_thmuse_storereversed_tl
-            {
-              \bool_gset_true:N \g__keythms_listof_writefile_bool
-              \cs_set_eq:NN \__keythms_withhooks_begin:nnn \__keythms_grabreversed_begin:nnn
-              \cs_set_eq:NN \__keythms_withhooks_end:n \__keythms_grabreversed_end:n
-            }
-          \__keythms_thm_prehead_code:n { #1 }
           \__keythms_withhooks_begin:nnV { #1 } { ##1 } \l__keythms_thmuse_note_tl
         }
         {
@@ -1157,6 +1267,8 @@
       }
     \hook_use:n { keytheorems/#1/prehead }
     \hook_use:n { keytheorems/allthms/prehead }
+    \tl_if_exist:cT { g__keythms_thm_#1_tcbprehead_tl }
+      { \tl_use:c { g__keythms_thm_#1_tcbprehead_tl } }
   }
 \cs_new_protected:Npn \__keythms_thm_posthead_code:n #1
   { % #1 = theorem name
@@ -1182,6 +1294,8 @@
   }
 \cs_new_protected:Npn \__keythms_thm_postfoot_code:n #1
   { % #1 = theorem name
+    \tl_if_exist:cT { g__keythms_thm_#1_tcbpostfoot_tl }
+      { \tl_use:c { g__keythms_thm_#1_tcbpostfoot_tl } }
     \hook_use:n { keytheorems/allthms/postfoot }
     \hook_use:n { keytheorems/#1/postfoot }
   }
@@ -1190,9 +1304,9 @@
     \keythms_listof_chaptervspacehack:
     \iow_shipout:Ne \@auxout
       {
-        \exp_not:N \@writefile { thlist }
+        \token_to_str:N \@writefile { thlist }
           {
-            \KeyThmsSavedTheorem{ #1 }
+            \token_to_str:N \KeyThmsSavedTheorem{ #1 }
               { \@currentlabel }
               { \@currentHref }
               { \thepage }
@@ -1206,9 +1320,9 @@
   { % #1 = theorem name, #2 = keys, #3 = body
     \iow_shipout:Ne \@auxout
       {
-        \exp_not:N \@writefile { thlist }
+        \token_to_str:N \@writefile { thlist }
           {
-            \KeyThmsSavedTheoremReversed { \l__keythms_thmuse_storereversed_tl }
+            \token_to_str:N \KeyThmsSavedTheoremReversed { \l__keythms_thmuse_storereversed_tl }
               { #1 }
               { \exp_not:n { #2 } }
               { \exp_not:n { #3 } }
@@ -1255,7 +1369,7 @@
 
 \cs_new_protected:Npn \KeyThmsContentsLine #1 { }
 % ^ initially a no-op, redefined where needed; important it's protected!
-\NewDocumentCommand \addtheoremcontentsline { m m }
+\NewDocumentCommand \addtheoremcontentsline { m +m }
   {
     \addtocontents { thlist }
       {
@@ -1266,7 +1380,7 @@
           }
       }
   }
-\NewDocumentCommand \addtotheoremcontents { m }
+\NewDocumentCommand \addtotheoremcontents { +m }
   {
     \addtocontents { thlist }
       {
@@ -1570,10 +1684,7 @@
         \cs_set_protected:Nn \keythms_listof_listcmd:nnnnnnn
           {
             \tl_if_empty:nF { ##7 }
-              {
-                \__keythms_getthm_theorem:nnnnn
-                  {##1}{##2}{##5}{##6}{##7}
-              }
+              { \__keythms_getthm_theorem:nnnnn {##1}{##2}{##5}{##6}{##7} }
           }
       },
     seq                 .code:n     = 
@@ -1625,7 +1736,7 @@
       }
   }
 
-\NewDocumentCommand \keytheoremlistset { m }
+\NewDocumentCommand \keytheoremlistset { +m }
   {
     \keys_set:nn { keytheorems/listof } { #1 }
   }
@@ -1829,7 +1940,7 @@
    }
 \cs_new_eq:NN \keythms_listof_tocline: \__keythms_listof_default_tocline:
 
-\NewDocumentCommand \listofkeytheorems { O{} }
+\NewDocumentCommand \listofkeytheorems { +O{} }
   {
     \bool_gset_true:N \g__keythms_listof_writefile_bool
     \group_begin:
@@ -1984,7 +2095,7 @@
 
 \cs_generate_variant:Nn \__keythms_thmuse_continues:n { V }
 
-\NewDocumentCommand \keytheoremset { m }
+\NewDocumentCommand \keytheoremset { +m }
   { % #1 = keys
     \keys_set:nn { keytheorems } { #1 }
   }
@@ -2011,11 +2122,11 @@
   {
     \bool_gset_true:N \g__keythms_thmtoolscompat_bool
     \__keythms_overload_code: % since thmtools overwrites \newtheorem
-    \ProvideDocumentCommand { \declaretheoremstyle } { O{} m }
+    \ProvideDocumentCommand { \declaretheoremstyle } { +O{} m }
       {
         \declarekeytheoremstyle { ##2 } { ##1 }
       }
-    \ProvideDocumentCommand { \declaretheorem } { O{} m }
+    \ProvideDocumentCommand { \declaretheorem } { +O{} m }
       {
         \newkeytheorem { ##2 } [ ##1 ]
       }
@@ -2026,9 +2137,9 @@
             \keythms_listof_chaptervspacehack:
             \iow_shipout:Ne \@auxout
               {
-                \exp_not:N \@writefile { thlist }
+                \token_to_str:N \@writefile { thlist }
                   {
-                    \KeyThmsSavedTheorem{ ####1 }
+                    \token_to_str:N \KeyThmsSavedTheorem{ ####1 }
                       { \@currentlabel }
                       { \@currentHref }
                       { \thepage }
@@ -2057,9 +2168,9 @@
           { % ####1 = theorem name, ####2 = keys, ####3 = body
             \iow_shipout:Ne \@auxout
               {
-                \exp_not:N \@writefile { thlist }
+                \token_to_str:N \@writefile { thlist }
                   {
-                    \KeyThmsSavedTheoremReversed { \l__keythms_thmuse_storereversed_tl }
+                    \token_to_str:N \KeyThmsSavedTheoremReversed { \l__keythms_thmuse_storereversed_tl }
                       { ####1 }
                       { store*=\l__keythms_thmuse_storereversed_tl,\exp_not:n { ####2 } } % this line is changed
                       { \exp_not:n { ####3 } }
@@ -2095,19 +2206,19 @@
       { % redefine since thmtools way is \renewcommand\listtheoremname{...}
         title .initial:n = \listtheoremname
       }
-    \ProvideDocumentCommand { \addtotheorempreheadhook } { O{allthms} m }
+    \ProvideDocumentCommand { \addtotheorempreheadhook } { O{allthms} +m }
       {
         \addtotheoremhook [ ##1 ] { prehead } { ##2 }
       }
-    \ProvideDocumentCommand { \addtotheorempostheadhook } { O{allthms} m }
+    \ProvideDocumentCommand { \addtotheorempostheadhook } { O{allthms} +m }
       {
         \addtotheoremhook [ ##1 ] { posthead } { ##2 }
       }
-    \ProvideDocumentCommand { \addtotheoremprefoothook } { O{allthms} m }
+    \ProvideDocumentCommand { \addtotheoremprefoothook } { O{allthms} +m }
       {
         \addtotheoremhook [ ##1 ] { prefoot } { ##2 }
       }
-    \ProvideDocumentCommand { \addtotheorempostfoothook } { O{allthms} m }
+    \ProvideDocumentCommand { \addtotheorempostfoothook } { O{allthms} +m }
       {
         \addtotheoremhook [ ##1 ] { postfoot } { ##2 }
       }
@@ -2448,7 +2559,7 @@
             \cs_set_protected:Npn \__keythms_listof_titlecmd:n ####1 { ##1 }
           },
       }
-    \RenewDocumentCommand \listofkeytheorems { O{} }
+    \RenewDocumentCommand \listofkeytheorems { +O{} }
       { % title command not customizable here
         \bool_gset_true:N \g__keythms_listof_writefile_bool
         \group_begin:
@@ -2544,15 +2655,23 @@
   {
     \tag_if_active:T
       {
-        \msg_new:nnn { keytheorems } { tcolorbox-tagging }
+        \msg_new:nnn { keytheorems } { tag-incompat-key }
           {
-            The~key~'tcolorbox'~does~not~currently~work~with~
+            The~key~'#1'~does~not~currently~work~with~
             tagging.~Ignoring~this~key.
           }
         \keys_define:nn { keytheorems/thm }
           {
             tcolorbox .code:n =
-              \msg_warning:nn { keytheorems } { tcolorbox-tagging },
+              {
+                \msg_warning:nn { keytheorems } { tag-incompat-key }
+                  { tcolorbox }
+              },
+            tcolorbox-no-titlebar .code:n =
+              {
+                \msg_warning:nn { keytheorems } { tag-incompat-key }
+                  { tcolorbox-no-titlebar }
+              },
           }
         \keys_define:nn { keytheorems/listof }
           {
@@ -2571,6 +2690,17 @@
                   { \makeatletter \@input { \jobname.##1 } }
               },
           }
+        \cs_set_protected:Npn \__keythms_thm_margincode:nnn #1#2#3
+          { % tagging code does not define theorems with lists
+            \tl_gput_right:cn { g__keythms_thm_preheadfromkeys_#1_tl }
+              {
+                \SetTemplateKeys{ block }{ display }
+                  {
+                    leftmargin = #2,
+                    rightmargin = #3,
+                  }
+              }
+          }
       }
   }
   { }



More information about the tex-live-commits mailing list.