-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpkv-def.dtx
2493 lines (2486 loc) · 84.7 KB
/
expkv-def.dtx
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
%
% File: expkv-def.dtx Copyright (C) 2020-2022 Jonathan P. Spratte
%
% This work may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this license or
% (at your option) any later version. The latest version of this license is in
% the file:
%
% http://www.latex-project.org/lppl.txt
%
% ------------------------------------------------------------------------------
%
%<*driver>^^A>>=
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
\expandafter\begingroup
\fi
\input l3docstrip.tex
\askforoverwritefalse
\preamble
--------------------------------------------------------------
expkv-def -- a key-defining frontend for expkv
E-mail: [email protected]
Released under the LaTeX Project Public License v1.3c or later
See http://www.latex-project.org/lppl.txt
--------------------------------------------------------------
Copyright (C) 2020-2022 Jonathan P. Spratte
This work may be distributed and/or modified under the conditions of the
LaTeX Project Public License (LPPL), either version 1.3c of this license or
(at your option) any later version. The latest version of this license is in
the file:
http://www.latex-project.org/lppl.txt
This work is "maintained" (as per LPPL maintenance status) by
Jonathan P. Spratte.
This work consists of the file expkv-def.dtx
and the derived files expkv-def.pdf
expkv-def.sty
expkv-def.tex
t-expkv-def.tex
\endpreamble
% stop docstrip adding \endinput
\postamble
\endpostamble
\generate{\file{expkv-def.sty}{\from{expkv-def.dtx}{pkg}}}
\generate{\file{expkv-def.tex}{\from{expkv-def.dtx}{tex}}}
\generate{\file{t-expkv-def.tex}{\from{expkv-def.dtx}{ctx}}}
\ifx\fmtname\nameofplainTeX
\expandafter\endbatchfile
\else
\expandafter\endgroup
\fi
%
\IfFileExists{expkv-def.tex}{\input{expkv-def.tex}}{}
\ProvidesFile{expkv-def.dtx}
[\csname ekvdDate\endcsname\ a key-defining frontend for expkv]
\PassOptionsToPackage{full}{textcomp}
\documentclass{l3doc}
\RequirePackage[oldstylenums,nott]{kpfonts}
\input{glyphtounicode}
\pdfgentounicode=1
\RequirePackage{tcolorbox}
\newtcolorbox{exresult}[2][]
{colback=expkvgrey!10!white,colframe=expkvgrey,fontupper=\small,width={#2},#1}
\newtcbox\exres[1][]
{
colback=expkvgrey!10!white
,colframe=expkvgrey
,size=small
,nobeforeafter
,tcbox raise base
,fontupper=\small
,#1
}
\RequirePackage{listings}
\RequirePackage{booktabs}
\RequirePackage{array}
\RequirePackage{collcell}
\RequirePackage{siunitx}
\RequirePackage{xcolor}
\RequirePackage{caption}
\RequirePackage{microtype}
\RequirePackage{accsupp}
\lstdefinelanguage{expkvd}[primitive]{TeX}
{
,moretexcs=[4]^^A e-TeX
{
expanded,
numexpr,
protected,
}
,moretexcs=[5]^^A plain/LaTeX
{
approx,
begin,
empty,
item,
LaTeX,
makeatletter,makeatother,
newcommand,newdimen,
RequirePackage,
rule,
TeX,
textit,texttt,
usepackage,
}
,moretexcs=[6]^^A used packages
{
^^A xfp
fpeval,
^^A keyval
setkeys,
^^A yax
defactiveparameter,storevalue,setparameterlist
}
,moretexcs=[2]^^A expkv-def macros
{
ekvdefinekeys
}
,moretexcs=[3]^^A expkv-pkg macros
{
^^A expkv
ekvdef,ekvdefNoVal,^^A
ekvlet,ekvletNoVal,ekvletkv,ekvletkvNoVal,^^A
ekvdefunknown,ekvdefunknownNoVal,^^A
ekvredirectunknown,ekvredirectunknownNoVal,^^A
ekvset,ekvsetSneaked,^^A
ekvsetdef,ekvsetSneakeddef,ekvsetdefSneaked,^^A
ekvparse,^^A
ekvVersion,ekvDate,^^A
ekvifdefined,ekvifdefinedNoVal,ekvifdefinedset,^^A
ekvbreak,ekvbreakPreSneak,ekvbreakPostSneak,^^A
ekvsneak,ekvsneakPre,^^A
ekvchangeset,^^A
ekvoptarg,ekvoptargTF,^^A
ekverr,
^^A expkv-cs
ekvcSecondaryKeys,ekvcSplitAndForward,
}
}
\colorlet{codeparam}{cyan!65!black}
\def\mylstwd{.55em}
\lstset
{
,language=expkvd
,flexiblecolumns=false
,basewidth=\mylstwd
,gobble=2
,basicstyle=\fontfamily{jkp}\itshape
,texcsstyle=*[1]{\bfseries\color{expkvgrey}} ^^A primitives
,texcsstyle=*[2]{\bfseries\color{expkvred}} ^^A expkv
,texcsstyle=*[3]{\color{expkvred}} ^^A expkv-pkg
,texcsstyle=*[4]{\bfseries\color{expkvgrey}} ^^A e-TeX
,texcsstyle=*[5]{\bfseries\color{expkvgrey}} ^^A plain/LaTeX macros
,texcsstyle=*[6]{} ^^A macros of other packages
,commentstyle=\color[gray]{0.4}
,literate=
{\{} {{\CodeUpBf\{}}{1}
{\}} {{\CodeUpBf\}}}{1}
{$} {{\CodeUpBf\$}}{1}
{[} {{\CodeUp[}}{1}
{]} {{\CodeUp]}}{1}
{(} {{\CodeUp(}}{1}
{)} {{\CodeUp)}}{1}
{*} {{$*$}}{1}
{1} {{\CodeUp{1}}}{1}
{2} {{\CodeUp{2}}}{1}
{3} {{\CodeUp{3}}}{1}
{4} {{\CodeUp{4}}}{1}
{5} {{\CodeUp{5}}}{1}
{6} {{\CodeUp{6}}}{1}
{7} {{\CodeUp{7}}}{1}
{8} {{\CodeUp{8}}}{1}
{9} {{\CodeUp{9}}}{1}
{0} {{\CodeUp{0}}}{1}
{##} {{\CodeColored{codeparam}{1}{\#}}}{1}
{##1}{{\CodeColored{codeparam}{2}{\#1}}}{2}
{##2}{{\CodeColored{codeparam}{2}{\#2}}}{2}
{##3}{{\CodeColored{codeparam}{2}{\#3}}}{2}
{##4}{{\CodeColored{codeparam}{2}{\#4}}}{2}
{##5}{{\CodeColored{codeparam}{2}{\#5}}}{2}
{##6}{{\CodeColored{codeparam}{2}{\#6}}}{2}
{##7}{{\CodeColored{codeparam}{2}{\#7}}}{2}
{##8}{{\CodeColored{codeparam}{2}{\#8}}}{2}
{##9}{{\CodeColored{codeparam}{2}{\#9}}}{2}
{<key>}{{$\langle$}key{$\rangle$}}{5}
{<set>}{{$\langle$}set{$\rangle$}}{5}
{<set1>}{{$\langle$}set1{$\rangle$}}{6}
{<set2>}{{$\langle$}set2{$\rangle$}}{6}
^^A,literate=*{<key>}{\key}{4}{<set>}{\set}{4}
}
\newcommand*\CodeColored[3]{\textcolor{#1}{\makebox[\dimexpr\mylstwd*#2]{#3}}}
\newcommand*\CodeUpBf[1]{\makebox[\mylstwd]{\textup{\textbf{#1}}}}
\newcommand*\CodeUp[1]{\makebox[\mylstwd]{\textup{#1}}}
\RequirePackage{randtext}
\let\metaORIG\meta
\protected\def\meta #1{\texttt{\metaORIG{#1}}}
\renewcommand*\thefootnote{\fnsymbol{footnote}}
\definecolor{expkvred}{HTML}{9F393D}
\colorlet{expkvgrey}{black!75}
\makeatletter
\newcommand*\expkv
{^^A
\texorpdfstring
{^^A
\mbox
{^^A
\BeginAccSupp{ActualText=expkv}^^A
\href{https://github.com/Skillmon/tex_expkv}
{^^A
\rmfamily
\bfseries
{\color{expkvgrey}e\kern-.05em x\kern-.05em}^^A
\lower.493ex
\hbox{{\color{expkvgrey}P}\kern-.1em{\color{expkvred}k}}^^A
\kern-.18em{\color{expkvred}v}^^A
}^^A
\EndAccSupp{}^^A
}^^A
}
{expkv}^^A
}
\newcommand*\expkvd
{^^A
\texorpdfstring
{^^A
\mbox
{^^A
\BeginAccSupp{ActualText=expkv-def}^^A
\href{https://github.com/Skillmon/tex_expkv-def}
{^^A
\rmfamily
\bfseries
{\color{expkvgrey}e\kern-.05em x\kern-.05em}^^A
\lower.493ex
\hbox{{\color{expkvgrey}P}\kern-.1em{\color{expkvred}k}}^^A
\kern-.18em{\color{expkvred}v}^^A
{\color{expkvgrey}^^A
\kern.05em\rule[-.1ex]{.08em}{1.2ex}\kern.05em\textsc{def}^^A
}^^A
}^^A
\EndAccSupp{}^^A
}^^A
}
{expkv-def}^^A
}
\newcommand\kv{\meta{key}=\meta{value}}
\newcommand\key{\meta{key}}
\newcommand\val{\meta{value}}
\newcommand\set{\meta{set}}
\newcommand\enfprefix{\textcolor{black}}
\newcommand\allprefix{\textcolor{gray}}
\newcommand\notprefix{\textcolor{red!80!black}}
\newcommand\printprefix[2]
{^^A
\ifcase\numexpr#1\relax\or
\enfprefix{#2}\or
\allprefix{#2}\or
\notprefix{#2}\fi
}
\newcommand\prefixes[4]
{^^A
\hfill
\printprefix{#1}{new}
\printprefix{#2}{also}
\printprefix{#3}{protected}
\printprefix{#4}{long}^^A
}
\hypersetup{linkcolor=red!80!black,urlcolor=purple!80!black}
\DoNotIndex{\def,\edef,\,,\=,\begingroup,\catcode,\chardef,\csname,\endcsname}
\DoNotIndex{\endgroup,\endinput,\errmessage,\expandafter,\input,\let,\long}
\DoNotIndex{\protected,\ProvidesFile,\ProvidesPackage,\relax,\space}
\DoNotIndex{\@,\unexpanded,\string,\expanded,\dimexpr,\global,\glueexpr,\hbox}
\DoNotIndex{\numexpr,\RequirePackage,\setbox,\the,\unless,\xdef,\@firstofone}
\DoNotIndex{\@firstoftwo,\@gobble,\@secondoftwo,\meaning,\detokenize}
\DoNotIndex{\romannumeral,\^}
\DoNotIndex{\ifcsname}
\DoNotIndex{\ifx}
\DoNotIndex{\ifdefined}
\DoNotIndex{\iffalse}
\DoNotIndex{\iftrue}
\DoNotIndex{\else}
\DoNotIndex{\fi}
\@gobble\fi ^^A ignoring \ifx, \ifcsname, etc., but only one \fi
\@gobble\fi ^^A ignoring \ifx, \ifcsname, etc., but only one \fi
\@gobble\fi ^^A ignoring \ifx, \ifcsname, etc., but only one \fi
\@gobble\fi ^^A ignoring \ifx, \ifcsname, etc., but only one \fi
\@ifdefinable\gobbledocstriptag{\def\gobbledocstriptag#1>{}}
\makeatother
\begin{document}
\title
{^^A
\texorpdfstring
{^^A
\huge\expkvd
\\[\medskipamount]
\Large a key-defining frontend for \expkv
}{expkv-def - a key-defining frontend for expkv}^^A
}
\date{\ekvdDate\space v\ekvdVersion}
\author{Jonathan P. Spratte\thanks{\protect\randomize{[email protected]}}}
\DocInput{expkv-def.dtx}
\end{document}
%</driver>^^A=<<
% \fi
%
% \maketitle
% \renewcommand*\thefootnote{\arabic{footnote}}
%
% \begin{abstract}
% \noindent\parfillskip=0pt
% \expkvd\ provides a small \kv\ interface to define keys for \expkv. Key-types
% are declared using prefixes, similar to static typed languages. The stylised
% name is \expkvd\ but the files use \file{expkv-def}, this is due to CTAN-rules
% which don't allow \string| in package names since that is the pipe symbol in
% *nix shells.
% \end{abstract}
%
% \tableofcontents
%
% \begin{documentation}^^A>>=
%
% \section{Documentation}
%
% Since the trend for the last couple of years goes to defining keys for a \kv\
% interface using a \kv\ interface, I thought that maybe providing such an
% interface for \expkv\ will make it more attractive for actual use, besides its
% unique selling points of being fully expandable, and fast and reliable. But at
% the same time I don't want to widen \expkv's initial scope. So here it is
% \expkvd, go define \kv\ interfaces with \kv\ interfaces.
%
% Unlike many of the other established \kv\ interfaces to define keys, \expkvd\
% works using prefixes instead of suffixes (\emph{e.g.}, |.tl_set:N| of
% \pkg{l3keys}) or directory like handlers (\emph{e.g.}, |/.store in| of
% \pkg{pgfkeys}). This was decided as a personal preference, more over in \TeX\
% parsing for the first space is way easier than parsing for the last one.
% \expkvd's prefixes are sorted into two categories: |p|-type, which are
% equivalent to \TeX's prefixes like |\long|, and |t|-type defining the type of
% the key. For a description of the available |p|-prefixes take a look at
% \autoref{sec:prefix:p}, the |t|-prefixes are described in
% \autoref{sec:prefix:t}.
%
% \expkvd\ is usable as generic code, as a \LaTeX\ package, and as a \ConTeXt\
% module. It'll automatically load \expkv\ in the same mode as well. To use it,
% just use one of
% \begin{lstlisting}
% \input expkv-def % plainTeX
% \usepackage{expkv-def} % LaTeX
% \usemodule[expkv-def] % ConTeXt
% \end{lstlisting}
%
% \subsection{Macros}
% Apart from version and date containers there is only a single user-facing
% macro, and that should be used to define keys.
%
% \begin{function}{\ekvdefinekeys}
% \begin{syntax}
% \cs{ekvdefinekeys}\marg{set}\{\kv, \ldots\}
% \end{syntax}
% In \set, define \key\ to have definition \val. The general syntax for \key\
% should be
% \begin{quote}\ttfamily\small
% \meta{prefix} \meta{name}
% \end{quote}
% Where \meta{prefix} is a space separated list of optional |p|-type prefixes
% followed by one |t|-type prefix. The syntax of \val\ is dependent on the
% used |t|-prefix.
% \end{function}
%
% \begin{function}{\ekvdDate,\ekvdVersion}
% These two macros store the version and date of the package.
% \end{function}
%
% \subsection{Prefixes}
% As already said there are |p|-prefixes and |t|-prefixes. Not every |p|-prefix
% is allowed for all |t|-prefixes.
%
% \subsubsection{\texttt{p}-Prefixes}\label{sec:prefix:p}
% The two |p|-type prefixes |long| and |protected| are pretty simple by nature,
% so their description is pretty simple. They affect the \key\ at use-time, so
% omitting |long| doesn't mean that a \meta{definition} can't contain a |\par|
% token, only that the \key\ will not accept a |\par| in \val. On the other
% hand |new| and |also| might be simple on first sight as well, but their rules
% are a bit more complicated.
%
% \begin{function}{also}
% The following key type will be \emph{added} to an existing \key's
% definition. You can't add a type taking an argument at use time to an
% existing key which doesn't take an argument and vice versa. Also you'll get
% an error if you try to add an action which isn't allowed to be either |long|
% or |protected| to a key which already is |long| or |protected| (the opposite
% order would be suboptimal as well, but can't be really captured with the
% current code).
%
% A key already defined as |long| or |protected| will stay |long| or
% |protected|, but you can as well add |long| or |protected| with the |also|
% definition.
%
% As a small example, suppose you want to create a boolean key, but
% additionally to setting a boolean value you want to execute some more code
% as well, you can use the following
% \begin{lstlisting}
% \ekvdefinekeys{also-example}
% {
% bool key = \ifmybool
% ,also code key = \domystuff{#1}
% }
% \end{lstlisting}
%
% If you use |also| on a |choice|, |bool|, |invbool|, or |boolpair| key it is
% tried to determine if the key already is of one of those types. If this test
% is true the declared choices will be added to the possible choices but the
% key's definition will not be changed other than that. If that wouldn't have
% been done, the callbacks of the different choices could get called multiple
% times.
% \end{function}
%
% \begin{function}{protected,protect}
% The following key will be defined |\protected|. Note that key-types which
% can't be defined expandable will always use |\protected|.
% \end{function}
%
% \begin{function}{long}
% The following key will be defined |\long|.
% \end{function}
%
% \begin{function}{new}
% The following key must be new (so previously undefined). An error is thrown
% if it is already defined and the new definition is ignored. |new| only
% asserts that there are no conflicts between |NoVal| keys and other |NoVal|
% keys or value taking keys and other value taking keys. For example you can
% use the following without an error:
% \begin{lstlisting}
% \ekvdefinekeys{new-example}
% {
% code key = \domystuffwitharg{#1}
% ,new noval key = \domystuffwithoutarg
% }
% \end{lstlisting}
% \end{function}
%
% \subsubsection{\texttt{t}-Prefixes}\label{sec:prefix:t}
% Since the |p|-type prefixes apply to some of the |t|-prefixes automatically
% but sometimes one might be disallowed we need some way to highlight this
% behaviour. In the following an enforced prefix will be printed black
% (\texttt{\enfprefix{protected}}), allowed prefixes will be grey
% (\texttt{\allprefix{protected}}), and disallowed prefixes will be red
% (\texttt{\notprefix{protected}}). This will be put flush-right in the syntax
% showing line.
%
% \begin{function}{code,ecode}
% \begin{syntax}
% code \key\ = \marg{definition} \prefixes2222
% \end{syntax}
% Define \key\ to expand to \meta{definition}. The \key\ will require a \val\
% for which you can use |#1| inside \meta{definition}. The |ecode| variant
% will fully expand \meta{definition} inside an |\edef|.
% \end{function}
%
% \begin{function}{noval,enoval}
% \begin{syntax}
% noval \key\ = \marg{definition} \prefixes2223
% \end{syntax}
% The |noval| type defines \key\ to expand to \meta{definition}. The \key\
% will not take a \val. |enoval| fully expands \meta{definition} inside an
% |\edef|.
% \end{function}
%
% \begin{function}{default,qdefault,odefault,fdefault,edefault}
% \begin{syntax}
% default \key\ = \marg{definition} \prefixes3223
% \end{syntax}
% This serves to place a default \val\ for a \key\ that takes an argument, the
% \key\ can be of any argument-grabbing kind, and when used without a \val\
% it will be passed \meta{definition} instead. The |qdefault| variant will
% expand the \key's code once, so will be slightly quicker, but not change if
% you redefine \key. |odefault| is just another name for |qdefault|. The
% |fdefault| version will expand the key code until a non-expandable token or
% a space is found, a space would be gobbled.\footnotemark{} The |edefault| on
% the other hand fully expands the \key-code with \meta{definition} as its
% argument inside of an |\edef|.
% \end{function}
% \footnotetext
% {^^A
% For those familiar with \TeX-coding: This uses a
% \cs[no-index]{romannumeral}-expansion.
% }
%
% \begin{function}{initial,oinitial,finitial,einitial}
% \begin{syntax}
% initial \key\ = \{\val\} \prefixes3333
% initial \key
% \end{syntax}
% With |initial| you can set an initial \val\ for an already defined argument
% taking \key. It'll just call the key-macro of \key\ and pass it \val. The
% |einitial| variant will expand \val\ using an |\edef| expansion prior to
% passing it to the key-macro and the |oinitial| variant will expand the first
% token in \val\ once. |finitial| will expand \val\ until a non-expandable
% token or a space is found, a space would be
% gobbled.\footnotemark
%
% If you don't provide a value (and no equals sign) a |noval| \key\ of the
% same name is called once (or, if you specified a |default| for a value
% taking key that would be used).
% \end{function}
% \footnotetext{Again using \cs[no-index]{romannumeral}.}
%
% \begin{function}{bool,gbool,boolTF,gboolTF}
% \begin{syntax}
% bool \key\ = \meta{cs} \prefixes2223
% \end{syntax}
% The \meta{cs} should be a single control sequence, such as |\iffoo|.
% This will define \key\ to be a boolean key, which only takes the values
% |true| or |false| and will throw an error for other values. If the key is
% used without a \val\ it'll have the same effect as if you use
% \texttt{\key=true}. |bool| and |gbool| will behave like \TeX-ifs so either
% be |\iftrue| or |\iffalse|. The |boolTF| and |gboolTF| variants will both
% take two arguments and if true the first will be used else the second, so
% they are always either |\@firstoftwo| or |\@secondoftwo|. The variants with
% a leading |g| will set the control sequence globally, the others locally. If
% \meta{cs} is not yet defined it'll be initialised as the |false| version.
% Note that the initialisation is \emph{not} done with |\newif|, so you will
% not be able to do |\footrue| outside of the \kv\ interface, but you could
% use |\newif| yourself. Even if the \key\ will not be |\protected| the
% commands which execute the |true| or |false| choice will be, so the usage
% should be safe in an expansion context (\emph{e.g.}, you can use
% \texttt{edefault \key\ = false} without an issue to change the default
% behaviour to execute the |false| choice). Internally a |bool| \key\ is the
% same as a |choice| key which is set up to handle |true| and |false| as
% choices.
% \end{function}
%
% \begin{function}{invbool,ginvbool,invboolTF,ginvboolTF}
% \begin{syntax}
% bool \key\ = \meta{cs} \prefixes2223
% \end{syntax}
% These are inverse boolean keys, they behave like |bool| and friends but set
% the opposite meaning to the macro \meta{cs} in each case. So if
% \texttt{key=true} is used |invbool| will set \meta{cs} to |\iffalse| and
% vice versa.
% \end{function}
%
% \begin{function}{boolpair,gboolpair,boolpairTF,gboolpairTF}
% \begin{syntax}
% boolpair \key\ = \meta{cs_1}\meta{cs_2} \prefixes2223
% \end{syntax}
% The |boolpair| key type behaves like both |bool| and |invbool|, the
% \meta{cs_1} will be set to the meaning according to the rules of |bool|, and
% \meta{cs_2} will be set to the opposite.
% \end{function}
%
% \begin{function}{store,estore,gstore,xstore}
% \begin{syntax}
% store \key\ = \meta{cs} \prefixes2212
% \end{syntax}
% The \meta{cs} should be a single control sequence, such as |\foo|.
% This will define \key\ to store \val\ inside of the control sequence. If
% \meta{cs} isn't yet defined it will be initialised as empty. The variants
% behave similarly to their |\def|, |\edef|, |\gdef|, and |\xdef|
% counterparts, but |store| and |gstore| will allow you to store macro
% parameters inside of them by using |\unexpanded|.
% \end{function}
%
% \begin{function}{data,edata,gdata,xdata}
% \begin{syntax}
% data \key\ = \meta{cs} \prefixes2212
% \end{syntax}
% The \meta{cs} should be a single control sequence, such as |\foo|. This will
% define \key\ to store \val\ inside of the control sequence. But unlike the
% |store| type, the macro \meta{cs} will be a switch at the same time, it'll
% take two arguments and if \key\ was used expands to the first argument
% followed by \val\ in braces, if \key\ was not used \meta{cs} will expand to
% the second argument (so behave like |\@secondoftwo|). The idea is that with
% this type you can define a key which should be typeset formatted. The
% |edata| and |xdata| variants will fully expand \val, the |gdata| and |xdata|
% variants will store \val\ inside \meta{cs} globally. The |p|-prefixes will
% only affect the key-macro, \meta{cs} will always be expandable and |\long|.
% \end{function}
%
% \begin{function}{dataT,edataT,gdataT,xdataT}
% \begin{syntax}
% dataT \key\ = \meta{cs} \prefixes2212
% \end{syntax}
% Just like |data|, but instead of \meta{cs} grabbing two arguments it'll only
% grab one, so by default it'll behave like |\@gobble|, and if a \val\ was
% given to \key\ the \meta{cs} will behave like |\@firstofone| appended by
% \marg{value}.
% \end{function}
%
% \begin{function}{int,eint,gint,xint}
% \begin{syntax}
% int \key\ = \meta{cs} \prefixes2212
% \end{syntax}
% The \meta{cs} should be a single control sequence, such as |\foo|.
% An |int| key will be a \TeX-count register. If \meta{cs} isn't defined yet,
% |\newcount| will be used to initialise it. The |eint| and |xint| versions
% will use |\numexpr| to allow basic computations in their \val. The |gint|
% and |xint| variants set the register globally.
% \end{function}
%
% \begin{function}{dimen,edimen,gdimen,xdimen}
% \begin{syntax}
% dimen \key\ = \meta{cs} \prefixes2212
% \end{syntax}
% The \meta{cs} should be a single control sequence, such as |\foo|.
% This is just like |int| but uses a dimen register, |\newdimen| and
% |\dimexpr| instead.
% \end{function}
%
% \begin{function}{skip,eskip,gskip,xskip}
% \begin{syntax}
% skip \key\ = \meta{cs} \prefixes2212
% \end{syntax}
% The \meta{cs} should be a single control sequence, such as |\foo|.
% This is just like |int| but uses a skip register, |\newskip| and |\glueexpr|
% instead.
% \end{function}
%
% \begin{function}{toks,gtoks,apptoks,gapptoks,pretoks,gpretoks}
% \begin{syntax}
% toks \key\ = \meta{cs} \prefixes2212
% \end{syntax}
% The \meta{cs} should be a single control sequence, such as |\foo|.
% Store \val\ inside of a toks-register. The |g| variants use |\global|, the
% |app| variants append \val\ to the contents of that register, the |pre|
% variants will prepend \val. If \meta{cs} is not yet defined it will be
% initialised with |\newtoks|.
% \end{function}
%
% \begin{function}{box,gbox}
% \begin{syntax}
% box \key\ = \meta{cs} \prefixes2212
% \end{syntax}
% The \meta{cs} should be a single control sequence, such as |\foo|.
% Typesets \val\ into a |\hbox| and stores the result in a box register. The
% boxes are colour safe. \expkvd\ doesn't provide a |vbox| type.
% \end{function}
%
% \begin{function}{meta}
% \begin{syntax}
% meta \key\ = \{\kv, \ldots\} \prefixes2222
% \end{syntax}
% This key type can set other keys, you can access the \val\ which was passed
% to \key\ inside the \kv\ list with |#1|. It works by calling a sub-|\ekvset|
% on the \kv\ list, so a |set| key will only affect that \kv\ list and not the
% current |\ekvset|. Since it runs in a separate |\ekvset| you can't use
% |\ekvsneak| using keys or similar macros in the way you normally could.
% \end{function}
%
% \begin{function}{nmeta}
% \begin{syntax}
% nmeta \key\ = \{\kv, \ldots\} \prefixes2223
% \end{syntax}
% This key type can set other keys, the difference to |meta| is, that this key
% doesn't take a value, so the \kv\ list is static.
% \end{function}
%
% \begin{function}{smeta}
% \begin{syntax}
% smeta \key\ = \marg{set}\{\kv, \ldots\} \prefixes2222
% \end{syntax}
% Yet another |meta| variant. An |smeta| key will take a \val\ which you can
% access using |#1|, but it sets the \kv\ list inside of \set, so is equal to
% \texttt{\cs[no-index]{ekvset}\marg{set}\{\kv, \ldots\}}.
% \end{function}
%
% \begin{function}{snmeta}
% \begin{syntax}
% snmeta \key\ = \marg{set}\{\kv, \ldots\} \prefixes2223
% \end{syntax}
% And the last |meta| variant. |snmeta| is a combination of |smeta| and
% |nmeta|. It doesn't take an argument and sets the \kv\ list inside of \set.
% \end{function}
%
% \begin{function}{set}
% \begin{syntax}
% set \key\ = \marg{set} \prefixes2233
% \end{syntax}
% This will define \key\ to change the set of the current |\ekvset|
% invocation to \set. You can omit \set\ (including the equals sign),
% which is the same as using \texttt{set \key\ = \{\key\}}. The created |set|
% key will not take a \val. Note that just like in \expkv\ it'll not be
% checked whether \set\ is defined and you'll get a low-level \TeX\ error if
% you use an undefined \set.
% \end{function}
%
% \begin{function}{choice}
% \begin{syntax}
% choice \key\ = \{\val=\meta{definition}, \ldots\} \prefixes2223
% \end{syntax}
% Defines \key\ to be a |choice| key, meaning it will only accept a limited
% set of values. You should define each possible \val\ inside of the
% \val=\meta{definition} list. If a defined \val\ is passed to \key\ the
% \meta{definition} will be left in the input stream. You can make
% individual values |protected| inside the \val=\meta{definition} list. By
% default a |choice| key is expandable, an undefined \val\ will throw an error
% in an expandable way (but see the |unknown-choice| prefix). You can add
% additional choices after the \key\ was created by using |choice| again for
% the same \key, redefining choices is possible the same way, but there is no
% interface to remove certain choices.
% \end{function}
%
% \begin{function}{choice-store}
% \begin{syntax}
% choice-store \key\ = \meta{cs}\{\val, \ldots\} \prefixes2223
% \end{syntax}
% This is defines a special type of |choice| key that'll store the given
% choice inside the macro \meta{cs} (so \meta{cs} should be a single control
% sequence name such as |\foo|). Since storing inside a macro can't be done
% expandably every choice-code is |\protected|, you might define the
% |choice-store| key itself as |protected| as well if you want. Since the
% definition of each choice is predefined with this key type the choice list
% should just be a comma separated list of valid choices.
% \end{function}
% This means that the following |choice| and |choice-store| keys are equivalent
% at use time:
% \begin{lstlisting}
% \newcommand*\mya{}
% \ekvdefinekeys{example}
% {
% choice key1 = {a=\def\mya{a}, b=\def\mya{b}, c=\def\mya{c}}
% ,choice-store key2 = \mya{a,b,c}
% }
% \end{lstlisting}
%
% \begin{function}{choice-enum}
% \begin{syntax}
% choice-enum \key\ = \meta{cs}\{\val, \ldots\} \prefixes2223
% \end{syntax}
% This is similar to |choice-store|, the differences are: \meta{cs} should be
% a count-register or is initialised as such if the \meta{cs} is undefined
% (via |\newcount|); instead of the value the position of the value in the
% given list is stored in this register (zero-based).
% \end{function}
% This means that the following |choice| and |choice-enum| keys are equivalent
% at use time:
% \begin{lstlisting}
% \newcount\myb
% \ekvdefinekeys{example}
% {
% choice key1 = {a={\myb=0 }, b={\myb=1 }, c={\myb=2 }}
% ,choice-enum key2 = \myb{a,b,c}
% }
% \end{lstlisting}
%
% \begin{function}{unknown-choice}
% \begin{syntax}
% unknown-choice \key\ = \marg{definition} \prefixes2323
% \end{syntax}
% By default an unknown \val\ passed to a |choice| or |bool| key will throw an
% error. However, with this prefix you can define an alternative action which
% should be executed if \key\ received an unknown choice. In \meta{definition}
% you can refer to the choice which was passed in with |#1|.
% \end{function}
%
% \begin{function}{unknown code}
% \begin{syntax}
% unknown code = \marg{definition} \prefixes2322
% \end{syntax}
% By default \expkv\ throws errors when it encounters unknown keys in a set.
% With the |unknown| prefix you can define handlers that deal with undefined
% keys, instead of a \key\ name you have to specify a subtype for this prefix,
% here the subtype is |code|.\par
% With |unknown code| the \meta{definition} is used for unknown keys which
% were provided a value (so corresponds to |\ekvdefunknown|), you can access
% the key name with |#1| and the value with |#2|.\footnotemark
% \end{function}
% \footnotetext
% {^^A
% There is some trickery involved to get this more intuitive argument order
% without any performance hit if you compare this to
% \cs[no-index]{ekvdefunknown} directly.^^A
% }
%
% \begin{function}{unknown noval}
% \begin{syntax}
% unknown noval = \marg{definition} \prefixes2323
% \end{syntax}
% This is like |unknown code| but uses \meta{definition} for unknown keys to
% which no value was passed (so corresponds to |\ekvdefunknownNoVal|). You can
% access the key name with |#1|.
% \end{function}
%
% \begin{function}{unknown redirect-code}
% \begin{syntax}
% unknown redirect-code = \marg{set-list} \prefixes2331
% \end{syntax}
% This uses a predefined action for |unknown code|. Instead of throwing an
% error, it is tried to find the \key\ in each \set\ in the comma separated
% \meta{set-list}. The first found match will be used and the remaining
% options from the list discarded. If the \key\ isn't found in any \set\ an
% expandable error will be thrown eventually. Internally \expkv's
% |\ekvredirectunknown| will be used.
% \end{function}
%
% \begin{function}{unknown redirect-noval}
% \begin{syntax}
% unknown redirect-noval = \marg{set-list} \prefixes2333
% \end{syntax}
% This behaves just like |unknown redirect-code| but will set up means to
% forward keys for |unknown noval|. Internally \expkv's
% |\ekvredirectunknownNoVal| will be used.
% \end{function}
%
% \begin{function}{unknown redirect}
% \begin{syntax}
% unknown redirect = \marg{set-list} \prefixes2333
% \end{syntax}
% This is a short cut to apply both, |unknown redirect-code| and
% |unknown redirect-noval|, as a result you might get doubled error messages,
% one from each.
% \end{function}
%
% \subsection{Bugs}
% I don't think there are any (but every developer says that), if you find some
% please let me know, either via the email address on the first page or on
% GitHub:
% \url{https://github.com/Skillmon/tex_expkv-def}
%
% \subsection{Example}
% The following is an example code defining each base key-type once. Please
% admire the very creative key-name examples.
%
% \begin{lstlisting}
% \ekvdefinekeys{example}
% {
% long code keyA = #1
% ,noval keyA = NoVal given
% ,bool keyB = \keyB
% ,boolTF keyC = \keyC
% ,store keyD = \keyD
% ,data keyE = \keyE
% ,dataT keyF = \keyF
% ,int keyG = \keyG
% ,dimen keyH = \keyH
% ,skip keyI = \keyI
% ,toks keyJ = \keyJ
% ,default keyJ = \empty test
% ,new box keyK = \keyK
% ,qdefault keyK = K
% ,choice keyL =
% {
% protected 1 = \texttt{a}
% ,2 = b
% ,3 = c
% ,4 = d
% ,5 = e
% }
% ,edefault keyL = 2
% ,meta keyM = {keyA={#1},keyB=false}
% ,invbool keyN = \keyN
% ,boolpair keyO = \keyOa\keyOb
% }
% \end{lstlisting}
%
% \bigskip
% Since the |data| type might be a bit strange, here is another usage example
% for it.
% \begin{lstlisting}
% \ekvdefinekeys{ex}
% {
% data name = \Pname
% ,data age = \Page
% ,dataT hobby = \Phobby
% }
% \newcommand\Person[1]
% {%
% \begingroup
% \ekvset{ex}{#1}%
% \begin{description}
% \item[\Pname{}{\errmessage{A person requires a name}}]
% \item[Age] \Page{\textit}{\errmessage{A person requires an age}}
% \Phobby{\item[Hobbies]}
% \end{description}
% \endgroup
% }
% \Person{name=Jonathan P. Spratte, age=young, hobby=\TeX\ coding}
% \Person{name=Some User, age=unknown, hobby=Reading Documentation}
% \Person{name=Anybody, age=any}
% \end{lstlisting}
% In this example a person should have a name and an age, but doesn't have to
% have hobbies. The name will be displayed as the description item and the age
% in Italics. If a person has no hobbies the description item will be silently
% left out. The result of the above code looks like this:
%
% \begin{exresult}{\linewidth}
% \ekvdefinekeys{ex}
% {
% data name = \Pname
% ,data age = \Page
% ,dataT hobby = \Phobby
% }
% \newcommand\Person[1]
% {%
% \begingroup
% \ekvset{ex}{#1}%
% \begin{description}
% \item[\Pname{}{\errmessage{A person requires a name}}]
% \item[Age] \Page{\textit}{\errmessage{A person requires an age}}
% \Phobby{\item[Hobbies]}
% \end{description}
% \endgroup
% }
% \Person{name=Jonathan P. Spratte, age=young, hobby=\TeX\ coding}
% \Person{name=Some User, age=unknown, hobby=Reading Documentation}
% \Person{name=Anybody, age=any}
% \end{exresult}
%
% \subsection{License}
%
% Copyright \textcopyright\ 2020\unless\ifnum\year=2020--\the\year\fi\
% Jonathan P. Spratte
%
% \medskip\noindent
% This work may be distributed and/or modified under the conditions of the
% \LaTeX\ Project Public License (LPPL), either version 1.3c of this license or
% (at your option) any later version. The latest version of this license is in
% the file:
%
% \url{http://www.latex-project.org/lppl.txt}
%
% \noindent
% This work is ``maintained'' (as per LPPL maintenance status) by
%
% \mbox{Jonathan P. Spratte}.
%
% \end{documentation}^^A=<<
%
% \begin{implementation}^^A>>=
%
% \clearpage
%
% \section{Implementation}^^A>>=
%^^A the LaTeX package >>=
% \subsection{The \LaTeX\ Package}
% Just like for \expkv\ we provide a small \LaTeX\ package that sets up things
% such that we behave nicely on \LaTeX\ packages and files system. It'll
% |\input| the generic code which implements the functionality.
% \gobbledocstriptag
%<*pkg>
% \begin{macrocode}
\RequirePackage{expkv}
\def\ekvd@tmp
{%
\ProvidesFile{expkv-def.tex}%
[\ekvdDate\space v\ekvdVersion\space a key-defining frontend for expkv]%
}
\input{expkv-def.tex}
\ProvidesPackage{expkv-def}%
[\ekvdDate\space v\ekvdVersion\space a key-defining frontend for expkv]
% \end{macrocode}
% \gobbledocstriptag
%</pkg>
%^^A=<<
%^^A the ConTeXt module >>=
% \subsection{The \ConTeXt\ module}
% \gobbledocstriptag
%<*ctx>
% \begin{macrocode}
\writestatus{loading}{ConTeXt User Module / expkv-def}
\usemodule[expkv]
\unprotect
\input expkv-def.tex
\writestatus{loading}
{ConTeXt User Module / expkv-def / Version \ekvdVersion\space loaded}
\protect\endinput
% \end{macrocode}
% \gobbledocstriptag
%</ctx>
%^^A=<<
%^^A main file >>=
% \subsection{The Generic Code}
% The rest of this implementation will be the generic code.
% \gobbledocstriptag
%<*tex>
%
% Load \expkv\ if the package didn't already do so -- since \expkv\ has
% safeguards against being loaded twice this does no harm and the overhead
% isn't that big. Also we reuse some of the internals of \expkv\ to save us from
% retyping them.
% \begin{macrocode}
\input expkv
% \end{macrocode}
%
% We make sure that \file{expkv-def.tex} is only input once:
% \begin{macrocode}
\expandafter\ifx\csname ekvdVersion\endcsname\relax
\else
\expandafter\endinput
\fi
% \end{macrocode}
%
% \begin{macro}{\ekvdVersion,\ekvdDate}