1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Math Macros Radicals}
15
16\unprotect
17
18
19
20
21
22
23
24
25
26
27
28
29\unexpanded\def\root#1\of{\rootradical{#1}}
30
31\unexpanded\def\sqrt{\doifelsenextoptionalcs\rootwithdegree\rootwithoutdegree}
32
33
34
35 \unexpanded\def\styledrootradical#1#2
36 {\normalexpanded{\rootradical
37 {\normalunexpanded{#1}}
38 {\noexpand\triggermathstyle{\number\normalmathstyle}
39 \normalunexpanded{#2}}}}
40
41
42
43
44
45
46
47
48\unexpanded\def\rootwithdegree[#1]{\rootradical{#1}}
49\unexpanded\def\rootwithoutdegree {\rootradical {}}
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89\installcorenamespace{mathradical}
90\installcorenamespace{mathradicalalternative}
91
92\installcommandhandler \??mathradical {mathradical} \??mathradical
93
94\setupmathradical
95 [\c!alternative=\v!normal,
96 \c!mpoffset=.25\exheight]
97
98\appendtoks
99 \setuevalue{\currentmathradical}{\math_radical_handle{\currentmathradical}}
100\to \everydefinemathradical
101
102\unexpanded\def\math_radical_handle#tag
103 {\begingroup
104 \edef\currentmathradical{#tag}
105 \doifelsenextoptionalcs\math_radical_degree_yes\math_radical_degree_nop}
106
107\def\math_radical_alternative{\csname\??mathradicalalternative\mathradicalparameter\c!alternative\endcsname}
108
109\def\m_math_no_degree{{}}
110
111\def\math_radical_degree_yes[#degree]{\edef\currentmathradicaldegree{#degree}\math_radical_indeed}
112\def\math_radical_degree_nop {\let\currentmathradicaldegree\m_math_no_degree\math_radical_indeed}
113
114\def\math_radical_indeed#body
115 {\math_radical_alternative{#body}\endgroup}
116
117\setvalue{\??mathradicalalternative\v!default}
118 {\rootradical{\currentmathradicaldegree}}
119
120\setvalue{\??mathradicalalternative\v!normal}#body
121 {\edef\p_color{\mathradicalparameter\c!color}
122 \ifx\p_color\empty
123 \styledrootradical{\currentmathradicaldegree}{#body}
124 \else\ifx\currentmathradicaldegree\empty
125 \pushcolor[\p_color]
126 \styledrootradical{\currentmathradicaldegree}
127 {\popcolor#body}
128 \else
129 \pushcolor[\p_color]
130 \styledrootradical{\popcolor\currentmathradicaldegree\pushcolor[\p_color]}
131 {\popcolor#body}
132 \fi\fi}
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190\startMPextensions
191 vardef math_radical_simple(expr w,h,d,o) =
192 (h2o,h2o) --
193 (h4o,do) --
194 (o,ho) --
195 (wo,ho) --
196 (wo,hh10o)
197 enddef ;
198\stopMPextensions
199
200\startuniqueMPgraphic{minifun::math:radical:default}
201 draw
202 math_radical_simple(OverlayWidth,OverlayHeight,OverlayDepth,OverlayOffset)
203
204 withpen pencircle scaled OverlayLineWidth
205
206 withcolor OverlayLineColor ;
207\stopuniqueMPgraphic
208
209
210
211\setvalue{\??mathradicalalternative\v!mp}#body
212 {\begingroup
213 \scratchoffset\mathradicalparameter\c!mpoffset
214 \setbox\nextbox\mathstylehbox{#body}
215
216
217 \d_overlay_width \wd\nextbox
218 \d_overlay_height \ht\nextbox
219 \d_overlay_depth \dp\nextbox
220 \d_overlay_offset \scratchoffset
221 \d_overlay_linewidth\the\dimexpr\triggeredmathstyleparameter\Umathfractionrule
222
223 \edef\overlaylinecolor{\mathradicalparameter\c!color}
224
225 \edef\p_mp{\mathradicalparameter\c!mp}
226
227 \setbox\scratchbox\hpack\bgroup
228 \uniqueMPgraphic
229 {\p_mp}
230
231 \egroup
232 \scratchdimen \wd\scratchbox
233 \scratchtopoffset \dimexpr\scratchoffset\dp\nextbox\relax
234 \scratchbottomoffset\dimexpr\scratchoffset\ht\nextbox2\relax
235 \hpack to \scratchdimen{\hss\box\nextbox\hskip\scratchoffset}
236 \hskip\scratchdimen
237 \lower\dimexpr\scratchtopoffset\box\scratchbox
238 \ifx\currentmathradicaldegree\empty \else
239 \setbox\scratchbox\mathstylehbox{\scriptscriptstyle\currentmathradicaldegree\hss}
240 \wd\scratchbox\scratchdimen
241 \hskip\scratchdimen
242 \raise\dimexpr\scratchbottomoffset\box\scratchbox
243 \fi
244 \endgroup}
245
246\definemathradical[sqrt][mp=minifun::math:radical:default]
247
248
249
250
251
252
253
254
255\installcorenamespace{mathornament}
256\installcorenamespace{mathornamentalternative}
257
258\installcommandhandler \??mathornament {mathornament} \??mathornament
259
260\setupmathornament
261 [\c!alternative=\v!mp,
262 \c!mpoffset=.25\exheight]
263
264\appendtoks
265 \setuevalue{\currentmathornament}{\math_ornament_handle{\currentmathornament}}
266\to \everydefinemathornament
267
268\unexpanded\def\math_ornament_handle#tag#body
269 {\begingroup
270 \edef\currentmathornament{#tag}
271 \csname\??mathornamentalternative\mathornamentparameter\c!alternative\endcsname{#body}
272 \endgroup}
273
274\setvalue{\??mathornamentalternative\v!mp}#body
275 {\begingroup
276 \scratchoffset\mathornamentparameter\c!mpoffset
277 \setbox\nextbox\mathstylehbox{#body}
278 \d_overlay_width \wd\nextbox
279 \d_overlay_height \ht\nextbox
280 \d_overlay_depth \dp\nextbox
281 \d_overlay_offset \scratchoffset
282 \d_overlay_linewidth\linewidth
283 \edef\overlaylinecolor{\mathornamentparameter\c!color}
284 \edef\p_mp{\mathornamentparameter\c!mp}
285
286 \setbox\scratchbox\hpack{\uniqueMPgraphic{\p_mp}}
287 \hpack to \wd\scratchbox{\hss\box\nextbox\hss}
288 \hskip\wd\scratchbox
289 \box\scratchbox
290 \endgroup}
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329\protect \endinput
330 |