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{mathframed}
38
39\defineframed[\??mathframed]
40
41\setupframed[\??mathframed][\c!location=\v!middle]
42
43\tolerant\permanent\protected\def\definemathframed[#1]#*[#2]#*[#S#3]
44 {\ifarguments\or
45 \defineframed[#1][\??mathframed]
46 \or
47 \defineframed[#1][\??mathframed][#2]
48 \or
49 \defineframed[#1][#2][#3]
50 \fi
51 \tolerant\frozen\protected\defcsname#1\endcsname{\math_framed{#1}}}
52
53\definemathframed[mathframed]
54
55\dimensiondef\d_math_framed_offset\zeropoint
56
57\def\math_framed#1#*[#S#2]#:#3
58 {\begingroup
59 \ifconditional\c_framed_math_framed
60 \defineboxanchor[temp]
61 \fi
62 \setmathatomrule\mathbegincode\mathbinarycode\allmathstyles\mathbegincode\mathbinarycode
63
64 \scratchdimen\Umathaxis\givenmathstyle\mathstyle
65
66 \cdef\currentframed{#1}
67 \setbox\scratchbox\hbox{\localframedwithsettings[#1][#2]
68 {\strut\global\dimensiondef\d_math_framed_offset\dimexpr
69 \framedoffset2
70
71 \relax}}
72
73 \setbox\scratchbox\hpack\bgroup
74 \startimath
75 \givenmathstyle\mathstyle
76 #3
77 \stopimath
78 \normalexpanded{\aftergrouped{
79 \integerdef\c_framed_math_last_left \the\lastleftclass
80 \integerdef\c_framed_math_last_right\the\lastrightclass
81 }}
82 \egroup
83
84 \boxymove\scratchbox\dimexpr
85 \scratchdimen
86 \d_math_framed_offset2
87 \relax
88
89 \setbox\scratchbox\hpack
90 \localframedwithsettings
91 [#1][#2]
92 {\box\scratchbox}
93
94 \boxymove\scratchbox\scratchdimen
95
96 \ifconditional\c_framed_math_framed
97 \boxsource\scratchbox \namedboxanchor{temp}
98 \fi
99
100 \mathatom
101 \s!class \mathexplicitcode
102 \ifnum\c_framed_math_last_left <\zerocount\else\s!leftclass \c_framed_math_last_left \fi
103 \ifnum\c_framed_math_last_right<\zerocount\else\s!rightclass\c_framed_math_last_right\fi
104 \bgroup
105 \ifconditional\c_framed_math_framed
106 \setboxanchor[temp][\c!corner={\v!left ,\v!bottom},\c!location={\v!right,\v!height}]
107 \hpack{\smallinfofont\the\c_framed_math_last_left}
108 \setboxanchor[temp][\c!corner={\v!right,\v!bottom},\c!location={\v!left ,\v!height}]
109 \hpack{\smallinfofont\the\c_framed_math_last_right}
110 \fi
111 \box\scratchbox
112 \egroup
113 \endgroup}
114
115\defineoverlay[mathstrikeout][\useMPgraphic{\framedparameter{mp}}]
116
117\definemathframed
118 [mathstrikeout]
119 [\c!offset=\v!overlay,
120 \c!mp=mathstrikeout,
121 \c!rulethickness=1.5\linewidth,
122 \c!background={\v!foreground,mathstrikeout},
123
124 \c!textstyle=\txx,
125 \c!mathstyle=\s!script,
126 \c!frame=\v!off,
127 \c!arrow=\v!yes]
128
129\definemathframed
130 [mathcrossout]
131 [mathstrikeout]
132 [\c!mp=mathcrossout,
133 strike:location=bottom]
134
135\permanent\protected\def\mathstrikeoutlabel
136 {\ifempty{\framedparameter{strike:math}}
137 \useframedstyleandcolor\c!textstyle\c!color
138 \framedparameter{strike:text}
139 \else
140 \startimath
141 \dousecolorparameter{\framedparameter\c!color}
142 \usemathstyleparameter\framedparameter\c!mathstyle
143 \framedparameter{strike:math}
144 \stopimath
145 \fi}
146
147\startuseMPgraphic{mathstrikeout}
148 path arr ; arr := (llcorner OverlayBox -- urcorner OverlayBox) ;
149 if "\framedparameter{arrow}" = "yes" : drawarrow else : draw fi arr
150 withpen pencircle scaled OverlayLineWidth
151 withcolor OverlayColor
152 ;
153 label.top("\mathstrikeoutlabel", point 1 of arr)
154 withcolor OverlayColor
155 ;
156
157
158
159
160
161 setbounds currentpicture to OverlayBox ;
162\stopuseMPgraphic
163
164\startuseMPgraphic{mathcrossout}
165 draw (
166 (llcorner OverlayBox -- urcorner OverlayBox) &&
167 (ulcorner OverlayBox -- lrcorner OverlayBox)
168 )
169 withpen pencircle scaled OverlayLineWidth
170 withcolor OverlayColor
171 ;
172 if "\framedparameter{strike:location}" = "bottom" :
173 label.bot("\mathstrikeoutlabel", center bottomboundary currentpicture)
174 else :
175 label.top("\mathstrikeoutlabel", center topboundary currentpicture)
176 fi
177 withcolor OverlayColor
178 ;
179 setbounds currentpicture to OverlayBox ;
180\stopuseMPgraphic
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
217
218
219
220
221
222
223
224\permanent\tolerant\protected\def\mparagraph[#S#1]#*#:#2
225 {\vcenter class \mathconstructcode \bgroup
226 \framed[\c!offset=\v!overlay,\c!frame=\v!overlay,\c!align=\v!middle,#1]{#2}
227 \egroup}
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243\newinteger\c_framed_mstyle
244
245\installcorenamespace{mathframed}
246
247\installframedcommandhandler \??mathframed {mathframed} \??mathframed
248
249\newtoks \t_pack_framed_mathframed
250\newdimension\d_pack_framed_mathframed
251
252\appendtoks
253 \frozen\protected\instance\edefcsname\currentmathframed\endcsname{\pack_framed_mathframed[\currentmathframed]}
254\to \everydefinemathframed
255
256\tolerant\protected\def\pack_framed_mathframed[#1]#*[#S#2]#:#3
257 {\begingroup
258 \cdef\currentmathframed{#1}
259 \setupcurrentmathframed[#2]
260 \c_framed_mstyle\normalmathstyle
261 \edef\m_framed_location{\mathframedparameter\c!location}
262 \ifx\m_framed_location\v!mathematics
263 \inheritedmathframedframed\bgroup
264 \setbox\scratchbox\hbox\bgroup
265 \Ustartmath
266 \triggermathstyle\c_framed_mstyle
267 \expand\t_pack_framed_mathframed
268 \mathatom \mathunspacedcode\bgroup
269 #3
270 \egroup
271 \Ustopmath
272 \egroup
273 \global\d_pack_framed_mathframed\dp\scratchbox
274 \dontleavehmode\box\scratchbox
275 \egroup
276 \else
277 \inheritedmathframedframed\bgroup
278 \hbox\bgroup
279 \Ustartmath
280 \triggermathstyle\c_framed_mstyle
281 #3
282 \Ustopmath
283 \egroup
284 \egroup
285 \fi
286 \endgroup}
287
288\appendtoks
289 \c_strc_math_ragged_status \plustwo
290 \c_strc_formulas_check_width\zerocount
291\to \t_pack_framed_mathframed
292
293\installframedlocator \v!mathematics
294 {}
295 {\pack_framed_locator_set_lo
296 \ifzeropt\d_framed_locator_lo\else
297 \lower\dimexpr\d_framed_locator_lo\d_pack_framed_mathframed\relax
298 \fi
299 \box\b_framed_normal}
300
301\definemathframed[mframed]
302\definemathframed[inmframed][\c!location=\v!low]
303\definemathframed[mcframed] [\c!location=\v!mathematics]
304\definemathframed[mtframed] [\c!location=\v!mathematics,\c!offset=\v!overlay,\c!frame=\v!overlay]
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
330
331
332
333
334
335
336
337
338
339
340
341
342\protect
343 |