| 1 |
\documentclass{article} |
| 2 |
\usepackage{keyreader}[2012/11/01] |
| 3 |
\usepackage{xcolor} |
| 4 |
\usepackage{graphicx} |
| 5 |
\makeatletter |
| 6 |
|
| 7 |
% Choice keys with braced default: |
| 8 |
\krddefinekeys[JKV]{jorg}{% |
| 9 |
choice/key1/{A/X}/{ |
| 10 |
A/X.do=\def\currcolor{blue}, |
| 11 |
A/Y.do=\def\currcolor{green}, |
| 12 |
B/X.do=\def\currcolor{red}, |
| 13 |
B/Y.do=\def\currcolor{magenta} |
| 14 |
} |
| 15 |
/\def\val{Value of key1: #1} |
| 16 |
; |
| 17 |
choice/align/justified/{ |
| 18 |
center.do=\def\curralign##1{\hfil##1\hfil}, |
| 19 |
right.do=\def\curralign##1{\hfill##1}, |
| 20 |
left.do=\def\curralign##1{##1\hfill}, |
| 21 |
justified.do=\let\curralign\@iden |
| 22 |
} |
| 23 |
; |
| 24 |
} |
| 25 |
\krdpresetkeys[JKV]{jorg}{key1=A/X,align=justified} |
| 26 |
\newcommand\jorgcommand[2][]{% |
| 27 |
\krdsetkeys[JKV]{jorg}{#1}% |
| 28 |
\endgraf\bigskip |
| 29 |
\parbox{\hsize}{\centering\textbf{\textcolor{\currcolor}{\val}}}% |
| 30 |
\endgraf |
| 31 |
\parbox{\hsize}{\curralign{\textcolor{\currcolor}{#2}}}% |
| 32 |
} |
| 33 |
|
| 34 |
% Shadow box: |
| 35 |
\newdimen\shadowsize |
| 36 |
\krddefinekeys*[KV]{ebox}[mp@]{% |
| 37 |
bool/frame/true; |
| 38 |
bool+/shadow/true// |
| 39 |
\mp@shadowtrue |
| 40 |
\@@warning{Invalid value for 'shadow': 'true' assumed} |
| 41 |
; |
| 42 |
cmd/framecolor/black; |
| 43 |
cmd/shadecolor/white; |
| 44 |
cmd/shadowcolor/gray; |
| 45 |
cmd/framesize/.4pt; |
| 46 |
cmd/boxsize/.1\columnwidth; |
| 47 |
cmd/shadowsize/1pt; |
| 48 |
choice+/align/center/ |
| 49 |
center.do=\let\mp@alignright\hfil\let\mp@alignleft\hfil, |
| 50 |
right.do=\let\mp@alignright\hfill\let\mp@alignleft\relax, |
| 51 |
left.do=\let\mp@alignright\relax\let\mp@alignleft\hfill, |
| 52 |
justified.do=\let\mp@alignright\relax\let\mp@alignleft\relax |
| 53 |
// |
| 54 |
\let\mp@alignright\hfil\let\mp@alignleft\hfil |
| 55 |
\@@warning{Invalid value for 'align'; 'center' used} |
| 56 |
; |
| 57 |
} |
| 58 |
\savevaluekeys[KV]{ebox}{frame,framecolor,framesize} |
| 59 |
\krdpresetkeys[KV]{ebox}{% |
| 60 |
frame,framecolor=black,shadecolor=white,framesize=0.5pt,boxsize,align |
| 61 |
} |
| 62 |
\krdpostsetkeys[KV]{ebox}{% |
| 63 |
shadow=\usevalue{frame},shadowcolor=\usevalue{framecolor}!40, |
| 64 |
shadowsize=\usevalue{framesize}*4 |
| 65 |
} |
| 66 |
\newcommand*\ebox[2][]{% |
| 67 |
\krdsetkeys[KV]{ebox}{#1}% |
| 68 |
\begingroup |
| 69 |
\ifmp@frame |
| 70 |
\fboxrule=\dimexpr\mp@framesize\relax |
| 71 |
\else |
| 72 |
\fboxrule=0pt |
| 73 |
\fi |
| 74 |
\ifmp@shadow |
| 75 |
\shadowsize=\dimexpr\mp@shadowsize\relax |
| 76 |
\else |
| 77 |
\shadowsize=0pt |
| 78 |
\fi |
| 79 |
\setbox0=\hbox{% |
| 80 |
\fcolorbox{\mp@framecolor}{\mp@shadecolor}{% |
| 81 |
\hbox to\mp@boxsize{% |
| 82 |
\mp@alignright #2\mp@alignleft |
| 83 |
}% |
| 84 |
}% |
| 85 |
}% |
| 86 |
\hskip\shadowsize |
| 87 |
\color{\mp@shadowcolor}% |
| 88 |
\rule[-\dp0]{\wd0}{\the\dimexpr\ht0+\dp0\relax}% |
| 89 |
\llap{\raisebox{\shadowsize}{\box0\hskip\shadowsize}}% |
| 90 |
\endgroup |
| 91 |
} |
| 92 |
\makeatother |
| 93 |
|
| 94 |
\begin{document} |
| 95 |
\parindent-60pt |
| 96 |
% Shadow boxes: |
| 97 |
\scalebox{2}{% |
| 98 |
\ebox[shadecolor=brown!70]{ebox1}% |
| 99 |
\ebox[framecolor=magenta,boxsize=2cm,align=right]{ebox2}% |
| 100 |
\ebox[shadow=false,framesize=1pt,framecolor=red,boxsize=1.5cm,align=left]{ebox3}% |
| 101 |
\ebox[framesize=1pt,framecolor=green,shadowcolor=blue]{ebox4}% |
| 102 |
\ebox[frame=false,shadow,shadowcolor=yellow,framesize=.5pt]{ebox5}% |
| 103 |
} |
| 104 |
|
| 105 |
% Choice keys: |
| 106 |
\def\name#1{\texttt{\textcolor{black}{#1}}} |
| 107 |
\def\atext{% |
| 108 |
\name{choice} keys of the \name{keyreader} package. |
| 109 |
} |
| 110 |
\jorgcommand[key1=A/X,align=justified]{\atext} |
| 111 |
\jorgcommand[key1=A/Y,align=center]{\atext} |
| 112 |
\jorgcommand[key1=B/X,align=right]{\atext} |
| 113 |
\jorgcommand[key1=B/Y,align=left]{\atext} |
| 114 |
\jorgcommand{\atext} |
| 115 |
% Invalid value for key1 ('x+y' not allowed): |
| 116 |
% \jorgcommand[key1=x+y]{\atext} |
| 117 |
|
| 118 |
\end{document} |