typo-itm.mkiv /size: 8578 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=typo-itm, % comes from core-mis
3
%D version=2012.06.28,
4
%D title=\CONTEXT\ Typesetting Macros,
5
%D subtitle=Item Lists,
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
Node
Macros
/
Item
Lists
}
15 16
\unprotect
17 18
%D This is a real old mechanism that we once used for questionaries. As it is documented
19
%D we keep it around. A more modern implementation would probably use another approach
20
%D but I don't want to spend too much time on it now. There are a couple of changes:
21
%D
22
%D \startitemize
23
%D \startitem textwidth sets the combined width \stopitem
24
%D \startitem width sets the symbolwidth \stopitem
25
%D \startitem alternative is used instead of location \stopitem
26
%D \stopitemize
27
%D
28
%D \startbuffer
29
%D \items[alternative=left]{a,b,c}
30
%D \items[alternative=left,align=middle,textalign=flushright,distance=1em]{a,b,c}
31
%D \items[alternative=right]{a,b,c}
32
%D \items[alternative=inmargin]{a,b,c}
33
%D \items[alternative=top]{a,b,c}
34
%D \items[alternative=bottom]{a,b,c}
35
%D \items[alternative=bottom,align=flushleft,textstyle=bold,color=red,textcolor=green]{a,b,c}
36
%D \stopbuffer
37
%D
38
%D \typebuffer
39
%D
40
%D This renders as:
41
%D
42
%D \getbuffer
43 44
\installcorenamespace
{
items
}
45
\installcorenamespace
{
itemsalternatives
}
46
\installcorenamespace
{
itemshorizontal
}
47
\installcorenamespace
{
itemsvertical
}
48 49
\installcommandhandler
\??items
{
items
}
\??items
50 51
\setupitems
52
[
\c!alternative
=
\v!left
,
53
\c!symbol
=
5
,
54
\c!textwidth
=
\availablehsize
,
55
\c!align
=
\v!middle
,
56
\c!textalign
=
\v!flushleft
,
57
\c!distance
=
\zeropoint
,
58
%\c!n=,
59
\c!before
=
\blank
,
60
\c!inbetween
=
{
\blank
[
\v!medium
]
}
,
61
\c!after
=
\blank
]
62 63
\unexpanded
\def
\items
64
{
\dosingleempty
\typo_items_process
}
65 66
\newcount
\c_typo_items_n
67
\newcount
\c_typo_items_m
68
\newdimen
\d_typo_items_text_width
69
\newdimen
\d_typo_items_symbol_width
70
\newdimen
\d_typo_items_distance
71
\newbox
\b_typo_items_symbols
72
\newbox
\b_typo_items_texts
73 74
\def
\typo_items_process
[
#
1
]
#
2
%
75
{
\bgroup
76
\setupitems
[
#
1
]
%
77
\edef
\p_typo_items_alternative
{
\itemsparameter
\c!alternative
}
%
78
\ifcsname
\??itemsalternatives
\p_typo_items_alternative
\endcsname
\else
79
\let
\p_typo_items_alternative
\v!left
80
\fi
81
\let
\currentitems
\p_typo_items_alternative
82
\setupcurrentitems
[
#
1
]
%
83
%
84
\edef
\p_typo_items_textwidth
{
\itemsparameter
\c!textwidth
}
%
85
\ifx
\p_typo_items_textwidth
\empty
86
\d_typo_items_text_width
\availablehsize
87
\else
88
\d_typo_items_text_width
\p_typo_items_textwidth
\relax
89
\fi
90
%
91
\edef
\p_typo_items_width
{
\itemsparameter
\c!width
}
%
92
\ifx
\p_typo_items_width
\empty
93
\d_typo_items_symbol_width
1
.
5
\emwidth
94
\else
95
\d_typo_items_symbol_width
\p_typo_items_width
\relax
96
\fi
97
%
98
\edef
\p_typo_items_distance
{
\itemsparameter
\c!distance
}
%
99
\ifx
\p_typo_items_distance
\empty
100
\d_typo_items_distance
\zeropoint
101
\else
102
\d_typo_items_distance
\p_typo_items_distance
\relax
103
\fi
104
%
105
\edef
\p_typo_items_symbol
{
\itemsparameter
\c!symbol
}
%
106
\ifx
\p_typo_items_symbol
\empty
107
\let
\m_typo_items_symbol
\firstofoneargument
108
\else
\ifx
\p_typo_items_symbol
\v!none
109
\let
\p_typo_items_symbol
\empty
110
\let
\m_typo_items_symbol
\firstofoneargument
111
\else
112
\doifelseconversiondefined
\p_typo_items_symbol
113
{
\def
\m_typo_items_symbol
{
\convertnumber
\p_typo_items_symbol
}
}
114
{
\doifelsesymboldefined
\p_typo_items_symbol
115
{
\def
\m_typo_items_symbol
{
\symbol
[
\p_typo_items_symbol
]
\gobbleoneargument
}
}
116
{
\let
\m_typo_items_symbol
\firstofoneargument
}
}
%
117
\fi
\fi
118
%
119
\edef
\p_typo_items_align
{
\itemsparameter
\c!align
}
%
120
\edef
\p_typo_items_textalign
{
\itemsparameter
\c!textalign
}
%
121
%
122
\edef
\p_typo_items_n
{
\itemsparameter
\c!n
}
%
123
\ifx
\p_typo_items_n
\empty
124
\getcommalistsize
[
#
2
]
%
125
\c_typo_items_n
\commalistsize
\relax
% \commalistcounter
126
\else
127
\c_typo_items_n
\p_typo_items_n
\relax
128
\fi
129
%
130
\parindent
\zeropoint
131
\dontcomplain
132
%
133
\itemsparameter
\c!before
134
\csname
\??itemsalternatives
\p_typo_items_alternative
\endcsname
{
#
2
}
%
135
\itemsparameter
\c!after
136
\egroup
}
137 138
% rendering
139 140
\setvalue
{
\??itemshorizontal
\v!margin
}
#
1
%
141
{
\ifnum
\c_typo_items_m
=
\plusone
\hss
\else
\hfill
\fi
142
\strut
#
1
%
143
\ifnum
\c_typo_items_m
=
\c_typo_items_n
\hss
\else
\hfill
\fi
}
144 145
\setvalue
{
\??itemshorizontal
\s!unknown
}
%
146
{
\simplealignedbox
\scratchwidth
\m_typo_items_align
}
147 148
\def
\typo_items_item_horizontal
149
{
\advance
\c_typo_items_m
\plusone
150
\csname
\??itemshorizontal
151
\ifcsname
\??itemshorizontal
\p_typo_items_align
\endcsname
152
\p_typo_items_align
153
\else
154
\s!unknown
155
\fi
156
\endcsname
}
157 158
\setvalue
{
\??itemsvertical
\s!unknown
}
%
159
{
\simplealignedbox
\scratchwidth
\m_typo_items_align
}
160 161
\def
\typo_items_item_vertical
162
{
\advance
\c_typo_items_m
\plusone
163
\csname
\??itemsvertical
164
\ifcsname
\??itemsvertical
\p_typo_items_align
\endcsname
165
\p_typo_items_align
166
\else
167
\s!unknown
168
\fi
169
\endcsname
}
170 171
\def
\typo_items_make_horizontal
#
1
%
172
{
\divide
\scratchwidth
\c_typo_items_n
173
\hbox
{
#
1
}
}
174 175
\def
\typo_items_make_vertical
#
1
%
176
{
\vbox
{
#
1
}
}
177 178
\def
\typo_items_construct_items_boxes
#
1
%
179
{
\setbox
\b_typo_items_texts
\hbox
180
{
\c_typo_items_m
\zerocount
181
\let
\m_typo_items_align
\p_typo_items_textalign
182
\scratchwidth
\d_typo_items_text_width
183
\useitemsstyleandcolor
\c!textstyle
\c!textcolor
184
\typo_items_make
{
\processcommalist
[
#
1
]
\typo_items_item
}
}
%
185
\ifx
\p_typo_items_symbol
\empty
186
\setbox
\b_typo_items_symbols
\emptyhbox
187
\else
188
\setbox
\b_typo_items_symbols
\hbox
189
{
\c_typo_items_m
\zerocount
190
\let
\m_typo_items_align
\p_typo_items_align
191
\scratchwidth
\d_typo_items_symbol_width
192
\useitemsstyleandcolor
\c!style
\c!color
193
\typo_items_make
{
\dorecurse
\c_typo_items_n
{
\typo_items_item
{
\strut
\m_typo_items_symbol
\recurselevel
}
}
}
}
%
194
\fi
}
195 196
% alternatives:
197 198
\defineitems
[
\v!top
]
[
\c!width
=
\d_typo_items_text_width
,
\c!textalign
=
\itemsparameter
\c!align
]
199 200
\setvalue
{
\??itemsalternatives
\v!top
}
#
1
%
201
{
\let
\typo_items_make
\typo_items_make_horizontal
202
\let
\typo_items_item
\typo_items_item_horizontal
203
\typo_items_construct_items_boxes
{
#
1
}
%
204
\noindent
\vbox
\bgroup
205
\forgetall
206
\ifvoid
\b_typo_items_symbols
\else
207
\box
\b_typo_items_symbols
208
\itemsparameter
\c!inbetween
209
\nointerlineskip
210
\fi
211
\box
\b_typo_items_texts
\ 212
\egroup
}
213 214
\defineitems
[
\v!bottom
]
[
\c!width
=
\d_typo_items_text_width
,
\c!textalign
=
\itemsparameter
\c!align
]
215 216
\setvalue
{
\??itemsalternatives
\v!bottom
}
#
1
%
217
{
\let
\typo_items_make
\typo_items_make_horizontal
218
\let
\typo_items_item
\typo_items_item_horizontal
219
\typo_items_construct_items_boxes
{
#
1
}
%
220
\noindent
\vbox
\bgroup
221
\forgetall
222
\box
\b_typo_items_texts
223
\ifvoid
\b_typo_items_symbols
\else
224
\itemsparameter
\c!inbetween
225
\nointerlineskip
226
\box
\b_typo_items_symbols
227
\fi
228
\egroup
}
229 230
\defineitems
[
\v!inmargin
]
[
\c!width
=
1
.
5
\emwidth
,
\c!align
=
\v!flushright
,
\c!distance
=
\leftmargindistance
]
231 232
\setvalue
{
\??itemsalternatives
\v!inmargin
}
#
1
%
233
{
\let
\typo_items_make
\typo_items_make_vertical
234
\let
\typo_items_item
\typo_items_item_vertical
235
\typo_items_construct_items_boxes
{
#
1
}
%
236
\noindent
\hbox
\bgroup
237
\ifvoid
\b_typo_items_symbols
\else
238
\llap
{
\box
\b_typo_items_symbols
\hskip
\d_typo_items_distance
}
%
239
\fi
240
\box
\b_typo_items_texts
241
\egroup
}
242 243
\defineitems
[
\v!left
]
[
\c!width
=
1
.
5
\emwidth
,
\c!align
=
\v!flushleft
]
244 245
\setvalue
{
\??itemsalternatives
\v!left
}
#
1
%
246
{
\let
\typo_items_make
\typo_items_make_vertical
247
\let
\typo_items_item
\typo_items_item_vertical
248
\advance
\d_typo_items_text_width
-
\dimexpr
\d_typo_items_symbol_width
+
\d_typo_items_distance
\relax
249
\typo_items_construct_items_boxes
{
#
1
}
%
250
\noindent
\hbox
\bgroup
251
\ifvoid
\b_typo_items_symbols
\else
252
\box
\b_typo_items_symbols
253
\kern
\d_typo_items_distance
254
\fi
255
\box
\b_typo_items_texts
256
\egroup
}
257 258
\defineitems
[
\v!right
]
[
\c!width
=
1
.
5
\emwidth
,
\c!align
=
\v!flushright
]
259 260
\setvalue
{
\??itemsalternatives
\v!right
}
#
1
%
261
{
\let
\typo_items_make
\typo_items_make_vertical
262
\let
\typo_items_item
\typo_items_item_vertical
263
\advance
\d_typo_items_text_width
-
\dimexpr
\d_typo_items_symbol_width
+
\d_typo_items_distance
\relax
264
\typo_items_construct_items_boxes
{
#
1
}
%
265
\noindent
\hbox
\bgroup
266
\box
\b_typo_items_texts
267
\ifvoid
\b_typo_items_symbols
\else
268
\kern
\d_typo_items_distance
269
\box
\b_typo_items_symbols
270
\fi
271
\egroup
}
272 273
\protect
\endinput
274