1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Structure Macros Enumerations}
15
16\unprotect
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\installcorenamespace{enumeration}
75
76\installcommandhandler \??enumeration {enumeration} \??enumeration
77
78\installcounterassociation{enumeration}
79
80\let\setupenumerations\setupenumeration
81
82\setupenumeration
83 [\c!alternative=\v!top,
84 \c!headstyle=\v!bold,
85 \c!titlestyle=\v!bold,
86
87
88
89
90 \c!width=8\emwidth,
91
92 \c!distance=\emwidth,
93 \c!titledistance=.5\emwidth,
94
95
96
97
98 \c!margin=\v!no,
99 \c!before=\blank,
100 \c!inbetween=\blank,
101 \c!after=\blank,
102 \c!indentnext=\v!yes,
103 \c!indenting=\v!never,
104 \c!titleleft=(,
105 \c!titleright=),
106
107 \c!closecommand=\wordright,
108 \c!display=\v!yes,
109
110 \c!titlecommand=,
111 \c!expansion=\v!no,
112
113
114 \c!way=\v!by\v!text,
115 \c!prefix=\v!no,
116 \c!prefixconnector=.,
117
118
119 \c!text=\currentenumeration,
120 \c!number=\v!yes,
121 \c!start=0,
122 \c!state=\v!start,
123 \c!levels=4,
124 \c!define=\v!yes]
125
126
127
128
129
130
131
132\protected\def\strc_define_commands_enumeration#tag#level#parent
133 {\ifempty{#parent}
134 \normalexpanded{\defineconstruction[#tag][\s!handler=\v!enumeration,\c!level=#level]}
135 \edefcsname\??enumeration#tag:\s!parent\endcsname{\??enumeration}
136 \else
137 \normalexpanded{\defineconstruction[#tag][#parent][\s!handler=\v!enumeration,\c!level=#level]}
138 \edefcsname\??enumeration#tag:\s!parent\endcsname{\??enumeration#parent}
139 \fi
140 \ifcstok{\enumerationparameter\c!define}\v!yes
141 \frozen\protected\instance\edefcsname\e!next #tag\endcsname{\strc_enumerations_next{#tag}{\number#level}}
142 \frozen\protected\instance\edefcsname\c!reset#tag\endcsname{\strc_enumerations_reset{#tag}{\number#level}}
143
144 \frozen\protected\instance\edefcsname #tag\endcsname{\namedenumeration[#tag]}
145 \frozen\protected\instance\edefcsname\e!start#tag\endcsname{\startnamedenumeration[#tag]}
146 \frozen\protected\instance \defcsname\e!stop #tag\endcsname{\stopnamedenumeration}
147 \fi}
148
149\lettonothing\m_strc_enumeration_sub
150
151\appendtoks
152 \lettonothing\m_strc_enumeration_sub
153 \ifempty\currentenumerationparent
154
155 \strc_define_commands_enumeration
156 {\m_strc_enumeration_sub\currentenumeration}
157 \plusone
158 \empty
159 \edef\p_levels{\enumerationparameter\c!levels}
160 \dostepwiserecurse\plustwo\p_levels\plusone
161 {\strc_define_commands_enumeration
162 {\v!sub\m_strc_enumeration_sub\currentenumeration}
163 \recurselevel
164 {\m_strc_enumeration_sub\currentenumeration}
165 \edef\m_strc_enumeration_sub{\v!sub\m_strc_enumeration_sub}}
166 \else
167
168 \edef\p_levels{\enumerationparameter\c!levels}
169 \dorecurse\p_levels
170 {\strc_define_commands_enumeration
171 {\m_strc_enumeration_sub\currentenumeration}
172 \recurselevel
173 {\m_strc_enumeration_sub\currentenumerationparent}
174 \edef\m_strc_enumeration_sub{\v!sub\m_strc_enumeration_sub}}
175 \fi
176 \edef\p_counter{\enumerationparameter\s!counter}
177 \ifempty\p_counter
178 \let\p_counter\currentenumeration
179 \fi
180 \doifelsecounter\p_counter\donothing{\strc_enumerations_define_counter\p_counter}
181 \letenumerationparameter\s!counter\p_counter
182
183\to \everydefineenumeration
184
185\protected\defcsname\??constructioninitializer\v!enumeration\endcsname
186 {\let \currentenumeration \currentconstruction
187 \enforced\let\constructionparameter \enumerationparameter
188 \enforced\let\constructionnamespace \??enumeration
189 \enforced\let\detokenizedconstructionparameter\detokenizedenumerationparameter
190 \enforced\let\letconstructionparameter \letenumerationparameter
191 \enforced\let\useconstructionstyleandcolor \useenumerationstyleandcolor
192 \enforced\let\setupcurrentconstruction \setupcurrentenumeration
193 \ifcstok{\constructionparameter\c!number}\v!yes
194 \c_strc_constructions_number_state\conditionaltrue
195 \iftrialtypesetting
196 \strc_counters_save\currentconstructionnumber
197 \fi
198 \strc_counters_increment_sub\currentconstructionnumber\currentconstructionlevel
199 \else
200 \c_strc_constructions_number_state\conditionalfalse
201 \fi
202 \ifcstok{\constructionparameter\c!title}\v!yes
203 \c_strc_constructions_title_state\conditionaltrue
204 \else
205 \c_strc_constructions_title_state\conditionalfalse
206 \fi}
207
208\protected\defcsname\??constructionfinalizer\v!enumeration\endcsname
209 {\ifconditional\c_strc_constructions_number_state
210 \iftrialtypesetting
211 \strc_counters_restore\currentconstructionnumber
212 \fi
213 \fi}
214
215
216
217\let\namedenumeration \nameddescription
218\let\startnamedenumeration\startnameddescription
219\let\stopnamedenumeration \stopnameddescription
220
221\protected\def\strc_enumerations_next {\strc_constructions_next_indeed \namedenumerationparameter}
222\protected\def\strc_enumerations_reset{\strc_constructions_reset_indeed\namedenumerationparameter}
223
224
225
226
227
228
229
230\def\strc_enumerations_define_counter#tag
231 {\definecounter[#tag]
232 \registerenumerationcounter{#tag}}
233
234\appendtoks
235 \synchronizeenumerationcounters
236\to \everysetupenumeration
237
238\appendtoks
239 \synchronizeenumerationcounters
240\to \everydefineenumeration
241
242
243
244
245
246\newtoks\everyenumeration
247
248\letcsname\??constructionmainhandler \v!enumeration\expandafter\endcsname\csname\??constructionmainhandler \v!description\endcsname
249\letcsname\??constructioncommandhandler\v!enumeration\expandafter\endcsname\csname\??constructioncommandhandler\v!description\endcsname
250\letcsname\??constructionstarthandler \v!enumeration\expandafter\endcsname\csname\??constructionstarthandler \v!description\endcsname
251\letcsname\??constructionstophandler \v!enumeration\expandafter\endcsname\csname\??constructionstophandler \v!description\endcsname
252
253\protected\defcsname\??constructiontexthandler\v!enumeration\endcsname
254 {\begingroup
255 \useconstructionstyleandcolor\c!headstyle\c!headcolor
256 \strc_enumerations_text
257 \endgroup}
258
259\protected\def\strc_enumerations_text
260 {\expand\everyenumeration
261 \ifconditional\c_strc_constructions_number_state
262 \ifx\currentconstructionreference\!!plustoken
263 \strc_enumerations_full_number_symbol
264 \orelse\ifx\currentconstructionreference\!!minustoken
265 \strc_enumerations_full_number_nop
266 \else
267 \strc_enumerations_full_number_coupling
268 \fi
269 \else
270 \strc_enumerations_full_number_nop
271 \fi}
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\protected\def\strc_enumerations_inject_text_with_space#1
299 {\edef\p_text{\constructionparameter\c!text}
300 \ifempty\p_text
301 \edef\p_text{\constructionparameter\c!label}
302 \ifempty\p_text
303 #1
304 \else
305 \labeltexts{\p_text}{#1}
306 \fi
307 \orelse\ifcstok{\constructionparameter\c!space}\v!no
308 \p_text{#1}
309 \else
310 \p_text{\removeunwantedspaces\nobreakspace#1}
311 \fi}
312
313\protected\def\strc_enumerations_inject_extra_text
314 {\ifconditional\c_strc_constructions_title_state
315 \clf_doifelselisthastitle{\currentconstructionmain}{\currentconstructionlistentry}
316 \strc_enumerations_inject_extra_text_indeed
317 \donothing
318 \fi}
319
320\protected\def\strc_enumerations_inject_text
321 {\constructionparameter\c!numbercommand
322 {\constructionparameter\c!text}}
323
324
325
326\protected\def\strc_enumerations_inject_extra_text_indeed
327 {\begingroup
328 \hskip{\constructionparameter\c!titledistance}
329 \useconstructionstyleandcolor\c!titlestyle\c!titlecolor
330 \constructionparameter\c!titlecommand
331 {\constructionparameter\c!titleleft
332 \clf_savedlisttitle{\currentconstructionmain}\currentconstructionlistentry\relax
333 \constructionparameter\c!titleright}
334 \endgroup}
335
336\protected\def\strc_enumerations_inject_symbol
337 {\begingroup
338 \useconstructionstyleandcolor\c!numberstyle\c!numbercolor
339 \constructionparameter\c!left
340 \constructionparameter\c!symbol
341 \constructionparameter\c!right
342 \endgroup}
343
344\protected\def\strc_enumerations_inject_number
345 {\begingroup
346 \useconstructionstyleandcolor\c!numberstyle\c!numbercolor
347 \constructionparameter\c!left
348 \constructionparameter\c!starter
349 \clf_savedlistprefixednumber{\currentconstructionmain}\currentconstructionlistentry\relax
350 \constructionparameter\c!stopper
351 \constructionparameter\c!right
352 \endgroup}
353
354\protected\def\strc_enumerations_inject_text_and_number
355 {\constructionparameter\c!numbercommand
356 {\strc_enumerations_inject_text_with_space
357 \strc_enumerations_inject_number}}
358
359\protected\def\strc_enumerations_inject_text_and_symbol
360 {\constructionparameter\c!numbercommand
361 {\strc_enumerations_inject_text_with_space
362 \strc_enumerations_inject_symbol}}
363
364\protected\def\strc_enumerations_full_number_yes
365 {\constructionparameter\c!headcommand
366 {\begstrut
367 \strc_enumerations_inject_text_and_number
368 \strc_enumerations_inject_extra_text
369 \endstrut}}
370
371\protected\def\strc_enumerations_full_number_nop
372 {\constructionparameter\c!headcommand
373 {\begstrut
374 \strc_enumerations_inject_text
375 \strc_enumerations_inject_extra_text
376 \endstrut}}
377
378\protected\def\strc_enumerations_full_number_symbol
379 {\constructionparameter\c!headcommand
380 {\begstrut
381 \strc_enumerations_inject_text_and_symbol
382 \strc_enumerations_inject_extra_text
383 \endstrut}}
384
385
386
387
388
389
390
391
392
393\protected\def\strc_enumerations_full_number_coupling
394 {\iflocation
395 \strc_enumerations_full_number_yes
396 \else
397 \iftrialtypesetting \else
398
399 \fi
400 \strc_enumerations_full_number_yes
401 \edef\p_coupling{\constructionparameter\c!coupling}
402 \ifempty\p_coupling \else
403 \symbolreference[order(construction:\p_coupling:\the\locationorder)]
404 \fi
405 \fi}
406
407\protected\def\strc_enumerations_skip_number_coupling[#tag]
408 {\clf_setnextreferenceorder{construction}{#tag}}
409
410\protect \endinput
411 |