meta-imp-mat.mkiv /size: 9064 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=meta-mat,
3%D        version=2013.07.19,
4%D          title=\METAPOST\ Graphics,
5%D       subtitle=Math,
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% A few accents:
15%
16% / for cambria
17
18%D We need this for Alan, who nests math in \METAPOST:
19
20\unprotect
21
22\setupmathstackers
23  [\c!mp=minifun::math:stacker:\number\scratchunicode]
24
25\protect
26
27\startMPextensions
28    vardef math_stacker_bracket_shape(expr delta, rotate) =
29        image (
30            draw
31                (0,OverlayOffset) --
32                (0,delta-OverlayOffset) --
33                (OverlayWidth,delta-OverlayOffset) --
34                (OverlayWidth,OverlayOffset)
35            withcolor
36                OverlayLineColor ;
37            setbounds currentpicture to boundingbox currentpicture bottomenlarged OverlayOffset ;
38            if rotate :
39                currentpicture := currentpicture rotated 180 ;
40            fi ;
41        )
42    enddef ;
43    vardef math_stacker_parent_shape(expr delta, rotate) =
44        image (
45            draw
46                (0,OverlayOffset) ...
47                (OverlayWidth/2,delta-OverlayOffset) ...
48                (OverlayWidth,OverlayOffset)
49            withcolor
50                OverlayLineColor ;
51            setbounds currentpicture to boundingbox currentpicture bottomenlarged OverlayOffset ;
52            if rotate :
53                currentpicture := currentpicture rotated 180 ;
54            fi ;
55        )
56    enddef ;
57    vardef math_stacker_brace_shape(expr delta, rotate) =
58        image (
59            draw
60                (0,OverlayOffset) ...
61                (OverlayWidth/4-OverlayOffset,delta-OverlayOffset) ...
62                (OverlayWidth/2-OverlayOffset,delta-OverlayOffset) ...
63                (OverlayWidth/2,delta) &
64                (OverlayWidth/2,delta) ...
65                (OverlayWidth/2+OverlayOffset,delta-OverlayOffset) ...
66                (3OverlayWidth/4+OverlayOffset,delta-OverlayOffset) ...
67                (OverlayWidth,OverlayOffset)
68            withcolor
69                OverlayLineColor ;
70            setbounds currentpicture to boundingbox currentpicture bottomenlarged OverlayOffset ;
71            if rotate :
72                currentpicture := currentpicture rotated 180 ;
73            fi ;
74        )
75    enddef ;
76    vardef math_stacker_bar_shape(expr rotate) =
77        image (
78            draw
79                (0,OverlayOffset) -- (OverlayWidth,OverlayOffset)
80            withcolor
81                OverlayLineColor ;
82            setbounds currentpicture to boundingbox currentpicture bottomenlarged OverlayOffset ;
83            if rotate :
84                currentpicture := currentpicture rotated 180 ;
85            fi ;
86        )
87    enddef ;
88    % arrows
89    vardef math_stacker_arrow_shape(expr axis, ex, em, rotate) =
90        image (
91            interim ahlength := ex/2;
92            drawarrow
93                ((OverlayWidth,ex/2) -- (0,ex/2))
94            withcolor
95                OverlayLineColor ;
96            setbounds currentpicture to unitsquare xysized(OverlayWidth,ex) ;
97            if rotate :
98                currentpicture := currentpicture rotated 180 ;
99            fi ;
100        )
101    enddef ;
102    vardef math_stacker_leftrightarrow_shape(expr axis, ex, em, rotate) =
103        image (
104            interim ahlength := ex/2;
105            drawdblarrow
106                ((OverlayWidth,ex/2) -- (0,ex/2))
107            withcolor
108                OverlayLineColor ;
109            setbounds currentpicture to unitsquare xysized(OverlayWidth,ex) ;
110            if rotate :
111                currentpicture := currentpicture rotated 180 ;
112            fi ;
113        )
114    enddef ;
115    vardef math_stacker_rightoverleftarrow_shape(expr axis, ex, em, rotate) =
116        image (
117            interim ahlength := ex/2;
118            drawdoublearrows
119                ((OverlayWidth,ex/2) -- (0,ex/2))
120            withcolor
121                OverlayLineColor ;
122            setbounds currentpicture to unitsquare xysized(OverlayWidth,ex) ;
123            if rotate :
124                currentpicture := currentpicture rotated 180 ;
125            fi ;
126        )
127    enddef ;
128
129    % main handler
130
131    def math_stacker_draw_accent(expr p) =
132%         draw p withpen pencircle scaled OverlayLineWidth xyscaled (2,3) rotated 45 ;
133%         draw p withpen pencircle xscaled (2OverlayLineWidth) yscaled (3OverlayLineWidth/4) rotated 45 ;
134        draw p withpen pencircle scaled OverlayLineWidth ;
135    enddef ;
136
137    def math_stacker_draw_arrow(expr p) =
138        draw p withpen pencircle scaled OverlayLineWidth ;
139    enddef ;
140\stopMPextensions
141
142\startuniqueMPgraphic{minifun::math:stacker:\number"\ifcase\contextlmtxmode FE3B4\else23B4\fi}{axis,ex,em}
143    math_stacker_draw_accent(math_stacker_bracket_shape(OverlayHeight,false)) ;
144\stopuniqueMPgraphic
145
146\startuniqueMPgraphic{minifun::math:stacker:\number"\ifcase\contextlmtxmode FE3B5\else23B5\fi}{axis,ex,em}
147    math_stacker_draw_accent(math_stacker_bracket_shape(OverlayDepth,true)) ;
148\stopuniqueMPgraphic
149
150\startuniqueMPgraphic{minifun::math:stacker:\number"\ifcase\contextlmtxmode FE3DC\else23DC\fi}{axis,ex,em}
151    math_stacker_draw_accent(math_stacker_parent_shape(OverlayHeight,false)) ;
152\stopuniqueMPgraphic
153
154\startuniqueMPgraphic{minifun::math:stacker:\number"\ifcase\contextlmtxmode FE3DD\else23DD\fi}{axis,ex,em}
155    math_stacker_draw_accent(math_stacker_parent_shape(OverlayDepth,true)) ;
156\stopuniqueMPgraphic
157
158\startuniqueMPgraphic{minifun::math:stacker:\number"\ifcase\contextlmtxmode FE3DE\else23DE\fi}{axis,ex,em}
159    math_stacker_draw_accent(math_stacker_brace_shape(OverlayHeight,false)) ;
160\stopuniqueMPgraphic
161
162\startuniqueMPgraphic{minifun::math:stacker:\number"\ifcase\contextlmtxmode FE3DF\else23DF\fi}{axis,ex,em}
163    math_stacker_draw_accent(math_stacker_brace_shape(OverlayDepth,true)) ;
164\stopuniqueMPgraphic
165
166\startuniqueMPgraphic{minifun::math:stacker:\number"\ifcase\contextlmtxmode FE33E\else203E\fi}{axis,ex,em}
167    math_stacker_draw_accent(math_stacker_bar_shape(false)) ;
168\stopuniqueMPgraphic
169
170\startuniqueMPgraphic{minifun::math:stacker:\number"\ifcase\contextlmtxmode FE33F\else203F\fi}{axis,ex,em}
171    math_stacker_draw_accent(math_stacker_bar_shape(true)) ;
172\stopuniqueMPgraphic
173
174\startuniqueMPgraphic{minifun::math:stacker:\number"2190}{axis,ex,em}
175    math_stacker_draw_arrow(math_stacker_arrow_shape(\MPvar{axis},\MPvar{ex},\MPvar{em},false)) ;
176\stopuniqueMPgraphic
177
178\startuniqueMPgraphic{minifun::math:stacker:\number"2192}{axis,ex,em}
179    math_stacker_draw_arrow(math_stacker_arrow_shape(\MPvar{axis},\MPvar{ex},\MPvar{em},true)) ;
180\stopuniqueMPgraphic
181
182\startuniqueMPgraphic{minifun::math:stacker:\number"2194}{axis,ex,em}
183    math_stacker_draw_arrow(math_stacker_leftrightarrow_shape(\MPvar{axis},\MPvar{ex},\MPvar{em},false)) ;
184\stopuniqueMPgraphic
185
186\startuniqueMPgraphic{minifun::math:stacker:\number"27F7}{axis,ex,em}
187    math_stacker_draw_arrow(math_stacker_leftrightarrow_shape(\MPvar{axis},\MPvar{ex},\MPvar{em},false)) ;
188\stopuniqueMPgraphic
189
190\startuniqueMPgraphic{minifun::math:stacker:\number"21C4}{axis,ex,em}
191    math_stacker_draw_arrow(math_stacker_rightoverleftarrow_shape(\MPvar{axis},\MPvar{ex},\MPvar{em},false)) ;
192\stopuniqueMPgraphic
193
194%D Radicals:
195
196\startMPextensions
197    vardef math_radical_simple(expr w,h,d,o) =
198        (-h/2-o,h/2-o) --
199        (-h/4-o,-d-o)  --
200        (-o,h+o)       --
201        (w+o,h+o)      --
202        (w+o,h-h/10+o)
203    enddef ;
204\stopMPextensions
205
206\startuniqueMPgraphic{minifun::math:radical:default}{axis,ex,em}
207    draw
208        math_radical_simple(OverlayWidth,OverlayHeight,OverlayDepth,OverlayOffset)
209     %  withpen pencircle xscaled (2OverlayLineWidth) yscaled (3OverlayLineWidth/4) rotated 30
210        withpen pencircle scaled OverlayLineWidth
211      % dashed evenly
212        withcolor OverlayLineColor ;
213\stopuniqueMPgraphic
214
215% already setup:
216%
217% definemathradical [sqrt]   [mp=minifun::math:radical:default]
218
219\continueifinputfile{meta-imp-mat.mkiv}
220
221\setupmathstackers [both]   [color=darkred,alternative=mp]
222\setupmathstackers [top]    [color=darkred,alternative=mp]
223\setupmathstackers [bottom] [color=darkred,alternative=mp]
224
225\startTEXpage[offset=10pt]
226
227$
228    \overbracket   {a+b+c+d} \quad
229    \underbracket  {a+b+c+d} \quad
230    \doublebracket {a+b+c+d}
231$
232\blank[2*big]
233$
234    \overparent   {a+b+c+d} \quad
235    \underparent  {a+b+c+d} \quad
236    \doubleparent {a+b+c+d}
237$
238\blank[2*big]
239$
240    \overbrace   {a+b+c+d} \quad
241    \underbrace  {a+b+c+d} \quad
242    \doublebrace {a+b+c+d}
243$
244\blank[2*big]
245$
246    \overbar   {a+b+c+d} \quad
247    \underbar  {a+b+c+d} \quad
248    \doublebar {a+b+c+d}
249$
250\blank[2*big]
251$
252    \overleftarrow  {a+b+c+d} \quad
253    \overrightarrow {a+b+c+d}
254$
255\blank[2*big]
256$
257    \underleftarrow  {a+b+c+d} \quad
258    \underrightarrow {a+b+c+d}
259$
260\blank[2*big]
261\setupmathradical[sqrt][alternative=mp,color=darkgreen]
262$
263    \sqrt[2]{a+b+c+d} \quad
264$
265
266\stopTEXpage
267