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\protected\def\strc_enumerations_inject_text_with_space
274 {\edef\p_text{\constructionparameter\c!text}
275 \ifempty\p_text \else
276 \p_text
277 \removeunwantedspaces
278 \nobreakspace
279 \fi}
280
281\protected\def\strc_enumerations_inject_extra_text
282 {\ifconditional\c_strc_constructions_title_state
283 \clf_doifelselisthastitle{\currentconstructionmain}\numexpr\currentconstructionlistentry\relax
284 \strc_enumerations_inject_extra_text_indeed
285 \donothing
286 \fi}
287
288\protected\def\strc_enumerations_inject_text
289 {\constructionparameter\c!numbercommand
290 {\constructionparameter\c!text}}
291
292
293
294\protected\def\strc_enumerations_inject_extra_text_indeed
295 {\begingroup
296 \hskip\constructionparameter\c!titledistance
297 \useconstructionstyleandcolor\c!titlestyle\c!titlecolor
298 \constructionparameter\c!titlecommand
299 {\constructionparameter\c!titleleft
300 \clf_savedlisttitle{\currentconstructionmain}\currentconstructionlistentry\relax
301 \constructionparameter\c!titleright}
302 \endgroup}
303
304\protected\def\strc_enumerations_inject_symbol
305 {\begingroup
306 \useconstructionstyleandcolor\c!numberstyle\c!numbercolor
307 \constructionparameter\c!left
308 \constructionparameter\c!symbol
309 \constructionparameter\c!right
310 \endgroup}
311
312\protected\def\strc_enumerations_inject_number
313 {\begingroup
314 \useconstructionstyleandcolor\c!numberstyle\c!numbercolor
315 \constructionparameter\c!left
316 \constructionparameter\c!starter
317 \clf_savedlistprefixednumber{\currentconstructionmain}\currentconstructionlistentry\relax
318 \constructionparameter\c!stopper
319 \constructionparameter\c!right
320 \endgroup}
321
322\protected\def\strc_enumerations_inject_text_and_number
323 {\constructionparameter\c!numbercommand
324 {\strc_enumerations_inject_text_with_space
325 \strc_enumerations_inject_number}}
326
327\protected\def\strc_enumerations_inject_text_and_symbol
328 {\constructionparameter\c!numbercommand
329 {\strc_enumerations_inject_text_with_space
330 \strc_enumerations_inject_symbol}}
331
332\protected\def\strc_enumerations_full_number_yes
333 {\constructionparameter\c!headcommand
334 {\begstrut
335 \strc_enumerations_inject_text_and_number
336 \strc_enumerations_inject_extra_text
337 \endstrut}}
338
339\protected\def\strc_enumerations_full_number_nop
340 {\constructionparameter\c!headcommand
341 {\begstrut
342 \strc_enumerations_inject_text
343 \strc_enumerations_inject_extra_text
344 \endstrut}}
345
346\protected\def\strc_enumerations_full_number_symbol
347 {\constructionparameter\c!headcommand
348 {\begstrut
349 \strc_enumerations_inject_text_and_symbol
350 \strc_enumerations_inject_extra_text
351 \endstrut}}
352
353
354
355
356
357
358
359
360
361\protected\def\strc_enumerations_full_number_coupling
362 {\iflocation
363 \strc_enumerations_full_number_yes
364 \else
365 \iftrialtypesetting \else
366
367 \fi
368 \strc_enumerations_full_number_yes
369 \edef\p_coupling{\constructionparameter\c!coupling}
370 \ifempty\p_coupling \else
371 \symbolreference[order(construction:\p_coupling:\the\locationorder)]
372 \fi
373 \fi}
374
375\protected\def\strc_enumerations_skip_number_coupling[#tag]
376 {\clf_setnextreferenceorder{construction}{#tag}}
377
378\protect \endinput
379 |