1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Packaging Macros Ruled Math}
15
16
17
18
19\unprotect
20
21
22
23
24\newconditional\c_framed_math_framed
25
26\installtextracker
27 {framed.math}
28 {\c_framed_math_framed\conditionaltrue}
29 {\c_framed_math_framed\conditionalfalse}
30
31\integerdef\c_framed_math_last_left \zerocount
32\integerdef\c_framed_math_last_right\zerocount
33
34\installglobalmacrostack\c_framed_math_last_left
35\installglobalmacrostack\c_framed_math_last_right
36
37\installcorenamespace{framedmath}
38
39\defineframed[\??framedmath]
40
41\setupframed[\??framedmath][\c!location=\v!middle]
42
43\tolerant\permanent\protected\def\defineframedmath[#1]#*[#2]#*[#S#3]
44 {\ifarguments\or
45 \defineframed[#1][\??framedmath]
46 \or
47 \defineframed[#1][\??framedmath][#2]
48 \or
49 \defineframed[#1][#2][#3]
50 \fi
51 \tolerant\frozen\protected\defcsname#1\endcsname{\math_framed{#1}}}
52
53\defineframedmath[framedmath]
54
55\tolerant\def\math_framed#1#*[#S#2]#:#3
56 {\begingroup
57 \ifconditional\c_framed_math_framed
58 \defineboxanchor[temp]
59 \fi
60 \setmathatomrule\mathbegincode\mathbinarycode\allmathstyles\mathbegincode\mathbinarycode
61
62 \scratchoffset\Umathaxis\givenmathstyle\mathstyle
63
64 \cdef\currentframed{#1}
65
66
67
68 \setbox\scratchbox\hpack\bgroup
69 \startimath
70 \givenmathstyle\mathstyle
71 \mathboundary\zerocount
72 #3
73 \mathboundary\plusone
74 \stopimath
75 \normalexpanded{\aftergrouped{
76 \integerdef\c_framed_math_last_left \the\lastleftclass \relax
77 \integerdef\c_framed_math_last_right\the\lastrightclass\relax
78 }}
79 \egroup
80
81 \setbox\scratchbox\hpack
82 \localframedwithsettings
83 [#1][#2]
84 {\box\scratchbox}
85
86 \boxymove\scratchbox\scratchoffset
87
88 \ifconditional\c_framed_math_framed
89 \boxsource\scratchbox \namedboxanchor{temp}
90 \fi
91
92 \mathatom
93 \s!class \mathexplicitcode
94 \ifnum\c_framed_math_last_left <\zerocount\else\s!leftclass \c_framed_math_last_left \fi
95 \ifnum\c_framed_math_last_right<\zerocount\else\s!rightclass\c_framed_math_last_right\fi
96 \bgroup
97 \ifconditional\c_framed_math_framed
98 \setboxanchor[temp][\c!corner={\v!left ,\v!bottom},\c!location={\v!right,\v!height}]
99 \hpack{\smallinfofont\the\c_framed_math_last_left}
100 \setboxanchor[temp][\c!corner={\v!right,\v!bottom},\c!location={\v!left ,\v!height}]
101 \hpack{\smallinfofont\the\c_framed_math_last_right}
102 \fi
103 \box\scratchbox
104 \egroup
105 \endgroup}
106
107\defineoverlay[mathstrikeout][\useMPgraphic{\framedparameter{mp}}]
108
109\defineframedmath
110 [mathstrikeout]
111 [\c!offset=\v!overlay,
112 \c!mp=mathstrikeout,
113 \c!rulethickness=1.5\linewidth,
114 \c!background={\v!foreground,mathstrikeout},
115
116 \c!textstyle=\txx,
117 \c!mathstyle=\s!script,
118 \c!frame=\v!off,
119 \c!arrow=\v!yes]
120
121\defineframedmath
122 [mathcrossout]
123 [mathstrikeout]
124 [\c!mp=mathcrossout,
125 strike:location=bottom]
126
127\permanent\protected\def\mathstrikeoutlabel
128 {\ifempty{\framedparameter{strike:math}}
129 \useframedstyleandcolor\c!textstyle\c!color
130 \framedparameter{strike:text}
131 \else
132 \startimath
133 \dousecolorparameter{\framedparameter\c!color}
134 \usemathstyleparameter\framedparameter\c!mathstyle
135 \framedparameter{strike:math}
136 \stopimath
137 \fi}
138
139\startuseMPgraphic{mathstrikeout}
140 path arr ; arr := (llcorner OverlayBox -- urcorner OverlayBox) ;
141 if "\framedparameter{arrow}" = "yes" : drawarrow else : draw fi arr
142 withpen pencircle scaled OverlayLineWidth
143 withcolor OverlayColor
144 ;
145 label.top("\mathstrikeoutlabel", point 1 of arr)
146 withcolor OverlayColor
147 ;
148
149
150
151
152
153 setbounds currentpicture to OverlayBox ;
154\stopuseMPgraphic
155
156\startuseMPgraphic{mathcrossout}
157 draw (
158 (llcorner OverlayBox -- urcorner OverlayBox) &&
159 (ulcorner OverlayBox -- lrcorner OverlayBox)
160 )
161 withpen pencircle scaled OverlayLineWidth
162 withcolor OverlayColor
163 ;
164 if "\framedparameter{strike:location}" = "bottom" :
165 label.bot("\mathstrikeoutlabel", center bottomboundary currentpicture)
166 else :
167 label.top("\mathstrikeoutlabel", center topboundary currentpicture)
168 fi
169 withcolor OverlayColor
170 ;
171 setbounds currentpicture to OverlayBox ;
172\stopuseMPgraphic
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216\permanent\tolerant\protected\def\mparagraph[#S#1]#*#:#2
217 {\vcenter class \mathconstructcode \bgroup
218 \framed[\c!offset=\v!overlay,\c!frame=\v!overlay,\c!align=\v!middle,#1]{#2}
219 \egroup}
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255\newinteger\c_framed_mstyle
256
257\installcorenamespace{mathframed}
258
259\installframedcommandhandler \??mathframed {mathframed} \??mathframed
260
261\newtoks \t_pack_framed_mathframed
262\newdimension\d_pack_framed_mathframed
263
264\appendtoks
265 \frozen\protected\instance\edefcsname\currentmathframed\endcsname{\pack_framed_mathframed[\currentmathframed]}
266\to \everydefinemathframed
267
268\tolerant\protected\def\pack_framed_mathframed[#1]#*[#S#2]#:#3
269 {\begingroup
270 \cdef\currentmathframed{#1}
271 \setupcurrentmathframed[#2]
272 \scratchdistance\ifchkdimension\mathframedparameter\c!backgroundoffset\or\lastchkdimension\else\zeropoint\fi
273 \ifmmode
274 \ifempty{\mathframedparameter\c!mathstyle}
275 \normalexpanded{\setmathframedparameter{\c!mathstyle}{\m_math_styles_current}}
276 \fi
277 \math_atom_by_parameter\mathframedparameter
278 \bgroup
279 \ifzeropt\scratchdistance\else\kern\scratchdistance\fi
280 \fi
281 \edef\m_framed_location{\mathframedparameter\c!location}
282 \dostarttaggednodetail\t!mrow
283 \ifx\m_framed_location\v!mathematics
284 \inheritedmathframedframed\bgroup
285 \setbox\scratchbox\hbox\bgroup
286 \Ustartmath
287 \usemathstyleparameter\mathframedparameter\c!mathstyle
288 \expand\t_pack_framed_mathframed
289 \mathatom \mathunspacedcode
290 \bgroup
291 #3
292 \egroup
293 \Ustopmath
294 \egroup
295 \global\d_pack_framed_mathframed\dp\scratchbox
296 \dontleavehmode\box\scratchbox
297 \egroup
298 \else
299 \inheritedmathframedframed\bgroup
300 \hbox\bgroup
301 \Ustartmath
302 \usemathstyleparameter\mathframedparameter\c!mathstyle
303 #3
304 \Ustopmath
305 \egroup
306 \egroup
307 \fi
308 \dostoptagged
309 \ifmmode
310 \ifzeropt\scratchdistance\else\kern\scratchdistance\fi
311 \egroup
312 \fi
313 \endgroup}
314
315\appendtoks
316 \c_strc_math_ragged_status \plustwo
317 \c_strc_formulas_check_width\zerocount
318\to \t_pack_framed_mathframed
319
320\installframedlocator \v!mathematics
321 {}
322 {\pack_framed_locator_set_lo
323 \ifzeropt\d_framed_locator_lo\else
324 \lower{\d_framed_locator_lo\d_pack_framed_mathframed}
325 \fi
326 \box\b_framed_normal}
327
328\definemathframed[mframed]
329\definemathframed[inmframed][\c!location=\v!low]
330\definemathframed[mcframed] [\c!location=\v!mathematics]
331\definemathframed[mtframed] [\c!location=\v!mathematics,\c!offset=\v!overlay,\c!frame=\v!overlay]
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369\protect
370 |