From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- .../contrib/conv-xkv/examples/convert2xkeyval.tex | 119 +++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 macros/latex/contrib/conv-xkv/examples/convert2xkeyval.tex (limited to 'macros/latex/contrib/conv-xkv/examples') diff --git a/macros/latex/contrib/conv-xkv/examples/convert2xkeyval.tex b/macros/latex/contrib/conv-xkv/examples/convert2xkeyval.tex new file mode 100644 index 0000000000..001e1c0325 --- /dev/null +++ b/macros/latex/contrib/conv-xkv/examples/convert2xkeyval.tex @@ -0,0 +1,119 @@ +\documentclass{article} +\usepackage{conv-xkv} +\usepackage{fancyvrb} + +% Use ordinary askii characters to declare a delimiter, usually +% the delimiter is some combination of special characters: !@#:%^&*()_+= +\DeclareDelimiter{arrow}{->} +% The colon delimiter is already defined, and need not be declared +%\DeclareDelimiter{colon}{:} + +% formatting cmd +\def\ameta#1{\ensuremath{\langle\textit{\texttt{#1}}\rangle}} + +\makeatletter +\define@key{dps}{fname}[]{\def\fname{#1}} +\define@key{dps}{mname}[]{\def\mname{#1}} +\define@key{dps}{lname}[]{\def\lname{#1}} +\define@choicekey{dps}{favorite}{AeB, AeB Pro, conv-xkv}[AeB]{\def\favoritepkg{#1}} +\define@key{kaf}{home}[]{\def\myhome{#1}} +\makeatother + +% Process keys using the arrow delimiter +\def\setName#1{\cxkvsetkeys(arrow){dps,kaf}{#1}} +% we use the default delimiter, colon (:) +\def\setOtherName#1{\cxkvsetkeys{dps}{#1}} +% we define the dps family for xkeyval +\def\setStandName#1{\setkeys{dps}{#1}} + +\let\pkg\textsf +\newcommand{\cs}[1]{\texttt{\char`\\#1}} +\def\newtopic{\par\medskip} + +\parindent0pt + +\begin{document} + +In the preamble, we declare \verb~\DeclareDelimiter{arrow}{->}~. + +\newtopic +The \pkg{conv-xkv} package converts key-values with alternate key-value delimiter +to a form the \pkg{xkeyval} package expects them to be in. + +\setName { + fname-> D., + mname-> P., + lname-> Story, + favorite-> conv-xkv, + home-> {Niceville, FL} +} +\begin{Verbatim}[xleftmargin=\leftmargini,fontsize=\small] +\def\setName#1{\cxkvsetkeys(arrow){dps,kaf}{#1}} +\setName { + fname-> D., + mname-> P., + lname-> Story, + favorite-> conv-xkv, + home-> {Niceville, FL} +} +\end{Verbatim} +The script above converts the notation \texttt{\ameta{key}\usekvdelim{arrow}\ameta{value}} to +the notation of \pkg{xkeyval}, \texttt{\ameta{key}=\ameta{value}}. It is then passed to the +\cs{setkeys} command of \pkg{xkeyval}. + +\newtopic\textbf{Results:} +My name is {\fname} {\mname} {\lname} and my favorite {\LaTeX} package is +\textsf{\favoritepkg}, my home is \myhome. + +\setOtherName { + fname: D., + mname: Paul, + lname: Story, + favorite % use default +} + +\newtopic Now we use the colon (:) delimiter: +\begin{Verbatim}[xleftmargin=\leftmargini,fontsize=\small] +\def\setOtherName#1{\cxkvsetkeys{dps}{#1}} +\setOtherName { + fname: D., + mname: Paul, + lname: Story, + favorite % use default +} +\end{Verbatim} +The script above converts the colon notation \texttt{\ameta{key}\usekvdelim{colon}\ameta{value}} to +the notation of \pkg{xkeyval}, \texttt{\ameta{key}=\ameta{value}}. This enables the implementation of +\pkg{xkeyval} in packages that want to use object-property notation. Other variations are +possible. + +\newtopic\textbf{Results:} +My name is {\fname} {\mname} {\lname} and my favorite {\LaTeX} package is +\textsf{\favoritepkg}. + +\newtopic +Now here are the same results using the \pkg{xkeyval} package with the key-value delimiter +\texttt{\ameta{key}=\ameta{value}} to verify that nothing has been disturbed. + +\setStandName { + fname= Don, + mname= Paulo, + lname= Story, + favorite +} +\begin{Verbatim}[xleftmargin=\leftmargini,fontsize=\small] +\def\setStandName#1{\setkeys{dps}{#1}} +\setStandName { + fname=Don, + mname=Paulo, + lname=Story, + favorite +} +\end{Verbatim} +\textbf{Results:} +My name is {\fname} {\mname} {\lname} and my favorite {\LaTeX} package is +\textsf{\favoritepkg}. + + +\end{document} + -- cgit v1.2.3