diff options
author | Karl Berry <karl@freefriends.org> | 2024-11-06 21:22:42 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2024-11-06 21:22:42 +0000 |
commit | c11d06b55738609e9da6f46f86c46745e6c4e614 (patch) | |
tree | 434728da72c60b079de7e42e62d681b96e58e43b | |
parent | 6080a7234933e9b3c6d93a031f09d08d2e25a1c6 (diff) |
keytheorems (6nov24)
git-svn-id: svn://tug.org/texlive/trunk@72780 c570f23f-e606-0410-a88d-b1316a301751
9 files changed, 432 insertions, 187 deletions
diff --git a/Master/texmf-dist/doc/latex/keytheorems/CHANGELOG.md b/Master/texmf-dist/doc/latex/keytheorems/CHANGELOG.md index de5d3ac354f..264b5ab0715 100644 --- a/Master/texmf-dist/doc/latex/keytheorems/CHANGELOG.md +++ b/Master/texmf-dist/doc/latex/keytheorems/CHANGELOG.md @@ -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 diff --git a/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.pdf b/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.pdf Binary files differindex 59baedc317a..fba3279b980 100644 --- a/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.pdf +++ b/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.pdf diff --git a/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.tex b/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.tex index 2af490c35e8..464d92e2d29 100644 --- a/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.tex +++ b/Master/texmf-dist/doc/latex/keytheorems/keytheorems-doc.tex @@ -22,6 +22,18 @@ \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@cref@updatelabeldata{\@currentcounter}%<--- was missing + \fi} +\makeatother +%%% END TEMPORARY + \makeatletter \newcommand\keythmsversion{\@keythms@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 @@ Several issues encountered with \pkg{thmtools} are avoided (see the README for a \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 @@ Consider \cref{abc,def}. \Autoref{abc} \dots \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 @@ Do not use this with the \refKey{break} key. \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 @@ Setting this key to |true| removes this space. \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 @@ Some font packages, all by Michael Sharpe, offer a |theoremfont| option that red 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,11 +1236,24 @@ The GitHub tests folder contains an example of a tagged PDF using \pkg{keytheore \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} diff --git a/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsart-support.tex b/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsart-support.tex index 69d70e3149d..b5b2b87683d 100644 --- a/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsart-support.tex +++ b/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsart-support.tex @@ -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 diff --git a/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsbook-support.tex b/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsbook-support.tex index 262e41db1b0..0471de9cc98 100644 --- a/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsbook-support.tex +++ b/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsbook-support.tex @@ -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 } diff --git a/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsproc-support.tex b/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsproc-support.tex index e941bf6c081..03867f28ca0 100644 --- a/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsproc-support.tex +++ b/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-amsproc-support.tex @@ -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 } diff --git a/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-beamer-support.tex b/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-beamer-support.tex index 7500327148b..734c5e36df0 100644 --- a/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-beamer-support.tex +++ b/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-beamer-support.tex @@ -9,7 +9,7 @@ { \protect\listofkeytheorems\space not~supported~with~beamer } -\RenewDocumentCommand \listofkeytheorems { o } +\RenewDocumentCommand \listofkeytheorems { +o } { \msg_warning:nn { keytheorems } { beamer-listof } } @@ -25,52 +25,100 @@ preheadhook = \def\inserttheoremblockenv{exampleblock}, } } -\keys_define:nn { keytheorems/thm } - { % redefine key to include \thm@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@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@space@setup { \thm@preskip=0pt \thm@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@preskip=0pt \thm@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@headsep + \group_end: + } + { + \end{tcolorbox} + \tl_if_novalue:nF { #2 } { \end{actionenv} } } \cs_set_protected:Npn \keythms_keyify_theorem:n #1 @@ -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 { - % \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: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 + } } - \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 + \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 } - \__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 } } diff --git a/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-memoir-support.tex b/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-memoir-support.tex index 27992798e41..0140580c660 100644 --- a/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-memoir-support.tex +++ b/Master/texmf-dist/tex/latex/keytheorems/class-support/keythms-memoir-support.tex @@ -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: diff --git a/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty b/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty index e1483782d9d..bd98b2a7e6d 100644 --- a/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty +++ b/Master/texmf-dist/tex/latex/keytheorems/keytheorems.sty @@ -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@date{2024-10-21} -\def\@keythms@version{0.1.8} +\def\@keythms@date{2024-11-05} +\def\@keythms@version{0.2.1} \ProvidesExplPackage{keytheorems}{\@keythms@date}{\@keythms@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,52 +482,34 @@ 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} }, 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@inlabel \indent \par \fi % eject a section head if one is pending - \if@nobreak - \adjust@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@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,40 +520,38 @@ 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 } } % 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,17 +696,32 @@ { \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 { \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,59 +746,150 @@ } \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_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_tcboxcode:nn #1#2 +\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@thm@head \__keythms_thm_storedeferredthmhead:n + \cs_set_eq:NN \deferred@thm@head \__keythms_thm_storedeferred@thm@head:n \cs_set_eq:NN \Hy@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@space@setup { \thm@preskip=0pt \thm@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} } } } } } } \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@preskip=0pt \thm@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@thm@head:n #1 + { + \if@inlabel \indent \par \fi % eject a section head if one is pending + \if@nobreak + \adjust@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@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@edef\qedsymbol{#2} } + \tl_if_novalue:nF { #2 } { \protected@edef\qedsymbol{#2} } \pushQED{\qed} } \tl_gput_left:cn { g__keythms_thm_prefootfromkeys_#1_tl } { - \tl_if_novalue:oF { #2 } { \protected@edef\qedsymbol{#2} } + \tl_if_novalue:nF { #2 } { \protected@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 { - \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: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 + } } - \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 + \cs_set_eq:NN \__keythms_withhooks_begin:nnn \__keythms_grab_begin:nnn + \cs_set_eq:NN \__keythms_withhooks_end:n \__keythms_grab_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, + } + } + } } } { } |