| 1 |
\documentclass{article} |
| 2 |
\usepackage{conv-xkv} |
| 3 |
\usepackage{fancyvrb} |
| 4 |
|
| 5 |
% Use ordinary askii characters to declare a delimiter, usually |
| 6 |
% the delimiter is some combination of special characters: !@#:%^&*()_+= |
| 7 |
\DeclareDelimiter{arrow}{->} |
| 8 |
% The colon delimiter is already defined, and need not be declared |
| 9 |
%\DeclareDelimiter{colon}{:} |
| 10 |
|
| 11 |
% formatting cmd |
| 12 |
\def\ameta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}} |
| 13 |
|
| 14 |
\makeatletter |
| 15 |
\define@key{dps}{fname}[]{\def\fname{#1}} |
| 16 |
\define@key{dps}{mname}[]{\def\mname{#1}} |
| 17 |
\define@key{dps}{lname}[]{\def\lname{#1}} |
| 18 |
\define@choicekey{dps}{favorite}{AeB, AeB Pro, conv-xkv}[AeB]{\def\favoritepkg{#1}} |
| 19 |
\define@key{kaf}{home}[]{\def\myhome{#1}} |
| 20 |
\makeatother |
| 21 |
|
| 22 |
% Process keys using the arrow delimiter |
| 23 |
\def\setName#1{\cxkvsetkeys(arrow){dps,kaf}{#1}} |
| 24 |
% we use the default delimiter, colon (:) |
| 25 |
\def\setOtherName#1{\cxkvsetkeys{dps}{#1}} |
| 26 |
% we define the dps family for xkeyval |
| 27 |
\def\setStandName#1{\setkeys{dps}{#1}} |
| 28 |
|
| 29 |
\let\pkg\textsf |
| 30 |
\newcommand{\cs}[1]{\texttt{\char`\\#1}} |
| 31 |
\def\newtopic{\par\medskip} |
| 32 |
|
| 33 |
\parindent0pt |
| 34 |
|
| 35 |
\begin{document} |
| 36 |
|
| 37 |
In the preamble, we declare \verb~\DeclareDelimiter{arrow}{->}~. |
| 38 |
|
| 39 |
\newtopic |
| 40 |
The \pkg{conv-xkv} package converts key-values with alternate key-value delimiter |
| 41 |
to a form the \pkg{xkeyval} package expects them to be in. |
| 42 |
|
| 43 |
\setName { |
| 44 |
fname-> D., |
| 45 |
mname-> P., |
| 46 |
lname-> Story, |
| 47 |
favorite-> conv-xkv, |
| 48 |
home-> {Niceville, FL} |
| 49 |
} |
| 50 |
\begin{Verbatim}[xleftmargin=\leftmargini,fontsize=\small] |
| 51 |
\def\setName#1{\cxkvsetkeys(arrow){dps,kaf}{#1}} |
| 52 |
\setName { |
| 53 |
fname-> D., |
| 54 |
mname-> P., |
| 55 |
lname-> Story, |
| 56 |
favorite-> conv-xkv, |
| 57 |
home-> {Niceville, FL} |
| 58 |
} |
| 59 |
\end{Verbatim} |
| 60 |
The script above converts the notation \texttt{\ameta{key}\usekvdelim{arrow}\ameta{value}} to |
| 61 |
the notation of \pkg{xkeyval}, \texttt{\ameta{key}=\ameta{value}}. It is then passed to the |
| 62 |
\cs{setkeys} command of \pkg{xkeyval}. |
| 63 |
|
| 64 |
\newtopic\textbf{Results:} |
| 65 |
My name is {\fname} {\mname} {\lname} and my favorite {\LaTeX} package is |
| 66 |
\textsf{\favoritepkg}, my home is \myhome. |
| 67 |
|
| 68 |
\setOtherName { |
| 69 |
fname: D., |
| 70 |
mname: Paul, |
| 71 |
lname: Story, |
| 72 |
favorite % use default |
| 73 |
} |
| 74 |
|
| 75 |
\newtopic Now we use the colon (:) delimiter: |
| 76 |
\begin{Verbatim}[xleftmargin=\leftmargini,fontsize=\small] |
| 77 |
\def\setOtherName#1{\cxkvsetkeys{dps}{#1}} |
| 78 |
\setOtherName { |
| 79 |
fname: D., |
| 80 |
mname: Paul, |
| 81 |
lname: Story, |
| 82 |
favorite % use default |
| 83 |
} |
| 84 |
\end{Verbatim} |
| 85 |
The script above converts the colon notation \texttt{\ameta{key}\usekvdelim{colon}\ameta{value}} to |
| 86 |
the notation of \pkg{xkeyval}, \texttt{\ameta{key}=\ameta{value}}. This enables the implementation of |
| 87 |
\pkg{xkeyval} in packages that want to use object-property notation. Other variations are |
| 88 |
possible. |
| 89 |
|
| 90 |
\newtopic\textbf{Results:} |
| 91 |
My name is {\fname} {\mname} {\lname} and my favorite {\LaTeX} package is |
| 92 |
\textsf{\favoritepkg}. |
| 93 |
|
| 94 |
\newtopic |
| 95 |
Now here are the same results using the \pkg{xkeyval} package with the key-value delimiter |
| 96 |
\texttt{\ameta{key}=\ameta{value}} to verify that nothing has been disturbed. |
| 97 |
|
| 98 |
\setStandName { |
| 99 |
fname= Don, |
| 100 |
mname= Paulo, |
| 101 |
lname= Story, |
| 102 |
favorite |
| 103 |
} |
| 104 |
\begin{Verbatim}[xleftmargin=\leftmargini,fontsize=\small] |
| 105 |
\def\setStandName#1{\setkeys{dps}{#1}} |
| 106 |
\setStandName { |
| 107 |
fname=Don, |
| 108 |
mname=Paulo, |
| 109 |
lname=Story, |
| 110 |
favorite |
| 111 |
} |
| 112 |
\end{Verbatim} |
| 113 |
\textbf{Results:} |
| 114 |
My name is {\fname} {\mname} {\lname} and my favorite {\LaTeX} package is |
| 115 |
\textsf{\favoritepkg}. |
| 116 |
|
| 117 |
|
| 118 |
\end{document} |
| 119 |
|