strc-enu.mkvi /size: 13 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=strc-enu, % moved from strc-des
3
%D version=2008.10.20,
4
%D title=\CONTEXT\ Structure Macros,
5
%D subtitle=Enumerations,
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
/
Enumerations
}
15 16
\unprotect
17 18
% command -> headcommand
19 20
%D Enumerations are just super descriptions. Therefore we implement
21
%D them as an extension. After all, the keys don't clash. In order
22
%D to be able to differentiate between specific settings we use
23
%D some flags. Unfortunately we have some historic differences
24
%D in default values. Therefore we push an extra step in the
25
%D parent chain (we might do the same for regular descriptions).
26 27
%D In order to be more flexible with theorems Aditya Mahajan added
28
%D support for titles and endsymbols. At the same time we added more
29
%D flexible support for inheriting numbers.
30
%D
31
%D \startbuffer
32
%D \defineenumeration[one]
33
%D \defineenumeration[two] [one] % clone one
34
%D \defineenumeration[three] [counter=one,style=slanted] % only use counter of one
35
%D \defineenumeration[four] [three] % clone three
36
%D \defineenumeration[five] [three] [counter=five] % clone three and use own counter
37
%D \defineenumeration[six] [three] [counter=four] % clone tree and use counter four (undefined)
38
%D
39
%D \startone test test 6 \stopone
40
%D \starttwo test test 7 \stoptwo
41
%D \startthree test test 8 \stopthree
42
%D \startfour test test 9 \stopfour
43
%D \startfive test test 2 \stopfive
44
%D \startsix test test 10 \stopsix
45
%D \stopbuffer
46
%D
47
%D \typebuffer \start \getbuffer \stop
48
%D
49
%D \starttyping
50
%D \setupenumerations[one] [prefix=yes,prefixsegments=section]
51
%D \setupenumerations[two] [prefix=yes,prefixsegments=section]
52
%D \setupenumerations[three][prefix=yes,prefixsegments=section]
53
%D \setupenumerations[four] [prefix=yes,prefixsegments=chapter:section]
54
%D \setupenumerations[five] [prefix=yes,prefixsegments=chapter:section]
55
%D \setupenumerations[six] [prefix=yes,prefixsegments=chapter:section]
56
%D \stoptyping
57 58
% list and titles are experimental
59
%
60
% \definedescription[test] [location=left,hang=4,headalign={right},distance=1em,list=test]
61
% \defineenumeration[lemma][title=yes,right=:,textdistance=1em, location=top, titlestyle=\bs,list=lemma]
62
% \defineenumeration[ammel][title=yes,right=:,textdistance=.5em,location=left,titlestyle=\it,width=9em]
63
%
64
% \placelist[enumeration:lemma]
65
% \placelist[description:test][width=0pt]
66
%
67
% \starttest {something something something} \input zapf \stoptest
68
% \startlemma {with a title of a certain length} \input tufte \stoplemma
69
% \startammel {with a title} \input zapf \stopammel
70
%
71
% \defineenumeration[lemma][...]
72
% \defineenumeration[titledlemma][lemma][title=yes,right=:,text=lemma,list=lemma]
73 74
\installcorenamespace
{
enumeration
}
75 76
\installcommandhandler
\??enumeration
{
enumeration
}
\??enumeration
77 78
\installcounterassociation
{
enumeration
}
79 80
\let
\setupenumerations\setupenumeration
81 82
\setupenumeration
% check with old
83
[
\c!alternative
=
\v!top
,
84
\c!headstyle
=
\v!bold
,
85
\c!titlestyle
=
\v!bold
,
86
%\c!style=,
87
%\c!color=,
88
%\c!headcolor=,
89
%\c!titlecolor=,
90
\c!width
=
8
\emwidth
,
91
%\c!distance=\zeropoint,
92
\c!distance
=
\emwidth
,
93
\c!titledistance
=
.
5
\emwidth
,
94
%\c!hang=,
95
%\c!sample=,
96
%\c!align=,
97
%\c!headalign=,
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
%\c!closesymbol=,
107
\c!closecommand
=
\wordright
,
108
\c!display
=
\v!yes
,
109
%\c!command=,
110
\c!titlecommand
=
,
111
\c!expansion
=
\v!no
,
112
%\c!xmlsetup=,
113
%\s!catcodes=,
114
\c!way
=
\v!by\v!text
,
115
\c!prefix
=
\v!no
,
116
\c!prefixconnector
=
.
,
117
%\c!starter=,
118
%\c!stopper=,
119
\c!text
=
\currentenumeration
,
120
\c!number
=
\v!yes
,
% else description
121
\c!start
=
0
,
122
\c!state
=
\v!start
,
123
\c!levels
=
4
]
124 125
% to be considered:
126
%
127
% \let\??construction\??enumeration
128
%
129
% with push/pop (also at definition time)
130 131
\unexpanded
\def
\strc_define_commands_enumeration
#
tag
#
level
#
parent
%
132
{
\doifelsenothing
{
#
parent
}
133
{
\normalexpanded
{
\defineconstruction
[#
tag
][
\s!handler
=
\v!enumeration
,
\c!level
=#
level
]
}
%
134
\setevalue
{
\??enumeration
#
tag
:
\s!parent
}{
\??enumeration
}}
%
135
{
\normalexpanded
{
\defineconstruction
[#
tag
][#
parent
][
\s!handler
=
\v!enumeration
,
\c!level
=#
level
]
}
%
136
\setevalue
{
\??enumeration
#
tag
:
\s!parent
}{
\??enumeration
#
parent
}}
%
137
\setuevalue
{
\e!next
#
tag
}{
\strc_enumerations_next
{
#
tag
}{
\number
#
level
}}
% obsolete
138
\setuevalue
{
\c!reset
#
tag
}{
\strc_enumerations_reset
{
#
tag
}{
\number
#
level
}}
% obsolete
139
%setuevalue{\c!set #tag}{\strc_enumerations_set {#tag}{\number#level}}% obsolete
140
\setuevalue
{
#
tag
}{
\strc_enumerations_command
{
#
tag
}}
% we could pass level here as well (faster)
141
\setuevalue
{
\e!start
#
tag
}{
\strc_enumerations_start
{
#
tag
}}
% we could pass level here as well (faster)
142
\setuevalue
{
\e!stop
#
tag
}{
\strc_enumerations_stop
}}
143 144
\appendtoks
145
\ifx
\currentenumerationparent
\empty
146
% clone => parent | subclone => clone | subsubclone => subclone
147
\let
\currentenumerationsub
\empty
148
\strc_define_commands_enumeration
149
{
\currentenumerationsub
\currentenumeration
}
%
150
\plusone
151
\empty
152
\edef
\p_levels
{
\enumerationparameter
\c!levels
}
%
153
\dostepwiserecurse
\plustwo
\p_levels
\plusone
154
{
\strc_define_commands_enumeration
155
{
\v!sub
\currentenumerationsub
\currentenumeration
}
%
156
\recurselevel
157
{
\currentenumerationsub
\currentenumeration
}
%
158
\edef
\currentenumerationsub
{
\v!sub
\currentenumerationsub
}}
%
159
\else
160
% clone => parent | subclone => subparent | subsubclone => subsubparent
161
\let
\currentenumerationsub
\empty
162
\edef
\p_levels
{
\enumerationparameter
\c!levels
}
%
163
\dorecurse
\p_levels
164
{
\strc_define_commands_enumeration
165
{
\currentenumerationsub
\currentenumeration
}
%
166
\recurselevel
167
{
\currentenumerationsub
\currentenumerationparent
}
%
168
\edef
\currentenumerationsub
{
\v!sub
\currentenumerationsub
}}
%
169
\fi
170
\edef
\p_counter
{
\enumerationparameter
\s!counter
}
% can inherit from parent
171
\ifx
\p_counter
\empty
%
172
\let
\p_counter
\currentenumeration
173
\fi
174
\doifelsecounter
\p_counter
\donothing
{
\strc_enumerations_define_counter
\p_counter
}
%
175
\letenumerationparameter
\s!counter
\p_counter
176
%\strc_enumerations_setup_counter\currentenumeration
177
\to
\everydefineenumeration
178 179
\let
\p_strc_constructions_title
\empty
180
\let
\p_strc_constructions_number
\empty
181 182
\unexpanded\setvalue
{
\??constructioninitializer\v!enumeration
}
%
183
{
\let
\currentenumeration
\currentconstruction
184
\let
\constructionparameter
\enumerationparameter
185
\let
\constructionnamespace
\??enumeration
186
\let
\detokenizedconstructionparameter
\detokenizedenumerationparameter
187
\let
\letconstructionparameter
\letenumerationparameter
188
\let
\useconstructionstyleandcolor
\useenumerationstyleandcolor
189
\let
\setupcurrentconstruction
\setupcurrentenumeration
190
\edef
\p_strc_constructions_number
{
\constructionparameter
\c!number
}
%
191
\ifx
\p_strc_constructions_number
\v!yes
192
\settrue
\c_strc_constructions_number_state
193
\iftrialtypesetting
194
\strc_counters_save
\currentconstructionnumber
195
\fi
196
\strc_counters_increment_sub
\currentconstructionnumber
\currentconstructionlevel
197
\else
198
\setfalse
\c_strc_constructions_number_state
199
\fi
200
\edef
\p_strc_constructions_title
{
\constructionparameter
\c!title
}
%
201
\ifx
\p_strc_constructions_title
\v!yes
202
\settrue
\c_strc_constructions_title_state
203
\else
204
\setfalse
\c_strc_constructions_title_state
205
\fi
}
206 207
\unexpanded\setvalue
{
\??constructionfinalizer\v!enumeration
}
%
208
{
\ifconditional
\c_strc_constructions_number_state
209
\iftrialtypesetting
210
\strc_counters_restore
\currentconstructionnumber
211
\fi
212
\fi
}
213 214
%D Interfaces:
215 216
\let
\strc_enumerations_command
\strc_descriptions_command
217
\let
\strc_enumerations_start
\strc_descriptions_start
218
\let
\strc_enumerations_stop
\strc_descriptions_stop
219 220
\unexpanded
\def
\strc_enumerations_next
{
\strc_constructions_next_indeed
\namedenumerationparameter
}
% #1#2
221
\unexpanded
\def
\strc_enumerations_reset
{
\strc_constructions_reset_indeed
\namedenumerationparameter
}
% #1#2
222
%unexpanded\def\strc_enumerations_set {\strc_constructions_set_indeed \namedenumerationparameter} % #1#2
223 224
%D Counters (maybe we can share this code): (not ok yet, messy with notes)
225 226
% Maybe we should move counters to the construction level as more derived mechanisms
227
% use it \unknown\ so don't depend on names here!
228 229
\def
\strc_enumerations_define_counter
#
tag
% todo: move inline
230
{
\definecounter
[#
tag
]
%
231
\registerenumerationcounter
{
#
tag
}}
232 233
\appendtoks
234
\synchronizeenumerationcounters
235
\to
\everysetupenumeration
236 237
\appendtoks
238
\synchronizeenumerationcounters
239
\to
\everydefineenumeration
240 241
%D Initializer:
242 243
%D The handlers.
244 245
\newtoks
\everyenumeration
246 247
\appendtoks
248
\disablepseudocaps
% sorry, uppercase causes troubles
249
\to
\everyenumeration
250 251
\expandafter\let\csname
\??constructionmainhandler
\v!enumeration
\expandafter\endcsname\csname
\??constructionmainhandler
\v!description
\endcsname
252
\expandafter\let\csname
\??constructioncommandhandler\v!enumeration
\expandafter\endcsname\csname
\??constructioncommandhandler\v!description
\endcsname
253
\expandafter\let\csname
\??constructionstarthandler
\v!enumeration
\expandafter\endcsname\csname
\??constructionstarthandler
\v!description
\endcsname
254
\expandafter\let\csname
\??constructionstophandler
\v!enumeration
\expandafter\endcsname\csname
\??constructionstophandler
\v!description
\endcsname
255 256
\unexpanded\setvalue
{
\??constructiontexthandler\v!enumeration
}
%
257
{
\begingroup
258
\useconstructionstyleandcolor
\c!headstyle\c!headcolor
259
\strc_enumerations_text
260
\endgroup
}
261 262
\unexpanded
\def
\strc_enumerations_text
263
{
\the
\everyenumeration
% will become obsolete
264
\ifconditional
\c_strc_constructions_number_state
265
\ifx
\currentconstructionreference
\!!plustoken
266
\strc_enumerations_full_number_symbol
267
\else\ifx
\currentconstructionreference
\!!minustoken
268
\strc_enumerations_full_number_nop
269
\else
270
\strc_enumerations_full_number_coupling
271
\fi\fi
272
\else
273
\strc_enumerations_full_number_nop
274
\fi
}
275 276
\unexpanded
\def
\strc_enumerations_inject_text_with_space
277
{
\edef
\p_text
{
\constructionparameter
\c!text
}
%
278
\ifx
\p_text
\empty
\else
279
\p_text
280
\removeunwantedspaces
281
\nobreakspace
282
\fi
}
283 284
\unexpanded
\def
\strc_enumerations_inject_extra_text
285
{
\ifconditional
\c_strc_constructions_title_state
286
\clf_doifelselisthastitle
{
\currentconstructionmain
}
\numexpr
\currentconstructionlistentry
\relax
287
\strc_enumerations_inject_extra_text_indeed
288
\donothing
289
\fi
}
290 291
\unexpanded
\def
\strc_enumerations_inject_text
292
{
\constructionparameter
\c!numbercommand
293
{
\constructionparameter
\c!text
}}
294 295
% head ( number title )
296 297
\unexpanded
\def
\strc_enumerations_inject_extra_text_indeed
298
{
\begingroup
299
\hskip
\constructionparameter
\c!titledistance
% we listen to the headstyle
300
\useconstructionstyleandcolor
\c!titlestyle\c!titlecolor
301
\constructionparameter
\c!titlecommand
302
{
\constructionparameter
\c!titleleft
303
\clf_savedlisttitle
{
\currentconstructionmain
}
\currentconstructionlistentry
\relax
304
\constructionparameter
\c!titleright
}
%
305
\endgroup
}
306 307
\unexpanded
\def
\strc_enumerations_inject_symbol
% todo check
308
{
\constructionparameter
\c!left
309
\constructionparameter
\c!symbol
310
\constructionparameter
\c!right
}
311 312
\unexpanded
\def
\strc_enumerations_inject_number
313
{
\constructionparameter
\c!left
314
\constructionparameter
\c!starter
315
\clf_savedlistprefixednumber
{
\currentconstructionmain
}
\currentconstructionlistentry
\relax
316
\constructionparameter
\c!stopper
317
\constructionparameter
\c!right
}
318 319
\unexpanded
\def
\strc_enumerations_inject_text_and_number
320
{
\constructionparameter
\c!numbercommand
321
{
\strc_enumerations_inject_text_with_space
322
\strc_enumerations_inject_number
}}
323 324
\unexpanded
\def
\strc_enumerations_inject_text_and_symbol
325
{
\constructionparameter
\c!numbercommand
326
{
\strc_enumerations_inject_text_with_space
327
\strc_enumerations_inject_symbol
}}
328 329
\unexpanded
\def
\strc_enumerations_full_number_yes
330
{
\constructionparameter
\c!headcommand
331
{
\begstrut
332
\strc_enumerations_inject_text_and_number
333
\strc_enumerations_inject_extra_text
334
\endstrut
}}
335 336
\unexpanded
\def
\strc_enumerations_full_number_nop
337
{
\constructionparameter
\c!headcommand
338
{
\begstrut
339
\strc_enumerations_inject_text
340
\strc_enumerations_inject_extra_text
341
\endstrut
}}
342 343
\unexpanded
\def
\strc_enumerations_full_number_symbol
344
{
\constructionparameter
\c!headcommand
345
{
\begstrut
346
\strc_enumerations_inject_text_and_symbol
347
\strc_enumerations_inject_extra_text
348
\endstrut
}}
349 350
% to be used in for instance:
351
%
352
% coupling=questions .... coupling=answers
353
%
354
% we will provide some more control, like skipping etc or reference relates
355 356
% to do / to be checked
357 358
\unexpanded
\def
\strc_enumerations_full_number_coupling
359
{
\iflocation
360
\strc_enumerations_full_number_yes
361
\else
362
\iftrialtypesetting
\else
363
% \doenumerationregistercoupling
364
\fi
365
\strc_enumerations_full_number_yes
366
\edef
\p_coupling
{
\constructionparameter
\c!coupling
}
%
367
\ifx
\p_coupling
\empty
\else
368
\symbolreference
[
order
(
construction
:
\p_coupling
:
\the
\locationorder
)]
%
369
\fi
370
\fi
}
371 372
\unexpanded
\def
\strc_enumerations_skip_number_coupling
[#
tag
]
% e.g. for questions with no answer
373
{
\clf_setnextreferenceorder
{
construction
}{
#
tag
}}
374 375
\protect
\endinput
376