summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/keyval2e/keyval2e-examples.tex
blob: a13274b3e20de36a1e56e6ae02e3449dfeeb18af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
% keyval2e.sty examples, version 0.0.2, August 2011

\documentclass{article}
\usepackage{keyval2e,color}
\makeatletter
\kve@definekeys[KV]{fam}[mp@]{%
  keyone/+/\ifstrcmpTF{#1}{+}{\def\userinput{#1}}{\def\userinput{not `+'}},
  keytwo/+,
  keythree/+,
  keyfour/+,
  keyfive/true/\ifmp@keyfive\def\x{keyfive is 'true'}\else
    \def\x{keyfive is 'false'}\fi,
  keysix/true
}

% \show\ifmp@keyfive

% The starred variant of \kve@definekeys gives error for the
% already defined key 'keyone':
% \kve@definekeys*[KV]{fam}[mp@]{keyone/+}

% Changing the family and macro-prefix makes 'keyone' definable again:
\kve@definekeys*[KV]{famx}[mpx@]{keyone/+}

\def\fourplus{+,+,+,+}
\newcommand*\putmany[2][*]{%
  \begingroup
  \toks@{}\@tempcnta\z@
  \loop
  \advance\@tempcnta\@ne
  \toks@\expandafter{\the\toks@#1}%
  \ifnum\@tempcnta<#2\relax
  \repeat
  \expandafter\endgroup\the\toks@
}
\newcommand{\testa}[2]{%
  \kve@setafterdefaults[KV]{fam}{#2}%
  \edef\tempa{\mp@keyone,\mp@keytwo,\mp@keythree,\mp@keyfour}%
  \noindent
  \vbox{%
    \hsize\dimexpr1.1\hsize\relax\leftskip=-1.5cm
    \def\redstar{\textcolor{red}{*}}\ttfamily
    Test #1: \redstar\space\texttt{\tempa}\space\redstar\space
    \ifxTF\tempa\fourplus
      {All values are defaults\putmany[\space]{2}}%
      {At least one value is set}%
    \@spaces\textcolor{red}{||} keyone's value: \userinput
  }%
}
\newcommand{\testb}[2][]{\testa{#2}{#1}}

\begin{document}

\title{The \texttt{\color{blue}keyval2e} Package \\Examples}
\maketitle

\testa{Aa}{}\\
\testa{Ba}{keyone=+,  keythree=+}\\
\testa{Ca}{keytwo=+,  keythree=a}\\
\testa{Da}{keyone=b,  keythree=a,keyfour=+}\\

\testb{Ab}\\
\testb[keyone=+,  keythree=+]{Bb}\\
\testb[keytwo=+,  keythree=a]{Cb}\\
\testb[keyone=b,  keytwo=+,keythree=a]{Db}\\

\end{document}