rework thmstyle package into LaTeX3 syntax and proper expansion

This commit is contained in:
Maximilian Keßler 2022-01-31 00:20:03 +01:00
parent ceb43f1672
commit 5437b8606c
3 changed files with 344 additions and 0 deletions

View File

@ -0,0 +1,6 @@
@default_files = ("thmstyle.dtx");
$makeindex = "makeindex -s gind.ist %O -o %D %S";
$clean_ext .= ' glo';
$clean_ext .= ' hd';
$clean_full_ext .= ' sty';
$emulate_aux = 1;

View File

@ -0,0 +1,10 @@
pdf:
latexmk
full:
latexmk -gg
clean:
latexmk -C
.PHONY: clean

View File

@ -0,0 +1,328 @@
% \iffalse meta-comment
%<*internal>
\begingroup
\input docstrip.tex
\keepsilent
\usedir{tex/latex/mkessler/thmstyle}
\askforoverwritefalse
\generate{\file{thmstyle.sty}{\from{thmstyle.dtx}{package}}}
\def\tmpa{plain}
\ifx\tmpa\fmtname\endgroup\expandafter\bye\fi
\endgroup
%</internal>
%
%% File: thmstyle.dtx
%
% Copyright (C) 2022 Maximilian Keßler
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version. The latest version
% of this license is in the file
%
% https://www.latex-project.org/lppl.txt
%
% -----------------------------------------------------------------------
%<package>\ProvidesExplPackage{thmstyle}{2022/01/17}{0.0.1}{Grouped theorems.}
%
%<*driver>
\documentclass[full,kernel]{l3doc}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{^^A
% The \pkg{thmstyle} package^^A
% }
%
% \author{^^A
% Maximilian Ke\ss ler
% }
%
% \date{Released 2022-01-12}
%
% \maketitle
%
% \begin{documentation}
%
%
%
% \end{documentation}
%
%
% \begin{implementation}
%
% \section{\pkg{thmstyle} implementation}
%
%
% \begin{macrocode}
%<*package>
% \end{macrocode}
%
% \begin{macrocode}
%<@@=thmstyle>
% \end{macrocode}
%
%
%
%
%
%
%
%
%
%
% \subsection{Dependencies}
%
%
%
% \begin{macrocode}
\RequirePackage{amsthm}
\RequirePackage{thmtools}
\RequirePackage{mdframed}
\RequirePackage{xcolor}
\RequirePackage{l3keys2e}
% \end{macrocode}
%
%
% \subsection{Initialization}
% \begin{variable}{\g_@@_default_styles_bool}
%
% Indicates whether the package will provide default styles.
%
% \begin{macrocode}
\bool_new:N \g_@@_default_styles_bool
% \end{macrocode}
% \end{variable}
%
%
%
%
% \begin{variable}{gold}
% New color
% \begin{macrocode}
\definecolor{gold}{RGB}{218,165,32}
% \end{macrocode}
% \end{variable}
%
%
%
%
%
%
%
% \subsection{Package options}
%
%
%
% \begin{macrocode}
\keys_define:nn { thmstyle }
{
default styles .set_bool:N = \g_@@_default_styles_bool,
default styles .default:n = { false },
}
% \end{macrocode}
%
%
% \begin{macrocode}
\ProcessKeyOptions { thmstyle }
% \end{macrocode}
%
%
%
%
% \subsection{Private Wrappers}
%
%
% \begin{macro}{\@@_mdframed_define_style:nn, \@@_mdframed_define_style:nx}
% \begin{syntax}
% \cs{@@_mdframed_define_style:nn}\marg{key=value list}\marg{style}
% \end{syntax}
%
%
%
% \begin{macrocode}
\cs_new:Npn \@@_mdframed_define_style:nn #1 #2
{
\mdfdefinestyle{#2}{#1}
}
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@@_thmtools_declare_style:nn, \@@_thmtools_declare_style:xx}
% \begin{syntax}
% \cs{@@_thmtools_declare_style:nn}\marg{key=value list}\marg{style}
% \end{syntax}
%
%
%
% \begin{macrocode}
\cs_new:Npn \@@_thmtools_declare_style:nn #1 #2
{
\declaretheoremstyle[#1]{#2}
}
\cs_generate_variant:Nn \@@_thmtools_declare_style:nn { x x }
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Generation of styles}
%
% \begin{macro}{\thmstyle_declare_mdf_style:nnn}
% \begin{syntax}
% \cs{thmstyle_declare_mdf_style:nnn}\marg{style}\marg{margin color}\marg{background color}
% \end{syntax}
%
%
% \begin{macrocode}
\cs_new:Npn \thmstyle_declare_mdf_style:nnn #1 #2 #3
{
\@@_mdframed_define_style:nn
{
linecolor = #2,
linewidth = 2pt,
leftmargin = 0pt,
rightmargin = 0pt,
rightline = false,
topline = false,
bottomline = false,
backgroundcolor = #3
}
{
#1
}
}
\cs_generate_variant:Nn \thmstyle_declare_mdf_style:nnn { x n x }
% \end{macrocode}
% \end{macro}
%
%
%
%
% \begin{macro}{\DeclareFancyMdfStyle}
% \begin{syntax}
% \cs{DeclareFancyMdfStyle}\oarg{background color}\marg{line color}\oarg{style}
% \end{syntax}
%
%
%
% \begin{macrocode}
\NewDocumentCommand { \DeclareFancyMdfStyle } { o m o }
{
\thmstyle_declare_mdf_style:xnx
{
\IfValueTF { #3 }
{
#3
}
{
md #2 margin
\IfValueT { #1 }
{
and #1 fill
}
}
}
{
#2
}
{
\IfValueTF { #1 }
{
#1
}
{
white
}
}
}
% \end{macrocode}
% \end{macro}
%
%
%
%
%
%
%
%
%
% \begin{macro}{\DeclareFancyThmStyle}
% \begin{syntax}
% \cs{DeclareFancyThmStyle}\oarg{background color}\marg{line color}\oarg{style}
% \end{syntax}
%
%
%
% \begin{macrocode}
\NewDocumentCommand { \DeclareFancyThmStyle } { o m o }
{
\DeclareFancyMdfStyle { #1 } { #2 }
\@@_thmtools_declare_style:xx
{
mdframed =
{
style = md #2 margin \IfValueT { #1 } { and #1 fill }
},
postheadspace = { 0.3em },
notefont = \mdseries,
}
{
\IfValueTF { #3 }
{ #3 }
{
thm #2 margin
\IfBooleanT { #1 }
{
and #1 fill
}
}
}
}
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Default styles}
%
%
% Here, we provide the default styles:
%
%
% \begin{macrocode}
\bool_if:NT \g_@@_default_styles_bool
{
\DeclareFancyThmStyle[red!8]{red}[thmredmarginandfill]
\DeclareFancyThmStyle[orange!10]{orange}[thmorangemarginandfill]
\DeclareFancyThmStyle[blue!7]{blue}[thmbluemarginandfill]
\DeclareFancyThmStyle{green!70!black}[thmgreenmargin]
\DeclareFancyThmStyle{gold}[thmgoldmargin]
\DeclareFancyThmStyle{yellow!80!orange}[thmyellowmargin]
\DeclareFancyThmStyle{gray}[thmgraymargin]
\DeclareFancyThmStyle[violet!7]{violet}[thmvioletmarginandfill]
\DeclareFancyThmStyle{violet}[thmvioletmargin]
\DeclareFancyThmStyle[blue!7]{red}[thmredmarginbluefill]
\DeclareFancyThmStyle{red}[thmredmargin]
\DeclareFancyThmStyle[blue!7]{orange}[thmorangemarginbluefill]
\DeclareFancyThmStyle[violet!20!gray!20]{black}[thmblackmarginandfill]
\DeclareFancyThmStyle{black}[thmblackmargin]
}
% \end{macrocode}
%
%
%
%
%
% \begin{macrocode}
%</package>
% \end{macrocode}
%
% \end{implementation}
%
%
%
% \newpage
% \PrintIndex