summaryrefslogtreecommitdiff
path: root/tex/context/base/x-set-11.mkiv
blob: d4b43a9eea0042f522571236b3f87b7b3ad88433 (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
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
%D \module
%D   [       file=x-set-11,
%D        version=2004.10.31,
%D         remark=setupx.tex: 1998.07.20 and later,
%D          title=\CONTEXT\ Setup Definitions,
%D       subtitle=Macro Definitions,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

% we can make this module a bit cleaner using more recent features
% like sorting the xml directly

% \startluacode
%     collectgarbage("stop")
%     function collectgarbage() return 0 end
% \stopluacode

% todo: for fun: pure lua interface, but as this style evolved over 15 years
% it's a waste of time
%
% todo:
%
% \setup{setupinterlinespace}
% \setup{setupinterlinespace:1}
% \setup{setupinterlinespace:2}
%
% cd:include -> filename
% cd:choice
%
% register, interaction

\startmessages  dutch  library: setup
        title:  setup
      formula:  formule
       number:  getal
         list:  lijst
    dimension:  maat
         mark:  markering
    reference:  verwijzing
      command:  commando
         file:  file
         name:  naam
   identifier:  naam
         text:  tekst
      section:  sectie
     singular:  naam enkelvoud
       plural:  naam meervoud
       matrix:  n*m
          see:  zie
     inherits:  erft van
            1:  de karakters < en > zijn globaal actief!
            2:  -- wordt verwerkt
            3:  -- is niet gedefinieerd
            4:  -- wordt nogmaals verwerkt
     optional:  optioneel
  displaymath:  formule
        index:  ingang
         math:  formule
      nothing:  leeg
         file:  file
     position:  positie
    reference:  verwijzing
       csname:  naam
  destination:  bestemming
      triplet:  triplet
         word:  woord
      content:  tekst
\stopmessages

\startmessages  english  library: setup
        title:  setup
      formula:  formula
       number:  number
         list:  list
    dimension:  dimension
         mark:  mark
    reference:  reference
      command:  command
         file:  file
         name:  name
   identifier:  identifier
         text:  text
      section:  section
     singular:  singular name
       plural:  plural name
       matrix:  n*m
          see:  see
     inherits:  inherits from
            1:  the characters < and > are globally active!
            2:  -- is processed
            3:  -- is undefined
            4:  -- is processed again
     optional:  optional
  displaymath:  formula
        index:  entry
         math:  formula
      nothing:  empty
         file:  file
     position:  position
    reference:  reference
       csname:  name
  destination:  destination
      triplet:  triplet
         word:  word
      content:  text
\stopmessages

\startmessages  german library: setup
        title:  Setup
      formula:  Formel
       number:  Nummer
         list:  Liste
    dimension:  Dimension
         mark:  Beschriftung
    reference:  Referenz
      command:  Befehl
         file:  Datei
         name:  Name
   identifier:  Name
         text:  Text
      section:  Abschnitt
     singular:  singular
       plural:  plural
       matrix:  n*m
          see:  siehe
     inherits:  inherits from
            1:  Die Zeichen < und > gelten global!
            2:  -- wird verarbeitet
            3:  -- ist undefiniert
            4:  -- ist mehrmals verarbeitet
     optional:  optioneel
  displaymath:  formula
        index:  entry
         math:  formula
      nothing:  empty
         file:  file
     position:  position
    reference:  reference
       csname:  name
  destination:  destination
      triplet:  triplet
         word:  word
      content:  text
\stopmessages

\startmessages  czech  library: setup
        title:  setup
      formula:  rovnice
       number:  cislo
         list:  seznam
    dimension:  dimenze
         mark:  znacka
    reference:  reference
      command:  prikaz
         file:  soubor
         name:  jmeno
   identifier:  jmeno
         text:  text
      section:  sekce
     singular:  jmeno v singularu
       plural:  jmeno v pluralu
       matrix:  n*m
          see:  viz
     inherits:  inherits from
            1:  znaky < a > jsou globalne aktivni!
            2:  -- je zpracovano
            3:  -- je nedefinovano
            4:  -- je zpracovano znovu
     optional:  optioneel
  displaymath:  formula
        index:  entry
         math:  formula
      nothing:  empty
         file:  file
     position:  position
    reference:  reference
       csname:  name
  destination:  destination
      triplet:  triplet
         word:  word
      content:  text
\stopmessages

\startmessages  italian library: setup
        title:  setup
      formula:  formula
       number:  number
         list:  list
    dimension:  dimension
         mark:  mark
    reference:  reference
      command:  command
         file:  file
         name:  name
   identifier:  name
         text:  text
      section:  section
     singular:  singular name
       plural:  plural name
       matrix:  n*m
          see:  see
     inherits:  inherits from
            1:  the characters < and > are globally active!
            2:  -- is processed
            3:  -- is undefined
            4:  -- is processed again
     optional:  optioneel
  displaymath:  formula
        index:  entry
         math:  formula
      nothing:  empty
         file:  file
     position:  position
    reference:  reference
       csname:  name
  destination:  destination
      triplet:  triplet
         word:  word
      content:  text
\stopmessages

\startmessages  romanian library: setup
        title:  setari
      formula:  formula
       number:  numar
         list:  lista
    dimension:  dimensiune
         mark:  marcaj
    reference:  referinta
      command:  comanda
         file:  fisier
         name:  nume
   identifier:  nume
         text:  text
      section:  sectiune
     singular:  nume singular
       plural:  nume pluram
       matrix:  n*m
          see:  vezi
     inherits:  inherits from
            1:  caracterele < si > sunt active global!
            2:  este procesat --
            3:  -- este nedefinit
            4:  -- este procesat din nou
     optional:  optioneel
  displaymath:  formula
        index:  entry
         math:  formula
      nothing:  empty
         file:  file
     position:  position
    reference:  reference
       csname:  name
  destination:  destination
      triplet:  triplet
         word:  word
      content:  text
\stopmessages

\startmessages  french  library: setup
        title:  réglage
      formula:  formule
       number:  numéro
         list:  liste
    dimension:  dimension
         mark:  marquage
    reference:  reference
      command:  commande
         file:  fichier
         name:  nom
   identifier:  identificateur
         text:  texte
      section:  section
     singular:  nom singulier
       plural:  nom pluriel
       matrix:  n*m
          see:  vois
     inherits:  herite de
            1:  les caractères < et > sont globalement actifs !
            2:  -- est traité
            3:  -- n'est pas défini
            4:  -- est traité de nouveau
     optional:  optionel
  displaymath:  formule
        index:  entrée
         math:  formule
      nothing:  vide
         file:  fichier
     position:  position
    reference:  réference
       csname:  nom
  destination:  destination
      triplet:  triplet
         word:  mot
      content:  texte
\stopmessages

\unprotect

% general

\unexpanded\def\setupnumfont {}
\unexpanded\def\setuptxtfont {}
\unexpanded\def\setupintfont {\WORD}
\unexpanded\def\setupvarfont {\sl}
\unexpanded\def\setupoptfont {\sl}
\unexpanded\def\setupalwcolor{}
\unexpanded\def\setupoptcolor{darkgray}

\def\c!setup!definereserved#1#2%
  {\setvalue{c!setup!:r:#1}{#2}}

\def\c!setup!reserved!#1%
  {\executeifdefined{c!setup!:r:#1}{#1}}

\def\c!setup!internal!#1%
  {\dontleavehmode
   \begingroup
   \setupintfont{#1}%
   \endgroup}

\def\c!setup!text!#1%
  {\dontleavehmode
   \begingroup
   \setupvarfont{#1}%
   \endgroup}

\def\c!setup!command!#1%
  {{\setupvarfont{\texescape...#1}}}

\def\??stp{@@stp}

\defineregister
  [texmacro]
% [texmacros]

\definesorting
  [texcommand]
% [texcommands]

\setupsorting
  [texcommand]
  [\c!command=\showsetupinlist,
   \c!criterium=\@@stpcriterium]

\pushmacro\setuptext

\defineframedtext
  [setuptext]
  [\c!width=\hsize,
   \c!height=\v!fit,
   \c!align=\v!right,
   \c!offset=0.75em]

\popmacro\setuptext

%D Loading:

\let\currentSETUPfullname\s!unknown

\startxmlsetups xml:setups:assemblename
    \doifelse {\xmlatt{#1}{type}} {environment} {
        \let\currentSETUPprefix\e!start
    } {
        \let\currentSETUPprefix\empty
    }
    \edef\currentSETUPname{\xmlatt{#1}{name}}
    \doifelse {\xmlatt{#1}{generated}} {yes} {
        \def\currentSETUPgenerated{*}
    } {
        \let\currentSETUPgenerated\empty
    }
    \doifelsenothing {\xmlatt{#1}{variant}} {
        \let\currentSETUPvariant\empty
    } {
        \def\currentSETUPvariant{:\xmlatt{#1}{variant}}
    }
    \edef\currentSETUPfullname {
        \currentSETUPprefix
        \currentSETUPname
        \currentSETUPvariant
        \currentSETUPgenerated
    }
\stopxmlsetups

\startxmlsetups xml:setups:register
    \xmlsetup{#1}{xml:setups:assemblename}
    % not really needed if we just use setups
    \expanded{\texcommand[stp:x:\currentSETUPfullname]{#1}}
\stopxmlsetups

\startxmlsetups xml:setups:basics
    \xmlinclude{#1}{include}{filename}%
    \xmlsetsetup {#1} {
        sequence|string|variable|assignments|keywords|content|displaymath|index|math|
        nothing|file|position|reference|csname|destination|triplet|word|
        resolve|parameter|constant|inherit|parameter|define
    } {xml:setups:*}
\stopxmlsetups

\xmlregisterdocumentsetup{setups}{xml:setups:basics}

\unexpanded\def\loadsetups{\complexorsimple\loadsetups}

\let\loadedsetups\empty % we load more setups, setups:<name>

\def\simpleloadsetups
  {\doifnotmode{no-setup-main}{\complexloadsetups[cont-en.xml]}}

\def\complexloadsetups[#1]%
  {\doifsomething{#1}
     {\doonlyonce{setups:#1}
        {\doglobal\prependtocommalist{setups:#1}\loadedsetups % last overloads first
         \xmlloadonly{setups:#1}{#1}{setups}%
         \xmlfilter{setups:#1}{/interface/command/command(xml:setups:register)}}}} % qualified path saves > 50% runtime

\newif\ifshortsetup

\unexpanded\def\setup     {\shortsetupfalse\doshowsetup}
\unexpanded\def\showsetup {\shortsetupfalse\doshowsetup}
\unexpanded\def\shortsetup{\shortsetuptrue \doshowsetup}
\unexpanded\def\setupsetup{\dodoubleargument\getparameters[\??stp]}

%unexpanded\def\showsetupinlist#1#2#3{\shortsetupfalse\showsetupindeed{#3}\par}
\unexpanded\def\showsetupinlist#1#2#3{\shortsetupfalse\xmlsetup{#3}{xml:setups:typeset}\par}

% todo: only references in lists

\def\doshowsetup
  {\dosingleempty\dodoshowsetup}

\def\dodoshowsetup[#1]%
  {\iffirstargument
     \dododoshowsetup{#1}%
   \else
     \expandafter\dododoshowsetup
   \fi}

\def\dododoshowsetup#1% this will trigger 'used'
  {\registersort[texcommand][stp:x:#1]%
   \showsetupindeed{#1}}

% \def\showsetupindeed#1%
%   {\xmlfilterlist{\loadedsetups}{interface/command[@name='#1']/command(xml:setups:typeset)}}

\def\showsetupindeed#1%
  {\xmlfilterlist{\loadedsetups}{/interface/command['#1' == (@type=='environment' and 'start' or '') .. @name]/command(xml:setups:typeset)}}

\unexpanded\def\placesetup    {\placelistofsorts[texcommand][\c!criterium=\v!used]}
\unexpanded\def\placeallsetups{\placelistofsorts[texcommand][\c!criterium=\v!all ]}

\let\placeeverysetup\placeallsetups

%D Typesetting:

\setupxml
  [\c!method=mkiv,       % mixed mode
   \c!default=\v!hidden, % ignore elements that are not defined
   \c!compress=\v!yes,   % strip comment
   \c!entities=\v!yes]   % replace entities

\newcounter\currentSETUPargument
\newcounter\maximumSETUPargument

\def\currentSETUPwidth{0pt}

\startxmlsetups xml:setups:typeset
    \getvalue{\e!start setuptext}
        \tttf
        \nohyphens
        \veryraggedright
        \doglobal\newcounter\currentSETUPargument
        \xdef\maximumSETUPargument{\xmlcount{#1}{/arguments/*}}
        \edef\currentSETUPhash{\xmlatt{#1}{hash}}
        \bgroup
            \enablemode[setups-pass-one]%
            \doif {\xmlatt{#1}{generated}} {yes} {
                \ttsl
            }
            \letterbackslash
            \doif {\xmlatt{#1}{type}} {environment} {
                \e!start
            }
            \xmlfilter{#1}{/sequence/first()}
            \ignorespaces
        \egroup
        \xmldoif{#1}{/arguments} {
            \bgroup
                \enablemode[setups-pass-one]
                \doglobal\newcounter\currentSETUPargument
                \ignorespaces
                \xmlfilter{#1}{/arguments/text()}
            \egroup
        }
        \doif {\xmlatt{#1}{type}} {environment} {
            \bgroup
                \enablemode[setups-pass-one]%
                \hskip.5em\unknown\hskip.5em
                \doif {\xmlatt{#1}{generated}} {yes} {
                    \ttsl
                }
                \tex{\e!stop}
                \xmlfilter{#1}{/sequence/first()}
                \ignorespaces
            \egroup
        }
        \endgraf
        \xmldoif{#1}{/arguments} {
            \bgroup
                \enablemode[setups-pass-two]
                \doglobal\newcounter\currentSETUPargument
               %\blank[\v!line] % packed mode (we could do \startunpacked ...)
                \godown[.75\lineheight]
                \switchtobodyfont[\v!small]
                \ignorespaces\xmlfilter{#1}{/arguments/text()}\endgraf
            \egroup
        }
    \getvalue{\e!stop setuptext}
\stopxmlsetups

\setupsetup
  [\c!before=,
   \c!after=,
   \c!command=\setup,
   \c!criterium=\v!used]

\startxmlsetups xml:setups:resolve
    \ignorespaces
    \xmlfilterlist{\loadedsetups}{/interface/define[@name='\xmlatt{#1}{name}']/first()}
\stopxmlsetups

%D This is the first pass; here we generate the top line.

\startxmlsetups xml:setups:define
    \ignorespaces\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:setups:sequence
    \ignorespaces\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:setups:string
    \xmlatt{#1}{value}\ignorespaces
\stopxmlsetups

\startxmlsetups xml:setups:content     \showSETUPcomponent{#1}{content}    {content}     \stopxmlsetups
\startxmlsetups xml:setups:displaymath \showSETUPcomponent{#1}{displaymath}{display math}\stopxmlsetups
\startxmlsetups xml:setups:index       \showSETUPcomponent{#1}{index}      {index}       \stopxmlsetups
\startxmlsetups xml:setups:math        \showSETUPcomponent{#1}{math}       {math}        \stopxmlsetups
\startxmlsetups xml:setups:nothing     \showSETUPcomponent{#1}{nothing}    {nothing}     \stopxmlsetups
\startxmlsetups xml:setups:file        \showSETUPcomponent{#1}{file}       {file name}   \stopxmlsetups
\startxmlsetups xml:setups:position    \showSETUPcomponent{#1}{position}   {position}    \stopxmlsetups
\startxmlsetups xml:setups:reference   \showSETUPcomponent{#1}{reference}  {reference}   \stopxmlsetups
\startxmlsetups xml:setups:csname      \showSETUPcomponent{#1}{csname}     {csname}      \stopxmlsetups
\startxmlsetups xml:setups:destination \showSETUPcomponent{#1}{destination}{destination} \stopxmlsetups
\startxmlsetups xml:setups:triplet     \showSETUPcomponent{#1}{triplet}    {triplet}     \stopxmlsetups
\startxmlsetups xml:setups:word        \showSETUPcomponent{#1}{word}       {word}        \stopxmlsetups

\def\showSETUPcomponent#1#2#3%
  {\doifmodeelse{setups-pass-one}
     {\getvalue{showSETUP#2}{#1}}
     {\simpleSETUPargument{#3}}}

%D This is the second pass; here we generate the table.

\unexpanded\def\startfirstSETUPcolumn#1%
  {\bgroup
   \advance\leftskip 2em
   \noindent\llap{\hbox to 2em{#1\hss}}}

\unexpanded\def\stopfirstSETUPcolumn
  {\endgraf
   \egroup}

\unexpanded\def\startsecondSETUPcolumn#1#2%
  {\bgroup
   \advance\hangindent\dimexpr\currentSETUPwidth+2.5em\relax
   \noindent \hbox to \hangindent{#1\hss\hbox to 2.5em{\hss#2\hss}}}

\unexpanded\def\stopsecondSETUPcolumn
  {\endgraf
   \egroup}

\def\secondSETUPcolumn#1#2%
  {\startsecondSETUPcolumn{#1}{#2}\stopsecondSETUPcolumn}

\def\previousSETUPargument{\currentSETUPargument}

\startxmlsetups xml:setups:parameter:measure
    \setbox0=\hbox{\c!setup!reserved!{\xmlatt{#1}{name}}}
    \ifdim\wd0>\currentSETUPwidth\xdef\currentSETUPwidth{\the\wd0}\fi
\stopxmlsetups

\startxmlsetups xml:setups:assignments
    \doifmodeelse{setups-pass-one} {
        \showSETUPassignment{#1}
    } {
        \xdef\currentSETUPwidth{0pt}%
        \bgroup
            \xmlfilter{#1}{/parameter/command(xml:setups:parameter:measure)}
        \egroup
        \startfirstSETUPcolumn{\showSETUPnumber}%
            \ignorespaces
            \xmldoifelse{#1}{/(parameter|inherit)}{
                \xmlflush{#1}
            } {
             ...
            }
            \let\previousSETUPargument\currentSETUPargument
        \stopfirstSETUPcolumn
        \blank[\v!halfline]
        \ignorespaces
    }
\stopxmlsetups

\startxmlsetups xml:setups:keywords
    \doifmodeelse{setups-pass-one} {
        \showSETUPkeyword{#1}
    } {
        \startfirstSETUPcolumn{\showSETUPnumber}%
            \ignorespaces
            \xmlflush{#1}
            \let\previousSETUPargument\currentSETUPargument
        \stopfirstSETUPcolumn
        \blank[\v!halfline]
        \ignorespaces
    }
\stopxmlsetups

\startxmlsetups xml:setups:parameter
    \startsecondSETUPcolumn{\c!setup!reserved!{\xmlatt{#1}{name}}}{=}
        \ignorespaces
        \xmlflush{#1}
        \doifmode{interface:setup:defaults} {
            \ifx\currentSETUPhash\empty \else
               \edef\currentSETUPvalue{\csname named\currentSETUPhash parameter\endcsname\empty{\xmlatt{#1}{name}}}
               \ifx\currentSETUPvalue\empty
                 \space=\space
                 \detokenize\expandafter{\currentSETUPvalue}
               \fi
            \fi
        }
    \stopsecondSETUPcolumn
    \ignorespaces
\stopxmlsetups

\startxmlsetups xml:setups:constant
    \doifmodeelse {setups-pass-one} {
    } {
        \doif {\xmlatt{#1}{default}} {yes} {
            \underbar % next needs to be {braced}
        }
        {\c!setup!reserved!{\xmlatt{#1}{type}}}
        \space
        \ignorespaces
    }
\stopxmlsetups

\startxmlsetups xml:setups:variable
    \doifmodeelse {setups-pass-one} {
        \expanded{\setupintfont{\xmlatt{#1}{value}}}\ignorespaces
    } {
        \c!setup!reserved!{\xmlatt{#1}{value}}
        \space
        \ignorespaces
    }
\stopxmlsetups

\startxmlsetups xml:setups:inherit
   \secondSETUPcolumn {
        \c!setup!text!{\getmessage{setup}{inherits}}
        \enspace
        \letterbackslash
        \xmlatt{#1}{name}
    } {}
    \ignorespaces
\stopxmlsetups

\def\simpleSETUPargument#1%
  {\startfirstSETUPcolumn{\showSETUPnumber}%
      \c!setup!internal!{#1}%
   \stopfirstSETUPcolumn
   \blank[\v!halfline]
   \ignorespaces}

\c!setup!definereserved {cd:command}        {\c!setup!internal!{\getmessage{setup}{command}}}
\c!setup!definereserved {cd:dimension}      {\c!setup!internal!{\getmessage{setup}{dimension}}}
\c!setup!definereserved {cd:file}           {\c!setup!internal!{\getmessage{setup}{file}}}
\c!setup!definereserved {cd:name}           {\c!setup!internal!{\getmessage{setup}{identifier}}}
\c!setup!definereserved {cd:character}      {\c!setup!internal!{\getmessage{setup}{character}}}
\c!setup!definereserved {cd:mark}           {\c!setup!internal!{\getmessage{setup}{mark}}}
\c!setup!definereserved {cd:number}         {\c!setup!internal!{\getmessage{setup}{number}}}
\c!setup!definereserved {cd:reference}      {\c!setup!internal!{\getmessage{setup}{reference}}}
\c!setup!definereserved {cd:plural}         {\c!setup!internal!{\getmessage{setup}{plural}}}
\c!setup!definereserved {cd:singular}       {\c!setup!internal!{\getmessage{setup}{singular}}}
\c!setup!definereserved {cd:text}           {\c!setup!internal!{\getmessage{setup}{text}}}
\c!setup!definereserved {cd:formula}        {\c!setup!internal!{\getmessage{setup}{formula}}}
\c!setup!definereserved {cd:file}           {\c!setup!internal!{\getmessage{setup}{file}}}
\c!setup!definereserved {cd:matrix}         {\c!setup!internal!{\getmessage{setup}{matrix}}}
\c!setup!definereserved {cd:list}           {\c!setup!internal!{\getmessage{setup}{list}}}
\c!setup!definereserved {cd:section}        {\c!setup!internal!{\getmessage{setup}{section}}}

\c!setup!definereserved {cd:noargument}     {\c!setup!command! {}}
\c!setup!definereserved {cd:oneargument}    {\c!setup!command! {\#1}}
\c!setup!definereserved {cd:twoarguments}   {\c!setup!command! {\#1\#2}}
\c!setup!definereserved {cd:threearguments} {\c!setup!command! {\#1\#2\#3}}

%D Auxiliary.

\unexpanded\def\showSETUP#1#2#3%
  {\bgroup
   \doglobal\increment\currentSETUPargument
   \setbox0=\hbox
     {\doifelse{\xmlatt{#1}{list}}{yes}{#3}{#2}}%
   \setbox2=\hbox to \wd0
     {\hss
      \raise1ex\hbox
        {\tx\ifcase\maximumSETUPargument\relax
           \or*\else\currentSETUPargument
         \fi}%
      \hss}%
   \setbox4=\hbox to \wd0
     {\hss
      \lower2ex\hbox
        \bgroup
          \txx\doif{\xmlatt{#1}{optional}}{yes}{\c!setup!internal!{\getmessage{setup}{optional}}}%
        \egroup
      \hss}%
   \ht2\ht\strutbox
   \dp4\dp\strutbox
   \hskip.5em\hsmash{\box0}\hsmash{\box4}\box2%
   \egroup
   \ignorespaces}

\def\showSETUPnumber
  {\doglobal\increment\currentSETUPargument
   \hbox to 2em
     {\ifcase\maximumSETUPargument\relax
        \or*\else\currentSETUPargument
      \fi
      \hss}}

\def\showSETUPassignment #1{\showSETUP{#1}{[.\lower.5ex\hbox{=}.]}              {[..,.\lower.5ex\hbox{=}.,..]}}
\def\showSETUPkeyword    #1{\showSETUP{#1}{[...]}                               {[...,...]}}
\def\showSETUPargument   #1{\showSETUP{#1}{\leftargument..\rightargument}       {\leftargument..,...,..\rightargument}}
\def\showSETUPdisplaymath#1{\showSETUP{#1}{\$\$...\$\$}                         {\$\$...\$\$}}
\def\showSETUPindex      #1{\showSETUP{#1}{\leftargument...\rightargument}      {\leftargument..+...+..\rightargument}}
\def\showSETUPmath       #1{\showSETUP{#1}{\$...\$}                             {\$...\$}}
\def\showSETUPnothing    #1{\showSETUP{#1}{...}                                 {}}
\def\showSETUPfile       #1{\showSETUP{#1}{~...~}                               {}}
\def\showSETUPposition   #1{\showSETUP{#1}{(...)}                               {(...,...)}}
\def\showSETUPreference  #1{\showSETUP{#1}{[...]}                               {[...,...]}}
\def\showSETUPcsname     #1{\showSETUP{#1}{{\c!setup!command!{}}}               {}}
\def\showSETUPdestination#1{\showSETUP{#1}{[\leftargument..[ref]\rightargument]}{[..,\leftargument..[ref,..]\rightargument,..]}}
\def\showSETUPtriplet    #1{\showSETUP{#1}{[x:y:z=]}                            {[x:y:z=,..]}}
\def\showSETUPword       #1{\showSETUP{#1}{\leftargument...\rightargument}      {\leftargument.. ... ..\rightargument}}
\def\showSETUPcontent    #1{\showSETUP{#1}{\leftargument...\rightargument}      {\leftargument.. ... ..\rightargument}}

% A prelude to a rewrite and some more:

\definetype[parametercommand][type]
\definetype[parameterkey]    [type]
\definetype[parametervalue]  [type][space=on]

\setuptype[parametercommand] [color=darkmagenta]
\setuptype[parametervalue]   [color=darkyellow]

\startxmlsetups xml:setups:parameters:value
    \edef\currentsetupparameterkey  {\xmlatt{#1}{name}}
    \edef\currentsetupparametervalue{\csname named\currentsetupparametercategory parameter\endcsname\currentsetupparameterinstance\currentsetupparameterkey}
    \ifx\currentsetupparameterinstance\empty
        \expanded {
            \NC \parameterkey  {\currentsetupparameterkey}
            \NC \parametervalue{\detokenize\expandafter{\currentsetupparametervalue}}
            \NC \NR
        }
    \else\ifx\currentsetupparametervalue\empty
    \else
        \edef\currentsetupparameterdefault{\csname named\currentsetupparametercategory parameter\endcsname\empty\currentsetupparameterkey}
        \ifx\currentsetupparametervalue\currentsetupparameterdefault
            % skip
        \else
            \expanded {
                \NC \parameterkey  {\currentsetupparameterkey}
                \NC \parametervalue{\detokenize\expandafter{\currentsetupparametervalue}}
                \NC \NR
            }
        \fi
    \fi\fi
\stopxmlsetups

\startxmlsetups xml:setups:parameters:values
    \blank[big]
    \expanded {
        \parametercommand {
            \currentsetupparametercommand
            \space:\space
            \ifx\currentsetupparameterinstance\empty
                defaults
            \else
                \currentsetupparameterinstance
            \fi
        }
    }
    \blank[big,samepage]
    \starttabulate[|l|p|]
        \xmlall
            {#1}
            {/interface/command[@name=='\currentsetupparametercommand']/arguments/assignments/parameter/command(xml:setups:parameters:value)}
        \ifnum\noftabulaterows = \zerocount
            \NC \parameterkey{no specific settings} \NC \NC \NR
        \fi
    \stoptabulate
\stopxmlsetups


\starttexdefinition showrootvalues [#1]
    \edef\currentsetupparametercategory{#1}
    \edef\currentsetupparametercommand{setup#1}
    \let\currentsetupparameterinstance\empty
    \xmlsetup{\loadedsetups}{xml:setups:parameters:values}
\stoptexdefinition

\starttexdefinition showinstancevalues [#1]#2[#3]
    \edef\currentsetupparametercategory{#1}
    \edef\currentsetupparametercommand{setup#1}
    \edef\currentsetupparameterinstance{#3}
    \xmlsetup{\loadedsetups}{xml:setups:parameters:values}
\stoptexdefinition

\protect \endinput