strc-syn.mkxl /size: 24 Kb    last modification: 2024-01-16 09:03
1%D \module
2%D   [       file=strc-syn,
3%D        version=2008.10.20,
4%D          title=\CONTEXT\ Structure Macros,
5%D       subtitle=Synonyms and Sorting,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Structure Macros / Synonyms and Sorting}
15
16\registerctxluafile{strc-syn}{autosuffix}
17
18%D Although we could nowadays build this on top of regular lists we keep this
19%D more efficient variant around. Eventually we can add some options to lists
20%D that also provide such functionality but at the cost of much more overhead.
21%D
22%D We show a usage of both synonyms and sorts, which are deep down variants of
23%D so called simple lists. A definition looks like this:
24%D
25%D \startbuffer
26%D \definesynonyms
27%D   [myabbreviation]
28%D
29%D \setupsynonyms
30%D   [myabbreviation]
31%D   [headstyle=bold,
32%D    headcolor=darkred,
33%D    synonymstyle=boldslanted,
34%D    synonymcolor=darkblue,
35%D    textstyle=slanted,
36%D    textcolor=darkgreen,
37%D    style=normal,
38%D    color=darkyellow]
39%D
40%D \definesorting
41%D   [mylogo]
42%D
43%D \setupsorting
44%D   [mylogo]
45%D   [style=bold,
46%D    color=darkmagenta]
47%D \stopbuffer
48%D
49%D \typebuffer \getbuffer
50%D
51%D More complex definitions involves commands to call up meanings and such. The
52%D use of the defined commands is as follows: \
53%D
54%D \startbuffer
55%D \myabbreviation [FIRST]  {TheFirst}  {The First Words}
56%D \myabbreviation [SECOND] {TheSecond} {The Second Words}
57%D \myabbreviation [THIRD]  {TheThird}  {The Third Words}
58%D
59%D \mylogo [FOURTH] {TheFourth}
60%D \stopbuffer
61%D
62%D \typebuffer \getbuffer
63%D
64%D By default a synonym is just typeset and flagged as being used, so that in
65%D a list it wil be shows with its meaning. You can however also expand the
66%D meaning automatically at first use:
67%D
68%D \startbuffer
69%D \setupsynonyms[myabbreviation][alternative=first]
70%D
71%D We have \FIRST, \SECOND\ and also \THIRD\ but no \FOURTH.
72%D
73%D We have \FIRST, \SECOND\ and also \THIRD\ but no \FOURTH.
74%D \stopbuffer
75%D
76%D \typebuffer \getbuffer
77%D
78%D We can change the order, as demonstrated in:
79%D
80%D \startbuffer
81%D \resetshownsynonyms[myabbreviation]
82%D
83%D \setupsynonyms[myabbreviation][alternative=last]
84%D
85%D We have \FIRST\ and \THIRD\ or \FOURTH.
86%D
87%D We have \FIRST\ and \THIRD\ or \FOURTH.
88%D \stopbuffer
89%D
90%D \typebuffer \getbuffer
91%D
92%D A list is called up with:
93%D
94%D \startbuffer
95%D \placelistofsynonyms[myabbreviation]
96%D
97%D \placelistofsorts[mylogo]
98%D \stopbuffer
99%D
100%D \typebuffer \getbuffer
101%D
102%D The lists are constructions (like descriptions are) and can be set up
103%D likewise.
104%D
105%D You can show the currently accessed entries as follows:
106%D
107%D \starttyping
108%D \startchapter[title=One]
109%D     test \FIRST\ test test \THIRD\ test \blank
110%D     \placelistofsynonyms[myabbreviation]
111%D     \resetsynonymsprogress[myabbreviation] % reset state
112%D \stopchapter
113%D
114%D \startchapter[title=Two]
115%D     test \FIRST\ test test \SECOND\ test \blank
116%D     \placelistofsynonyms[myabbreviation][criterium=current]
117%D     \resetsynonymsprogress[myabbreviation] % reset state
118%D \stopchapter
119%D
120%D \startchapter[title=Three]
121%D     test test test test test test \blank
122%D     \placelistofsynonyms[myabbreviation][criterium=current] % also reset state
123%D \stopchapter
124%D
125%D \startchapter[title=All]
126%D     \placelistofsynonyms[myabbreviation][criterium=all]
127%D \stopchapter
128%D \stoptyping
129
130% todo: add 'define only' option to descriptions, then add sorting (also based on key)
131% and call to definition -> replaces this module
132
133\unprotect
134
135% split but common in lua
136
137\permanent\protected\def\preprocessexpansion#1#2#3#4% do this at the lua end if still needed
138  {\ifx#1\s!xml
139     \xmlstartraw
140       \xdef#2{#4}%
141     \xmlstopraw
142     \glet#3\s!xml
143   \else
144     \ifx#1\v!yes
145       \xdef#2{#4}%
146     \else
147       \xdef#2{\detokenize{#4}}%
148     \fi
149     \glet#3\s!tex
150   \fi}
151
152%D We now use a simple list variant:
153
154\installcorenamespace {simplelist}
155
156\installcommandhandler \??simplelist {simplelist} \??simplelist
157
158\aliased\let\setupsimplelists\setupsimplelist
159
160\setupsimplelists[%
161    %c!title=,
162    %c!text=,
163    %
164    %c!style=,
165    %c!color=,
166    %c!command=,
167    %c!align=,
168    %
169    %c!headstyle=,
170    %c!headcolor=,
171    %c!headalign=,
172    %
173    %c!titlestyle=,
174    %c!titlecolor=,
175    %c!titlecommand=,
176    %c!titleleft=,
177    %c!titleright=,
178    %
179    %c!closesymbol=,
180    %c!closecommand=,
181    %
182    \c!alternative=\v!left,
183    \c!display=\v!yes,
184    \c!width=7\emwidth,
185    \c!distance=\emwidth,
186    \c!titledistance=.5\emwidth,
187    %c!hang=,
188    %c!sample=,
189    \c!margin=\v!no,
190    \c!before=\startpacked,
191    \c!inbetween=\blank,
192    \c!after=\stoppacked,
193    %c!indentnext=,
194    %c!indenting=,
195    %
196    \c!expansion=\v!no,
197    %c!xmlsetup=,
198    %s!catcodes=,
199    \s!language=\currentmainlanguage,
200]
201
202\newconditional\c_strc_constructions_define_commands
203
204\appendtoks
205    \c_strc_constructions_define_commands\conditionalfalse
206    \ifempty\currentsimplelistparent
207        \defineconstruction[\currentsimplelist][\s!handler=\v!simplelist,\c!level=1]%
208    \else
209        \defineconstruction[\currentsimplelist][\currentsimplelistparent][\s!handler=\v!simplelist,\c!level=1]%
210    \fi
211    \c_strc_constructions_define_commands\conditionaltrue
212\to \everydefinesimplelist
213
214\protected\defcsname\??constructioninitializer\v!simplelist\endcsname
215  {\let         \currentsimplelist               \currentconstruction
216   \enforced\let\constructionparameter           \simplelistparameter
217   \enforced\let\constructionnamespace           \??simplelist
218   \enforced\let\detokenizedconstructionparameter\detokenizedsimplelistparameter
219   \enforced\let\letconstructionparameter        \letsimplelistparameter
220   \enforced\let\useconstructionstyleandcolor    \usesimpleliststyleandcolor
221   \enforced\let\setupcurrentconstruction        \setupcurrentsimplelist}
222
223\protected\defcsname\??constructionfinalizer\v!simplelist\endcsname
224  {}
225
226\protected\defcsname\??constructiontexthandler\v!simplelist\endcsname
227  {\begingroup
228   \useconstructionstyleandcolor\c!headstyle\c!headcolor
229   \expand\everyconstruction
230   \constructionparameter\c!headcommand
231     {\strut
232      \currentsimplelistentry}%
233   \endgroup}
234
235% And we build on top of this.
236
237\ifdefined\dotagsynonym \else \aliased\let\dotagsynonym\relax \fi
238\ifdefined\dotagsorting \else \aliased\let\dotagsorting\relax \fi
239
240\definesimplelist
241  [\v!synonym]
242  [\c!state=\v!start,
243  %\c!synonymstyle=,
244  %\c!textstyle=,
245  %\c!headstyle=,
246  %\c!headcolor=,
247  %\c!criterium=,
248   \c!location=\v!left,
249   \c!width=5\emwidth,
250   \c!distance=\zeropoint,
251  %\c!sample=,
252  %\c!hang=,
253  %\c!align=,
254  %\c!before=,
255  %\c!inbetween=,
256  %\c!after=,
257   \c!indentnext=\v!no,
258  %\c!expansion=,
259   \c!method=]
260
261\aliased\let\setupsynonyms\setupsimplelist
262
263% these  might become private
264
265\mutable\lettonothing\currentsynonymoption
266\mutable\lettonothing\currentsynonymcoding
267\mutable\lettonothing\currentsynonymexpansion
268\mutable\lettonothing\currentsynonym
269\mutable\lettonothing\currentsynonymtag
270\mutable\lettonothing\currentsynonymtext
271\mutable\lettonothing\currentsynonymsortkey
272
273\permanent\tolerant\protected\def\definesynonyms[#1]#*[#2]#*[#3]#*[#4]% name plural \meaning \use
274  {\ifnum\lastarguments=\plusfour
275     \protected\instance\def#4##1{\strc_synonyms_insert{#1}{##1}}% name tag
276     \frozen\instance\protected\defcsname#1\endcsname{\definesynonym[\v!no][#1]}% \name
277   \else
278     \frozen\instance\protected\defcsname#1\endcsname{\definesynonym[\v!yes][#1]}% \name
279   \fi
280   \ifparameter#3\or
281     \frozen\instance\protected\def#3##1{\strc_synonyms_insert_meaning{#1}{##1}}% \meaning
282   \fi
283   \cdef\currentsynonym{#1}%
284   %
285  %\checksynonymparent
286  %\setupcurrentsynonym[\s!single={#1},\s!multi={#2}]%
287   \c_strc_constructions_define_commands\conditionalfalse
288   \definesimplelist
289     [\currentsynonym]%
290     [\v!sorting]
291     [\s!single={#1},%
292      \s!multi={#2}]%
293   \c_strc_constructions_define_commands\conditionaltrue
294   \ifparameter#2\or
295     %
296     \presetheadtext[#2=\Word{#2}]% changes the \if...argument
297     %
298     % These will go away. Actually the overloads catched this empty case!
299     %
300     \frozen\instance\protected\defcsname\e!setup #2\e!endsetup\endcsname{\setupsynonyms[#1]}% obsolete definition
301     \frozen\instance\protected\defcsname\e!place   \e!listof#2\endcsname{\placelistofsynonyms[#1]}% accepts extra argument
302     \frozen\instance\protected\defcsname\e!complete\e!listof#2\endcsname{\completelistofsynonyms[#1]}%
303   \fi}
304
305% \abbreviation[XXX][321]{321}{Three, Two, One} : optional sort key
306
307\permanent\tolerant\protected\def\definesynonym[#1]#*[#2]#*[#3]#*[#4]% [yes][abbreviation][FOO]{foo}{foo me}
308  {\begingroup
309   \edef\currentsynonymoption{#1}%
310   \cdef\currentsynonym{#2}%
311   \edef\currentsynonymtag{#3}%
312   \edef\currentsynonymsortkey{#4}%
313   \strc_synonyms_define_entry}
314
315% \installcorenamespace {synonymentry}
316%
317% \installsetuponlycommandhandler \??synonymentry {synonymentry}
318%
319% \permanent\tolerant\protected\def\setsynonym[#1]#*[#2]%
320%   {\begingroup
321%    \setupsynonymentry[#2]%
322%    \cdef\currentsynonym       {#1}%
323%    \edef\currentsynonymoption {\synonymentryparameter\c!option}%
324%    \edef\currentsynonymtag    {\synonymentryparameter\c!tag}%
325%    \edef\currentsynonymsortkey{\synonymentryparameter\c!sortkey}%
326%    \strc_synonyms_define_entry{\synonymentryparameter\c!text}{\synonymentryparameter\c!meaning}}
327
328\def\strc_synonyms_define_entry#1#2%
329  {\let\currentsimplelist\currentsynonym
330   \ifempty\currentsynonymtag
331     \edef\currentsynonymtag{#1}%
332   \fi
333   \ifempty\currentsynonymtag \else
334     % this is not that efficient, esp when we load a big list
335     \edef\currentsynonymexpansion{\simplelistparameter\c!expansion}%
336     \preprocessexpansion\currentsynonymexpansion\m_synonyms_text   \currentsynonymcoding{#1}%
337     \preprocessexpansion\currentsynonymexpansion\m_synonyms_meaning\currentsynonymcoding{#2}%
338     % currently they all end up in the tuc file
339     \clf_registersynonym
340        {\currentsynonym}%
341        {synonym}%
342        {%
343            metadata {%
344                catcodes \catcodetable
345                coding   {\currentsynonymcoding}%
346            \ifx\currentsynonymcoding\s!xml
347                xmlroot  {\xmldocument}%
348            \fi
349            }%
350            definition {%
351                tag     {\currentsynonymtag}%
352                sortkey {\currentsynonymsortkey}%
353                synonym {\m_synonyms_text}%
354                meaning {\m_synonyms_meaning}%
355              % used    false
356            }%
357        }%
358     \relax
359     \ifx\currentsynonymoption\v!yes
360      %\instance\setuxvalue\currentsynonymtag{\strc_synonyms_insert{\currentsynonym}{\currentsynonymtag}}%
361       \protected\instance\xdefcsname\currentsynonymtag\endcsname
362         {\strc_synonyms_insert{\currentsynonym}{\currentsynonymtag}}%
363     \fi
364   \fi
365   \endgroup}
366
367\permanent\tolerant\protected\def\registersynonym  [#1]#*[#2]{\clf_registerusedsynonym{#1}{#2}}
368\permanent         \protected\def\currentsynonymname         {\clf_synonymname\currentsimplelist\currentsynonymtag}
369\permanent         \protected\def\currentsynonymmeaning      {\clf_synonymmeaning\currentsimplelist\currentsynonymtag}
370\permanent         \protected\def\currentsynonympages        {\clf_synonympages\currentsimplelist\currentsynonymtag}
371\permanent         \protected\def\doifelsecurrentsynonymused {\clf_doifelsesynonymused\currentsimplelist\currentsynonymtag}
372\permanent         \protected\def\doifelsecurrentsynonymshown{\clf_doifelsesynonymshown\currentsimplelist\currentsynonymtag}
373\permanent         \protected\def\resetusedsynonyms      [#1]{\clf_resetsynonyms{#1}{used}}
374\permanent         \protected\def\resetshownsynonyms     [#1]{\clf_resetsynonyms{#1}{shown}}
375\permanent         \protected\def\resetlistsynonyms      [#1]{\clf_resetsynonyms{#1}{list}}
376\permanent         \protected\def\resetsynonyms          [#1]{\clf_resetsynonyms{#1}{all}}
377\permanent         \protected\def\resetsynonymsprogress  [#1]{\clf_resetsynonyms{#1}{progress}}
378
379\permanent\protected\def\registercurrentsynonympage % \registercurrentsortingpage
380  {\ifcstok{\simplelistparameter\v!page}\v!yes
381     \clf_enhancesynonym\currentsimplelist\currentsynonymtag
382   \fi}
383
384\aliased\let\rawsynonymname   \clf_synonymname
385\aliased\let\rawsynonymmeaning\clf_synonymmeaning
386\aliased\let\rawsynonympages  \clf_synonympages
387
388\permanent\protected\def\synonymname   [#1]#*[#2]{\clf_synonymname   {#1}{#2}}
389\permanent\protected\def\synonymmeaning[#1]#*[#2]{\clf_synonymmeaning{#1}{#2}}
390\permanent\protected\def\synonympages  [#1]#*[#2]{\clf_synonympages  {#1}{#2}}
391
392\installcorenamespace{simplelistalternative} % specific ways of rendering a list
393\installcorenamespace{simplelistrenderings}  % a namespace for setups (rather local)
394
395\installcommandhandler \??simplelistalternative {simplelistalternative} \??simplelistalternative
396
397\setupsimplelist
398  [\v!synonym]
399  [\c!alternative=\v!normal]
400
401\protected\def\strc_synonyms_insert_meaning#1#2% name tag
402  {\dontleavehmode % otherwise we don't get it right at the beginning of a par
403   \begingroup
404   \cdef\currentsimplelist{#1}%
405   \def\currentsynonymtag{#2}%
406   \fastsetup{\??simplelistrenderings::\v!text}%
407   \endgroup}
408
409\protected\def\strc_synonyms_insert#1#2% name tag
410  {\dontleavehmode % otherwise we don't get it right at the beginning of a par
411   \begingroup
412   \cdef\currentsimplelist{#1}%
413   \let\currentsynonym\currentsimplelist % for a while
414   \def\currentsynonymtag{#2}%
415   \edef\currentsimplelistalternative{\simplelistparameter\c!alternative}%
416   \doifnotcommandhandler\??simplelistalternative\currentsimplelistalternative
417     {\let\currentsimplelistalternative\v!normal}%
418   \fastsetup{\??simplelistrenderings:\v!synonym:\currentsimplelistalternative}%
419   \normalexpanded{\endgroup\simplelistparameter\c!next}}
420
421% \setupsimplelistalternative
422%   [\c!command=\directsimplelistparameter\c!command]
423
424\definesimplelistalternative
425  [\v!normal]
426  [\c!inbetween=\space,
427   \c!left=(,
428   \c!right=)]
429
430\definesimplelistalternative
431  [\v!first]
432  [\v!normal]
433
434\definesimplelistalternative
435  [\v!last]
436  [\v!normal]
437
438\startsetups[\??simplelistrenderings::\v!synonym]
439    \begingroup
440    \dostarttaggedchained\t!synonym\currentsynonym\??simplelist
441    \dotagsynonym
442    \usesimpleliststyleandcolor\c!synonymstyle\c!synonymcolor
443    \registercurrentsynonympage
444    \simplelistparameter\c!synonymcommand{\currentsynonymname}%
445    \dostoptagged
446    \endgroup
447\stopsetups
448
449\startsetups[\??simplelistrenderings::\v!text]
450    \begingroup
451    \usehyphensparameter\simplelistparameter
452    \usesimpleliststyleandcolor\c!textstyle\c!textcolor
453    \simplelistparameter\c!textcommand{\currentsynonymmeaning}%
454    \endgroup
455\stopsetups
456
457\startsetups[\??simplelistrenderings:\v!synonym:\v!normal]
458    \fastsetup{\??simplelistrenderings::\v!synonym}
459\stopsetups
460
461\startsetups[\??simplelistrenderings:\v!synonym:\v!first]
462    \fastsetup{\??simplelistrenderings::\v!synonym}
463    \doifelsecurrentsynonymshown \donothing {
464        \simplelistalternativeparameter\c!inbetween
465        \simplelistalternativeparameter\c!left
466        \fastsetup{\??simplelistrenderings::\v!text}
467        \simplelistalternativeparameter\c!right
468    }
469\stopsetups
470
471\startsetups[\??simplelistrenderings:\v!synonym:\v!last]
472    \doifelsecurrentsynonymshown {
473        \fastsetup{\??simplelistrenderings::\v!synonym}
474    } {
475        \fastsetup{\??simplelistrenderings::\v!text}
476        \simplelistalternativeparameter\c!inbetween
477        \simplelistalternativeparameter\c!left
478        \fastsetup{\??simplelistrenderings::\v!synonym}
479        \simplelistalternativeparameter\c!right
480    }
481\stopsetups
482
483\aliased\let\synonymentry\relax
484
485\permanent\tolerant\protected\def\placelistofsynonyms[#1]#*[#S#2]%
486  {\begingroup
487   \cdef\currentsimplelist{#1}%
488   \doifelsecommandhandler\??simplelist\currentsimplelist
489     {\strc_constructions_initialize{#1}%
490      \setupcurrentsimplelist[#2]%
491      \enforced\let\synonymentry\strc_synonym_normal
492      % so we can hook tabulate into before and after
493      \normalexpanded{\simplelistparameter\c!before
494        \noexpand\clf_processsynonyms
495           {#1}%
496           {%
497               criterium {\simplelistparameter\c!criterium}%
498               language  {\simplelistparameter\s!language}%
499               method    {\simplelistparameter\c!method}%
500           }%
501        \relax
502      \simplelistparameter\c!after}%
503      \relax}%
504     {}% todo: message that invalid
505   \endgroup}
506
507\permanent\tolerant\protected\def\completelistofsynonyms[#1]#*[#S#2]%
508  {\begingroup
509   \cdef\currentsimplelist{#1}%
510   \doifelsecommandhandler\??simplelist\currentsimplelist
511     {\normalexpanded{\startnamedsection[\v!chapter][\c!title={\headtext{\simplelistparameter\s!multi}},\c!reference=#1]}%
512        \placelistofsynonyms[#1][#2]%
513        \page
514      \stopnamedsection}%
515     {}% todo: message that invalid
516   \endgroup}
517
518\mutable\lettonothing\currentsimplelistentry
519
520\protected\def\strc_synonym_normal#1#2#3#4%
521  {\begingroup
522   \def\currentsimplelistentry{#3}%
523   \csname\??constructionstarthandler\v!construction\endcsname
524   #4%
525   \csname\??constructionstophandler\v!construction\endcsname
526   \endgroup}
527
528%D Sorting (a simplified version of synonym).
529
530\definesimplelist
531  [\v!sorting]
532  [\c!state=\v!start,
533  %\c!command=, % we test for defined !
534  %\c!criterium=,
535  %\c!style=,
536   \c!before=\startpacked,
537   \c!after=\stoppacked,
538  %\c!expansion=,
539   \c!method=]
540
541\aliased\let\setupsorting\setupsimplelist
542
543% some of these might become private
544
545\mutable\lettonothing\currentsortingoption
546\mutable\lettonothing\currentsortingcoding
547\mutable\lettonothing\currentsortingexpansion
548\mutable\lettonothing\currentsorting
549\mutable\lettonothing\currentsortingtag
550\mutable\lettonothing\currentsortingtext
551
552\permanent\tolerant\protected\def\definesorting[#1]#*[#2]#*[#3]%
553  {\ifnum\lastarguments=\plusthree
554  %\ifparameter#3\or
555     \ifcstok{#3}\v!none
556       % skip
557     \orelse\ifrelax#3\relax
558       % skip
559     \else
560       \protected\instance\def#3##1{\strc_sorting_insert{#1}{##1}}%
561     \fi
562     \frozen\instance\protected\defcsname#1\endcsname{\definesort[\v!no][#1]}%
563   \else
564     \frozen\instance\protected\defcsname#1\endcsname{\definesort[\v!yes][#1]}%
565   \fi
566   \cdef\currentsorting{#1}%
567   \c_strc_constructions_define_commands\conditionalfalse
568   \definesimplelist
569     [\currentsorting]%
570     [\v!sorting]
571     [\s!single={#1},%
572      \s!multi={#2}]%
573   \c_strc_constructions_define_commands\conditionaltrue
574   \ifparameter#2\or
575     %
576     \presetheadtext[#2=\Word{#2}]% changes the \if...argument
577     %
578     % These will go away. Actually the overloads catched this empty case!
579     %
580     %
581     \presetheadtext[#2=\Word{#2}]%
582     %
583     \frozen\instance\protected\defcsname\e!setup #2\e!endsetup\endcsname{\setupsorting[#1]}% obsolete definition
584     \frozen\instance\protected\defcsname\e!place   \e!listof#2\endcsname{\placelistofsorts[#1]}%
585     \frozen\instance\protected\defcsname\e!complete\e!listof#2\endcsname{\completelistofsorts[#1]}%
586   \fi}
587
588\permanent\tolerant\protected\def\definesort[#1]#*[#2]#*[#3]%
589  {\begingroup
590   \edef\currentsortingoption{#1}%
591   \cdef\currentsorting{#2}%
592   \edef\currentsortingtag{#3}%
593   \strc_sorting_define_entry}
594
595\def\strc_sorting_define_entry#1%
596  {%\let\currentsimplelist\currentsimplelist
597   \ifempty\currentsortingtag
598     \edef\currentsortingtag{#1}%
599   \fi
600   \ifempty\currentsortingtag \else
601     \edef\currentsortingexpansion{\simplelistparameter\c!expansion}%
602     \preprocessexpansion\currentsortingexpansion\currentsortingtext\currentsortingcoding{#1}%
603     \clf_registersynonym
604        {\currentsorting}%
605        {sorting}%
606        {%
607            metadata {%
608                catcodes \catcodetable
609                coding   {\currentsortingcoding}%
610            \ifx\currentsortingcoding\s!xml
611                xmlroot  {\xmldocument}%
612            \fi
613            }%
614            definition {%
615                tag     {\currentsortingtag}%
616                synonym {\currentsortingtext}%
617              % used    false
618            }%
619        }%
620     \relax
621     \ifx\currentsortingoption\v!yes
622      %\instance\setuxvalue\currentsortingtag{\strc_sorting_insert{\currentsorting}{\currentsortingtag}}%
623       \protected\instance\xdefcsname\currentsortingtag\endcsname
624         {\strc_sorting_insert{\currentsorting}{\currentsortingtag}}%
625     \fi
626   \fi
627   \endgroup}
628
629\permanent\protected\def\currentsortingname         {\clf_synonymname\currentsimplelist\currentsortingtag}
630\permanent\protected\def\currentsortingpages        {\clf_synonympages\currentsimplelist\currentsortingtag}
631\permanent\protected\def\doifelsecurrentsortingused {\clf_doifelsesynonymused\currentsimplelist\currentsortingtag}
632
633\permanent\protected\def\sortingname [#1]#*[#2]{\clf_synonymname {#1}{#2}}
634\permanent\protected\def\sortingpages[#1]#*[#2]{\clf_synonympages{#1}{#2}}
635
636\aliased\let\rawsortingname \clf_synonymname
637\aliased\let\rawsortingpages\clf_synonymmeaning
638
639\aliased\let\registercurrentsortingpage\registercurrentsynonympage
640
641\setupsimplelist
642  [\v!sorting]
643  [\c!alternative=\v!normal]
644
645\protected\def\strc_sorting_insert#1#2% name tag
646  {\dontleavehmode % otherwise we don't get it right at the beginning of a par
647   \begingroup
648   % no kap currently, of .. we need to map cap onto WORD
649   \cdef\currentsorting{#1}%
650   \edef\currentsortingtag{#2}%
651   \let\currentsimplelist\currentsorting
652   \edef\currentsimplelistalternative{\simplelistparameter\c!alternative}%
653   \doifnotcommandhandler\??simplelistalternative\currentsimplelistalternative
654     {\let\currentsimplelistalternative\v!normal}%
655   \fastsetup{\??simplelistrenderings:\v!sorting:\currentsimplelistalternative}%
656   \normalexpanded{\endgroup\simplelistparameter\c!next}}
657
658% or:
659%
660% \doifelsesetups{\??simplelistrenderings:\v!sorting:\currentsimplelistalternative}
661%    {\fastsetup{\??simplelistrenderings:\v!sorting:\currentsimplelistalternative}}
662%    {\fastsetup{\??simplelistrenderings:\v!sorting:\v!normal}}
663
664\startsetups [\??simplelistrenderings:\v!sorting:\v!normal]
665   \fastsetup{\??simplelistrenderings::\v!sorting}%
666\stopsetups
667
668\startsetups [\??simplelistrenderings::\v!sorting]
669    \begingroup
670    \dostarttaggedchained\t!sorting\currentsorting\??simplelist
671    \dotagsorting
672    \usesimpleliststyleandcolor\c!style\c!color
673    \registercurrentsortingpage
674    \currentsortingname
675    \dostoptagged
676    \endgroup
677\stopsetups
678
679\permanent\tolerant\protected\def\registersort[#1]#*[#2]%
680  {\clf_registerusedsynonym{#1}{#2}}
681
682\permanent\tolerant\protected\def\registersortpage[#1]#*[#2]%
683  {\clf_enhancesynonym{#1}{#2}}
684
685% before after
686%
687% maybe just 'commandset' and then combine
688
689\permanent\tolerant\protected\def\placelistofsorts[#1]#*[#S#2]%
690  {\begingroup
691   \cdef\currentsimplelist{#1}%
692   \strc_constructions_initialize{#1}%
693   \setupcurrentsimplelist[#2]%
694   \edef\p_simplelist_command{\simplelistparameter\c!command}%
695   \ifempty\p_simplelist_command
696     \enforced\let\synonymentry\strc_sorting_normal
697   \else
698     \enforced\let\synonymentry\strc_sorting_command
699   \fi
700   % so we can hook tabulate into before and after
701   \normalexpanded{\simplelistparameter\c!before
702     \noexpand\clf_processsynonyms
703        {#1}%
704        {%
705            criterium {\simplelistparameter\c!criterium}%
706            language  {\simplelistparameter\s!language}%
707            method    {\simplelistparameter\c!method}%
708        }%
709     \relax
710   \simplelistparameter\c!after}%
711   \endgroup}
712
713\permanent\tolerant\protected\def\completelistofsorts[#1]#*[#S#2]%
714  {\begingroup
715   \cdef\currentsimplelist{#1}%
716   \normalexpanded{\startnamedsection[\v!chapter][\c!title={\headtext{\simplelistparameter\s!multi}},\c!reference=#1]}%
717   \placelistofsorts[#1][#2]%
718   \page
719   \stopnamedsection
720   \endgroup}
721
722\def\strc_sorting_command#1#2#3#4% #4 is meaning but empty here
723  {\p_simplelist_command{#1}{#2}{#3}}
724
725\def\strc_sorting_normal#1#2#3#4% #4 is meaning but empty here
726  {\begingroup
727   \usesimpleliststyleandcolor\c!style\c!color
728   #3%
729   \endgroup
730   \par}
731
732%D Presets.
733
734% To be considered:
735%
736% \setupsimplelist
737%   [\v!sorting]
738%   [\c!headstyle=\simplelistparameter\c!synonymstyle,
739%    \c!headcolor=\simplelistparameter\c!synonymcolor,
740%    \c!style=\simplelistparameter\c!textstyle,
741%    \c!color=\simplelistparameter\c!textcolor]
742
743\definesynonyms
744  [\v!abbreviation]
745  [\v!abbreviations]
746  [\infull]
747
748\setupsynonyms
749  [\v!abbreviation]
750  [\c!hyphens=\v!no, % new, not yet in setup definitions
751   \c!textstyle=\v!capital]
752
753\definesorting
754  [\v!logo]
755  [\v!logos]
756% [\logogram] % no
757
758\protect \endinput
759