1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Font Macros Math}
15
16\unprotect
17
18
19
20\ifdefined\??fontinstanceready \else \installcorenamespace{fontinstanceready} \fi
21\ifdefined\??fontinstancebasic \else \installcorenamespace{fontinstancebasic} \fi
22\ifdefined\??fontinstanceclass \else \installcorenamespace{fontinstanceclass} \fi
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40\newtoks \t_font_math_strategies
41\newconditional\c_font_synchronize_math_fonts \settrue\c_font_synchronize_math_fonts
42
43\unexpanded\def\font_helpers_synchronize_math
44 {\ifconditional\c_font_synchronize_math_fonts\the\t_font_math_strategies\fi}
45
46\unexpanded\def\textonly{\setfalse\c_font_synchronize_math_fonts}
47
48
49
50
51
52
53
54
55
56
57\let\c_font_fam_mr \zerocount
58\let\c_font_fam_mr_lr\plusone
59\let\c_font_fam_mr_rl\plustwo
60
61\let\c_font_fam_mb \plusthree
62\let\c_font_fam_mb_lr\plusfour
63\let\c_font_fam_mb_rl\plusfive
64
65\definesystemattribute[mathfamily][public]
66
67\newconditional\c_font_bidirectional_mathstrategy
68\newconditional\c_font_complete_bold_mathstrategy \settrue\c_font_complete_bold_mathstrategy
69
70\def\mathtextsuffix {text}
71\def\mathscriptsuffix {script}
72\def\mathscriptscriptsuffix{scriptscript}
73
74\def\mathsizesuffix{\ifcase\fontface\or\mathtextsuffix\or\mathscriptsuffix\or\mathscriptscriptsuffix\fi}
75
76
77
78
79
80\def\font_helpers_set_math_family_a
81 {\ifcsname\??fontinstanceready\fontclass \fontbody\s!mm\fontfamily\fontsize\endcsname \setfalse\c_font_auto_size
82 \lastnamedcs \else
83 \ifcsname\??fontinstanceready\fontclass \fontbody\s!mm\fontfamily \endcsname \settrue \c_font_auto_size
84 \lastnamedcs \else
85 \font_helpers_set_math_family_b
86 \fi\fi}
87
88\def\font_helpers_set_math_family_b
89 {\ifcsname\??fontinstanceready\defaultfontclass\fontbody\s!mm\fontfamily\fontsize\endcsname \setfalse\c_font_auto_size
90 \lastnamedcs \else
91 \ifcsname\??fontinstanceready\defaultfontclass\fontbody\s!mm\fontfamily \endcsname \settrue \c_font_auto_size
92 \lastnamedcs \else
93 \font_helpers_set_math_family_c
94 \fi\fi}
95
96\def\font_helpers_set_math_family_c
97 {\ifcsname\??fontinstanceready \fontbody\s!mm\fontfamily\fontsize\endcsname \setfalse\c_font_auto_size
98 \lastnamedcs \else
99 \ifcsname\??fontinstanceready \fontbody\s!mm\fontfamily \endcsname \settrue \c_font_auto_size
100 \lastnamedcs \else
101 \settrue \c_font_auto_size
102 \fi\fi}
103
104\let\mathsizesuffix\empty
105
106\def\font_helpers_set_math_family_indeed#mrtag#family
107 {\let\savedfontbody\fontbody
108 \let\fontfamily#family
109
110
111 \let\mathsizesuffix\mathscriptscriptsuffix\let\fontface\!!plusthree
112 \font_helpers_set_math_family_a\scriptscriptfont#mrtag\font
113 \font_helpers_set_math_family_a\scriptscriptfont#mrtag\font
114 \let\mathsizesuffix\mathscriptsuffix \let\fontface\!!plustwo
115 \font_helpers_set_math_family_a\scriptfont #mrtag\font
116 \font_helpers_set_math_family_a\scriptfont #mrtag\font
117 \let\mathsizesuffix\mathtextsuffix \let\fontface\!!plusone
118 \font_helpers_set_math_family_a\textfont #mrtag\font
119 \font_helpers_set_math_family_a\textfont #mrtag\font
120 \let\mathsizesuffix\empty \let\fontface\!!zerocount
121 \let\fontbody\savedfontbody
122 \setfalse\c_font_auto_size}
123
124\def\font_helpers_set_math_family_bold_a#font#mbfam#mrfam
125 {\ifcsname\??fontinstanceready\fontclass\fontbody\s!mm\fontfamily\fontsize\endcsname \setfalse\c_font_auto_size
126 \lastnamedcs #font#mbfam\font \else
127 \ifcsname\??fontinstanceready\fontclass\fontbody\s!mm\fontfamily \endcsname \settrue \c_font_auto_size
128 \lastnamedcs #font#mbfam\font \else
129 #font#mbfam#font#mrfam
130 \fi\fi}
131
132\def\font_helpers_set_math_family_bold_indeed#mbfam#familytag#mrfam
133 {\let\savedfontclass\defaultfontclass
134 \let\defaultfontclass\fontclass
135 \let\savedfontbody\fontbody
136 \let\fontfamily#familytag
137 \let\mathsizesuffix\mathscriptscriptsuffix\let\fontface\!!plusthree
138 \font_helpers_set_math_family_bold_a\scriptscriptfont#mbfam#mrfam
139 \font_helpers_set_math_family_bold_a\scriptscriptfont#mbfam#mrfam
140 \let\mathsizesuffix\mathscriptsuffix \let\fontface\!!plustwo
141 \font_helpers_set_math_family_bold_a\scriptfont #mbfam#mrfam
142 \font_helpers_set_math_family_bold_a\scriptfont #mbfam#mrfam
143 \let\mathsizesuffix\mathtextsuffix \let\fontface\!!plusone
144 \font_helpers_set_math_family_bold_a\textfont #mbfam#mrfam
145 \font_helpers_set_math_family_bold_a\textfont #mbfam#mrfam
146 \let\mathsizesuffix\empty \let\fontface\!!zerocount
147 \let\fontbody\savedfontbody
148 \let\defaultfontclass\savedfontclass
149 \setfalse\c_font_auto_size}
150
151
152
153
154
155
156
157
158\newconditional\optimizemathfontdefinitions \settrue\optimizemathfontdefinitions
159
160\def\font_helpers_set_math_family#mrfam#familytag
161 {\ifconditional\optimizemathfontdefinitions
162 \ifcsname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize1\endcsname
163
164 \font_helpers_preset_math_family_indeed#mrfam#familytag
165 \else
166
167 \font_helpers_set_math_family_indeed#mrfam#familytag
168 \fi
169 \else
170 \font_helpers_set_math_family_indeed#mrfam#familytag
171 \fi}
172
173\def\font_helpers_set_math_family_bold#mbfam#familytag#mrfam
174 {\ifconditional\optimizemathfontdefinitions
175
176 \ifcsname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize1\endcsname
177 \font_helpers_preset_math_family_indeed#mbfam#familytag
178 \else
179 \font_helpers_set_math_family_bold_indeed#mbfam#familytag#mrfam
180 \fi
181 \else
182 \font_helpers_set_math_family_bold_indeed#mbfam#familytag#mrfam
183 \fi}
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198\def\font_helpers_preset_math_family_indeed#fam#familytag
199 {\expandafter\let\expandafter\v_font_math_one\csname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize1\endcsname
200 \ifx\v_font_math_one\relax
201 \font_helpers_preset_math_family_warning
202 \else\ifnum\fontid\textfont#fam=\fontid\v_font_math_one\else
203 \font_helpers_preset_math_family_indeed_changed#fam#familytag
204 \fi\fi}
205
206\def\font_helpers_preset_math_family_warning
207 {\writestatus{fonts}{math: unset for global bodyfont \fontclass\space at \fontbody}}
208
209\def\font_helpers_preset_math_family_indeed_changed#fam#familytag
210 {\scriptscriptfont#fam\csname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize3\endcsname
211 \scriptfont #fam\csname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize2\endcsname
212 \textfont #fam\v_font_math_one}
213
214\let\font_helpers_reset_fontclass_math_families\gobbleoneargument
215
216
217
218
219
220
221
222
223
224
225\let\m_font_class_direction\empty
226\let\m_font_class_features \empty
227\let\m_font_class_fallbacks\empty
228\let\m_font_class_goodies \empty
229
230\let\m_font_direction\empty
231\let\m_font_features \empty
232\let\m_font_fallbacks\empty
233\let\m_font_goodies \empty
234
235\appendtoks
236
237
238 \edef\m_font_class_direction{\begincsname\??fontclass\fontclass\s!mm\s!direction\endcsname}
239
240 \ifx\m_font_class_direction\v!both
241 \settrue\c_font_bidirectional_mathstrategy
242 \else
243 \setfalse\c_font_bidirectional_mathstrategy
244 \fi
245\to \t_font_math_strategies
246
247\def\font_helpers_bidirectional_mathstrategy_yes
248 {\font_helpers_set_math_family\c_font_fam_mr_lr\s!mrlr
249 \font_helpers_set_math_family\c_font_fam_mr_rl\s!mrrl
250 \ifnum\fontid\textfont\c_font_fam_mr=\fontid\textfont\c_font_fam_mr_lr\else
251 \font_helpers_bidirectional_mathstrategy_yes_changed
252 \fi}
253
254\def\font_helpers_bidirectional_mathstrategy_yes_changed
255 {\textfont \c_font_fam_mr\textfont \c_font_fam_mr_lr
256 \scriptfont \c_font_fam_mr\scriptfont \c_font_fam_mr_lr
257 \scriptscriptfont\c_font_fam_mr\scriptscriptfont\c_font_fam_mr_lr}
258
259\def\font_helpers_bidirectional_mathstrategy_nop
260 {\font_helpers_set_math_family\c_font_fam_mr\s!mr
261 \ifnum\fontid\textfont\c_font_fam_mr_rl=\fontid\textfont\c_font_fam_mr\else
262 \font_helpers_bidirectional_mathstrategy_nop_changed
263 \fi}
264
265\def\font_helpers_bidirectional_mathstrategy_nop_changed
266 {\textfont \c_font_fam_mr_lr\textfont \c_font_fam_mr
267 \scriptfont \c_font_fam_mr_lr\scriptfont \c_font_fam_mr
268 \scriptscriptfont\c_font_fam_mr_lr\scriptscriptfont\c_font_fam_mr
269 \textfont \c_font_fam_mr_rl\textfont \c_font_fam_mr
270 \scriptfont \c_font_fam_mr_rl\scriptfont \c_font_fam_mr
271 \scriptscriptfont\c_font_fam_mr_rl\scriptscriptfont\c_font_fam_mr}
272
273\appendtoks
274 \ifconditional\c_font_bidirectional_mathstrategy
275 \font_helpers_bidirectional_mathstrategy_yes
276 \else
277 \font_helpers_bidirectional_mathstrategy_nop
278 \fi
279\to \t_font_math_strategies
280
281\def\font_helpers_complete_bold_mathstrategy_yes_bidi
282 {\font_helpers_set_math_family_bold\c_font_fam_mb_lr\s!mblr\c_font_fam_mr_lr
283 \font_helpers_set_math_family_bold\c_font_fam_mb_rl\s!mbrl\c_font_fam_mr_rl
284 \ifnum\fontid\textfont\c_font_fam_mb=\fontid\textfont\c_font_fam_mb_lr\else
285 \font_helpers_complete_bold_mathstrategy_yes_bidi_changed
286 \fi}
287
288\def\font_helpers_complete_bold_mathstrategy_yes_bidi_changed
289 {\textfont \c_font_fam_mb\textfont \c_font_fam_mb_lr
290 \scriptfont \c_font_fam_mb\scriptfont \c_font_fam_mb_lr
291 \scriptscriptfont\c_font_fam_mb\scriptscriptfont\c_font_fam_mb_lr}
292
293\def\font_helpers_complete_bold_mathstrategy_yes
294 {\font_helpers_set_math_family_bold\c_font_fam_mb\s!mb\c_font_fam_mr\relax
295 \ifnum\fontid\textfont\c_font_fam_mb_rl=\fontid\textfont\c_font_fam_mb\else
296 \font_helpers_complete_bold_mathstrategy_yes_changed
297 \fi}
298
299\def\font_helpers_complete_bold_mathstrategy_yes_changed
300 {\textfont \c_font_fam_mb_rl\textfont \c_font_fam_mb
301 \scriptfont \c_font_fam_mb_rl\scriptfont \c_font_fam_mb
302 \scriptscriptfont\c_font_fam_mb_rl\scriptscriptfont\c_font_fam_mb
303 \textfont \c_font_fam_mb_lr\textfont \c_font_fam_mb
304 \scriptfont \c_font_fam_mb_lr\scriptfont \c_font_fam_mb
305 \scriptscriptfont\c_font_fam_mb_lr\scriptscriptfont\c_font_fam_mb}
306
307\def\font_helpers_complete_bold_mathstrategy_nop
308 {\ifnum\fontid\textfont\c_font_fam_mb=\fontid\textfont\c_font_fam_mr\else
309 \font_helpers_complete_bold_mathstrategy_nop_changed
310 \fi}
311
312\def\font_helpers_complete_bold_mathstrategy_nop_changed
313 {\textfont \c_font_fam_mb \textfont \c_font_fam_mr
314 \scriptfont \c_font_fam_mb \scriptfont \c_font_fam_mr
315 \scriptscriptfont\c_font_fam_mb \scriptscriptfont\c_font_fam_mr
316 \textfont \c_font_fam_mb_lr\textfont \c_font_fam_mr_lr
317 \scriptfont \c_font_fam_mb_lr\scriptfont \c_font_fam_mr_lr
318 \scriptscriptfont\c_font_fam_mb_lr\scriptscriptfont\c_font_fam_mr_lr
319 \textfont \c_font_fam_mb_rl\textfont \c_font_fam_mr_rl
320 \scriptfont \c_font_fam_mb_rl\scriptfont \c_font_fam_mr_rl
321 \scriptscriptfont\c_font_fam_mb_rl\scriptscriptfont\c_font_fam_mr_rl}
322
323\def\font_helpers_apply_complete_bold_mathstrategy
324 {\ifconditional\c_font_complete_bold_mathstrategy
325 \ifconditional\c_font_bidirectional_mathstrategy
326 \font_helpers_complete_bold_mathstrategy_yes_bidi
327 \else
328 \font_helpers_complete_bold_mathstrategy_yes
329 \fi
330 \else
331 \font_helpers_complete_bold_mathstrategy_nop
332 \fi}
333
334\appendtoks
335 \font_helpers_apply_complete_bold_mathstrategy
336\to \t_font_math_strategies
337
338\ifdefined\defaultmathfamily \else
339 \setnewconstant\defaultmathfamily\zerocount
340\fi
341
342\appendtoks
343 \fam\defaultmathfamily
344\to \everymathematics
345
346\unexpanded\def\font_helpers_synchronize_math_family_mr
347 {\c_attr_mathfamily\ifconditional\c_font_bidirectional_mathstrategy
348 \ifconditional\c_math_right_to_left
349 \plustwo
350 \else
351 \plusone
352 \fi
353 \else
354 \zerocount
355 \fi}
356
357\unexpanded\def\font_helpers_synchronize_math_family_mb
358 {\c_attr_mathfamily\ifconditional\c_font_bidirectional_mathstrategy
359 \ifconditional\c_math_right_to_left
360 \ifconditional\c_font_pseudo_bold_math_state\pluseight\else\plusfive\fi
361 \else
362 \ifconditional\c_font_pseudo_bold_math_state\plusseven\else\plusfour\fi
363 \fi
364 \else
365 \ifconditional\c_font_pseudo_bold_math_state\plussix\else\plusthree\fi
366 \fi}
367
368\installcorenamespace{fontmathsynchronizer}
369\installcorenamespace{fontmathstoredstrategy}
370
371\letvalue{\??fontmathsynchronizer\s!tf }\font_helpers_synchronize_math_family_mr
372\letvalue{\??fontmathsynchronizer\s!sl }\font_helpers_synchronize_math_family_mr
373\letvalue{\??fontmathsynchronizer\s!it }\font_helpers_synchronize_math_family_mr
374\letvalue{\??fontmathsynchronizer\s!bf }\font_helpers_synchronize_math_family_mb
375\letvalue{\??fontmathsynchronizer\s!bs }\font_helpers_synchronize_math_family_mb
376\letvalue{\??fontmathsynchronizer\s!bi }\font_helpers_synchronize_math_family_mb
377\letvalue{\??fontmathsynchronizer\empty}\font_helpers_synchronize_math_family_mr
378
379
380
381
382\def\font_helpers_synchronize_math_family
383 {\ifcsname\??fontmathsynchronizer\fontalternative\endcsname
384 \lastnamedcs
385 \else
386 \font_helpers_synchronize_math_family_mr
387 \fi}
388
389\ifdefined \fontid
390 \appendtoks
391 \ifnum\fontid\textfont\zerocount=\fontid\textfont\plusthree
392 \letvalue{\??fontmathstoredstrategy\fontclass}\font_helpers_set_math_partial_bold_strategy
393 \else
394 \letvalue{\??fontmathstoredstrategy\fontclass}\font_helpers_set_math_full_bold_strategy
395 \fi
396 \to \t_font_math_strategies
397\else
398 \appendtoks
399 \edef\currentmathfontmr{\fontname\textfont\zerocount}
400 \edef\currentmathfontmb{\fontname\textfont\plusthree}
401 \ifx\currentmathfontmr\currentmathfontmb
402 \letvalue{\??fontmathstoredstrategy\fontclass}\font_helpers_set_math_partial_bold_strategy
403 \else
404 \letvalue{\??fontmathstoredstrategy\fontclass}\font_helpers_set_math_full_bold_strategy
405 \fi
406 \to \t_font_math_strategies
407\fi
408
409
410\def\font_helpers_synchronize_math_bold_strategy{\begincsname\??fontmathstoredstrategy\fontclass\endcsname}
411
412\newconditional\c_font_pseudo_bold_math_state
413
414\def\font_helpers_set_math_partial_bold_strategy{\settrue \c_font_pseudo_bold_math_state}
415\def\font_helpers_set_math_full_bold_strategy {\setfalse\c_font_pseudo_bold_math_state}
416
417\appendtoks
418 \font_helpers_synchronize_math_bold_strategy
419\to \everymathematics
420
421
422
423
424
425
426\ifdefined\mathdefault \else \let\mathdefault\relax \fi
427
428\newconditional\c_math_bold
429
430\unexpanded\def\mr
431 {\ifmmode
432 \font_helpers_synchronize_math_family_mr
433 \else
434 \font_helpers_set_current_font_alternative\s!mr
435 \fi
436 \mathdefault
437 \setfalse\c_math_bold}
438
439\unexpanded\def\mb
440 {\ifmmode
441 \font_helpers_synchronize_math_family_mb
442 \else
443 \font_helpers_set_current_font_alternative\s!mb
444 \fi
445 \mathdefault
446 \settrue\c_math_bold}
447
448\appendtoks
449 \font_helpers_synchronize_math_family
450\to \everymathematics
451
452\appendtoks
453 \ifconditional\c_math_bold\mb\fi
454\to \everymathematics
455
456
457
458
459
460
461
462
463
464
465\setnewconstant\synchronizebigmathflag\plusone
466
467\appendtoks
468 \ifcase\synchronizebigmathflag
469
470 \or
471 \synchronizebigmath
472 \or
473
474 \fi
475\to \everymathematics
476
477\unexpanded\def\nobigmath {\synchronizebigmathflag\zerocount}
478\unexpanded\def\autobigmath{\synchronizebigmathflag\plusone\synchronizebigmath}
479\unexpanded\def\bigmath {\synchronizebigmathflag\plustwo\synchronizebigmath}
480
481\let\bigmathfontsize\empty
482
483\unexpanded\def\synchronizebigmath
484 {\ifx\bigmathfontsize\fontsize
485
486 \else
487 \let\bigmathfontsize\fontsize
488 \font_helpers_synchronize_math
489 \fi}
490
491\unexpanded\def\font_helpers_check_big_math_synchronization
492 {\ifcase\synchronizebigmathflag
493
494 \or
495 \ifmmode \synchronizebigmath \fi
496 \or
497 \synchronizebigmath
498 \fi}
499
500\protect \endinput
501 |