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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97\installcorenamespace{mathradical}
98\installcorenamespace{mathradicalalternative}
99
100\installcommandhandler \??mathradical {mathradical} \??mathradical
101
102\setupmathradical
103 [\c!alternative=\v!normal,
104 \c!mpoffset=.25\exheight,
105 \c!height=\zeropoint,
106 \c!depth=\zeropoint,
107 \c!strut=\v!height,
108
109 \c!mindepth=.20\exheight,
110 \c!source=\zerocount,
111 \c!left="221A,
112 \c!mathstyle=\v!normal,
113 \c!right=\zerocount,
114 \c!leftmargin=\zeropoint,
115 \c!rightmargin=\zeropoint]
116
117\appendtoks
118 \frozen\protected\instance\edefcsname\currentmathradical\endcsname{\math_radical_handle{\currentmathradical}}
119\to \everydefinemathradical
120
121\mutable\lettonothing\currentmathradical
122\mutable\lettonothing\currentmathradicaldegree
123
124\setmathignore\Umathradicaldegreebefore\plusone
125
126\installcorenamespace{mathwhateverstrut}
127
128\defcsname\??mathwhateverstrut\v!height\endcsname{\mathheightstrut}
129\defcsname\??mathwhateverstrut\v!depth \endcsname{\mathdepthstrut}
130\defcsname\??mathwhateverstrut\v!math \endcsname{\mathstrut}
131\defcsname\??mathwhateverstrut\v!yes \endcsname{\strut}
132
133
134\tolerant\protected\def\math_radical_handle#tag#*[#S#settings]#*[#degree]#:#body
135 {\begingroup
136 \cdef\currentmathradical{#tag}
137 \ifhastok={#settings}
138 \lettonothing\currentmathradicaldegree
139 \setupcurrentmathradical[#settings]
140 \ifparameter#degree\or
141 \edef\currentmathradicaldegree{#degree}
142 \else
143 \edef\currentmathradicaldegree{\mathradicalparameter\c!n}
144 \fi
145 \else
146 \edef\currentmathradicaldegree{#settings}
147 \fi
148 \ifempty\currentmathradicaldegree
149 \let\currentmathradicaldegree\m_math_no_degree
150 \fi
151 \ifcase\mathradicalparameter\c!right\else
152 \let\currentmathradicaldegree\m_math_no_degree
153 \fi
154 \math_radical_alternative{
155 \begincsname\??mathwhateverstrut\mathradicalparameter\c!strut\endcsname
156 \scratchdimen\mathradicalparameter\c!leftmargin \relax\ifzeropt\scratchdimen\else\kern\scratchdimen\fi
157 #body
158 \scratchdimen\mathradicalparameter\c!rightmargin\relax\ifzeropt\scratchdimen\else\kern\scratchdimen\fi
159 }
160 \endgroup}
161
162\def\m_math_no_degree{{}}
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\def\math_radical_alternative{\csname\??mathradicalalternative\mathradicalparameter\c!alternative\endcsname}
190
191
192
193
194\protected\def\math_radical_common#degree#body
195 {\scratchcounter\ifcstok{\mathradicalparameter\c!rule}\v!symbol
196 \mathradicalparameter\c!top\relax
197 \else
198 \zerocount
199 \fi
200 \edef\xxx{\expandedmathstyleparameter\mathradicalparameter\c!mathstyle}
201 \Urooted
202 \s!height\dimexpr\ifcstok{\mathradicalparameter\c!height}\v!none\scaledpoint\else\mathradicalparameter\c!height\fi\relax
203 \s!depth \dimexpr\ifcstok{\mathradicalparameter\c!depth }\v!none\scaledpoint\else\mathradicalparameter\c!depth \fi\relax
204 \s!source\numexpr\namedboxanchor{\mathradicalparameter\c!source}\relax
205 \s!style \normalmathstyle
206 \ifzeronum\scratchcounter\else
207 top
208 \fi
209 \ifcstok{\mathradicalparameter\c!rule}\v!no
210 norule
211 \orelse\ifcstok{\lastnamedcs}\v!bottom
212 reflected
213 \fi
214 \zerocount \mathradicalparameter\c!left
215 \zerocount \mathradicalparameter\c!right
216 \ifzeronum\scratchcounter\else
217 \zerocount\scratchcounter
218 \fi
219 \relax
220 {\mathstrut#degree}
221 {
222 \expandedmathstyleparameter\mathradicalparameter\c!mathstyle
223 #body}}
224
225\protected\def\math_radical_mindepth
226 {\scratchdepth\mathradicalparameter\c!mindepth\relax
227 \ifzerodim\scratchdepth\else
228 \srule \s!depth\scratchdepth\s!height\zeropoint\s!width\zeropoint\relax
229 \fi}
230
231\defcsname\??mathradicalalternative\v!default\endcsname#body
232 {\math_radical_common{\currentmathradicaldegree}{\math_radical_mindepth#body}}
233
234\defcsname\??mathradicalalternative\v!normal\endcsname#body
235 {\edef\p_color{\mathradicalparameter\c!color}
236 \ifempty\p_color
237 \math_radical_common{\currentmathradicaldegree}{\math_radical_mindepth#body}
238 \orelse\ifempty\currentmathradicaldegree
239 \pushcolor[\p_color]
240 \math_radical_common{}
241 {\popcolor\math_radical_mindepth#body}
242 \else
243 \pushcolor[\p_color]
244 \math_radical_common{\popcolor\currentmathradicaldegree\pushcolor[\p_color]}
245 {\popcolor\math_radical_mindepth#body}
246 \fi}
247
248\startMPextensions
249 vardef math_radical_simple(expr w,h,d,o) =
250 (h2o,h2o) --
251 (h4o,do) --
252 (o,ho) --
253 (wo,ho) --
254 (wo,hh10o)
255 enddef ;
256\stopMPextensions
257
258\startuniqueMPgraphic{minifun::math:radical:default}
259 draw
260 math_radical_simple(OverlayWidth,OverlayHeight,OverlayDepth,OverlayOffset)
261
262 withpen pencircle scaled OverlayLineWidth
263
264 withcolor OverlayLineColor ;
265\stopuniqueMPgraphic
266
267
268
269\defcsname\??mathradicalalternative\v!mp\endcsname#body
270 {\begingroup
271 \scratchoffset\mathradicalparameter\c!mpoffset
272 \setbox\nextbox\mathstylehbox{#body}
273
274
275 \d_overlay_width \wd\nextbox
276 \d_overlay_height \ht\nextbox
277 \d_overlay_depth \dp\nextbox
278 \d_overlay_offset \scratchoffset
279 \d_overlay_linewidth\the\dimexpr\triggeredmathstyleparameter\Umathfractionrule
280
281 \edef\overlaylinecolor{\mathradicalparameter\c!color}
282
283 \edef\p_mp{\mathradicalparameter\c!mp}
284
285 \setbox\scratchbox\hpack\bgroup
286 \uniqueMPgraphic
287 {\p_mp}
288
289 \egroup
290 \scratchdimen \wd\scratchbox
291 \scratchtopoffset \dimexpr\scratchoffset\dp\nextbox\relax
292 \scratchbottomoffset\dimexpr\scratchoffset\ht\nextbox2\relax
293 \hpack to \scratchdimen{\hss\box\nextbox\kern\scratchoffset}
294 \kern\scratchdimen
295 \lower\dimexpr\scratchtopoffset\box\scratchbox
296 \ifx\currentmathradicaldegree\empty \else
297 \setbox\scratchbox\mathstylehbox{\scriptscriptstyle\currentmathradicaldegree\hss}
298 \wd\scratchbox\scratchdimen
299 \kern\scratchdimen
300 \raise\dimexpr\scratchbottomoffset\box\scratchbox
301 \fi
302 \endgroup}
303
304\pushoverloadmode
305
306\definemathradical[root][mp=minifun::math:radical:default]
307\definemathradical[sqrt][root]
308
309\popoverloadmode
310
311
312
313
314
315
316
317
318\installcorenamespace{mathornament}
319\installcorenamespace{mathornamentalternative}
320
321\installcommandhandler \??mathornament {mathornament} \??mathornament
322
323\setupmathornament
324 [\c!alternative=\v!mp,
325 \c!mpoffset=.25\exheight]
326
327\appendtoks
328 \frozen\protected\instance\edefcsname\currentmathornament\endcsname
329 {\math_ornament_handle{\currentmathornament}}
330\to \everydefinemathornament
331
332\protected\def\math_ornament_handle#tag#body
333 {\begingroup
334 \cdef\currentmathornament{#tag}
335 \csname\??mathornamentalternative\mathornamentparameter\c!alternative\endcsname{#body}
336 \endgroup}
337
338\defcsname\??mathornamentalternative\v!mp\endcsname#body
339 {\begingroup
340 \scratchoffset\mathornamentparameter\c!mpoffset
341 \setbox\nextbox\mathstylehbox{#body}
342 \d_overlay_width \wd\nextbox
343 \d_overlay_height \ht\nextbox
344 \d_overlay_depth \dp\nextbox
345 \d_overlay_offset \scratchoffset
346 \d_overlay_linewidth\linewidth
347 \edef\overlaylinecolor{\mathornamentparameter\c!color}
348 \edef\p_mp{\mathornamentparameter\c!mp}
349
350 \setbox\scratchbox\hpack{\uniqueMPgraphic{\p_mp}}
351 \hpack to \wd\scratchbox{\hss\box\nextbox\hss}
352 \kern\wd\scratchbox
353 \box\scratchbox
354 \endgroup}
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395\integerdef\radicalbarextenderuc\privatecharactercode{radical bar extender}
396
397\integerdef\delimitedleftannuitylonguc \privatecharactercode{delimited left annuity long}
398\integerdef\delimitedleftannuityshortuc \privatecharactercode{delimited left annuity short}
399\integerdef\delimitedrightannuitylonguc \privatecharactercode{delimited right annuity long}
400\integerdef\delimitedrightannuityshortuc\privatecharactercode{delimited right annuity short}
401
402\integerdef\delimitedbottomleftannuitylonguc \privatecharactercode{delimited bottom left annuity long}
403\integerdef\delimitedbottomleftannuityshortuc \privatecharactercode{delimited bottom left annuity short}
404\integerdef\delimitedbottomrightannuitylonguc \privatecharactercode{delimited bottom right annuity long}
405\integerdef\delimitedbottomrightannuityshortuc\privatecharactercode{delimited bottom right annuity short}
406
407
408
409\setupmathradical
410 [\c!rule=\v!symbol,
411 \c!top=\radicalbarextenderuc]
412
413\definemathradical
414 [rannuity]
415 [\c!rule=\v!yes,
416 \c!left=\zerocount,
417 \c!right=\delimitedrightannuitylonguc,
418 \c!rightmargin=.05\emwidth]
419
420\definemathradical
421 [lannuity]
422 [\c!rule=\v!yes,
423 \c!left=\delimitedleftannuitylonguc,
424 \c!right=\zerocount,
425 \c!leftmargin=.05\emwidth]
426
427\definemathradical
428 [lrannuity]
429 [\c!rule=\v!yes,
430 \c!left=\delimitedleftannuityshortuc,
431 \c!right=\delimitedrightannuitylonguc,
432 \c!leftmargin=.05\emwidth,
433 \c!rightmargin=.05\emwidth]
434
435\definemathradical
436 [rlannuity]
437 [\c!rule=\v!yes,
438 \c!left=\delimitedleftannuitylonguc,
439 \c!right=\delimitedrightannuityshortuc,
440 \c!leftmargin=.05\emwidth,
441 \c!rightmargin=.05\emwidth]
442
443\definemathradical
444 [annuity]
445 [rannuity]
446
447\definemathradical
448 [lbannuity]
449 [lannuity]
450 [\c!rule=\v!bottom,
451 \c!left=\delimitedbottomleftannuitylonguc]
452
453\definemathradical
454 [rbannuity]
455 [rannuity]
456 [\c!rule=\v!bottom,
457 \c!right=\delimitedbottomrightannuitylonguc]
458
459\definemathradical
460 [rlbannuity]
461 [rlannuity]
462 [\c!rule=\v!bottom,
463 \c!left=\delimitedbottomleftannuityshortuc,
464 \c!right=\delimitedbottomrightannuitylonguc]
465
466\definemathradical
467 [lrbannuity]
468 [lrannuity]
469 [\c!rule=\v!bottom,
470 \c!left=\delimitedbottomleftannuitylonguc,
471 \c!right=\delimitedbottomrightannuityshortuc]
472
473\protect \endinput
474 |