1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17\writestatus{loading}{ConTeXt Font Macros Math}
18
19\unprotect
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\ifdefined\??fontinstanceready \else \installcorenamespace{fontinstanceready} \fi
50\ifdefined\??fontinstancebasic \else \installcorenamespace{fontinstancebasic} \fi
51\ifdefined\??fontinstanceclass \else \installcorenamespace{fontinstanceclass} \fi
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72\newtoks \t_font_math_strategies
73\newconditional\c_font_synchronize_math_fonts \c_font_synchronize_math_fonts\conditionaltrue
74
75\protected\def\font_helpers_synchronize_math
76 {\ifconditional\c_font_synchronize_math_fonts\expand\t_font_math_strategies\fi}
77
78\permanent\protected\def\textonly{\c_font_synchronize_math_fonts\conditionalfalse}
79
80
81
82
83
84
85
86
87\aliased\let\c_font_fam_mr\zerocount
88\aliased\let\c_font_fam_mb\plusthree
89
90\definesystemattribute[mathfamily][public]
91
92
93
94\newconditional\c_font_complete_bold_mathstrategy \c_font_complete_bold_mathstrategy\conditionaltrue
95
96\immutable\def\mathtextsuffix {text}
97\immutable\def\mathscriptsuffix {script}
98\immutable\def\mathscriptscriptsuffix{scriptscript}
99
100
101
102
103\def\font_helpers_set_math_family_a
104 {\ifcsname\??fontinstanceready\fontclass \fontbody\s!mm\fontfamily\fontsize\endcsname \c_font_auto_size\conditionalfalse
105 \lastnamedcs \orelse
106 \ifcsname\??fontinstanceready\fontclass \fontbody\s!mm\fontfamily \endcsname \c_font_auto_size\conditionaltrue
107 \lastnamedcs \else
108 \font_helpers_set_math_family_b
109 \fi}
110
111\def\font_helpers_set_math_family_b
112 {\ifcsname\??fontinstanceready\defaultfontclass\fontbody\s!mm\fontfamily\fontsize\endcsname \c_font_auto_size\conditionalfalse
113 \lastnamedcs \orelse
114 \ifcsname\??fontinstanceready\defaultfontclass\fontbody\s!mm\fontfamily \endcsname \c_font_auto_size\conditionaltrue
115 \lastnamedcs \else
116 \font_helpers_set_math_family_c
117 \fi}
118
119\def\font_helpers_set_math_family_c
120 {\ifcsname\??fontinstanceready \fontbody\s!mm\fontfamily\fontsize\endcsname \c_font_auto_size\conditionalfalse
121 \lastnamedcs \orelse
122 \ifcsname\??fontinstanceready \fontbody\s!mm\fontfamily \endcsname \c_font_auto_size\conditionaltrue
123 \lastnamedcs \else
124 \c_font_auto_size\conditionaltrue
125 \fi}
126
127\mutable\lettonothing\mathsizesuffix
128
129\mutable\let\fontfamily\relax
130
131\newinteger\c_math_last_family_used
132
133\def\font_helpers_set_math_family_indeed_normal#mrtag#family
134 {\let\savedfontbody\fontbody
135 \let\savedfontstyle\fontstyle
136 \let\fontstyle\s!mm
137 \let\fontfamily#family
138 \c_math_last_family_used\zerocount
139
140
141
142 \let\mathsizesuffix\mathscriptscriptsuffix
143 \let\fontface\!!plusthree
144 \font_helpers_set_math_family_a\scriptscriptfont#mrtag\font
145 \font_helpers_set_math_family_a\scriptscriptfont#mrtag\font
146 \let\mathsizesuffix\mathscriptsuffix
147 \let\fontface\!!plustwo
148 \font_helpers_set_math_family_a\scriptfont #mrtag\font
149 \font_helpers_set_math_family_a\scriptfont #mrtag\font
150 \let\mathsizesuffix\mathtextsuffix
151 \let\fontface\!!plusone
152 \font_helpers_set_math_family_a\textfont #mrtag\font
153 \font_helpers_set_math_family_a\textfont #mrtag\font
154 \lettonothing\mathsizesuffix
155 \let\fontface\!!zerocount
156 \let\fontstyle\savedfontstyle
157 \let\fontbody\savedfontbody
158 \c_font_auto_size\conditionalfalse}
159
160\def\font_helpers_set_math_family_set_scales_normal
161 {\glyphtextscale \plusthousand
162 \glyphscriptscale \plusthousand
163 \glyphscriptscriptscale\plusthousand}
164
165\def\font_helpers_set_math_family_set_scales_compact
166 {\glyphtextscale \plusthousand
167 \glyphscriptscale \plusthousand
168 \glyphscriptscriptscale\plusthousand}
169
170\installcorenamespace{compactmathrscale}
171
172\def\font_helpers_set_math_scales_compact
173 {\glyphtextscale \the\floatexpr\v_font_size_relative*\plusthousand\relax
174 \glyphscriptscale \glyphtextscale
175 \glyphscriptscriptscale\glyphtextscale
176 \global\expandafter\integerdef\csname\??compactmathrscale\the\fontid\font\endcsname\glyphtextscale}
177
178\def\font_helpers_get_math_scales_compact
179 {\ifcsname\??compactmathrscale\the\fontid\font\endcsname
180 \glyphtextscale \lastnamedcs
181 \glyphscriptscale \glyphtextscale
182 \glyphscriptscriptscale\glyphtextscale
183 \fi}
184
185\def\font_helpers_set_math_family_indeed_compact#mrfam#family
186 {\let\savedfontbody\fontbody
187 \let\savedfontstyle\fontstyle
188 \let\fontstyle\s!mm
189 \let\fontfamily#family
190 \c_math_last_family_used\zerocount
191
192
193 \let\mathsizesuffix\mathtextsuffix
194 \let\fontface\!!plusone
195
196 \font_helpers_set_math_family_a\textfont #mrfam\font
197 \font_helpers_set_math_family_a\textfont #mrfam\font
198 \scriptfont #mrfam\font
199 \scriptscriptfont#mrfam\font
200 \font_helpers_set_math_scales_compact
201 \lettonothing\mathsizesuffix
202 \let\fontface\!!zerocount
203 \let\fontstyle\savedfontstyle
204 \let\fontbody\savedfontbody
205 \c_font_auto_size\conditionalfalse}
206
207
208
209\def\font_helpers_set_math_family_bold_indeed_normal#mbfam#family#mrfam
210 {\let\savedfontclass\defaultfontclass
211 \let\defaultfontclass\fontclass
212 \let\savedfontbody\fontbody
213 \let\savedfontstyle\fontstyle
214 \let\fontstyle\s!mm
215 \let\fontfamily#family
216 \c_math_last_family_used\zerocount
217 \font_helpers_set_math_family_set_scales_normal
218 \let\mathsizesuffix\mathscriptscriptsuffix
219 \let\fontface\!!plusthree
220 \font_helpers_set_math_family_bold_a\scriptscriptfont#mbfam#mrfam
221 \font_helpers_set_math_family_bold_a\scriptscriptfont#mbfam#mrfam
222 \let\mathsizesuffix\mathscriptsuffix
223 \let\fontface\!!plustwo
224 \font_helpers_set_math_family_bold_a\scriptfont #mbfam#mrfam
225 \font_helpers_set_math_family_bold_a\scriptfont #mbfam#mrfam
226 \let\mathsizesuffix\mathtextsuffix
227 \let\fontface\!!plusone
228 \font_helpers_set_math_family_bold_a\textfont #mbfam#mrfam
229 \font_helpers_set_math_family_bold_a\textfont #mbfam#mrfam
230 \lettonothing\mathsizesuffix
231 \let\fontface\!!zerocount
232 \let\fontstyle\savedfontstyle
233 \let\fontbody\savedfontbody
234 \let\defaultfontclass\savedfontclass
235 \c_font_auto_size\conditionalfalse}
236
237\def\font_helpers_set_math_family_bold_indeed_compact#mbfam#family#mrfam
238 {\let\savedfontclass\defaultfontclass
239 \let\defaultfontclass\fontclass
240 \let\savedfontbody\fontbody
241 \let\savedfontstyle\fontstyle
242 \let\fontstyle\s!mm
243 \let\fontfamily#family
244 \c_math_last_family_used\zerocount
245 \let\mathsizesuffix\mathtextsuffix
246 \let\fontface\!!plusone
247 \font_helpers_set_math_family_bold_a\textfont #mbfam#mrfam
248 \font_helpers_set_math_family_bold_a\textfont #mbfam#mrfam
249 \scriptfont #mbfam\textfont#mbfam
250 \scriptscriptfont#mbfam\textfont#mbfam
251 \lettonothing\mathsizesuffix
252 \let\fontface\!!zerocount
253 \let\fontstyle\savedfontstyle
254 \let\fontbody\savedfontbody
255 \let\defaultfontclass\savedfontclass
256 \c_font_auto_size\conditionalfalse}
257
258\def\font_helpers_set_math_family_bold_a#font#mbfam#mrfam
259 {\ifcsname\??fontinstanceready\fontclass\fontbody\s!mm\fontfamily\fontsize\endcsname \c_font_auto_size\conditionalfalse
260 \lastnamedcs #font#mbfam\font \orelse
261 \ifcsname\??fontinstanceready\fontclass\fontbody\s!mm\fontfamily \endcsname \c_font_auto_size\conditionaltrue
262 \lastnamedcs #font#mbfam\font \else
263 #font#mbfam#font#mrfam
264 \fi}
265
266
267
268
269
270
271
272
273\newconditional\optimizemathfontdefinitions \optimizemathfontdefinitions\conditionaltrue
274
275\def\font_helpers_set_math_family_normal#mrfam#familytag
276 {\ifconditional\optimizemathfontdefinitions
277 \ifcsname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize1\endcsname
278
279 \font_helpers_preset_math_family_indeed#mrfam#familytag
280 \else
281
282 \font_helpers_set_math_family_indeed_normal#mrfam#familytag
283 \fi
284 \else
285 \font_helpers_set_math_family_indeed_normal#mrfam#familytag
286 \fi}
287
288\def\font_helpers_set_math_family_bold_normal#mbfam#familytag#mrfam
289 {\ifconditional\optimizemathfontdefinitions
290 \ifcsname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize1\endcsname
291 \font_helpers_preset_math_family_indeed#mbfam#familytag
292 \else
293 \font_helpers_set_math_family_bold_indeed_normal#mbfam#familytag#mrfam
294 \fi
295 \else
296 \font_helpers_set_math_family_bold_indeed_normal#mbfam#familytag#mrfam
297 \fi}
298
299\def\font_helpers_set_math_family_compact#mrfam#familytag
300 {\ifconditional\optimizemathfontdefinitions
301 \ifcsname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize\endcsname
302
303 \font_helpers_preset_math_family_indeed#mrfam#familytag
304 \else
305
306 \font_helpers_set_math_family_indeed_compact#mrfam#familytag
307 \fi
308 \else
309 \font_helpers_set_math_family_indeed_compact#mrfam#familytag
310 \fi}
311
312\def\font_helpers_set_math_family_bold_compact#mbfam#familytag#mrfam
313 {\ifconditional\optimizemathfontdefinitions
314 \ifcsname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize\endcsname
315 \font_helpers_preset_math_family_indeed#mbfam#familytag
316 \else
317 \font_helpers_set_math_family_bold_indeed_compact#mbfam#familytag#mrfam
318 \fi
319 \else
320 \font_helpers_set_math_family_bold_indeed_compact#mbfam#familytag#mrfam
321 \fi}
322
323\aliased\let\font_helpers_set_math_family \font_helpers_set_math_family_normal
324\aliased\let\font_helpers_set_math_family_bold\font_helpers_set_math_family_bold_normal
325
326\appendtoks
327 \aliased\let\font_helpers_set_math_family \font_helpers_set_math_family_compact
328 \aliased\let\font_helpers_set_math_family_bold\font_helpers_set_math_family_bold_compact
329\to \everycompactfontmode
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344\def\font_helpers_preset_math_family_indeed_normal#fam#familytag
345 {\expandafter\let\expandafter\font_math_last_font\csname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize1\endcsname
346 \font_math_last_font
347 \ifnum\fontid\textfont#fam=\fontid\font\else
348 \font_helpers_preset_math_family_indeed_changed_normal#fam#familytag
349 \fi}
350
351\def\font_helpers_preset_math_family_indeed_changed_normal#fam#familytag
352 {\font_helpers_set_math_family_set_scales_normal
353 \csname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize3\endcsname\scriptscriptfont#fam\font
354 \csname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize2\endcsname\scriptfont #fam\font
355
356 \font_math_last_font \textfont #fam\font}
357
358\def\font_helpers_preset_math_family_indeed_compact#fam#familytag
359 {\csname\??fontinstanceclass\fontclass\fontbody\s!mm#familytag\fontsize\endcsname
360 \ifnum\fontid\textfont#fam=\fontid\font\else
361 \font_helpers_preset_math_family_indeed_changed_compact#fam
362 \fi}
363
364\def\font_helpers_preset_math_family_indeed_changed_compact#fam
365 {\scriptscriptfont#fam\font
366 \scriptfont #fam\font
367 \textfont #fam\font
368 \font_helpers_get_math_scales_compact}
369
370\aliased\let\font_helpers_preset_math_family_indeed\font_helpers_preset_math_family_indeed_normal
371
372\appendtoks
373 \enforced\let\font_helpers_preset_math_family_indeed\font_helpers_preset_math_family_indeed_compact
374\to \everycompactfontmode
375
376\let\font_helpers_reset_fontclass_math_families\gobbleoneargument
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399\appendtoks
400 \font_helpers_set_math_family\c_font_fam_mr\s!mr
401\to \t_font_math_strategies
402
403\def\font_helpers_complete_bold_mathstrategy_yes
404 {\font_helpers_set_math_family_bold\c_font_fam_mb\s!mb\c_font_fam_mr\relax}
405
406\def\font_helpers_complete_bold_mathstrategy_nop
407 {\ifnum\fontid\textfont\c_font_fam_mb=\fontid\textfont\c_font_fam_mr\else
408 \font_helpers_complete_bold_mathstrategy_nop_changed
409 \fi}
410
411\def\font_helpers_complete_bold_mathstrategy_nop_changed
412 {\textfont \c_font_fam_mb\textfont \c_font_fam_mr
413 \scriptfont \c_font_fam_mb\scriptfont \c_font_fam_mr
414 \scriptscriptfont\c_font_fam_mb\scriptscriptfont\c_font_fam_mr}
415
416\def\font_helpers_apply_complete_bold_mathstrategy
417 {\ifconditional\c_font_complete_bold_mathstrategy
418 \font_helpers_complete_bold_mathstrategy_yes
419 \else
420 \font_helpers_complete_bold_mathstrategy_nop
421 \fi}
422
423\appendtoks
424 \font_helpers_apply_complete_bold_mathstrategy
425\to \t_font_math_strategies
426
427\ifdefined\defaultmathfamily \else
428 \setnewconstant\defaultmathfamily\zerocount
429\fi
430
431\appendtoks
432 \fam\zerocount
433\to \everymathematics
434
435\protected\def\font_helpers_synchronize_math_family_mr
436 {\c_attr_mathfamily\zerocount
437 \font_helpers_synchronize_math_parameters_normal}
438
439\protected\def\font_helpers_synchronize_math_family_mb
440 {\c_attr_mathfamily\ifconditional\c_font_pseudo_bold_math_state\plussix\else\plusthree\fi
441 \font_helpers_synchronize_math_parameters_bold}
442
443\installcorenamespace{fontmathsynchronizer}
444\installcorenamespace{fontmathstoredstrategy}
445
446\letcsname\??fontmathsynchronizer\s!tf \endcsname\font_helpers_synchronize_math_family_mr
447\letcsname\??fontmathsynchronizer\s!sl \endcsname\font_helpers_synchronize_math_family_mr
448\letcsname\??fontmathsynchronizer\s!it \endcsname\font_helpers_synchronize_math_family_mr
449\letcsname\??fontmathsynchronizer\s!bf \endcsname\font_helpers_synchronize_math_family_mb
450\letcsname\??fontmathsynchronizer\s!bs \endcsname\font_helpers_synchronize_math_family_mb
451\letcsname\??fontmathsynchronizer\s!bi \endcsname\font_helpers_synchronize_math_family_mb
452\letcsname\??fontmathsynchronizer\empty\endcsname\font_helpers_synchronize_math_family_mr
453
454\def\font_helpers_synchronize_math_family
455 {\ifcsname\??fontmathsynchronizer\fontalternative\endcsname
456 \lastnamedcs
457 \else
458 \font_helpers_synchronize_math_family_mr
459 \fi}
460
461\appendtoks
462 \ifnum\fontid\textfont\zerocount=\fontid\textfont\plusthree
463 \letcsname\??fontmathstoredstrategy\fontclass\endcsname\font_helpers_set_math_partial_bold_strategy
464 \else
465 \letcsname\??fontmathstoredstrategy\fontclass\endcsname\font_helpers_set_math_full_bold_strategy
466 \fi
467\to \t_font_math_strategies
468
469\def\font_helpers_synchronize_math_bold_strategy{\begincsname\??fontmathstoredstrategy\fontclass\endcsname}
470
471\newconditional\c_font_pseudo_bold_math_state
472
473\def\font_helpers_set_math_partial_bold_strategy{\c_font_pseudo_bold_math_state\conditionaltrue}
474\def\font_helpers_set_math_full_bold_strategy {\c_font_pseudo_bold_math_state\conditionalfalse}
475
476\appendtoks
477 \font_helpers_synchronize_math_bold_strategy
478\to \everymathematics
479
480
481
482
483
484
485\ifdefined\mathdefault \else \let\mathdefault\relax \fi
486
487\newconditional\c_math_bold
488
489\permanent\protected\def\mr
490 {\ifmmode
491 \font_helpers_synchronize_math_family_mr
492 \else
493 \font_helpers_set_current_font_alternative\s!mr
494 \fi
495 \mathdefault
496 \c_math_bold\conditionalfalse}
497
498\permanent\protected\def\mb
499 {\ifmmode
500 \font_helpers_synchronize_math_family_mb
501 \else
502 \font_helpers_set_current_font_alternative\s!mb
503 \fi
504 \mathdefault
505 \c_math_bold\conditionaltrue}
506
507\appendtoks
508 \font_helpers_synchronize_math_family
509\to \everymathematics
510
511\appendtoks
512 \ifconditional\c_math_bold\mb\fi
513\to \everymathematics
514
515
516
517
518
519
520
521
522
523
524\setnewconstant\synchronizebigmathflag\plusone
525
526\appendtoks
527 \ifcase\synchronizebigmathflag
528
529 \or
530 \synchronizebigmath
531 \or
532
533 \fi
534\to \everymathematics
535
536\permanent\protected\def\nobigmath {\synchronizebigmathflag\zerocount}
537\permanent\protected\def\autobigmath{\synchronizebigmathflag\plusone\synchronizebigmath}
538\permanent\protected\def\bigmath {\synchronizebigmathflag\plustwo\synchronizebigmath}
539
540\mutable\lettonothing\bigmathfontsize
541
542\permanent\protected\def\synchronizebigmath
543 {\ifx\bigmathfontsize\fontsize
544
545 \else
546 \let\bigmathfontsize\fontsize
547 \font_helpers_synchronize_math
548 \fi}
549
550\protected\def\font_helpers_check_big_math_synchronization
551 {\ifcase\synchronizebigmathflag
552
553 \or
554 \ifmmode \synchronizebigmath \fi
555 \or
556 \synchronizebigmath
557 \fi}
558
559\appendtoks
560 \enforced\lettonothing\synchronizebigmath
561 \enforced\lettonothing\font_helpers_check_big_math_synchronization
562\to \everycompactfontmode
563
564
565
566
567
568
569
570
571
572
573\installcorenamespace{mscaled}
574
575\mutable\def\mathscalefactor{0.7}
576
577\newinteger\c_math_m_scaled \c_math_m_scaled\plusthousand
578
579\permanent\protected\def\setmscale#1
580 {\ifmmode
581 \iftok{#1}{}
582 \c_math_m_scaled{(\numericscale\mathscalefactor)*\c_math_m_scaled\plusthousand}
583 \orelse\iftok{#1}{=}
584 \c_math_m_scaled\plusthousand
585 \orelse\iftok{#1}{x}
586 \c_math_m_scaled{\plusthousand*\dimexpr\xtextface\relax\dimexpr\textface\relax}
587 \orelse\iftok{#1}{xx}
588 \c_math_m_scaled{\plusthousand*\dimexpr\xxtextface\relax\dimexpr\textface\relax}
589 \else
590 \c_math_m_scaled\numericscale#1\relax
591 \fi
592 \scaledmathstyle
593 \ifnum\glyphscale=\plusthousand
594 \c_math_m_scaled
595 \else
596 {(\c_math_m_scaled*\glyphscale)\plusthousand}
597 \fi
598 \fi}
599
600\permanent\protected\def\setmxscale {\ifmmode\scaledmathstyle{\glyphscale*\dimexpr\xtextface \relax\dimexpr\textface\relax}\fi}
601\permanent\protected\def\setmxxscale{\ifmmode\scaledmathstyle{\glyphscale*\dimexpr\xxtextface\relax\dimexpr\textface\relax}\fi}
602
603\permanent\protected\def\mx
604 {\enforced\let\mx\mxx
605 \setmxscale}
606
607\permanent\protected\def\mxx
608 {\enforced\let\mx\relax
609 \enforced\let\mxx\relax
610 \setmxxscale}
611
612
613
614
615\def\font_helpers_synchronize_math_parameters_normal
616 {\c_math_last_family_used\mathstylefontid\textstyle\zerocount
617 \textfont \c_font_fam_mr\textfont \c_font_fam_mr
618 \scriptfont \c_font_fam_mr\scriptfont \c_font_fam_mr
619 \scriptscriptfont\c_font_fam_mr\scriptscriptfont\c_font_fam_mr}
620
621\def\font_helpers_synchronize_math_parameters_bold
622 {\c_math_last_family_used\mathstylefontid\textstyle\zerocount
623 \textfont \c_attr_mathfamily\textfont \c_attr_mathfamily
624 \scriptfont \c_attr_mathfamily\scriptfont \c_attr_mathfamily
625 \scriptscriptfont\c_attr_mathfamily\scriptscriptfont\c_attr_mathfamily}
626
627\appendtoks
628 \ifnum\c_math_last_family_used=\mathstylefontid\textstyle\zerocount\else
629 \font_helpers_synchronize_math_parameters_normal
630 \fi
631\to\everybodyfont
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646\mutable\lettonothing\currentmathfontclass
647
648\def\math_synchronize_setup
649 {\let\currentmathfontclass\fontclass
650 \fastsetup{\s!math:\fontclass}}
651
652\appendtoks
653 \ifx\fontclass\currentmathfontclass\else
654 \math_synchronize_setup
655 \fi
656\to \everymathematics
657
658\protect \endinput
659 |