Debian Codegraph @

texmf-dist/source/latex/thmtools/thmdef-shaded.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2010-2014 by Ulrich M. Schwarz
4 % Copyright (C) 2019 by Frank Mittelbach
5 % Copyright (C) 2020- by Yukai Chou
6 %
7 % This file may be distributed and/or modified under the conditions of
8 % the LaTeX Project Public License, version 1.3c.
9 % The license can be obtained from
10 % http://www.latex-project.org/lppl/lppl-1-3c.txt
11 %
12 %\fi
13 %
14 %\iffalse (hide this from DocInput)
15 %<*shaded>
16 %\fi
17 %
18 % Mostly, this key wraps the theorem in a |shadebox| environment.
19 % The parameters are set by treating the value we are given as
20 % a new key-val list, see below.
21 %
22 % \begin{macrocode}
23 \define@key{thmdef}{shaded}[{}]{%
24 \thmt@trytwice{}{%
25 \RequirePackage{shadethm}%
26 \RequirePackage{thm-patch}%
27 \addtotheorempreheadhook[\thmt@envname]{%
28 \setlength\shadedtextwidth{\linewidth}%
29 \kvsetkeys{thmt@shade}{#1}\begin{shadebox}}%
30 \addtotheorempostfoothook[\thmt@envname]{\end{shadebox}}%
31 }%
32 }
33 % \end{macrocode}
34 % The docs for |shadethm| say:
35 % \begin{quote}
36 % There are some parameters you could set the default for (try them as is,
37 % first).
38 % \begin{itemize}
39 % \item |shadethmcolor|\quad The shading color of the background. See the
40 % documentation for the color package, but with a `gray' model, I find .97
41 % looks good out of my printer, while a darker shade like .92 is needed
42 % to make it copy well. (Black is 0, white is 1.)
43 % \item |shaderulecolor|\quad The shading color of the border of the shaded box.
44 % See (i). If shadeboxrule is set to 0pt then this won't print anyway.
45 % \item |shadeboxrule|\quad The width of the border around the shading. Set it to
46 % 0pt (not just 0) to make it disappear.
47 % \item |shadeboxsep|\quad The length by which the shade box surrounds the text.
48 % \end{itemize}
49 % \end{quote}
50 %
51 % So, let's just define keys for all of these.
52 %
53 % \begin{macrocode}
54 \define@key{thmt@shade}{textwidth} {\setlength\shadedtextwidth{#1}}
55 \define@key{thmt@shade}{bgcolor} {\thmt@definecolor{shadethmcolor}{#1}}
56 \define@key{thmt@shade}{rulecolor} {\thmt@definecolor{shaderulecolor}{#1}}
57 \define@key{thmt@shade}{rulewidth} {\setlength\shadeboxrule{#1}}
58 \define@key{thmt@shade}{margin} {\setlength\shadeboxsep{#1}}
59 \define@key{thmt@shade}{padding} {\setlength\shadeboxsep{#1}}
60 \define@key{thmt@shade}{leftmargin} {\setlength\shadeleftshift{#1}}
61 \define@key{thmt@shade}{rightmargin}{\setlength\shaderightshift{#1}}
62 % \end{macrocode}
63 %
64 % What follows is wizardry you don't have to understand. In essence,
65 % we want to support two notions of color: one is ``everything that goes
66 % after |\definecolor{shadethmcolor}|'', such as
67 % |{rgb}{0.8,0.85,1}|. On the other hand, we'd also like
68 % to recognize an already defined color name such as |blue|.
69 %
70 % To handle the latter case, we need to copy the definition of one color
71 % into another. The \pkg{xcolor} package offers |\colorlet| for that,
72 % for the \pkg{color} package, we just cross our fingers.
73 % \begin{macrocode}
74 \def\thmt@colorlet#1#2{%
75 %\typeout{don't know how to let color `#1' be like color `#2'!}%
76 \@xa\let\csname\string\color@#1\@xa\endcsname
77 \csname\string\color@#2\endcsname
78 % this is dubious at best, we don't know what a backend does.
79 }
80 \AtBeginDocument{%
81 \ifcsname colorlet\endcsname
82 \let\thmt@colorlet\colorlet
83 \fi
84 }
85 % \end{macrocode}
86 % Now comes the interesting part: we assume that a simple color name
87 % must not be in braces, and a color definition starts with an opening
88 % curly brace. (So, if |\definecolor| ever gets an optional arg,
89 % we are in a world of pain.)
90 %
91 % If the second argument to |\thmt@definecolor| (the key) starts
92 % with a brace,
93 % then |\thmt@def@color| will have an empty second argument,
94 % delimited by the brace of the key. Hopefully, the key will have exactly
95 % enough arguments to satisfy |\definecolor|. Then,
96 % |thmt@drop@relax| will be executed and gobble the fallback
97 % values and the |\thmt@colorlet|.
98 %
99 % If the key does not contain an opening brace, |\thmt@def@color|
100 % will drop everything up to |{gray}{0.5}|. So, first the color
101 % gets defined to a medium gray, but then, it immediately gets overwritten
102 % with the definition corresponding to the color name.
103 % \begin{macrocode}
104 \def\thmt@drop@relax#1\relax{}
105 \def\thmt@definecolor#1#2{%
106 \thmt@def@color{#1}#2\thmt@drop@relax
107 {gray}{0.5}%
108 \thmt@colorlet{#1}{#2}%
109 \relax
110 }
111 \def\thmt@def@color#1#2#{%
112 \definecolor{#1}}
113 % \end{macrocode}
114 %\iffalse (hide this from DocInput)
115 %</shaded>
116 %\fi