font-mat.mklx /size: 26 Kb    last modification: 2024-01-16 09:02
1%D \module
2%D   [       file=font-mat,
3%D        version=2011.01.13, % (copied fron font-ini)
4%D          title=\CONTEXT\ Font Macros,
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% because we cannot mix we can just 'redefine' the relevant
15% macro when \ifconditional\c_font_compact
16
17\writestatus{loading}{ConTeXt Font Macros / Math}
18
19\unprotect
20
21%D The original (\MKIV) approach to bidi is that we have two extra families for
22%D regular, bold and pseudobold:
23%D
24%D regular    normal=0 l2r=1 r2l=2
25%D bold       normal=3 l2r=4 r2l=5
26%D pseudobold normal=6 l2r=7 r2l=8
27%D
28%D where l2r is just an alias. Because we're now using the mirror lookup (like
29%D we do a smaller lookup) in the engine we now just have:
30%D
31%D regular    normal=0
32%D bold       normal=3
33%D pseudobold normal=6
34%D
35%D And when one can wonder if pseudobold is needed (just bolden); we can then
36%D actually go down to only two families. It is one of these cases when it hurts
37%D to throw away a nice old mechanism that worked quite well so here we keep it
38%D commented. For what it's worth: this variant switches a bit faster too and
39%D produces less logging but I doubt if anyone will notice that.
40
41%D We now have bidi handled via a tweak in the goodie file which means that we
42%D could simplify the implementation and get rid of the (four) extra families
43%D needed. For now we retain the zero/three designation for mr/mb but that might
44%D go away. Actually we could drop the number of families in the engine to sixteen
45%D again or even four if we need the space for more classes or something else.
46
47%D Be nice:
48
49\ifdefined\??fontinstanceready \else \installcorenamespace{fontinstanceready} \fi
50\ifdefined\??fontinstancebasic \else \installcorenamespace{fontinstancebasic} \fi
51\ifdefined\??fontinstanceclass \else \installcorenamespace{fontinstanceclass} \fi
52
53%D The order 3 2 1 of size matters is historic and was needed for math-fbk relative
54%D size storage! It is no longer relevant.
55
56%D \macros
57%D   {textonly}
58%D
59%D Traditionally math has a big impact on font definitions, mainly because we need
60%D to define alphabet variants using families and fonts. This means that one can
61%D easily get 10 fonts loaded per math size. In \MKIV\ we use a different approach:
62%D one family which has either a virtual font made of traditional fonts, or an
63%D \OPENTYPE\ font that has it all.
64%D
65%D We currently use only one math family but in the future we might consider using a
66%D second one for bold math. For the moment we keep the \MKII\ method of using a
67%D token register for definitions but we already dropped the text and symbols ones
68%D since they now live in the same family. When we go always compact we can simplify
69%D the code even more. For previous implementations see the \MKIV\ code and the
70%D repository pre October 2022.
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 % math stuff in mmode
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} % document this
79
80%D The main math font definer. We have removed some optimized code simply because we
81%D now always have a fontclass. We could check for fontclass being default or empty
82%D and save a few tests but it does not help us when no math is defined.
83%D
84%D Because we want to keep mr=.. and mb=... settings (read: not break downward
85%D compatibility by enforcing mrlr etc) we need a bit more code that optimal.
86
87\aliased\let\c_font_fam_mr\zerocount  % math regular
88\aliased\let\c_font_fam_mb\plusthree  % math bold
89
90\definesystemattribute[mathfamily][public]
91
92% when we are always true we can as well remove this test:
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%D Beware: truefontname also does a fallback on defaultfontclass so there can be
101%D some interference here, which is why we use a different method for bold.
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 % for now public but it is a helper
130
131\newinteger\c_math_last_family_used
132
133\def\font_helpers_set_math_family_indeed_normal#mrtag#family% \fontface etc are also used later on
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   % the order is important as we depend on known id's when completing fonts
140   % enabling is needed when we have fallbacks which spoils the families; per
141   % mid 2022 this is no longer true as we do fallbacks differently
142   \let\mathsizesuffix\mathscriptscriptsuffix
143   \let\fontface\!!plusthree
144   \font_helpers_set_math_family_a\scriptscriptfont#mrtag\font % defines
145   \font_helpers_set_math_family_a\scriptscriptfont#mrtag\font % enables / still needed ?
146   \let\mathsizesuffix\mathscriptsuffix
147   \let\fontface\!!plustwo
148   \font_helpers_set_math_family_a\scriptfont      #mrtag\font % defines
149   \font_helpers_set_math_family_a\scriptfont      #mrtag\font % enables / still needed ?
150   \let\mathsizesuffix\mathtextsuffix
151   \let\fontface\!!plusone
152   \font_helpers_set_math_family_a\textfont        #mrtag\font % defines
153   \font_helpers_set_math_family_a\textfont        #mrtag\font % enables / still needed ?
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% \fontface etc are also used later on
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   % the order is important as we depend on known id's when completing fonts
192   % enabling is needed when we have fallbacks which spoils the families
193   \let\mathsizesuffix\mathtextsuffix
194   \let\fontface\!!plusone
195   % todo: set them al on one go
196   \font_helpers_set_math_family_a\textfont        #mrfam\font % defines
197   \font_helpers_set_math_family_a\textfont        #mrfam\font % enables / still needed ?
198                                  \scriptfont      #mrfam\font % reuses
199                                  \scriptscriptfont#mrfam\font % reuses
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% why somewhat more save here than normal
208
209\def\font_helpers_set_math_family_bold_indeed_normal#mbfam#family#mrfam% \c_font_fam_mb \s!mb \c_font_fam_mr
210  {\let\savedfontclass\defaultfontclass
211   \let\defaultfontclass\fontclass % else truefontname falls back on the wrong one
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% defines
221   \font_helpers_set_math_family_bold_a\scriptscriptfont#mbfam#mrfam% enables / still needed ?
222   \let\mathsizesuffix\mathscriptsuffix
223   \let\fontface\!!plustwo
224   \font_helpers_set_math_family_bold_a\scriptfont      #mbfam#mrfam% defines
225   \font_helpers_set_math_family_bold_a\scriptfont      #mbfam#mrfam% enables / still needed ?
226   \let\mathsizesuffix\mathtextsuffix
227   \let\fontface\!!plusone
228   \font_helpers_set_math_family_bold_a\textfont        #mbfam#mrfam% defines
229   \font_helpers_set_math_family_bold_a\textfont        #mbfam#mrfam% enables / still needed ?
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% \c_font_fam_mb \s!mb \c_font_fam_mr
238  {\let\savedfontclass\defaultfontclass
239   \let\defaultfontclass\fontclass % else truefontname falls back on the wrong one
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% defines
248   \font_helpers_set_math_family_bold_a\textfont        #mbfam#mrfam% enables / still needed ?
249                                       \scriptfont      #mbfam\textfont#mbfam% reuses
250                                       \scriptscriptfont#mbfam\textfont#mbfam% reuses
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% optimized: math fonts are never changed (10K \bfa $x$: 3.2 => 2.5 (baseline 1.0))
267%
268% sort of tricky: we cannot reset in \everybeforedefinetypeface as we don't know
269% all sizes so we postpone the optimization to the first starttext
270%
271% pitfall: we should reset them when a fontclass name is reused
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-\fontsize-1\endcsname
278       % \writestatus{fonts}{math: reusing \fontclass\fontbody\s!mm#familytag\fontsize1}%
279       \font_helpers_preset_math_family_indeed#mrfam#familytag%
280     \else
281       % \writestatus{fonts}{math: defining \fontclass\fontbody\s!mm#familytag\fontsize1}%
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-\fontsize-1\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       % \writestatus{fonts}{math: reusing \fontclass\fontbody\s!mm#familytag\fontsize1}%
303       \font_helpers_preset_math_family_indeed#mrfam#familytag%
304     \else
305       % \writestatus{fonts}{math: defining \fontclass\fontbody\s!mm#familytag\fontsize1}%
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%D It can happen that we use a bodyfont with no math in which case we have a problem
332%D with setting the global bodyfont size in the page builder. For instance in:
333%D
334%D \starttext
335%D     \definetypeface[test][rm][serif][pagella][default]
336%D     \setupbodyfont[test]
337%D     test
338%D \stoptext
339%D
340%D This is why we need the check. At the cost of some extra checking we gain a
341%D little in restoring global states and, what's more important, we get rid of large
342%D math parameter push/pop in tracingall when not needed.
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-\fontsize-1\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-\fontsize-3\endcsname\scriptscriptfont#fam\font
354   \csname\??fontinstanceclass\fontclass-\fontbody-\s!mm-#familytag-\fontsize-2\endcsname\scriptfont      #fam\font
355 % \csname\??fontinstanceclass\fontclass-\fontbody-\s!mm-#familytag-\fontsize-1\endcsname\textfont        #fam\font}
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%D It would be nice if characters could be defined in a neutral way (say fam 255)
379%D and be mapped to a real family during noad list construction. However, this
380%D changes tex in critical places so for the moment we simulate this using
381%D manipulation.
382%D
383%D For tracing purposes we use three families but in l2r mode 1 and 2 are copies of
384%D 0 while in rl mode 0 is a copy of 1. There is no real overhead involved in this.
385%D This also permits different font definitions for normal and mixed.
386
387% moved to ini
388%
389% \lettonothing\m_font_class_direction
390% \lettonothing\m_font_class_features
391% \lettonothing\m_font_class_fallbacks
392% \lettonothing\m_font_class_goodies
393%
394% \lettonothing\m_font_direction
395% \lettonothing\m_font_features
396% \lettonothing\m_font_fallbacks
397% \lettonothing\m_font_goodies
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 % no longer used, always zero
429\fi
430
431\appendtoks
432    \fam\zerocount % all characters and symbols are in this family
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%D Bold is somewhat special as we might want both full-bold-math mixed regular-math,
481%D as well as automatic adaption to outer bold (in titles and inline text bold) so
482%D we will need explicit switches as well as an automatic one. (We will use lucida
483%D as an example.)
484
485\ifdefined\mathdefault \else \let\mathdefault\relax \fi
486
487\newconditional\c_math_bold
488
489\permanent\protected\def\mr % math regular
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 % math bold
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 % auto bold
509\to \everymathematics
510
511\appendtoks
512    \ifconditional\c_math_bold\mb\fi
513\to \everymathematics
514
515%D \macros
516%D   {bigmath,nobigmath}
517%D
518%D We can inhibit this slow||downer with:
519
520% these can best be combined
521
522% 0=never 1=everymath 2=always
523
524\setnewconstant\synchronizebigmathflag\plusone
525
526\appendtoks
527  \ifcase\synchronizebigmathflag
528    % never
529  \or
530    \synchronizebigmath
531  \or
532    % always
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     % already in sync
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     % never
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%D This is an experiment!
565
566% x$ x \beginmathgroup\scaledmathstyle600 x\endmathgroup x$x
567% $ x{\setmscale{.5}x{\setmscale{.25}x}x}x$
568% $ x{\setmscale{x}x{\setmscale{xx}x}x}x$
569% $x \beginmathgroup\mxx x\endmathgroup x $
570% $x \begingroup\mxx x\endgroup x $ % this one is like style, bleeds over group
571% $x {\mxx x} x $
572
573\installcorenamespace{mscaled}
574
575\mutable\def\mathscalefactor{0.7} % 1/sqrt(2} = 0.70710678118655
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\numexpr(\numericscale\mathscalefactor)*\c_math_m_scaled/\plusthousand\relax
583     \orelse\iftok{#1}{=}%
584       \c_math_m_scaled\plusthousand
585     \orelse\iftok{#1}{x}%
586       \c_math_m_scaled\numexpr\plusthousand*\dimexpression\xtextface\relax/\dimexpression\textface\relax\relax
587     \orelse\iftok{#1}{xx}%
588       \c_math_m_scaled\numexpr\plusthousand*\dimexpression\xxtextface\relax/\dimexpression\textface\relax\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         \numexpr(\c_math_m_scaled*\glyphscale)/\plusthousand\relax
597       \fi
598   \fi}
599
600\permanent\protected\def\setmxscale {\ifmmode\scaledmathstyle\numexpr\glyphscale*\dimexpression\xtextface \relax/\dimexpression\textface\relax\relax\fi}
601\permanent\protected\def\setmxxscale{\ifmmode\scaledmathstyle\numexpr\glyphscale*\dimexpression\xxtextface\relax/\dimexpression\textface\relax\relax\fi}
602
603\permanent\protected\def\mx
604  {\aliased\let\mx\mxx
605   \setmxscale}
606
607\permanent\protected\def\mxx
608  {\aliased\let\mx\relax
609   \aliased\let\mxx\relax
610   \setmxxscale}
611
612%D This is nasty, as the engine only stores the last set family parameters (per style) which
613%D in our case can be bold.
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%D Something new, see type {type-imp-antykwa} for an example:
634
635% if we get more:
636
637% \installcorenamespace {fractionbar}
638% \installcorenamespace {radicalbar}
639
640% \def\installfractionbar#1#2{\defcsname\??fractionbar#1\endcsname{#2}}
641% \def\installradicalbar #1#2{\defcsname\??radicalbar #1\endcsname{#2}}
642
643% \def\fractionbarunicode{\ifcsname\??fractionbar\fontclass\endcsname\lastnamedcs\else\zerocount\fi}
644% \def\radicalbarunicode {\ifcsname\??radicalbar \fontclass\endcsname\lastnamedcs\else\zerocount\fi}
645
646\mutable\lettonothing\currentmathfontclass
647
648\def\math_synchronize_setup
649  {\let\currentmathfontclass\fontclass
650   \fastsetup\fontclass}
651
652\appendtoks
653    \ifx\fontclass\currentmathfontclass\else
654        \math_synchronize_setup
655    \fi
656\to \everymathematics
657
658\protect \endinput
659