font-ini.mkvi /size: 110 Kb    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=font-ini,
3%D        version=1998.09.11, % (second)
4%D        version=2001.02.20, % (third)
5%D          title=\CONTEXT\ Font Macros,
6%D       subtitle=Initialization,
7%D         author=Hans Hagen,
8%D           date=\currentdate,
9%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
10%C
11%C This module is part of the \CONTEXT\ macro||package and is
12%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
13%C details.
14
15% todo: < 3 pt => 3pt
16% todo: check where more class usage
17% todo: split font-nam (style/alternative/size)
18% todo: split font-dim (scales etc)
19% todo: reconsider defaultfontclass
20%
21
22%D Watch out: as we define inside macros in sometimes special ways,
23%D an occasional \type {\normaldef} is used in order to please the
24%D \MKVI\ parser.
25
26%D Beware, we use a special set of parameters here:
27%D
28%D \starttabulate[|l|l|]
29%D \NC system variable (fixed) \NC \type {\s!text}           \NC \NR
30%D \NC system variable (fixed) \NC \type {\s!script}         \NC \NR
31%D \NC system variable (fixed) \NC \type {\s!scriptscript}   \NC \NR
32%D \NC system variable (fixed) \NC \type {\s!x}              \NC \NR
33%D \NC system variable (fixed) \NC \type {\s!xx}             \NC \NR
34%D \NC variable (value)        \NC \type {\v!big}            \NC \NR
35%D \NC variable (value)        \NC \type {\v!small}          \NC \NR
36%D \NC constant (regular key)  \NC \type {\c!interlinespace} \NC \NR
37%D \NC constant (regular key)  \NC \type {\c!em}             \NC \NR
38%D \stoptabulate
39%D
40%D The math related ones are similar to the ones used in \TEX\ itself,
41%D the size related ones show up as keywords in the user interface
42%D when switching sizes, and the two constants are used in key|/|value
43%D situations.
44
45%D We should consider design sizes ... maybe kick 'm out which removes
46%D the size code and simplifies things considerably. After all, there
47%D will be no latin modern math in sizes.
48
49\writestatus{loading}{ConTeXt Font Macros / Initialization}
50
51%D Documentation is somewhat messy as it contains bits and pieces of
52%D previous versions.
53
54\unprotect
55
56%D There are several ways to specify a font. Three of them are pure \TEX\ ones, the
57%D fourth one is new:
58%D
59%D \starttyping
60%D \font\name=cmr12
61%D \font\name=cmr12 at 10pt
62%D \font\name=cmr12 scaled 2
63%D \font\name=cmr12 sa 1.440
64%D \stoptyping
65%D
66%D The non||\TEX\ alternative \type{sa} stands for {\em scaled at}. This means as
67%D much as: scale the bodyfontsize with this factor. The scaled option is not that
68%D useful as one needs to know the design size.
69%D
70%D Because \type {sa} (scaled at) and \type {mo} (mapped on) are not low level \TEX\
71%D supported alternatives, we have to test for it ourselves. In doing so, we need an
72%D auxiliary \DIMENSION. We cannot use \type{\scratchdimen} because font loading can
73%D happen at any moment due to postponed loading. We could instead have used dirty
74%D grouping tricks, but this one works too.
75
76% \enableexperiments[fonts.autorscale]
77%
78% \starttypescript[mscore]
79%     \definetypeface [mscore] [rm] [serif] [mscoretimes]   [default]
80%     \definetypeface [mscore] [ss] [sans]  [mscorearial]   [default] [rscale=auto] % 0.860]
81%     \definetypeface [mscore] [tt] [mono]  [mscorecourier] [default] [rscale=auto] % 1.065]
82%     \definetypeface [mscore] [mm] [math]  [times]         [default] [rscale=auto] % 1.020]
83% \stoptypescript
84%
85% \starttext
86%    \setupbodyfont[mscore,12pt]
87%    \startTEXpage
88%        test \ss test \tt test
89%    \stopTEXpage
90% \stoptext
91
92% \definetypeface[one][rm][serif][computer-roman][default]
93% \definetypeface[two][rm][serif][computer-roman][default][rscale=.9]
94%
95% {\one \bf test \two test}
96% {\one \bf test \pushcurrentfont \two \popcurrentfont test}
97
98%D \macros
99%D   {rm,ss,tt,hw,cg}
100%D
101%D Fonts are defined in separate files. When we define a font, we distinguish
102%D between several styles. In most cases we will use:
103%D
104%D \startlinecorrection
105%D \starttable[|l||]
106%D \HL
107%D \NC roman regular serif    \NC \type{\rm} \NC\FR
108%D \NC sansserif sans support \NC \type{\ss} \NC\MR
109%D \NC type teletype mono     \NC \type{\tt} \NC\LR
110%D \HL
111%D \stoptable
112%D \stoplinecorrection
113%D
114%D The number of styles is not limited to these three. When using Lucida Bright we
115%D can for instance also define:
116%D
117%D \startlinecorrection
118%D \starttable[|l||]
119%D \HL
120%D \NC handwritten  \NC \type{\hw} \NC\FR
121%D \NC calligraphic \NC \type{\cg} \NC\LR
122%D \HL
123%D \stoptable
124%D \stoplinecorrection
125%D
126%D Within such a font set (\type{cmr}) and style (\type{\rm}) we can define a number
127%D of text font alternatives:
128%D
129%D \startlinecorrection
130%D \starttable[|l||]
131%D \HL
132%D \NC typeface    \NC \type{\tf} \NC\FR
133%D \NC boldface    \NC \type{\bf} \NC\MR
134%D \NC slanted     \NC \type{\sl} \NC\MR
135%D \NC italic      \NC \type{\it} \NC\MR
136%D \NC boldslanted \NC \type{\bs} \NC\MR
137%D \NC bolditalic  \NC \type{\bi} \NC\MR
138%D \NC smallcaps   \NC \type{\sc} \NC\LR
139%D \HL
140%D \stoptable
141%D \stoplinecorrection
142%D
143%D Internally fonts are stored as combination of size, style
144%D and alternative, e.g. \type{12pt}+\type{\ss}+\type{\bf}. Users are not confronted
145%D with sizes, but use the style or style+alternative to activate them.
146%D
147%D During the definition of a bodyfont one can also declare the available larger
148%D alternatives:
149%D
150%D \starttyping
151%D \tf \tfa \tfb \tfc ...
152%D \bf \bfa \bfb \bfc ...
153%D \sl \sla \slb \slc ...
154%D \stoptyping
155%D
156%D The smaller ones are automatically supplied and derived from
157%D the the bodyfont environment.
158%D
159%D \starttyping
160%D \tfx \tfxx
161%D \bfx \bfxx
162%D \slx \slxx
163%D \stoptyping
164%D
165%D There are only two smaller alternatives per style. The larger alternatives on the
166%D other hand have no limitations.
167%D
168%D These larger alternatives are mostly used in chapter and section titles or on
169%D title pages. When one switches to a larger alternative, the bold an other ones
170%D automatically adapt themselves:
171%D
172%D \startbuffer
173%D \tfd Hi \bf there\sl, here \tfb I \bf am
174%D \stopbuffer
175%D
176%S \startnarrower
177%D \typebuffer
178%S \stopnarrower
179%D
180%D therefore becomes:
181%D
182%D \startexample
183%D \getbuffer
184%D \stopexample
185%D
186%D Maybe this mechanism isn't always as logic, but as said before, we tried to make
187%D it as intuitive as possible.
188%D
189%D So a specific kind of glyph can be characterized by:
190%D
191%D \startnarrower
192%D family (cmr) + bodyfont (12pt) + style (rm) + alternative (bf) + size (a)
193%D \stopnarrower
194%D
195%D The last component (the size) is optional.
196%D
197%D We introduced \type {\tf} as command to call for the current normally sized
198%D typeface. This commands results in roman, sans serif, teletype or whatever style
199%D is in charge. Such rather massive switches of style sometimes take more
200%D processing time than comfortable. Of course there is a workaround for this: we
201%D can call fonts directly by means of commands like:
202%D
203%D \starttyping
204%D \rmtf \sssl \tttf \rmbsa
205%D \stoptyping
206%D
207%D One should realize that this fast calls have limitations, they lack for instance
208%D automatic super- and subscript support.
209%D
210%D This leaves us two more commands: \type {\tx} and \type {\txx}. These activate a
211%D smaller and even more smaller font than the current one and adapt themselves to
212%D the current alternative, so when \type {\bf} is active, \type {\tx} gives a
213%D smaller boldface, which in turn can be called directly by \type {\bfx}.
214%D
215%D These two smaller alternatives are specified by the bodyfont environment and
216%D therefore not necessarily have similar sizes as \type {\scriptsize} and \type
217%D {\scriptscriptsize}. The main reason for this incompatibility (which can easily
218%D be undone) lays in the fact that we often want a bit bigger characters than in
219%D math mode. In \CONTEXT\ for instance the \type {\tx} and \type {\txx} commands
220%D are used for surrogate \cap {smallcaps} which support both nesting and
221%D alternatives, like in {\bf \cap {a \cap {small} world}}, which was typeset by
222%D
223%D \starttyping
224%D \bf\cap{a \cap{small} world}
225%D \stoptyping
226%D
227%D And compare $\rm \scriptstyle THIS$ with the slightly larger \cap {THIS}:
228%D \ruledhbox {$\rm \scriptstyle scriptstyle: THIS$} or \ruledhbox {\cap {x style:
229%D THIS}} makes a big difference.
230%D
231%D The \type {x..d} sizes should be used grouped. If you don't group them, i.e. call
232%D them in a row, \CONTEXT\ will not be able to sort out your intention (\type {x}
233%D inside \type {d} inside \type {x}. etc.). The following table demonstrates this:
234%D
235%D \def\FontState{\setstrut\ruledhbox{\strut Hello}}
236%D
237%D \starttabulate[|||||]
238%D \HL
239%D \NC \rlap{\quad\bf grouped} \NC \NC \type {\tx} \NC \type {\txx} \NC \NR
240%D \HL
241%D \NC \type{\tfx}  \NC \tfx  \FontState \NC \tfx \tx \FontState \NC \tfx \txx \FontState  \NC \NR
242%D \NC \type{\tfxx} \NC \tfxx \FontState \NC \tfxx\tx \FontState \NC \tfxx\txx \FontState  \NC \NR
243%D \NC \type{\tf}   \NC \tf   \FontState \NC \tf  \tx \FontState \NC \tf  \txx \FontState  \NC \NR
244%D \NC \type{\tfa}  \NC \tfa  \FontState \NC \tfa \tx \FontState \NC \tfa \txx \FontState  \NC \NR
245%D \NC \type{\tfb}  \NC \tfb  \FontState \NC \tfb \tx \FontState \NC \tfb \txx \FontState  \NC \NR
246%D \NC \type{\tfc}  \NC \tfc  \FontState \NC \tfc \tx \FontState \NC \tfc \txx \FontState  \NC \NR
247%D \NC \type{\tfd}  \NC \tfd  \FontState \NC \tfd \tx \FontState \NC \tfd \txx \FontState  \NC \NR
248%D \NC \type{\tfx}  \NC \tfx  \FontState \NC \tfx \tx \FontState \NC \tfx \txx \FontState  \NC \NR
249%D \NC \type{\tfxx} \NC \tfxx \FontState \NC \tfxx\tx \FontState \NC \tfxx\txx \FontState  \NC \NR
250%D \HL
251%D \stoptabulate
252%D
253%D \blank
254%D
255%D \starttabulate[|||||]
256%D \HL
257%D \NC \rlap{\quad\bf stacked} \NC \NC \type {\tx} \NC \type {\txx} \NC \NR
258%D \HL
259%D \NC \type{\tfx}
260%D \NC \tfx                                   \FontState
261%D \NC \tfx                              \tx  \FontState
262%D \NC \tfx                              \txx \FontState
263%D \NC \NR
264%D \NC \type{\tfxx}
265%D \NC \tfx\tfxx                              \FontState
266%D \NC \tfx\tfxx                         \tx  \FontState
267%D \NC \tfx\tfxx                         \txx \FontState
268%D \NC \NR
269%D \NC \type{\tf}
270%D \NC \tfx\tfxx\tf                           \FontState
271%D \NC \tfx\tfxx\tf                      \tx  \FontState
272%D \NC \tfx\tfxx\tf                      \txx \FontState
273%D \NC \NR
274%D \NC \type{\tfa}
275%D \NC \tfx\tfxx\tf\tfa                       \FontState
276%D \NC \tfx\tfxx\tf\tfa                  \tx  \FontState
277%D \NC \tfx\tfxx\tf\tfa                  \txx \FontState
278%D \NC \NR
279%D \NC \type{\tfb}
280%D \NC \tfx\tfxx\tf\tfa\tfb                   \FontState
281%D \NC \tfx\tfxx\tf\tfa\tfb              \tx  \FontState
282%D \NC \tfx\tfxx\tf\tfa\tfb              \txx \FontState
283%D \NC \NR
284%D \NC \type{\tfc}
285%D \NC \tfx\tfxx\tf\tfa\tfb\tfc               \FontState
286%D \NC \tfx\tfxx\tf\tfa\tfb\tfc          \tx  \FontState
287%D \NC \tfx\tfxx\tf\tfa\tfb\tfc          \txx \FontState
288%D \NC \NR
289%D \NC \type{\tfd}
290%D \NC \tfx\tfxx\tf\tfa\tfb\tfd               \FontState
291%D \NC \tfx\tfxx\tf\tfa\tfb\tfd          \tx  \FontState
292%D \NC \tfx\tfxx\tf\tfa\tfb\tfd          \txx \FontState
293%D \NC \NR
294%D \NC \type{\tfx}
295%D \NC \tfx\tfxx\tf\tfa\tfb\tfc\tfx           \FontState
296%D \NC \tfx\tfxx\tf\tfa\tfb\tfc\tfx      \tx  \FontState
297%D \NC \tfx\tfxx\tf\tfa\tfb\tfc\tfx      \txx \FontState
298%D \NC \NR
299%D \NC \type{\tfxx}
300%D \NC \tfx\tfxx\tf\tfa\tfb\tfc\tfx\tfxx      \FontState
301%D \NC \tfx\tfxx\tf\tfa\tfb\tfc\tfx\tfxx \tx  \FontState
302%D \NC \tfx\tfxx\tf\tfa\tfb\tfc\tfx\tfxx \txx \FontState
303%D \NC \NR
304%D \HL
305%D \stoptabulate
306
307\fontslantperpoint   \nullfont      0\scaledpoint
308\fontinterwordspace  \nullfont 256377\scaledpoint
309\fontinterwordstretch\nullfont 128188\scaledpoint
310\fontinterwordshrink \nullfont  85459\scaledpoint
311\fontexheight        \nullfont 338952\scaledpoint
312\fontemwidth         \nullfont 786432\scaledpoint
313\fontextraspace      \nullfont  85459\scaledpoint
314
315\appendtoks
316    \fontslantperpoint   \nullfont      0\scaledpoint
317    \fontinterwordspace  \nullfont 256377\scaledpoint
318    \fontinterwordstretch\nullfont 128188\scaledpoint
319    \fontinterwordshrink \nullfont  85459\scaledpoint
320    \fontexheight        \nullfont 338952\scaledpoint
321    \fontemwidth         \nullfont 786432\scaledpoint
322    \fontextraspace      \nullfont  85459\scaledpoint
323\to \everyjob
324
325%D Tracing
326
327\newtoks\t_font_tracers_definitions
328
329\unexpanded\def\tracefontdefinitions
330  {\the\t_font_tracers_definitions}
331
332%D Some housekeeping macros:
333
334\unexpanded\def\setfontparameters
335  {\setfalse\c_font_synchronize
336   \the\everybodyfont
337   \settrue\c_font_synchronize}
338
339\let\savedfont\empty
340
341\installmacrostack\savedfont
342
343\unexpanded\def\savefont
344  {\edef\savedfont{\the\font}% gives \csname
345   \push_macro_savedfont}
346
347\unexpanded\def\restorefont
348  {\pop_macro_savedfont
349   \savedfont}
350
351\unexpanded\def\pushcurrentfont
352  {\edef\popcurrentfont
353     {\def\noexpand\fontbody       {\fontbody}%
354      \def\noexpand\fontstyle      {\fontstyle}%
355      \def\noexpand\fontalternative{\fontalternative}%
356      \def\noexpand\fontsize       {\fontsize}%
357      \font_helpers_check_big_math_synchronization
358      \font_helpers_synchronize_font}}
359
360%D \macros{definedfont}
361
362\let\thedefinedfont\relax % not to be confused with \everydefinefont
363
364\unexpanded\def\definedfont
365  {\doifelsenextoptionalcs\font_basics_defined_font_yes\font_basics_defined_font_nop}
366
367\def\font_basics_defined_font_yes[#specification]%
368  {\c_font_feature_inheritance_mode\c_font_feature_inheritance_fontonly
369   \font_basics_define_font_without_parameters{thedefinedfont}{#specification}%
370   \thedefinedfont
371   \the\everydefinedfont}
372
373\def\font_basics_defined_font_nop
374  {\c_font_feature_inheritance_mode\c_font_feature_inheritance_fontonly
375   \thedefinedfont
376   \the\everydefinedfont}
377
378%D \macros{startfont}
379
380\unexpanded\def\startfont{\begingroup\definedfont}
381\unexpanded\def\stopfont {\endgroup}
382
383%D \macros
384%D   {everybodyfont,everyglobalbodyfont}
385%D
386%D Every change in bodyfont size has conseqences for the baseline distance and skips
387%D between paragraphs. These are initialized in other modules. Here we only provide
388%D the hooks that garantees their handling.
389%D
390%D At the system level one can initialize thing like:
391%D
392%D \starttyping
393%D \appendtoks \setupspacing \to \everybodyfont
394%D \stoptyping
395
396%D \macros
397%D   {globalbodyfontsize,localbodyfontsize,bodyfontsize}
398%D
399%D Here we have to distinguish between the global (overal) bodyfont size and the
400%D local (sometimes in the textflow) size. We store these dimensions in two
401%D \DIMENSION\ registers. These registers are not to be misused in calculations.
402
403\ifdefined\globalbodyfontsize\else \newdimen\globalbodyfontsize \fi \globalbodyfontsize=12pt
404\ifdefined\localbodyfontsize \else \newdimen\localbodyfontsize  \fi \localbodyfontsize =\globalbodyfontsize
405\ifdefined\bodyfontsize      \else \newdimen\bodyfontsize       \fi \bodyfontsize      =\globalbodyfontsize
406
407%D When we assign for instance 12pt to a \DIMENSION\ register the \type {\the}'d
408%D value comes out as 12.0pt, which is often not the way users specify the bodyfont
409%D size. Therefore we use normalized values. They are cached to save overhead in
410%D \LUA\ calls.
411
412% \setnewconstant\fontdigits\plustwo % from now on always 2
413
414\installcorenamespace{fontnormalizedbody}
415
416% \def\normalizebodyfontsize#macro#body%
417%   {\expandafter\let\expandafter#macro\csname\??fontnormalizedbody\number\fontdigits:\number\dimexpr#body\endcsname
418%    \ifx#macro\relax
419%       \normalizebodyfontsize_indeed#macro{#body}%
420%    \fi}
421%
422% \def\normalizebodyfontsize_indeed#macro#body%
423%   {\edef#macro{\ctxcommand{nbfs(\number\dimexpr#body,\number\fontdigits)}}%
424%    \expandafter\glet\csname\??fontnormalizedbody\number\fontdigits:\number\dimexpr#body\endcsname#macro}
425%
426% \def\thenormalizedbodyfontsize#body%
427%   {\ctxcommand{nbfs(\number\dimexpr#body\relax,\number\fontdigits)}}
428%
429% caching is less relevant now
430
431\def\normalizebodyfontsize#macro#body%
432  {\expandafter\let\expandafter#macro\csname\??fontnormalizedbody\number\dimexpr#body\endcsname
433   \ifx#macro\relax
434      \normalizebodyfontsize_indeed#macro{#body}%
435   \fi}
436
437\def\normalizebodyfontsize_indeed#macro#body%
438  {\edef#macro{\clf_nbfs\dimexpr#body\relax}%
439   \expandafter\glet\csname\??fontnormalizedbody\number\dimexpr#body\endcsname#macro}
440
441\def\thenormalizedbodyfontsize#body%
442  {\clf_nbfs\dimexpr#body\relax}
443
444\edef\normalizedglobalbodyfontsize{\thenormalizedbodyfontsize\bodyfontsize}
445\edef\normalizedlocalbodyfontsize {\thenormalizedbodyfontsize\bodyfontsize}
446\edef\normalizedbodyfontsize      {\thenormalizedbodyfontsize\bodyfontsize}
447
448%D \macros
449%D   {mapfontsize}
450%D
451%D For special purposes, like in math, you may want to use slightly different sizes
452%D than the ones given. This happens for instance with the Math Times fonts. Mapped
453%D font sizes can be specified by using the \type {mo} key instead of \type {sa} in
454%D font definitions.
455%D
456%D \startbuffer
457%D \mapfontsize[10pt][11pt]
458%D \mapfontsize[11pt][12pt]
459%D \mapfontsize[12pt][13pt]
460%D
461%D \definefont[test][Serif]\test TEST \par
462%D \definefont[test][Serif sa 5]\test TEST \par
463%D \definefont[test][Serif mo 5]\test TEST \par
464%D \definefont[test][Serif sa d]\test TEST \par
465%D \definefont[test][Serif at 60pt]\test TEST \par
466%D \definefont[test][Serif scaled 6000]\test TEST \par
467%D \stopbuffer
468%D
469%D \typebuffer
470%D
471%D \startpacked
472%D \getbuffer
473%D \stoppacked
474
475\installcorenamespace{mappedfontsize}
476
477\unexpanded\def\mapfontsize
478  {\dodoubleargument\font_basics_map_fontsize}
479
480\def\font_basics_map_fontsize[#from][#to]%
481  {\setvalue{\??mappedfontsize\the\dimexpr#from\relax}{#to}}
482
483\def\font_basics_set_mapped_fontsize#from%
484  {\ifcsname\??mappedfontsize\the\dimexpr#from\relax\endcsname
485     \lastnamedcs\else#from%
486   \fi}
487
488\installcorenamespace{fontbodyknown}
489\installcorenamespace{fontclassyes}   % fontclass
490\installcorenamespace{fontclassnop}   % nofontclass
491
492\def\font_helpers_process_relative_size_list#command% could be a toks
493  {#command\v!big
494   #command\v!small}
495
496\let\v_font_size_relative  \plusone
497\def\v_font_size_absolute {\fontbody}
498
499\let\v_font_rscale_default\!!plusone
500\let\p_font_rscale        \v_font_rscale_default
501
502\def\font_helpers_check_relative_font_id % can be plugged in later
503  {\let\p_font_rscale\minusone
504   \let\p_font_rscale\v_font_rscale_default}
505
506\def\font_helpers_check_relative_font_size#style%
507  {\edef\p_font_rscale
508     {\ifcsname\??fontclass\fontclass#style\s!rscale\endcsname
509        \lastnamedcs
510      \else\ifcsname\??fontclass\defaultfontclass#style\s!rscale\endcsname % brr
511        \lastnamedcs
512      \else
513        \v_font_rscale_default
514      \fi\fi}%
515   % move elsewhere
516   \ifx\p_font_rscale\v!auto
517     \let\p_font_rscale\plusone
518     \font_helpers_check_relative_font_id
519   \else
520     \let\relativefontid\minusone
521   \fi}
522
523\def\font_rscale_xx#style%
524  {\ifcsname\??fontclass\fontclass#style\s!rscale\endcsname
525     \lastnamedcs
526   \else
527     \v_font_rscale_default
528   \fi}
529
530\def\font_rscale_mm
531  {\ifcsname\??fontclass\fontclass\s!mm\s!rscale\endcsname
532     \lastnamedcs
533   \else
534     \v_font_rscale_default
535   \fi}
536
537\def\font_helpers_register_fontbody#body%
538  {\expandafter\let\csname\??fontbodyknown#body\endcsname\empty}
539
540%D \macros
541%D   {definefontstyle,definefontsize,definefontalternative}
542%D
543%D When setting of switching the overall style we can use the short identifier like
544%D rm and ss, but when defined we can also use more verbose names like roman or
545%D sansserif. Such names are defined by:
546%D
547%D \starttyping
548%D \definefontstyle [serif,rm] [rm]
549%D \definefontstyle [sansserif,ss] [ss]
550%D \stoptyping
551
552\installcorenamespace{fontstyle}      % full style prefix (roman etc)
553\installcorenamespace{fontshortstyle} % short style prefix (rm etc)
554
555\installcorenamespace{fontstyleknown}
556\installcorenamespace{fontalternativeknown}
557\installcorenamespace{fontsizeknown}
558
559\newtoks\t_font_style_commands
560\newtoks\t_font_size_commands
561\newtoks\t_font_alternative_commands
562
563\setnewmacro\m_font_style_command      \gobbleoneargument
564\setnewmacro\m_font_size_command       \gobbleoneargument
565\setnewmacro\m_font_alternative_command\gobbleoneargument
566
567\def\font_helpers_process_style_list      #command{\def\m_font_style_command      {#command}\the\t_font_style_commands}
568\def\font_helpers_process_size_list       #command{\def\m_font_size_command       {#command}\the\t_font_size_commands}
569\def\font_helpers_process_alternative_list#command{\def\m_font_alternative_command{#command}\the\t_font_alternative_commands}
570
571\def\font_helpers_register_style            #style{\expandafter\let\csname\??fontstyleknown            #style\endcsname\empty}
572\def\font_helpers_register_size              #size{\expandafter\let\csname\??fontsizeknown              #size\endcsname\empty}
573\def\font_helpers_register_alternative#alternative{\expandafter\let\csname\??fontalternativeknown#alternative\endcsname\empty}
574
575\unexpanded\def\definefontstyle
576  {\dodoubleargument\font_basics_define_fontstyle}
577
578\def\font_basics_define_fontstyle[#commands][#style]% style: rm ss tt ...
579  {\ifcsname\??fontstyleknown#style\endcsname \else % can be delayed till used (cg, hw)
580     \font_helpers_register_style{#style}%
581     \toksapp\t_font_style_commands{\m_font_style_command{#style}}%
582   \fi
583   \processcommalist[#commands]{\font_basics_define_fontstyle_indeed{#style}}}
584
585\def\font_basics_define_fontstyle_indeed#style#command%
586  {\setvalue{\??fontshortstyle#command}{#style}%
587   \setvalue{\??fontstyle     #command}{\csname#style\endcsname}}
588
589\unexpanded\def\definefontsize[#size]%
590  {\ifcsname\??fontsizeknown#size\endcsname \else
591     \font_helpers_register_size{#size}%
592     \toksapp\t_font_size_commands{\m_font_size_command{#size}}%
593   \fi
594   \font_helpers_check_fontname_combinations}
595
596\unexpanded\def\definefontalternative[#alternative]%
597  {\ifcsname\??fontalternativeknown#alternative\endcsname \else
598     \font_helpers_register_alternative{#alternative}%
599     \toksapp\t_font_alternative_commands{\m_font_alternative_command{#alternative}}%
600   \fi
601   \font_helpers_check_fontname_combinations}
602
603\unexpanded\def\font_helpers_check_fontname_combinations % we need to split math and text here ... todo (math only has mr and mb)
604  {\font_helpers_process_style_list\font_helpers_check_fontname_combinations_s}
605
606\def\font_helpers_check_fontname_combinations_s#style%
607  {\font_helpers_process_alternative_list{\font_helpers_check_fontname_combinations_indeed_s_a{#style}}}
608
609\def\font_helpers_check_fontname_combinations_indeed_s_a#style#alternative%
610  {\font_helpers_process_size_list{\font_basics_check_fontname_combination{#style}{#alternative}}}
611
612\definefontstyle [\s!mm] [\s!mm]
613\definefontstyle [\s!rm] [\s!rm]
614\definefontstyle [\s!ss] [\s!ss]
615\definefontstyle [\s!tt] [\s!tt]
616
617%D We define all the font switching commands globally. After all they are part of
618%D the formal font interface once defined. The size can be empty (so checking is
619%D needed as \type {\bf} is already defined).
620%D
621%D The \type {\normal..} variants are available as extras for cases where the \type
622%D {..} is overloaded.
623
624\newmacro\m_font_mm
625
626\def\font_basics_check_fontname_combination#style% alternative size
627  {\edef\m_font_mm{#style}%
628   \ifx\m_font_mm\s!mm % prevents \max and alike (re)defs
629     \expandafter\font_basics_check_math_bodyfont
630   \else
631     \expandafter\font_basics_check_text_bodyfont
632   \fi{#style}} % no \m_font_mm, not expanded later on
633
634% \def\font_basics_check_math_bodyfont#style#alternative#size%
635%   {%setugvalue{#alternative}{\font_helpers_set_current_font_alternative{#alternative}}% \mr \mb
636%    \setugvalue{#style}{\font_helpers_set_current_font_style{#style}}}% \mm
637
638\def\font_basics_check_math_bodyfont#style#alternative#size%
639  {}
640
641% \def\font_basics_check_text_bodyfont#style#alternative#size% size can be empty (checking needed as \bf is already defined)
642%   {\setugvalue{#style#size}{\font_helpers_set_current_font_style_size{#style}{#size}}% \rma
643%    \setugvalue{#alternative#size}{\font_helpers_set_current_font_alternative_size{#alternative}{#size}}% \sla
644%    \setugvalue{#style#alternative#size}{\font_helpers_set_current_font_style_alternative_size{#style}{#alternative}{#size}}% \rmsla
645%    \ifcsname\s!normal#style\endcsname % text/math check
646%      \expandafter\let\csname#style\expandafter\endcsname\csname\s!normal#style\endcsname
647%    \else
648%      \setugvalue{#style}{\font_helpers_set_current_font_style{#style}}% \rm
649%    \fi
650%    \ifcsname\s!normal#alternative\endcsname % text/math check
651%      \expandafter\let\csname#alternative\expandafter\endcsname\csname\s!normal#alternative\endcsname
652%    \else
653%      \setugvalue{#alternative}{\font_helpers_set_current_font_alternative{#alternative}}% \sl
654%    \fi
655%    \setugvalue{#style\s!x}{\font_helpers_set_current_font_x_style_alternative{#style}}% \rmx
656%    \setugvalue{#style\s!xx}{\font_helpers_set_current_font_xx_style_alternative{#style}}% \rmxx
657%    \setugvalue{#alternative\s!x}{\font_helpers_set_current_font_x_alternative{#alternative}}% \slx
658%    \setugvalue{#alternative\s!xx}{\font_helpers_set_current_font_xx_alternative{#alternative}}% \slxx
659%    \setugvalue{#style#alternative}{\font_helpers_set_current_font_style_alternative{#style}{#alternative}}}% \rmsl
660
661% \def\font_basics_check_text_bodyfont#style#alternative#size% size can be empty (checking needed as \bf is already defined)
662%   {\ifcsname#style#size\endcsname\else
663%      \setugvalue{#style#size}{\font_helpers_set_current_font_style_size{#style}{#size}}% \rma
664%    \fi
665%    \ifcsname#alternative#size\endcsname\else
666%      \setugvalue{#alternative#size}{\font_helpers_set_current_font_alternative_size{#alternative}{#size}}% \sla
667%    \fi
668%    \ifcsname#style#alternative#size\endcsname\else
669%      \setugvalue{#style#alternative#size}{\font_helpers_set_current_font_style_alternative_size{#style}{#alternative}{#size}}% \rmsla
670%    \fi
671%    \ifcsname#style\endcsname\else
672%      \setugvalue{#style}{\font_helpers_set_current_font_style{#style}}% \rm
673%    \fi
674%    \ifcsname#alternative\endcsname\else
675%      \setugvalue{#alternative}{\font_helpers_set_current_font_alternative{#alternative}}% \sl
676%    \fi
677%    \ifcsname#style\s!x\endcsname\else
678%      \setugvalue{#style\s!x }{\font_helpers_set_current_font_x_style_alternative{#style}}% \rmx
679%      \setugvalue{#style\s!xx}{\font_helpers_set_current_font_xx_style_alternative{#style}}% \rmxx
680%    \fi
681%    \ifcsname#alternative\s!x\endcsname\else
682%      \setugvalue{#alternative\s!x }{\font_helpers_set_current_font_x_alternative{#alternative}}% \slx
683%      \setugvalue{#alternative\s!xx}{\font_helpers_set_current_font_xx_alternative{#alternative}}% \slxx
684%    \fi
685%    \ifcsname#style#alternative\endcsname\else
686%      \setugvalue{#style#alternative}{\font_helpers_set_current_font_style_alternative{#style}{#alternative}}% \rmsl
687%    \fi}
688
689\def\font_basics_check_text_bodyfont_step#whatever#body% size can be empty (checking needed as \bf is already defined)
690  {\ifcsname#whatever\endcsname\else
691     \setugvalue{#whatever}{#body}%
692   \fi}
693
694\def\font_basics_check_text_bodyfont#style#alternative#size% size can be empty (checking needed as \bf is already defined)
695  {\font_basics_check_text_bodyfont_step{#style#size}{\font_helpers_set_current_font_style_size{#style}{#size}}% \rma
696   \font_basics_check_text_bodyfont_step{#alternative#size}{\font_helpers_set_current_font_alternative_size{#alternative}{#size}}% \sla
697   \font_basics_check_text_bodyfont_step{#style#alternative#size}{\font_helpers_set_current_font_style_alternative_size{#style}{#alternative}{#size}}% \rmsla
698   \font_basics_check_text_bodyfont_step{#style}{\font_helpers_set_current_font_style{#style}}% \rm
699   \font_basics_check_text_bodyfont_step{#alternative}{\font_helpers_set_current_font_alternative{#alternative}}% \sl
700   \font_basics_check_text_bodyfont_step{#style\s!x }{\font_helpers_set_current_font_x_style_alternative{#style}}% \rmx
701   \font_basics_check_text_bodyfont_step{#style\s!xx}{\font_helpers_set_current_font_xx_style_alternative{#style}}% \rmxx
702   \font_basics_check_text_bodyfont_step{#alternative\s!x }{\font_helpers_set_current_font_x_alternative{#alternative}}% \slx
703   \font_basics_check_text_bodyfont_step{#alternative\s!xx}{\font_helpers_set_current_font_xx_alternative{#alternative}}% \slxx
704   \font_basics_check_text_bodyfont_step{#style#alternative}{\font_helpers_set_current_font_style_alternative{#style}{#alternative}}}% \rmsl
705
706%D Scaling macros:
707%D
708%D This system is somewhat complicated by two (possible conflicting) demands:
709%D
710%D \startitemize
711%D \item We support wildcards like \type {sa *} which will adapt to the current
712%D       size. This is also the default specification.
713%D \item We support named scales like \type {sa d}; beware: \type {x} and \type {xx}
714%D       are valid scales but they are not alway the same as the ones used in for
715%D       instance \type {\bfx} because there the sized come from the bodyfont
716%D       environment. In the future there maybe a switch that also honors the
717%D       environment in named scales.
718%D \stopitemize
719%D
720%D Keep in mind that the smaller sizes are just for text super and subscripts while
721%D larger sizes can be used in titles where for instance math follows the size.
722
723% b:x{\definedfont[SerifBold sa  b]x}{\bfb  x $x^x$}\par
724% 1:x{\definedfont[SerifBold sa  1]x}{\bf   x $x^x$}\par
725% x:x{\definedfont[SerifBold sa  x]x}{\bfx  x $x^x$}\par
726% xx:x{\definedfont[SerifBold sa xx]x}{\bfxx x $x^x$}\par
727%
728% *:x{\definedfont[Serif sa *]x}\par
729% 1:x{\definedfont[Serif sa 1]x}\par
730% 2:x{\definedfont[Serif sa 2]x}\par
731% 3:x{\definedfont[Serif sa 3]x}\par
732% 4:x{\definedfont[Serif sa 4]x}\par
733% 5:x{\definedfont[Serif sa 5]x}\par
734
735\def\safontscale{\number\dimexpr\v_font_size_absolute\relax}
736\def\mofontscale{\number\dimexpr\font_basics_set_mapped_fontsize\v_font_size_absolute\relax}
737
738\let\somefontname\s!unknown
739\let\somefontspec\s!unknown
740\let\somefontsize\zerocount
741
742\newcount\scaledfontmode  % also used at the lua end
743\newcount\scaledfontsize  % also used at the lua end
744\newcount\lastfontid      % also used at the lua end / tex end
745\newtoks \everydefinefont
746
747\let\relativefontid\minusone % todo, not yet used
748
749\let\c_font_feature_inheritance_fontnone  \zerocount  % none
750\let\c_font_feature_inheritance_fontonly  \plusone    % fontonly
751\let\c_font_feature_inheritance_classonly \plustwo    % classonly
752\let\c_font_feature_inheritance_fontfirst \plusthree  % fontfirst
753\let\c_font_feature_inheritance_classfirst\plusfour   % classfirst
754
755\let\c_font_feature_inheritance_default   \c_font_feature_inheritance_fontfirst
756
757\setnewconstant\c_font_feature_inheritance_mode \c_font_feature_inheritance_default
758
759\newdimen      \d_font_scaled_text_face
760\newdimen      \d_font_scaled_font_size
761\newconditional\c_font_body_scale
762\newfraction   \f_font_body_scale
763
764\unexpanded\def\font_helpers_low_level_define#specification#csname%
765  {% we can now set more at the lua end
766   \glet\somefontname\defaultfontfile
767   \let\somefontsize\empty
768   \clf_definefont_one{\detokenize\expandafter{\normalexpanded{#specification}}}% the escapestring catches at \somedimen
769   % sets \scaledfontmode and \somefontname and \somefontsize
770   \ifcase\fontface\relax
771   % \let\v_font_size_absolute\textface % fontbody
772   \or
773     \let\v_font_size_absolute\textface
774   \or
775     \let\v_font_size_absolute\scriptface
776   \or
777     \let\v_font_size_absolute\scriptscriptface
778   \or
779     \let\v_font_size_absolute\xtextface
780   \or
781     \let\v_font_size_absolute\xxtextface
782   \fi
783   %
784   \ifcase\scaledfontmode\relax
785     % none, avoid the designsize if possible
786     \d_font_scaled_font_size-\plusthousand\scaledpoint
787   \or
788     % at
789     \d_font_scaled_font_size\somefontsize
790   \or
791     % sa
792     \d_font_scaled_font_size\v_font_size_absolute\relax
793     \d_font_scaled_font_size\currentfontbodysize\d_font_scaled_font_size % uses \somefontsize set by lua
794   \or
795     % mo
796     \d_font_scaled_font_size\font_basics_set_mapped_fontsize\v_font_size_absolute
797     \d_font_scaled_font_size\currentfontbodysize\d_font_scaled_font_size
798   \or
799     % scaled, don't use this one as it's unpredictable
800     \d_font_scaled_font_size-\somefontsize\scaledpoint
801   \else % ht cp
802     % experiment, yet undocumented
803     \d_font_scaled_font_size\somefontsize
804   \fi
805   \relax
806   \d_font_scaled_font_size\v_font_size_relative\d_font_scaled_font_size
807   \ifconditional\c_font_auto_size
808     \font_helpers_check_body_scale\fontsize
809     \ifconditional\c_font_body_scale
810       \d_font_scaled_font_size\f_font_body_scale\d_font_scaled_font_size
811       \d_font_scaled_text_face\f_font_body_scale\dimexpr\textface\relax
812     \else
813       \d_font_scaled_font_size\f_font_body_scale
814       \d_font_scaled_text_face\textface
815     \fi
816   \else
817     \d_font_scaled_text_face\textface
818   \fi
819   \edef\somefontspec{at \number\d_font_scaled_font_size sp}%
820   \edef\somefontfile{\truefontname\somefontname}%
821   \ifx\somefontfile\s!unknown
822     \edef\somefontfile{\defaultfontfile}%
823   \fi
824   \font_helpers_update_font_parameters
825   \font_helpers_update_font_class_parameters
826  %\writestatus{fonts}{low level define: #csname/\somefontfile/\number\d_font_scaled_font_size/\fontface/\number\d_font_scaled_text_face}%
827   \clf_definefont_two
828      \ifx\fontclass\empty\s!false\else\s!true\fi
829      {#csname}%
830      {\somefontfile}%
831      \d_font_scaled_font_size
832      \c_font_feature_inheritance_mode
833      {\m_font_class_features}%
834      {\m_font_features}%
835      {\m_font_class_fallbacks}%
836      {\m_font_fallbacks}%
837      \fontface
838      \d_font_scaled_text_face
839      \relativefontid
840      {\m_font_class_goodies}%
841      {\m_font_goodies}%
842      {\m_font_class_designsize}%
843      {\m_font_designsize}%
844      \scaledfontmode
845   \relax
846   \ifcase\scaledfontsize
847    %\scaledfontsize\plusone
848     \let\somefontspec\empty
849     \let\lastrawfontcall\relax
850     \expandafter\let\csname#csname\endcsname\relax
851   \else
852     \edef\somefontspec{at \number\scaledfontsize sp}% we need the resolved designsize (for fallbacks)
853     \expandafter\let\expandafter\lastrawfontcall\csname#csname\endcsname
854     \the\everydefinefont
855   \fi
856   \c_font_feature_inheritance_mode\c_font_feature_inheritance_default}
857
858% \def\font_helpers_check_body_scale#fontsize%  gets character (x xx a etc)
859%   {\ifcsname\??fontenvironments\fontclass\fontbody #fontsize\endcsname \setfalse\c_font_body_scale \expandafter\let\expandafter\f_font_body_scale
860%      \csname\??fontenvironments\fontclass\fontbody #fontsize\endcsname \else
861%    \ifcsname\??fontenvironments\fontclass\s!default#fontsize\endcsname \settrue \c_font_body_scale \expandafter\let\expandafter\f_font_body_scale
862%      \csname\??fontenvironments\fontclass\s!default#fontsize\endcsname \else
863%    \ifcsname\??fontenvironments          \fontbody #fontsize\endcsname \setfalse\c_font_body_scale \expandafter\let\expandafter\f_font_body_scale
864%      \csname\??fontenvironments          \fontbody #fontsize\endcsname \else
865%    \ifcsname\??fontenvironments          \s!default#fontsize\endcsname \settrue \c_font_body_scale \expandafter\let\expandafter\f_font_body_scale
866%      \csname\??fontenvironments          \s!default#fontsize\endcsname \else
867%    \ifcsname\??fontenvironments\fontclass\s!default\s!text  \endcsname \settrue \c_font_body_scale \expandafter\let\expandafter\f_font_body_scale
868%      \csname\??fontenvironments\fontclass\s!default\s!text  \endcsname \else
869%    \ifcsname\??fontenvironments          \s!default\s!text  \endcsname \settrue \c_font_body_scale \expandafter\let\expandafter\f_font_body_scale
870%      \csname\??fontenvironments          \s!default\s!text  \endcsname
871%    \else
872%      \settrue \c_font_body_scale
873%      \let\f_font_body_scale\plusone
874%    \fi\fi\fi\fi\fi\fi}
875
876\def\font_helpers_check_body_scale#fontsize%  gets character (x xx a etc)
877  {\ifcsname\??fontenvironments\fontclass\fontbody#fontsize\endcsname
878     \expandafter\let\expandafter\f_font_body_scale\lastnamedcs
879     \setfalse\c_font_body_scale % !
880   \else\ifcsname\??fontenvironments\fontclass\s!default#fontsize\endcsname
881     \expandafter\let\expandafter\f_font_body_scale\lastnamedcs
882     \settrue\c_font_body_scale
883   \else\ifcsname\??fontenvironments\fontbody#fontsize\endcsname
884     \expandafter\let\expandafter\f_font_body_scale\lastnamedcs
885     \setfalse\c_font_body_scale % !
886   \else\ifcsname\??fontenvironments\s!default#fontsize\endcsname
887     \expandafter\let\expandafter\f_font_body_scale\lastnamedcs
888     \settrue\c_font_body_scale
889   \else\ifcsname\??fontenvironments\fontclass\s!default\s!text\endcsname
890     \expandafter\let\expandafter\f_font_body_scale\lastnamedcs
891     \settrue\c_font_body_scale
892   \else\ifcsname\??fontenvironments\s!default\s!text\endcsname
893     \expandafter\let\expandafter\f_font_body_scale\lastnamedcs
894     \settrue\c_font_body_scale
895   \else
896     \let\f_font_body_scale\plusone
897     \settrue\c_font_body_scale
898   \fi\fi\fi\fi\fi\fi}
899
900%D The following macros are used at the \LUA\ end. Watch the \type {\normal}
901%D hackery: this makes the mkvi parser happy.
902
903% \normaldef\fntsetdefname {\glet\somefontname\defaultfontfile}    % do before calling
904% \normaldef\fntsetnopsize {\let\somefontsize\empty}                     % do before calling
905% \normaldef\fntsetsomename{\normalgdef\somefontname} % takes argument
906% \normaldef\fntsetsomesize{\normaldef\somefontsize}  % takes argument
907
908\newif\ifskipfontcharacteristics \skipfontcharacteristicstrue
909
910\tracingfonts\plussix % <id: name @ size>
911
912%D When fontclasses are used, we define the font global, since namespaces are
913%D used. Otherwise we parse the specs each time.
914
915\let\fontfile\s!unknown
916
917%D Relatively new:
918
919\installcorenamespace{fonts}
920\installcorenamespace{fontslanguage}
921
922\installsetuponlycommandhandler \??fonts {fonts}
923
924\newconstant\c_fonts_auto_language
925
926\letvalue{\??fontslanguage\v!auto}\plusone % experimental
927%letvalue{\??fontslanguage\v!yes }\plustwo % less efficient, for experiments
928
929\appendtoks
930    \c_fonts_auto_language
931      \ifcsname\??fontslanguage\fontsparameter\c!language\endcsname
932        \lastnamedcs
933      \else
934        \zerocount
935      \fi
936\to \everysetupfonts
937
938\appendtoks
939    \ifcase\c_fonts_auto_language
940        % nothing
941    \or
942        \addfflanguage
943  % \or
944        % font
945    \fi
946\to \everylanguage
947
948% \setupfonts
949%   [\c!language=\v!auto]
950
951%D \macros
952%D  {everyfont,everyfontswitch}
953
954\ifdefined\everyfont       \else \newtoks\everyfont       \fi
955\ifdefined\everyfontswitch \else \newtoks\everyfontswitch \fi
956
957\def\setfontcharacteristics{\the\everyfont}
958
959% \appendtoks
960%     \ifcase\c_fonts_auto_language
961%         % nothing
962%     \or
963%         % auto
964%     \or
965%         \addfflanguage
966%     \fi
967% \to \everyfont
968
969%D \macros
970%D   {definefont}
971%D
972%D We also accept \type{sa a}||\type{sa d} as specification.
973%D
974%D Before we implement the main definition macro, we first show one for local use:
975%D
976%D \starttyping
977%D \definefont[Some][LucidaBright at 100pt]    \Some some
978%D \definefont[More][LucidaBright scaled 3000] \More more
979%D \definefont[Nice][LucidaBright mo 2]        \Nice nice
980%D \definefont[Text][LucidaBright sa 5.4]      \Text last
981%D \stoptyping
982%D
983%D The implementation looks as follows:
984
985\unexpanded\def\definefont % [name][spec][1.6 | line=10pt | setup_id]
986  {\dotripleempty\font_basics_define_font}
987
988\def\font_basics_define_font
989  {\ifthirdargument
990     \expandafter\font_basics_define_font_a
991   \else
992     \expandafter\font_basics_define_font_b
993   \fi}
994
995\def\font_basics_define_font_a[#name][#specification][#settings]% [name][spec][1.6 | line=10pt | setup_id]
996  {\doifelsesetups{#settings}%
997     {\setuvalue{#name}{\font_basics_define_font_with_setups    {#name}{#specification}{#settings}}}
998     {\setuvalue{#name}{\font_basics_define_font_with_parameters{#name}{#specification}{#settings}}}}
999
1000\def\font_basics_define_font_b[#name][#specification][#dummy]%
1001  {\setuvalue{#name}{\font_basics_define_font_without_parameters{#name}{#specification}}}
1002
1003\def\font_basics_define_font_with_parameters#name#specification#settings%
1004  {\font_basics_define_font_without_parameters{#name}{#specification}%
1005   \setuplocalinterlinespace[#settings]%
1006   \setupspacing\relax} % is this really needed ?
1007
1008\def\font_basics_define_font_with_setups#name#specification#settings%
1009  {\font_basics_define_font_without_parameters{#name}{#specification}%
1010   \setups[#settings]}
1011
1012%D Beware, in the frozen variants no settings are supported yet, but that might happen
1013%D some day.
1014
1015\unexpanded\def\definefrozenfont
1016  {\dotripleempty\font_basics_define_frozen_font}
1017
1018% \def\font_basics_define_frozen_font[#name][#specification][#settings]%
1019%   {\begingroup
1020%    \font_basics_define_font[#name][#specification][#settings]%
1021%    \csname#name\endcsname
1022%    \expandafter\expandafter\expandafter\endgroup\expandafter\let\csname#name\endcsname\lastrawfontcall}
1023
1024\def\font_basics_define_frozen_font[#name][#specification][#settings]%
1025  {\begingroup
1026   \font_basics_define_font[#name][#specification][#settings]%
1027   \csname#name\endcsname
1028   \glet\lastglobalrawfontcall\lastrawfontcall
1029   \endgroup
1030   \expandafter\let\csname#name\endcsname\lastglobalrawfontcall}
1031
1032%D The instance namespace protection makes the switch local so that we can redefine a
1033%D logical name and/or change the size in between.
1034
1035% todo: now mathsize twice in name (so it can go here)
1036% todo: check when mathsize is needed
1037
1038\ifdefined\??fontinstanceready \else \installcorenamespace{fontinstanceready} \fi
1039\ifdefined\??fontinstancebasic \else \installcorenamespace{fontinstancebasic} \fi
1040\ifdefined\??fontinstanceclass \else \installcorenamespace{fontinstanceclass} \fi
1041
1042\newconditional\c_font_auto_size \settrue\c_font_auto_size
1043
1044\let\lastfontidentifier\empty
1045
1046\def\v_font_identifier_basic{\??fontinstancebasic           \lastfontidentifier-\fontsize-\fontface}
1047\def\v_font_identifier_class{\??fontinstanceclass\fontclass-\lastfontidentifier-\fontsize-\fontface}
1048
1049\let\v_font_identifier_basic_saved\v_font_identifier_basic
1050\let\v_font_identifier_class_saved\v_font_identifier_class
1051
1052% \def\v_font_identifier_class{\??fontinstanceclass\fontclass-\lastfontidentifier-\fontstyle-\fontsize} % no \fontface
1053
1054\def\font_basics_define_font_without_parameters#identifier#2%
1055  {\c_font_feature_inheritance_mode\c_font_feature_inheritance_fontonly
1056   \edef\lastfontidentifier{#identifier}%
1057   \let\v_font_size_relative\v_font_rscale_default
1058   \let\v_font_size_absolute\fontbody
1059   \font_helpers_low_level_define{#2}\v_font_identifier_basic
1060   \csname\v_font_identifier_basic\endcsname
1061   \setfalse\c_font_auto_size
1062   \setfontcharacteristics
1063   \the\everyfontswitch
1064   \let\v_font_identifier_basic\v_font_identifier_basic_saved}
1065
1066\unexpanded\def\font_helpers_trigger#identifier% make a traced variant
1067  {\edef\lastfontidentifier{#identifier}%
1068   \ifcsname\v_font_identifier_class\endcsname
1069     % \writestatus{fonts}{trigger: reusing \v_font_identifier_class}%
1070     \expandafter\font_helpers_trigger_reuse
1071   \else
1072     % \writestatus{fonts}{trigger: defining \v_font_identifier_class}%
1073     \expandafter\font_helpers_trigger_define
1074   \fi}
1075
1076\def\font_helpers_trigger_define#relative#absolute#specification%
1077  {\def\v_font_size_relative{#relative}%
1078   \def\v_font_size_absolute{#absolute}%
1079   \font_helpers_low_level_define{#specification}\v_font_identifier_class
1080   \csname\v_font_identifier_class\endcsname
1081   \setfalse\c_font_auto_size
1082   \ifskipfontcharacteristics \else
1083     \setfontcharacteristics
1084     \the\everyfontswitch
1085   \fi
1086   \let\v_font_identifier_class\v_font_identifier_class_saved}
1087
1088\def\font_helpers_trigger_reuse#relative#absolute#specification%
1089  {\csname\v_font_identifier_class\endcsname
1090   \setfalse\c_font_auto_size
1091   \ifskipfontcharacteristics \else
1092     \setfontcharacteristics
1093     \the\everyfontswitch
1094   \fi
1095   \let\v_font_identifier_class\v_font_identifier_class_saved}
1096
1097%D \macros
1098%D   {currentfontbodyscale}
1099%D
1100%D Sometimes we need to have access to the font scale including the \type {a}||\type
1101%D {d} sizes. The next macro returns the current scaling factor. Take a look at
1102%D \type {cont-log.tex} for an example of its use.
1103
1104\installcorenamespace{fontenvironments}
1105
1106% \def\currentfontbodysize
1107%   {\ifcsname\??fontenvironments\s!default\somefontsize\endcsname
1108%      \csname\??fontenvironments\s!default\somefontsize\endcsname
1109%    \else
1110%      \somefontsize
1111%    \fi}
1112%
1113% \def\currentfontbodyscale
1114%   {\csname\??fontenvironments\s!default
1115%      \ifcsname\??fontenvironments\s!default\fontsize\endcsname  \fontsize  \else
1116%      \ifcsname\??fontenvironments\s!default\s!text  \endcsname  \s!text    \fi\fi
1117%    \endcsname}
1118
1119% \def\currentfontbodysize % gets number (the normal sa 1 etc)
1120%   {\ifcsname\??fontenvironments\fontclass\s!default\somefontsize\endcsname
1121%      \csname\??fontenvironments\fontclass\s!default\somefontsize\endcsname
1122%    \else\ifcsname\??fontenvironments\s!default\somefontsize\endcsname
1123%      \csname\??fontenvironments\s!default\somefontsize\endcsname
1124%    \else
1125%      \somefontsize
1126%    \fi\fi}
1127
1128\def\currentfontbodysize % gets number (the normal sa 1 etc)
1129  {\ifcsname\??fontenvironments\fontclass\s!default\somefontsize\endcsname
1130     \lastnamedcs
1131   \else\ifcsname\??fontenvironments\s!default\somefontsize\endcsname
1132     \lastnamedcs
1133   \else
1134     \somefontsize
1135   \fi\fi}
1136
1137\def\currentfontbodyscale % gets character (x xx a etc)
1138  {\csname\??fontenvironments
1139     \ifcsname\??fontenvironments\fontclass\s!default\fontsize\endcsname\fontclass\s!default\fontsize\else
1140     \ifcsname\??fontenvironments          \s!default\fontsize\endcsname          \s!default\fontsize\else
1141     \ifcsname\??fontenvironments\fontclass\s!default\s!text  \endcsname\fontclass\s!default\s!text  \else
1142     \ifcsname\??fontenvironments          \s!default\s!text  \endcsname          \s!default\s!text  \else
1143                                                                                  \s!default         \fi\fi\fi\fi
1144   \endcsname}
1145
1146\def\font_currentfontbodyscale % gets character (x xx a etc)
1147  {\ifcsname\??fontenvironments\fontclass\s!default\fontsize\endcsname\lastnamedcs\else
1148   \ifcsname\??fontenvironments          \s!default\fontsize\endcsname\lastnamedcs\else
1149   \ifcsname\??fontenvironments\fontclass\s!default\s!text  \endcsname\lastnamedcs\else
1150   \ifcsname\??fontenvironments          \s!default\s!text  \endcsname\lastnamedcs\else
1151     \csname\??fontenvironments          \s!default         \endcsname            \fi\fi\fi\fi}
1152
1153\def\currentfontscale % used in default definition
1154  {\csname\??fontenvironments
1155     \ifcsname\??fontenvironments\fontclass\s!default\xfontsize\endcsname\fontclass\s!default\fontsize\else
1156     \ifcsname\??fontenvironments          \s!default\xfontsize\endcsname          \s!default\fontsize\else
1157     \ifcsname\??fontenvironments\fontclass\s!default\s!text   \endcsname\fontclass\s!default\s!text  \else
1158     \ifcsname\??fontenvironments          \s!default\s!text   \endcsname          \s!default\s!text  \else
1159                                                                                   \s!default         \fi\fi\fi\fi
1160   \endcsname}
1161
1162\def\font_currentfontscale % used in default definition
1163  {\ifcsname\??fontenvironments\fontclass\s!default\xfontsize\endcsname\lastnamedcs\else
1164   \ifcsname\??fontenvironments          \s!default\xfontsize\endcsname\lastnamedcs\else
1165   \ifcsname\??fontenvironments\fontclass\s!default\s!text   \endcsname\lastnamedcs\else
1166   \ifcsname\??fontenvironments          \s!default\s!text   \endcsname\lastnamedcs\else
1167     \csname\??fontenvironments          \s!default          \endcsname            \fi\fi\fi\fi}
1168
1169\setvalue{\??fontenvironments\s!default}{1}
1170
1171%D In the following macros we use \type {\currentxfontsize} to hold the current
1172%D x||size of the font. This enables us to support for instance \type {\sl} inside a
1173%D \type {\tx} switch.
1174
1175\newconstant\currentxfontsize
1176
1177\def\xfontsize{\ifcase\currentxfontsize\fontsize\or\s!x\else\s!xx\fi}
1178
1179%D Now we enter the area of font switching. The switching mechanism has to take care
1180%D of several situations, like:
1181%D
1182%D \startitemize[packed]
1183%D \item changing the overal document fonts (including margins, headers and footers)
1184%D \item changing local fonts (only the running text)
1185%D \item smaller and even more smaller alternatives (super- and subscripts)
1186%D \stopitemize
1187%D
1188%D \TEX\ offers a powerfull family mechanism for super- and subscripts in math mode.
1189%D In text mode however, we don't use families for the smaller alternatives, and
1190%D therefore have to take care of it otherwise.
1191%D
1192%D \macros
1193%D   {definebodyfontenvironment,setupbodyfontenvironment}
1194%D
1195%D The relationship between the several sizes of a font, is
1196%D defined by:
1197%D
1198%D \showsetup{definebodyfontenvironment}
1199%D
1200%D Later on we will see how these parameters are used, so for the moment we stick
1201%D with an example:
1202%D
1203%D \starttyping
1204%D \definebodyfontenvironment
1205%D   [12pt]
1206%D   [        text=12pt,
1207%D          script=9pt,
1208%D    scriptscript=7pt,
1209%D               x=10pt,
1210%D              xx=8pt,
1211%D             big=12pt,
1212%D           small=10pt]
1213%D \stoptyping
1214%D
1215%D The first argument specifies the bodyfont size to which the settings apply. All
1216%D second parameters are specified in dimensions and tell us more about related
1217%D sizes.
1218%D
1219%D Afterwards, one can change values with
1220%D
1221%D \showsetup{setupbodyfontenvironment}
1222%D
1223%D When instead of a size the keyword \type{unknown} is
1224%D passed, fractions (relations) are used instead of fixed
1225%D sizes.
1226
1227%D {\bf Remark:} We need to cover the following cases, otherwise users can get
1228%D confused:
1229%D
1230%D \starttyping
1231%D \setupbodyfont[23pt]
1232%D
1233%D \definebodyfontenvironment[23pt]
1234%D \setupbodyfont[23pt]
1235%D
1236%D \definebodyfontenvironment[23pt]
1237%D \definebodyfont[23pt][rm,ss,tt][default]
1238%D \setupbodyfont[23pt]
1239%D \stoptyping
1240%D
1241%D Beware: while some font defs can be global, the bodyfont environment checks
1242%D local. This means that multiple local checks resulting in definitions are not
1243%D that efficient. So, apart from an occasional switch, one should define an
1244%D environment at the outer level.
1245
1246% \definebodyfontenvironment[33pt]
1247% \definebodyfontenvironment[dejavu][default][1=.5]
1248% \definebodyfontenvironment[dejavu][default][x=1.2]
1249% \definebodyfontenvironment[dejavu][default][a=5]
1250% \definebodyfontenvironment[dejavu][33pt][x=100pt]
1251
1252% the lookup order is:
1253%
1254% [class] [dimension] [parameters]
1255% [class] [default]   [parameters] % factors
1256%         [dimension] [parameters]
1257%         [default]   [parameters] % factors
1258%
1259% with defaults providing factors
1260
1261% todo: class:size
1262% todo: make assignments global
1263
1264\letvalue\??fontenvironments\empty % so we default to empty
1265
1266\def\bodyfontvariable#parameter%
1267  {\csname\??fontenvironments
1268     \ifcsname\??fontenvironments\fontclass\normalizedbodyfontsize#parameter\endcsname\fontclass\normalizedbodyfontsize#parameter\else
1269     \ifcsname\??fontenvironments\fontclass                       #parameter\endcsname\fontclass                       #parameter\else
1270     \ifcsname\??fontenvironments          \normalizedbodyfontsize#parameter\endcsname          \normalizedbodyfontsize#parameter\else
1271     \ifcsname\??fontenvironments\s!default                       #parameter\endcsname\s!default                       #parameter\fi\fi\fi\fi
1272   \endcsname}
1273
1274\def\font_bodyfontvariable#parameter%
1275  {\ifcsname\??fontenvironments\fontclass\normalizedbodyfontsize#parameter\endcsname\lastnamedcs\else
1276   \ifcsname\??fontenvironments\fontclass                       #parameter\endcsname\lastnamedcs\else
1277   \ifcsname\??fontenvironments          \normalizedbodyfontsize#parameter\endcsname\lastnamedcs\else
1278   \ifcsname\??fontenvironments\s!default                       #parameter\endcsname\lastnamedcs\fi\fi\fi\fi}
1279
1280\def\bodyfontsizevariable#size#parameter%
1281  {\csname\??fontenvironments
1282     \ifcsname\??fontenvironments\fontclass#size#parameter\endcsname\fontclass#size#parameter\else
1283     \ifcsname\??fontenvironments\fontclass     #parameter\endcsname\fontclass     #parameter\else
1284     \ifcsname\??fontenvironments          #size#parameter\endcsname          #size#parameter\else
1285     \ifcsname\??fontenvironments\s!default     #parameter\endcsname\s!default     #parameter\fi\fi\fi\fi
1286   \endcsname}
1287
1288\def\font_bodyfontsizevariable#size#parameter%
1289  {\ifcsname\??fontenvironments\fontclass#size#parameter\endcsname\lastnamedcs\else
1290   \ifcsname\??fontenvironments\fontclass     #parameter\endcsname\lastnamedcs\else
1291   \ifcsname\??fontenvironments          #size#parameter\endcsname\lastnamedcs\else
1292   \ifcsname\??fontenvironments\s!default     #parameter\endcsname\lastnamedcs\fi\fi\fi\fi}
1293
1294\def\bodyfontinterlinespace{\bodyfontvariable\c!interlinespace} % used elsewhere
1295
1296% \def\bodyfontdimension#class#size#parameter#body%
1297%   {\the\dimexpr
1298%      \ifcsname\??fontenvironments     #class#size#parameter\endcsname
1299%        \csname\??fontenvironments     #class#size#parameter\endcsname                   \else
1300%      \ifcsname\??fontenvironments#class\s!default#parameter\endcsname
1301%        \csname\??fontenvironments#class\s!default#parameter\endcsname\dimexpr#body\relax\else     % factor
1302%      \ifcsname\??fontenvironments           #size#parameter\endcsname
1303%        \csname\??fontenvironments           #size#parameter\endcsname                   \else
1304%        \csname\??fontenvironments      \s!default#parameter\endcsname\dimexpr#body\relax\fi\fi\fi % factor
1305%    \relax}
1306
1307\def\bodyfontdimension#class#size#parameter#body%
1308  {\the\dimexpr
1309     \ifcsname\??fontenvironments     #class#size#parameter\endcsname \lastnamedcs                   \else
1310     \ifcsname\??fontenvironments#class\s!default#parameter\endcsname \lastnamedcs\dimexpr#body\relax\else     % factor
1311     \ifcsname\??fontenvironments           #size#parameter\endcsname \lastnamedcs                   \else
1312                                                                      \lastnamedcs\dimexpr#body\relax\fi\fi\fi % factor
1313   \relax}
1314
1315\unexpanded\def\definebodyfontenvironment
1316  {\dotripleempty\font_basics_define_body_font_environment}
1317
1318\let\setupbodyfontenvironment\definebodyfontenvironment
1319
1320\installcorenamespace{fontenvironmentknown}
1321
1322\def\font_helpers_register_environment#class#body%
1323  {\expandafter\let\csname\??fontenvironmentknown#class#body\endcsname\empty}
1324
1325\newmacro\m_font_body
1326\newmacro\m_font_body_normalized
1327
1328\def\font_basics_define_body_font_environment
1329  {\ifthirdargument
1330     \singleexpandafter\font_basics_define_body_font_environment_class
1331   \else\ifsecondargument
1332     \doubleexpandafter\font_basics_define_body_font_environment_empty
1333   \else
1334     \doubleexpandafter\font_basics_define_body_font_environment_unset
1335   \fi\fi}
1336
1337%D First we handle the class specific case. Beware: you can change values before
1338%D a bodyfont is loaded but changing them afterwards can be sort of tricky as
1339%D values are not consulted afterwards.
1340
1341\def\processbodyfontenvironmentlist#1% no \unexpanded as then we cannot use it in alignments
1342  {\clf_processbodyfontsizes{\strippedcsname#1}}
1343
1344\def\bodyfontenvironmentlist
1345  {\clf_getbodyfontsizes}
1346
1347\def\font_basics_define_body_font_environment_class[#class][#body][#settings]%
1348  {\edef\m_font_body{#body}%
1349   \ifx\m_font_body\s!default
1350     % these are the last resort within a class
1351     \getrawparameters[\??fontenvironments#class\s!default][#settings]%
1352   \else
1353     \normalizebodyfontsize\m_font_body_normalized\m_font_body
1354     \font_basics_define_body_font_environment_size[#class][\m_font_body_normalized][#settings]%
1355     \clf_registerbodyfontsize{\m_font_body_normalized}%
1356   \fi}
1357
1358%D The empty case uses the same code but needs to ignore the current class settings
1359%D (just to be sure, as it's not really needed).
1360
1361\def\font_basics_define_body_font_environment_empty[#body][#settings][#dummy]%
1362  {\push_macro_fontclass
1363   \let\fontclass\empty
1364   \font_basics_define_body_font_environment_class[][#body][#settings]%
1365   \pop_macro_fontclass}
1366
1367\def\font_basics_define_body_font_environment_unset[#body][#dummya][#dummyb]%
1368  {\push_macro_fontclass
1369   \let\fontclass\empty
1370   \font_basics_define_body_font_environment_class[][#body][]%
1371   \pop_macro_fontclass}
1372
1373%D We don't check too soon as we can refer to later definitions.
1374
1375\newconditional\c_font_defining_environment_state % controls messages
1376
1377\def\font_basics_define_body_font_environment_size[#class][#normalizedbody][#settings]% normalized body
1378  {\getrawparameters[\??fontenvironments#class#normalizedbody][#settings]%
1379   \ifcsname\??fontenvironmentknown#class#normalizedbody\endcsname
1380     % environment and size already defined
1381   \else\ifproductionrun
1382     \push_macro_fontclass
1383     \edef\fontclass{#class}%
1384     \font_helpers_register_environment{#class}{#normalizedbody}%
1385     \settrue\c_font_defining_environment_state
1386     \font_helpers_define_unknown_font{#normalizedbody}% current class
1387     \setfalse\c_font_defining_environment_state
1388     \pop_macro_fontclass
1389   \fi\fi
1390   \font_helpers_register_fontbody{#normalizedbody}}
1391
1392%D Checking
1393
1394\def\font_helpers_check_bodyfont_environment#normalizedbody#body%
1395  {\ifcsname\??fontenvironmentknown\fontclass#normalizedbody\endcsname
1396     % already defined
1397   \else
1398     \font_helpers_check_bodyfont_environment_indeed{#normalizedbody}{#body}%
1399   \fi}
1400
1401\def\font_helpers_check_bodyfont_environment_indeed#normalizedbody#body%
1402  {\font_helpers_register_environment\fontclass{#normalizedbody}%
1403   \ifcsname\??fontbodyknown#normalizedbody\endcsname
1404   \else
1405     \font_helpers_define_unknown_font{#normalizedbody}%
1406   \fi}
1407
1408%D We default all parameters to the main bodyfont size, so the next setup is valid
1409%D too:
1410%D
1411%D \starttyping
1412%D \definebodyfontenvironment[24pt]
1413%D \stoptyping
1414%D
1415%D All parameters can be redefined when needed, so one doesnot have to stick to the
1416%D default ones.
1417
1418%D \macros
1419%D   {definebodyfont}
1420%D
1421%D The next step in defining a bodyfont involves the actual font files, which can be
1422%D recognized by their extension \type {tfm}. Installing those file is often beyond
1423%D the scope of the user and up to the system administrator.
1424%D
1425%D \showsetup{definebodyfont}
1426%D
1427%D This commands takes three arguments: a (series of) bodyfont size(s), the style
1428%D group to which the definitions belong, and an alternative, as specified by the
1429%D \TEX\ (math) families, extended with~a, b~\unknown.
1430%D
1431%D We show two examples, that show all the alternative scaling options. The \type
1432%D {\tfa} alternatives can be extended with \type {\bfa}, \type {\slb}, etc. or even
1433%D \type {e} and higher alternatives. The magic scaled values are derived from plain
1434%D \TEX's \type {\magstep}:
1435%D
1436%D \starttyping
1437%D \definebodyfont [12pt] [rm]
1438%D   [tf=cmr12,
1439%D    bf=cmbx12,
1440%D    it=cmti12,
1441%D    sl=cmsl12,
1442%D    bi=cmbxti10 at 12pt,
1443%D    bs=cmbxsl10 at 12pt,
1444%D   tfa=cmr12    scaled 1.200,
1445%D   tfb=cmr12    scaled 1.440,
1446%D   tfc=cmr12    scaled 1.728,
1447%D   tfd=cmr12    scaled 2.074,
1448%D    sc=cmcsc10  at 12pt]
1449%D
1450%D \definebodyfont [12pt,11pt,10pt,9pt,8pt] [rm]
1451%D   [tf=lbr  sa 1,
1452%D    bf=lbd  sa 1,
1453%D    it=lbi  sa 1,
1454%D    sl=lbsl sa 1,
1455%D    bi=lbdi sa 1,
1456%D    bs=lbdi sa 1,
1457%D   tfa=lbr  sa 1.200,
1458%D   tfb=lbr  sa 1.440,
1459%D   tfc=lbr  sa 1.728,
1460%D   tfd=lbr  sa 2.074,
1461%D    sc=lbr  sa 0.833]
1462%D \stoptyping
1463%D
1464%D The second example shows that we can define more sizes at once. The main
1465%D difference between these examples is that the Computer Modern Roman come in many
1466%D design sizes. This means that there we cannot define them in bulk using \type
1467%D {sa}. Instead of \type {rm} (roman) one can define \type {ss} (sans serif), \type
1468%D {tt} (teletype), \type {hw} (hand written), \type {cg} (calygraphic) and whatever
1469%D styles.
1470%D
1471%D The first argument may be a comma separated list. This, combined with
1472%D specifications using \type{sa} can save a lot of typing. Although all arguments
1473%D should be specified, we treat the second argument as optional.
1474%D
1475%D Defining a bodyfont involves two actions: defining the specific style related
1476%D alternatives, like \type {\rma}, \type {\bfa} and \type {\rmsla}, and storing the
1477%D definitions of their bodyfont size related fonts. The first step is bodyfont
1478%D independant but executed every time. This permits user definitions like \type
1479%D {\tfw} or \type {\bfq} for real large alternatives.
1480%D
1481%D If we move design size info to the lfg file (after all only lm has design sizes)
1482%D we can get rid of much code .. 2012 or so.
1483
1484\installcorenamespace{fontdefinitions}
1485
1486% [class] [name]      [rm,ss] [settings]
1487% [class] [10pt,11pt] [rm,ss] [settings]
1488% [class] [10pt,11pt] [rm,ss] [name]
1489
1490% [class] [name]              [settings]   == [name]      [rm] [settings]
1491% [class] [10pt,11pt]         [settings]   == [name]      [rm] [settings]
1492% [class] [10pt,11pt]         [name]       == [10pt,11pt] [rm] [name]
1493
1494\unexpanded\def\definebodyfont
1495  {\doquadrupleempty\font_basics_define_body_font}
1496
1497\def\font_basics_define_body_font[#1][#2][#3][#4]%
1498  {\iffourthargument
1499     \processcommacommand[#1]{\font_basics_define_body_font_class_given[#2][#3][#4]}%
1500   \else
1501     \font_basics_define_body_font_class_known[#1][#2][#3]%
1502   \fi}
1503
1504\def\font_basics_define_body_font_class_given[#1][#2][#3]#4%
1505  {\push_macro_fontclass
1506   \doifelse{#4}\s!default
1507     {\let\fontclass\empty}
1508     {\def\fontclass{#4}}%
1509   \definebodyfont[#1][#2][#3]%
1510   \pop_macro_fontclass}
1511
1512\def\font_basics_define_body_font_class_known
1513  {\ifthirdargument
1514     \singleexpandafter\font_basics_define_body_font_a
1515   \else\ifsecondargument
1516     \doubleexpandafter\font_basics_define_body_font_b
1517   \else
1518     \doubleexpandafter\font_basics_define_body_font_c
1519   \fi\fi}
1520
1521\unexpanded\def\font_basics_define_body_font_b[#whatever][#specification][#dummy]% body|identifier defs|identifier
1522  {\font_basics_define_body_font_a[#whatever][\s!rm][#specification]}
1523
1524\unexpanded\def\font_basics_define_body_font_c[#whatever][#dummya][#dummyb]% body|identifier
1525  {\font_basics_define_body_font_a[#whatever][\s!rm][]}
1526
1527\unexpanded\def\font_basics_define_body_font_a[#whatever]%
1528  {\doifelsenumber{#whatever}%
1529     \font_basics_define_body_font_body
1530     \font_basics_define_body_font_name
1531     [#whatever]}
1532
1533% \unexpanded\def\font_basics_define_body_font_body[#body][#style][#specification]%
1534%   {\doifelseassignment{#specification}
1535%      \font_basics_define_body_font_body_assignment
1536%      \font_basics_define_body_font_body_identifier
1537%      [#body][#style][#specification]}%
1538
1539\unexpanded\def\font_basics_define_body_font_body[#body][#style][#specification]%
1540  {\ifcondition\validassignment{#specification}%
1541     \expandafter\font_basics_define_body_font_body_assignment
1542   \else
1543     \expandafter\font_basics_define_body_font_body_identifier
1544   \fi
1545   [#body][#style][#specification]}%
1546
1547% \unexpanded\def\font_basics_define_body_font_name[#name][#style][#specification]%
1548%   {\doifelseassignment{#specification}
1549%      \font_basics_define_body_font_name_assignment
1550%      \font_basics_define_body_font_name_identifier
1551%      [#name][#style][#specification]}%
1552
1553\unexpanded\def\font_basics_define_body_font_name[#name][#style][#specification]%
1554  {\ifcondition\validassignment{#specification}%
1555     \expandafter\font_basics_define_body_font_name_assignment
1556   \else
1557     \expandafter\font_basics_define_body_font_name_identifier
1558   \fi
1559   [#name][#style][#specification]}%
1560
1561\unexpanded\def\font_basics_define_body_font_body_assignment[#bodylist][#stylelist][#assignments]%
1562  {\processcommalist[#bodylist]{\font_basics_define_body_font_body_assignment_a{#stylelist}{#assignments}}}
1563
1564\unexpanded\def\font_basics_define_body_font_body_assignment_a#stylelist#assignments#body%
1565  {\normalizebodyfontsize\m_font_asked_body{#body}%
1566   % normally we define quite a lot in advance, i.e global defs
1567   \font_helpers_check_bodyfont_environment\m_font_asked_body\m_font_asked_body % !!
1568   \processcommalist[#stylelist]{\font_basics_define_body_font_body_assignment_b{#assignments}}}
1569
1570\unexpanded\def\font_basics_define_body_font_body_assignment_b#assignments#style%
1571  {\edef\m_font_asked_style{#style}%
1572   \processcommalist[#assignments]\font_basics_define_body_font_defs}
1573
1574\unexpanded\def\font_basics_define_body_font_defs
1575  {\ifx\fontclass\empty
1576     \expandafter\font_basics_define_body_font_defs_nop
1577   \else
1578     \expandafter\font_basics_define_body_font_defs_yes
1579   \fi}
1580
1581\unexpanded\def\font_basics_define_body_font_defs_yes_normal#assignment%
1582  {\ifx\m_font_asked_style\s!mm
1583     \expandafter\font_basics_define_body_font_yes_mm
1584   \else
1585     \expandafter\font_basics_define_body_font_yes_xx
1586   \fi[#assignment]}
1587
1588\unexpanded\def\font_basics_define_body_font_defs_nop_normal#assignment%
1589  {\ifx\m_font_asked_style\s!mm
1590     \expandafter\font_basics_define_body_font_nop_mm
1591   \else
1592     \expandafter\font_basics_define_body_font_nop_xx
1593   \fi[#assignment]}
1594
1595\unexpanded\def\font_basics_define_body_font_defs_yes_traced#assignment%
1596  {\writestatus\m!fonts{[\fontclass] [\m_font_asked_body] [\m_font_asked_style] [#assignment]}%
1597   \ifx\m_font_asked_style\s!mm
1598     \expandafter\font_basics_define_body_font_yes_mm
1599   \else
1600     \expandafter\font_basics_define_body_font_yes_xx
1601   \fi[#assignment]}
1602
1603\unexpanded\def\font_basics_define_body_font_defs_nop_traced#assignment%
1604  {\writestatus\m!fonts{[\fontclass] [\m_font_asked_body] [\m_font_asked_style] [#assignment]}%
1605   \ifx\m_font_asked_style\s!mm
1606     \expandafter\font_basics_define_body_font_nop_mm
1607   \else
1608     \expandafter\font_basics_define_body_font_nop_xx
1609   \fi[#assignment]}
1610
1611\let\font_basics_define_body_font_defs_yes\font_basics_define_body_font_defs_yes_normal
1612\let\font_basics_define_body_font_defs_nop\font_basics_define_body_font_defs_nop_normal
1613
1614\appendtoks
1615    \let\font_basics_define_body_font_defs_yes\font_basics_define_body_font_defs_yes_traced
1616    \let\font_basics_define_body_font_defs_nop\font_basics_define_body_font_defs_nop_traced
1617\to \t_font_tracers_definitions
1618
1619%D We split into two characters (first part of spec) and the rest: the first two are
1620%D the style and the rest is a size, although in practice one will seldom define the
1621%D size directly. We might even drop that as it gives faster code.
1622
1623\unexpanded\def\font_basics_define_body_font_nop_xx[#one#two#rest=#value]% local
1624  {\ifcsname\m_font_asked_style#one#two#rest\endcsname\else\font_basics_check_fontname_combination\m_font_asked_style{#one#two}{#rest}\fi
1625   \expandafter\let\csname\??fontinstanceclass\m_font_asked_body-\m_font_asked_style-#one#two-#rest-0\endcsname\undefined
1626   \unexpanded\expandafter\normaledef\csname\??fontinstanceready\m_font_asked_body-\m_font_asked_style-#one#two-#rest-0\endcsname
1627     {\font_helpers_trigger{\m_font_asked_body-\m_font_asked_style-#one#two#rest}{\noexpand\font_rscale_xx{\m_font_asked_style}}{\m_font_asked_body}{\normalunexpanded{#value}}}%
1628   \expandafter\let\csname\??fontinstanceclass\m_font_asked_body-\m_font_asked_style-#one#two-#rest-4\endcsname\undefined
1629   \unexpanded\expandafter\normaledef\csname\??fontinstanceready\m_font_asked_body-\m_font_asked_style-#one#two-#rest-4\endcsname
1630     {\font_helpers_trigger{\m_font_asked_body-\m_font_asked_style-#one#two#rest}{\noexpand\font_rscale_xx{\m_font_asked_style}}{\m_font_asked_body}{\normalunexpanded{#value}}}%
1631   \expandafter\let\csname\??fontinstanceclass\m_font_asked_body-\m_font_asked_style-#one#two-#rest-5\endcsname\undefined
1632   \unexpanded\expandafter\normaledef\csname\??fontinstanceready\m_font_asked_body-\m_font_asked_style-#one#two-#rest-5\endcsname
1633     {\font_helpers_trigger{\m_font_asked_body-\m_font_asked_style-#one#two#rest}{\noexpand\font_rscale_xx{\m_font_asked_style}}{\m_font_asked_body}{\normalunexpanded{#value}}}%
1634  }
1635
1636\unexpanded\def\font_basics_define_body_font_yes_xx[#one#two#rest=#value]% global
1637  {\ifcsname\m_font_asked_style#one#two#rest\endcsname\else\font_basics_check_fontname_combination\m_font_asked_style{#one#two}{#rest}\fi
1638   \expandafter\glet\csname\??fontinstanceclass\fontclass-\m_font_asked_body-\m_font_asked_style-#one#two-#rest-1\endcsname\undefined
1639   \unexpanded\expandafter\normalxdef\csname\??fontinstanceready\fontclass-\m_font_asked_body-\m_font_asked_style-#one#two-#rest-0\endcsname
1640     {\font_helpers_trigger{\m_font_asked_body-\m_font_asked_style-#one#two#rest-0}{\number\p_font_rscale}{\m_font_asked_body}{\normalunexpanded{#value}}}%
1641   \expandafter\glet\csname\??fontinstanceclass\fontclass-\m_font_asked_body-\m_font_asked_style-#one#two-#rest-2\endcsname\undefined
1642   \unexpanded\expandafter\normalxdef\csname\??fontinstanceready\fontclass-\m_font_asked_body-\m_font_asked_style-#one#two-#rest-4\endcsname
1643     {\font_helpers_trigger{\m_font_asked_body-\m_font_asked_style-#one#two#rest-4}{\number\p_font_rscale}{\m_font_asked_body}{\normalunexpanded{#value}}}%
1644   \expandafter\glet\csname\??fontinstanceclass\fontclass-\m_font_asked_body-\m_font_asked_style-#one#two-#rest-3\endcsname\undefined
1645   \unexpanded\expandafter\normalxdef\csname\??fontinstanceready\fontclass-\m_font_asked_body-\m_font_asked_style-#one#two-#rest-5\endcsname
1646     {\font_helpers_trigger{\m_font_asked_body-\m_font_asked_style-#one#two#rest-5}{\number\p_font_rscale}{\m_font_asked_body}{\normalunexpanded{#value}}}%
1647  }
1648
1649% \writestatus{fonts}{define \m_asked_style\space yes: {\expandafter\meaning\csname\fontclass\m_font_asked_body\m_font_asked_style#one#two#rest\endcsname}
1650
1651%D Here the rest concerns rl or lr so in this case it is not a size specifier but
1652%D a directional one.
1653
1654\unexpanded\def\font_basics_define_body_font_nop_mm[#one#two#rest=#value]% local
1655  {%\ifcsname\s!mm\endcsname\else\font_basics_check_fontname_combination\s!mm{#one#two}{#rest}\fi
1656   \expandafter\let\csname\??fontinstanceclass\m_font_asked_body-\s!mm-#one#two#rest-1\endcsname\undefined
1657 % \expandafter\let\csname\??fontinstanceclass\m_font_asked_body-\s!mm-#one#two#rest-2\endcsname\undefined
1658 % \expandafter\let\csname\??fontinstanceclass\m_font_asked_body-\s!mm-#one#two#rest-3\endcsname\undefined
1659   \unexpanded\expandafter\normaledef\csname\??fontinstanceready\m_font_asked_body-\s!mm-#one#two#rest\endcsname
1660     {\font_helpers_trigger{\m_font_asked_body-\s!mm-#one#two#rest}{\noexpand\font_rscale_mm}{\m_font_asked_body}{\normalunexpanded{#value}}}%
1661  }
1662
1663% \writestatus{fonts}{define \m_asked_style\space nop: \expandafter\meaning\csname\m_font_asked_body\m_font_asked_style#one#two#rest\endcsname}%
1664
1665\unexpanded\def\font_basics_define_body_font_yes_mm[#one#two#rest=#value]% global
1666  {%\ifcsname\s!mm\endcsname\else\font_basics_check_fontname_combination\s!mm{#one#two}{#rest}\fi
1667   \expandafter\glet\csname\??fontinstanceclass\fontclass-\m_font_asked_body-\s!mm-#one#two#rest-1\endcsname\undefined
1668 % \expandafter\glet\csname\??fontinstanceclass\fontclass-\m_font_asked_body-\s!mm-#one#two#rest-2\endcsname\undefined
1669 % \expandafter\glet\csname\??fontinstanceclass\fontclass-\m_font_asked_body-\s!mm-#one#two#rest-3\endcsname\undefined
1670   \unexpanded\expandafter\normalxdef\csname\??fontinstanceready\fontclass-\m_font_asked_body-\s!mm-#one#two#rest\endcsname
1671     {\font_helpers_trigger{\m_font_asked_body-\s!mm-#one#two#rest}{\number\p_font_rscale}{\m_font_asked_body}{\normalunexpanded{#value}}}%
1672  }
1673
1674% \writestatus{fonts}{define \m_asked_style\space yes: \expandafter\meaning\csname\fontclass\m_font_asked_body\m_font_asked_style#one#two#rest\endcsname}%
1675
1676\unexpanded\def\font_basics_define_body_font_body_identifier[#bodylist][#stylelist][#name]%
1677  {\processcommalist[#bodylist]{\font_basics_define_body_font_body_identifier_a{#stylelist}{#name}}}
1678
1679\unexpanded\def\font_basics_define_body_font_body_identifier_a#stylelist#name#body%
1680  {\normalizebodyfontsize\m_font_asked_body{#body}%
1681   \font_helpers_check_bodyfont_environment\m_font_asked_body\m_font_asked_body % !!
1682   \processcommalist[#stylelist]{\font_basics_define_body_font_body_identifier_b{#name}}}
1683
1684\unexpanded\def\font_basics_define_body_font_body_identifier_b#name#style%
1685  {\edef\m_font_asked_style{#style}%
1686  %\writestatus\m!fonts{[\fontclass] [\m_font_asked_body] [\m_font_asked_style] => [#name]}%
1687   \csname\??fontdefinitions#name:\m_font_asked_style\endcsname} % no checking
1688
1689\unexpanded\def\font_basics_define_body_font_name_assignment[#name][#stylelist][#assignments]%
1690  {\processcommalist[#stylelist]{\font_basics_define_body_font_name_assignment_a{#name}{#assignments}}}
1691
1692\unexpanded\def\font_basics_define_body_font_name_assignment_a#name#assignments#style%
1693  {%\writestatus\m!fonts{[#name:#style] => [#assignments]}%
1694   \setevalue{\??fontdefinitions#name:#style}{\font_basics_define_body_font_default{#assignments}}}
1695
1696\unexpanded\def\font_basics_define_body_font_name_identifier[#name][#stylelist][#identifier]%
1697  {\processcommalist[#stylelist]{\font_basics_define_body_font_name_identifier_a{#name}{#identifier}}}
1698
1699\unexpanded\def\font_basics_define_body_font_name_identifier_a#name#identifier#style%
1700  {%\writestatus\m!fonts{[#name:#style] => [##identifier:#style]}%
1701   \ifcsname\??fontdefinitions#name:#style\endcsname
1702     \expandafter\let\csname\??fontdefinitions#name:#style\expandafter\endcsname\csname\??fontdefinitions#identifier:#style\endcsname
1703   \else
1704     \expandafter\def\csname\??fontdefinitions#name:#style\endcsname{\csname\??fontdefinitions#identifier:#style\endcsname}%
1705   \fi}
1706
1707%D The unknown:
1708
1709\newconditional\c_font_defining_unknown
1710\newconditional\c_font_defining_state
1711
1712\unexpanded\def\font_helpers_define_unknown_font#body% one level only
1713  {\font_helpers_register_fontbody{#body}% prevents loop, can go
1714   \setfalse\c_font_defining_state
1715   \font_helpers_process_relative_size_list{\font_helpers_define_unknown_check_sizes{#body}}%
1716   \ifconditional\c_font_defining_state
1717     \setfalse\c_font_defining_state
1718     \font_helpers_process_style_list{\font_helpers_define_unknown_check_definitions{#body}}%
1719     \ifconditional\c_font_defining_state
1720       \ifconditional\c_font_defining_environment_state\else
1721        %\showmessage\m!fonts{14}{#body}% main
1722         \clf_registerunknownbodysize{#body}%
1723       \fi
1724       \setfalse\c_font_defining_state
1725       \font_helpers_register_fontbody{#body}%
1726       % needed ?
1727       \ifconditional\c_font_defining_unknown
1728       \else
1729         \settrue\c_font_defining_unknown
1730         \font_helpers_process_relative_size_list{\font_helpers_define_unknown_check_relatives{#body}}%
1731         \setfalse\c_font_defining_unknown
1732       \fi
1733     \fi
1734   \fi}
1735
1736\def\font_helpers_define_unknown_check_sizes#body#relativesize%
1737  {\ifcsname\??fontenvironments\s!default#relativesize\endcsname % fontclass ?
1738     \expandafter\normalizebodyfontsize\csname\??fontenvironments#body#relativesize\endcsname{\csname\??fontenvironments\s!default#relativesize\endcsname\dimexpr#body\relax}%
1739     \settrue\c_font_defining_state
1740   \fi}
1741
1742\def\font_helpers_define_unknown_check_definitions#body#style%
1743  {\ifcsname\??fontdefinitions\s!default:#style\endcsname
1744     \edef\m_font_asked_body{#body}%
1745     \edef\m_font_asked_style{#style}%
1746     \lastnamedcs
1747     \settrue\c_font_defining_state
1748   \fi}
1749
1750% \def\font_helpers_define_unknown_check_relatives#body#relativesize%
1751%   {\ifcsname\??fontbodyknown\csname\??fontenvironments#body#relativesize\endcsname\endcsname \else
1752%      % how \lastnamedcs here
1753%      \expandafter\font_helpers_define_unknown_font\csname\??fontenvironments#body#relativesize\endcsname
1754%      \settrue\c_font_defining_state
1755%    \fi}
1756
1757\def\font_helpers_define_unknown_check_relatives#body#relativesize%
1758  {\ifcsname\??fontbodyknown\csname\??fontenvironments#body#relativesize\endcsname\endcsname \else
1759     \expandafter\font_helpers_define_unknown_font\csname\??fontenvironments#body#relativesize\endcsname
1760     \settrue\c_font_defining_state
1761   \fi}
1762
1763\unexpanded\def\font_basics_define_body_font_default#assignments%
1764  {\font_helpers_check_relative_font_size\m_font_asked_style % still needed here?
1765   \ifcsname\m_font_asked_style\endcsname\else
1766     \normalexpanded{\definefontstyle[\m_font_asked_style][\m_font_asked_style]}%
1767   \fi
1768   \processcommalist[#assignments]\font_basics_define_body_font_defs
1769   \let\p_font_rscale\v_font_rscale_default}
1770
1771%D These macros show that quite some definitions take place. Fonts are not loaded
1772%D yet! This means that at format generation time, no font files are present.
1773
1774% \unexpanded\def\font_basics_switch_points#body%
1775%   {\ifcsname\??fontbodyknown#body\endcsname \else
1776%      % we need to check the relative sizes for this body
1777%      \font_helpers_define_unknown_font{#body}%
1778%    \fi%
1779%    \ifcsname\??fontbodyknown#body\endcsname % always true now
1780%      \font_basics_complete_switch{#body}%
1781%      \localbodyfontsize#body\relax
1782%      \normalizebodyfontsize\normalizedbodyfontsize\localbodyfontsize
1783%      \font_helpers_check_bodyfont_environment\normalizedbodyfontsize\normalizedbodyfontsize % !!
1784%    \else
1785%      \showmessage\m!fonts4{#body}%
1786%    \fi}
1787
1788\unexpanded\def\font_basics_switch_points#body%
1789  {\ifcsname\??fontbodyknown#body\endcsname \else
1790     % we need to check the relative sizes for this body
1791     \font_helpers_define_unknown_font{#body}%
1792   \fi%
1793   \ifcsname\??fontbodyknown#body\endcsname % always true now
1794     \font_basics_complete_switch{#body}%
1795     \localbodyfontsize#body\relax
1796     \normalizebodyfontsize\normalizedbodyfontsize\localbodyfontsize
1797     \font_helpers_check_bodyfont_environment\normalizedbodyfontsize\normalizedbodyfontsize % !!
1798   \else
1799     \showmessage\m!fonts4{#body}%
1800   \fi}
1801
1802\unexpanded\def\font_basics_switch_style#style%
1803  {\ifcsname\??fontstyle#style\endcsname
1804     \lastnamedcs
1805     \edef\fontstyle{#style}%
1806     \ifmmode\mr\fi % in order to be compatible with \rm in math mode
1807     % \the\everybodyfont % cleaner, in setting size as well as style
1808   \else
1809     \showmessage\m!fonts5{#style}%
1810   \fi}
1811
1812%D Here comes the main font switching macros. These macros handle changes in size as
1813%D well as returning to the global bodyfont size.
1814
1815\ifdefined\font_preloads_at_definition \else \let\font_preloads_at_definition\relax \fi
1816
1817\def\font_helpers_set_font#method#specification%
1818  {\edef\m_font_specification{#specification}%
1819   \ifx\m_font_specification\empty \else
1820     \ifx\m_font_specification\v!global % we can have all kind of presets
1821       \restoreglobalbodyfont
1822     \else
1823       \processcommacommand[\m_font_specification]{\font_helpers_set_font_check_size}%
1824       \processcommacommand[\m_font_specification]{\font_helpers_set_font_set_font{#method}}%
1825       \ifproductionrun
1826         \font_preloads_at_definition
1827         \font_basics_switch_points\normalizedbodyfontsize
1828         \font_basics_switch_style\fontstyle
1829         \ifx\defaultfontclass\empty
1830           \let\defaultfontclass\fontclass
1831         \fi
1832       \fi
1833     \fi
1834     \currentxfontsize\zerocount
1835   \fi}
1836
1837\def\font_helpers_set_font_check_size#option%
1838  {\doifelsenumber{#option}{\font_helpers_check_bodyfont_environment{#option}{#option}}\donothing}
1839
1840\def\font_helpers_set_font_set_font#method#option% method=1: set, method=2: switch
1841  {\doifsomething{#option}{\font_helpers_set_font_set_font_option{#method}{#option}}}
1842
1843\def\font_helpers_set_font_set_font_option#method#option%
1844  {\doifelsenumber{#option}%
1845     \font_helpers_set_font_set_font_option_body
1846     \font_helpers_set_font_set_font_option_keyword
1847     {#method}{#option}{#option}}
1848
1849\newmacro\m_font_keyword
1850
1851\unexpanded\def\font_helpers_set_font_set_font_option_keyword#method#keyword#message%
1852  {\edef\m_font_keyword{#keyword}%
1853   \ifcsname\??fontenvironments\normalizedbodyfontsize\m_font_keyword\endcsname
1854     \edef\m_font_step{\font_bodyfontvariable\m_font_keyword}%
1855     \normalexpanded{\font_helpers_set_font_set_font_option_body{#method}{\m_font_step}{#message}}%
1856   \else\ifx\m_font_keyword\v!reset
1857     \let\fontstyle\empty % new 31/7/2006
1858     \let\fontsize \empty
1859   \else\ifcsname\??fontstyle\m_font_keyword\endcsname
1860     \let\fontstyle\m_font_keyword
1861   \else
1862     \setcurrentfontclass\m_font_keyword
1863     \ifcase#method\relax
1864       \let\globalfontclass\globalfontclass % -)
1865     \else
1866       \let\globalfontclass\fontclass
1867     \fi
1868     \font_helpers_set_fontstyle_of_fontclass
1869   \fi\fi\fi}
1870
1871\def\font_helpers_set_fontstyle_of_fontclass % will be overloaded later
1872  {\let\fontstyle\s!rm}
1873
1874\unexpanded\def\font_helpers_set_font_set_font_option_body#method#body#message%
1875  {\normalizebodyfontsize\normalizedsetfont{#body}% redundant for some calls
1876   \ifcsname\??fontbodyknown\normalizedsetfont\endcsname \else
1877     \font_helpers_define_unknown_font\normalizedsetfont
1878   \fi
1879   \ifcsname\??fontbodyknown\normalizedsetfont\endcsname
1880     \localbodyfontsize\normalizedsetfont
1881     \let\normalizedbodyfontsize\normalizedsetfont
1882   \else
1883     \showmessage\m!fonts4{#message}%
1884    %\font_helpers_set_font_set_font_option_body_fallbacks{#method}{#body}%
1885   \fi}
1886
1887% we need to check the fontclass
1888
1889\def\registerfontclass#class%
1890  {\letgvalue{\??fontclassyes#class}\v!yes} % global ?
1891
1892\def\setcurrentfontclass#class%
1893  {\ifcsname\??fontclassyes#class\endcsname
1894     \edef\fontclass{#class}%
1895   \else\ifcsname\??fontclassnop#class\endcsname
1896     % already tried
1897   \else   % too messy: \ifcase\currentgrouplevel % (unpredictable)
1898     \trycurrentfontclass{#class}%
1899   \fi\fi} % \fi}
1900
1901\ifdefined\trycurrentfontclass \else
1902
1903    \unexpanded\def\trycurrentfontclass#typeface%
1904      {\letvalueempty{\??fontclassnop#typeface}}
1905
1906\fi
1907
1908\let\defaultfontstyle      \s!rm
1909\let\defaultfontalternative\s!tf
1910\let\defaultfontsize       \empty
1911\let\defaultfontface       \!!zerocount
1912
1913%D So far for synchronisation. (We can inline the following macros.)
1914
1915\unexpanded\def\setcurrentfont#body#style#alternative#size% not used
1916  {\edef\fontbody       {#body}%
1917   \edef\fontstyle      {#style}%
1918   \edef\fontalternative{#alternative}%
1919   \edef\fontsize       {#size}%
1920   \font_helpers_check_big_math_synchronization
1921   \font_helpers_synchronize_font}
1922
1923\unexpanded\def\setcurrentfontbody#body% % not used
1924  {\edef\fontbody{#body}%
1925   \font_helpers_synchronize_font}
1926
1927% For Taco: optional fall backs:
1928
1929\ifdefined\font_typescripts_inherit_check \else
1930    \let\font_typescripts_inherit_check\gobbleoneargument % implemented in type-ini
1931\fi
1932
1933\unexpanded\def\font_helpers_set_current_font_style#style%
1934  {\edef\fontstyle{#style}%
1935   \font_typescripts_inherit_check\fontstyle
1936   \ifmmode\mr\fi % otherwise \rm not downward compatible ... not adapted yet
1937   \font_helpers_synchronize_font}
1938
1939\unexpanded\def\font_helpers_set_current_xsize_alternative#xsize#alternative%
1940  {\edef\fontface{#xsize}%
1941   \edef\fontalternative{#alternative}%
1942   \font_helpers_synchronize_font}
1943
1944\unexpanded\def\font_helpers_set_current_font_alternative#alternative%
1945  {\edef\fontalternative{#alternative}%
1946   \font_helpers_synchronize_font}
1947
1948\unexpanded\def\font_helpers_set_current_font_size#size%
1949  {\edef\fontsize{#size}%
1950   \font_helpers_check_big_math_synchronization % double? better in everymath?
1951   \font_helpers_synchronize_font}
1952
1953\unexpanded\def\font_helpers_set_current_font_style_alternative#style#alternative% \rmsl
1954  {\edef\fontstyle      {#style}%
1955   \edef\fontalternative{#alternative}%
1956   \font_helpers_synchronize_font}
1957
1958\unexpanded\def\font_helpers_set_current_font_style_size#style#size% \rma
1959  {\edef\fontstyle{#style}%
1960   \edef\fontsize {#size}%
1961   \font_helpers_check_big_math_synchronization % double? better in everymath?
1962   \font_helpers_synchronize_font}
1963
1964\unexpanded\def\font_helpers_set_current_font_alternative_size#alternative#size% \sla
1965  {\edef\fontalternative{#alternative}%
1966   \edef\fontsize       {#size}%
1967   \font_helpers_check_big_math_synchronization % double? better in everymath?
1968   \font_helpers_synchronize_font}
1969
1970\unexpanded\def\font_helpers_set_current_font_style_alternative_size#style#alternative#size% \rmsla
1971  {\edef\fontstyle      {#style}%
1972   \edef\fontalternative{#alternative}%
1973   \edef\fontsize       {#size}%
1974   \font_helpers_check_big_math_synchronization % double? better in everymath?
1975   \font_helpers_synchronize_font}
1976
1977\unexpanded\def\font_helpers_synchronize_font % we can have dups i.e. no need to let fontstrategy
1978  {\ifx\fontclass\empty
1979     \applyfontstrategies
1980   \else
1981     \applyfontclassstrategies
1982   \fi
1983   \setfalse\c_font_auto_size
1984   \ifskipfontcharacteristics
1985     \setfontcharacteristics
1986     \the\everyfontswitch
1987   \fi}
1988
1989%D This is the resolver for special cases (sizes) and in practice it is not called
1990%D that often so further optimization makes no sense.
1991
1992\def\font_helpers_check_strategy_class_a % --- --- --- --- % pt tt bf a
1993  {\ifcsname\??fontinstanceready\fontclass-\fontbody-\fontstyle-\fontalternative-\fontsize-\fontface\endcsname
1994     \setfalse\c_font_auto_size
1995     \lastnamedcs
1996   \else
1997     \expandafter\font_helpers_check_strategy_class_b
1998   \fi}
1999
2000\def\font_helpers_check_strategy_class_b % --- --- --- def % pt tt bf
2001  {\ifcsname\??fontinstanceready\fontclass-\fontbody-\fontstyle-\fontalternative-\defaultfontsize-\fontface\endcsname
2002     \settrue\c_font_auto_size
2003     \lastnamedcs
2004   \else
2005     \expandafter\font_helpers_check_strategy_class_c
2006   \fi}
2007
2008\def\font_helpers_check_strategy_class_c % --- --- def --- % pt tt tf a
2009  {\ifcsname\??fontinstanceready\fontclass-\fontbody-\fontstyle-\defaultfontalternative-\fontsize-\fontface\endcsname
2010     \settrue\c_font_auto_size
2011     \lastnamedcs
2012   \else
2013     \expandafter\font_helpers_check_strategy_class_d
2014   \fi}
2015
2016\def\font_helpers_check_strategy_class_d % --- --- def def % pt tt tf
2017  {\ifcsname\??fontinstanceready\fontclass-\fontbody-\fontstyle-\defaultfontalternative-\defaultfontsize-\fontface\endcsname
2018     \settrue\c_font_auto_size
2019     \lastnamedcs
2020   \else
2021     \expandafter\font_helpers_check_strategy_class_e
2022   \fi}
2023
2024\def\font_helpers_check_strategy_class_e % --- def def def % pt rm tf
2025  {\ifcsname\??fontinstanceready\fontclass-\fontbody-\defaultfontstyle-\defaultfontalternative-\defaultfontsize-\fontface\endcsname
2026     \setfalse\c_font_auto_size
2027     \lastnamedcs
2028   \else
2029     \expandafter\font_helpers_check_strategy_class_f
2030   \fi}
2031
2032\def\font_helpers_check_strategy_class_f % def def def def % rm tf
2033  {\ifcsname\??fontinstanceready\fontclass-\defaultfontbody-\defaultfontstyle-\defaultfontalternative-\defaultfontsize-\fontface\endcsname
2034     \settrue\c_font_auto_size
2035     \lastnamedcs
2036   \else
2037     \expandafter\font_helpers_check_strategy_a
2038   \fi}
2039
2040% no class
2041
2042\def\font_helpers_check_strategy_a % --- --- --- --- % pt tt bf a
2043  {\ifcsname\??fontinstanceready\fontbody-\fontstyle-\fontalternative-\fontsize-\fontface\endcsname
2044     \setfalse\c_font_auto_size
2045     \lastnamedcs
2046   \else
2047     \expandafter\font_helpers_check_strategy_b
2048   \fi}
2049
2050\def\font_helpers_check_strategy_b % --- --- --- --- % pt tt bf a
2051  {\ifcsname\??fontinstanceready\fontbody-\fontstyle-\fontalternative-\defaultfontsize-\fontface\endcsname
2052     \settrue\c_font_auto_size
2053     \lastnamedcs
2054   \else
2055     \expandafter\font_helpers_check_strategy_c
2056   \fi}
2057
2058\def\font_helpers_check_strategy_c % --- --- --- --- % pt tt bf a
2059  {\ifcsname\??fontinstanceready\fontbody-\fontstyle-\defaultfontalternative-\fontsize-\fontface\endcsname
2060     \settrue\c_font_auto_size
2061     \lastnamedcs
2062   \else
2063     \expandafter\font_helpers_check_strategy_d
2064   \fi}
2065
2066\def\font_helpers_check_strategy_d % --- --- --- --- % pt tt bf a
2067  {\ifcsname\??fontinstanceready\fontbody-\fontstyle-\defaultfontalternative-\defaultfontsize-\fontface\endcsname
2068     \settrue\c_font_auto_size
2069     \lastnamedcs
2070   \else
2071     \expandafter\font_helpers_check_strategy_e
2072   \fi}
2073
2074\def\font_helpers_check_strategy_e % --- --- --- --- % pt tt bf a
2075  {\ifcsname\??fontinstanceready\fontbody-\defaultfontstyle-\defaultfontalternative-\defaultfontsize-\fontface\endcsname
2076     \setfalse\c_font_auto_size
2077     \lastnamedcs
2078   \else
2079     \expandafter\font_helpers_check_strategy_f
2080   \fi}
2081
2082\def\font_helpers_check_strategy_f % --- --- --- --- % pt tt bf a
2083  {\ifcsname\??fontinstanceready\defaultfontbody-\defaultfontstyle-\defaultfontalternative-\defaultfontsize-\fontface\endcsname
2084     \settrue\c_font_auto_size
2085     \lastnamedcs
2086   \fi}
2087
2088\let\applyfontstrategies     \font_helpers_check_strategy_a
2089\let\applyfontclassstrategies\font_helpers_check_strategy_class_a
2090
2091%D Let's synchronize:
2092
2093\newconditional\c_font_synchronize \settrue\c_font_synchronize
2094
2095\prependtoks
2096    \ifconditional\c_font_synchronize
2097        \font_helpers_synchronize_math
2098        \font_helpers_synchronize_font % problem: syncs last font
2099    \fi
2100\to \everybodyfont
2101
2102%D Setting the normal sizes as well as the x and xx smaller sizes is accomplished by
2103%D the next set of macros. When in math mode, the commands \type {\tx} and \type
2104%D {\txx} are just a switch to the script and double script styles, but in text mode
2105%D the values defined by the bodyfontenvironment are used. Here we also set \type
2106%D {\currentxfontsize}.
2107
2108\def\font_helpers_set_current_font_xxx_alternative#alternative#xsize#scriptstyle%
2109  {\ifmmode
2110     #scriptstyle%
2111   \else
2112     \font_helpers_set_current_xsize_alternative{#xsize}{#alternative}%
2113   \fi}
2114
2115\def\font_helpers_reset_x_fontsize
2116  {\ifcase\currentxfontsize\else
2117     \currentxfontsize\zerocount
2118     % also \sx and \sxx ?
2119     \let\tx \normaltx
2120     \let\txx\normaltxx
2121   \fi}
2122
2123% \def\font_helpers_check_nested_x_fontsize % option
2124%   {\ifcase\currentxfontsize\else\ifx\fontsize\empty\else
2125%      \currentxfontsize\zerocount
2126%      \let\fontsize\empty
2127%      \let\tx\normaltx
2128%      \let\txx\normaltxx
2129%    \fi\fi}
2130%   {}
2131
2132\let\font_helpers_check_nested_x_fontsize\relax
2133
2134\def\font_helpers_set_current_font_x_alternative#alternative%
2135  {\font_helpers_check_nested_x_fontsize
2136   \font_helpers_set_current_font_xxx_alternative{#alternative}{4}\scriptstyle
2137   \currentxfontsize\plusone
2138   \let\tx\txx}
2139
2140\def\font_helpers_set_current_font_xx_alternative#alternative%
2141  {\font_helpers_check_nested_x_fontsize
2142   \font_helpers_set_current_font_xxx_alternative{#alternative}{5}\scriptscriptstyle
2143   \currentxfontsize\plustwo
2144   \let\tx\empty
2145   \let\txx\empty}
2146
2147%D This alterative is not really needed, but for old time's sake we keep it there.
2148%D We can speed it up when needed.
2149
2150\def\font_helpers_set_current_font_x_style_alternative #alternative{\csname#alternative\endcsname\tx}
2151\def\font_helpers_set_current_font_xx_style_alternative#alternative{\csname#alternative\endcsname\txx}
2152
2153%D These macros also show us that when we call for \type {\tx}, this macro is
2154%D redefined to be \type {\txx}. Therefore calls like:
2155%D
2156%D \startbuffer
2157%D {small \tx  is \tx  beautiful}
2158%D {small \tx  is \txx beautiful}
2159%D {small \txx is \tx  beautiful}
2160%D {small \txx is \txx beautiful}
2161%D \stopbuffer
2162%D
2163%D \typebuffer
2164%D
2165%D result in:
2166%D
2167%D \startlines
2168%D \getbuffer
2169%D \stoplines
2170%D
2171%D Setting the main size involves the style list and therefore takes a bit more
2172%D time. Keep in mind that the fontsize is represented by a character or empty.
2173
2174% \unexpanded\def\tx {\font_helpers_set_current_font_x_alternative \fontalternative}
2175% \unexpanded\def\txx{\font_helpers_set_current_font_xx_alternative\fontalternative}
2176
2177% \unexpanded\def\tx
2178%   {\ifmmode
2179%      \scriptstyle
2180%    \else
2181%      \let\fontface\!!plusfour
2182%      \let\fontalternative\fontalternative
2183%      \font_helpers_synchronize_font
2184%    \fi
2185%    \currentxfontsize\plusone
2186%    \let\tx\txx}
2187%
2188% \unexpanded\def\txx
2189%   {\ifmmode
2190%      \scriptscriptstyle
2191%    \else
2192%      \let\fontface\!!plusfive
2193%      \let\fontalternative\fontalternative
2194%      \font_helpers_synchronize_font
2195%    \fi
2196%    \currentxfontsize\plustwo}
2197
2198\installcorenamespace{fontscalex}
2199\installcorenamespace{fontscalexx}
2200
2201\newconditional\c_font_inherit_scale
2202
2203\def\font_scale_inherit#1%
2204  {\begingroup
2205   \scratchcounterone\fontid\font\relax
2206   \currentxfontsize\plusone
2207   \normalexpanded{\definedfont[\clf_specifiedfont\scratchcounterone\font_currentfontscale\relax]}%
2208   \scratchcountertwo\fontid\font\relax
2209   \currentxfontsize\plustwo
2210   \normalexpanded{\definedfont[\clf_specifiedfont\scratchcounterone\font_currentfontscale\relax]}%
2211   \scratchcounterthree\fontid\font\relax
2212   % parent -> x -> xx
2213   % parent -> xx
2214   \global\expandafter\chardef\csname\??fontscalex \number\scratchcounterone\endcsname\scratchcountertwo
2215   \global\expandafter\chardef\csname\??fontscalexx\number\scratchcounterone\endcsname\scratchcounterthree
2216   \global\expandafter\chardef\csname\??fontscalex \number\scratchcountertwo\endcsname\scratchcounterthree
2217   \global\expandafter\chardef\csname\??fontscalexx\number\scratchcountertwo\endcsname\scratchcounterthree
2218   \endgroup
2219   \setfontid\csname#1\number\fontid\font\endcsname}
2220
2221\def\font_scale_inherit_x
2222  {\ifcsname\??fontscalex\number\fontid\font\endcsname
2223     \setfontid\lastnamedcs
2224   \else
2225     \font_scale_inherit\??fontscalex
2226   \fi
2227   \ifskipfontcharacteristics
2228     \setfontcharacteristics
2229     \the\everyfontswitch
2230   \fi}
2231
2232\def\font_scale_inherit_xx
2233  {\ifcsname\??fontscalexx\number\fontid\font\endcsname
2234     \setfontid\lastnamedcs
2235   \else
2236     \font_scale_inherit\??fontscalexx
2237   \fi
2238   \ifskipfontcharacteristics
2239     \setfontcharacteristics
2240     \the\everyfontswitch
2241   \fi}
2242
2243\def\font_scale_defined_x
2244  {\let\fontface\!!plusfour
2245   \let\fontalternative\fontalternative
2246   \font_helpers_synchronize_font}
2247
2248\def\font_scale_defined_xx
2249  {\let\fontface\!!plusfive
2250   \let\fontalternative\fontalternative
2251   \font_helpers_synchronize_font}
2252
2253\unexpanded\def\tx
2254  {\currentxfontsize\plusone
2255   \ifmmode
2256     \scriptstyle
2257   \else\ifconditional\c_font_inherit_scale
2258     \font_scale_inherit_x
2259   \else
2260     \font_scale_defined_x
2261   \fi\fi
2262   \let\tx\txx}
2263
2264\unexpanded\def\txx
2265  {\currentxfontsize\plustwo
2266   \ifmmode
2267     \scriptscriptstyle
2268   \else\ifconditional\c_font_inherit_scale
2269     \font_scale_inherit_xx
2270   \else
2271     \font_scale_defined_xx
2272   \fi\fi
2273   \let\tx \empty
2274   \let\txx\empty}
2275
2276\unexpanded\def\sx
2277  {\currentxfontsize\plusone
2278   \ifmmode
2279     \scriptstyle
2280   \else
2281     \font_scale_inherit_x
2282   \fi
2283   \let\tx\txx
2284   \let\sx\sxx}
2285
2286\unexpanded\def\sxx
2287  {\currentxfontsize\plustwo
2288   \ifmmode
2289     \scriptscriptstyle
2290   \else
2291     \font_scale_inherit_xx
2292   \fi
2293   \let\tx \empty
2294   \let\txx\empty
2295   \let\sx \empty
2296   \let\sxx\empty}
2297
2298\unexpanded\def\useinheritxsizes{\settrue \c_font_inherit_scale} % not yet public, playground for WS and me
2299\unexpanded\def\usedefinedxsizes{\setfalse\c_font_inherit_scale} % not yet public, playground for WS and me
2300
2301\let\normaltx \tx
2302\let\normaltxx\txx
2303
2304\let\normalsx \sx
2305\let\normalsxx\sxx
2306
2307%D When asking for a complete font switch, for instance from 10 to 12~points, the
2308%D next macro does the job. First we normalize the size, next we define the current
2309%D range of text, script and scriptscript sizes, then we set the text fonts and the
2310%D math families and finally we activate the default typeface and also set the font
2311%D specific parameters assigned to \type {\everybodyfont}.
2312
2313\def\textface        {\currentbodyfontdimension\s!text        }
2314\def\scriptface      {\currentbodyfontdimension\s!script      }
2315\def\scriptscriptface{\currentbodyfontdimension\s!scriptscript}
2316\def\xtextface       {\currentbodyfontdimension\s!x           }
2317\def\xxtextface      {\currentbodyfontdimension\s!xx          }
2318
2319% \unexpanded\def\font_basics_complete_switch#size%
2320%   {\bodyfontsize#size\relax
2321%    \normalizebodyfontsize\normalizedbodyfontsize\bodyfontsize
2322%    \edef\textface        {\currentbodyfontdimension\s!text        }%
2323%    \edef\scriptface      {\currentbodyfontdimension\s!script      }%
2324%    \edef\scriptscriptface{\currentbodyfontdimension\s!scriptscript}}%
2325
2326\installcorenamespace{fontbodyfaces}
2327
2328\unexpanded\def\font_basics_complete_switch#size%
2329  {\bodyfontsize#size\relax
2330   \normalizebodyfontsize\normalizedbodyfontsize\bodyfontsize
2331   \expandafter\let\expandafter\font_basics_set_faces\csname\??fontbodyfaces\fontbody\endcsname
2332   \ifx\font_basics_set_faces\relax
2333     \font_basics_set_faces_preset
2334   \fi
2335   \font_basics_set_faces}
2336
2337\def\font_basics_set_faces_preset
2338  {\edef\font_basics_set_faces{% 0.2 sec on 10K \tfa
2339     \noexpand\edef\noexpand\textface        {\currentbodyfontdimension\s!text        }%
2340     \noexpand\edef\noexpand\scriptface      {\currentbodyfontdimension\s!script      }%
2341     \noexpand\edef\noexpand\scriptscriptface{\currentbodyfontdimension\s!scriptscript}%
2342     \noexpand\edef\noexpand\xtextface       {\currentbodyfontdimension\s!x           }%
2343     \noexpand\edef\noexpand\xxtextface      {\currentbodyfontdimension\s!xx          }%
2344   }%
2345   \expandafter\glet\csname\??fontbodyfaces\fontbody\endcsname\font_basics_set_faces}
2346
2347% \def\currentbodyfontdimension#parameter%
2348%   {\the\dimexpr
2349%      \ifcsname\??fontenvironments\fontclass\normalizedbodyfontsize#parameter\endcsname
2350%        \csname\??fontenvironments\fontclass\normalizedbodyfontsize#parameter\endcsname \else
2351%      \ifcsname\??fontenvironments\fontclass\s!default             #parameter\endcsname
2352%        \csname\??fontenvironments\fontclass\s!default             #parameter\endcsname
2353%        \dimexpr\normalizedbodyfontsize\relax                                           \else     % factor
2354%      \ifcsname\??fontenvironments          \normalizedbodyfontsize#parameter\endcsname
2355%        \csname\??fontenvironments          \normalizedbodyfontsize#parameter\endcsname \else
2356%        \csname\??fontenvironments          \s!default             #parameter\endcsname
2357%        \dimexpr\normalizedbodyfontsize\relax                                           \fi\fi\fi % factor
2358%    \relax}
2359
2360\def\currentbodyfontdimension#parameter% there can be factors here
2361  {\the\dimexpr
2362     \ifcsname\??fontenvironments\fontclass\normalizedbodyfontsize#parameter\endcsname
2363       \lastnamedcs
2364     \else\ifcsname\??fontenvironments\fontclass\s!default#parameter\endcsname
2365       \lastnamedcs
2366       \dimexpr\normalizedbodyfontsize\relax
2367     \else\ifcsname\??fontenvironments\normalizedbodyfontsize#parameter\endcsname
2368       \lastnamedcs
2369     \else
2370       \csname\??fontenvironments\s!default#parameter\endcsname
2371       \dimexpr\normalizedbodyfontsize\relax
2372     \fi\fi\fi
2373   \relax}
2374
2375%D \macros
2376%D   {setupbodyfont,switchtobodyfont}
2377%D
2378%D The next two macros are user ones. With \type {\setupbodyfont} one can set the
2379%D document bodyfont size, font family, style and/or options defined in files, for
2380%D example:
2381%D
2382%D \starttyping
2383%D \setupbodyfont[modern,12pt,roman]
2384%D \stoptyping
2385%D
2386%D This command affects the document as a whole: text, headers and footers. The
2387%D second macro however affects only the text:
2388%D
2389%D \starttyping
2390%D \switchtobodyfont[10pt]
2391%D \stoptyping
2392%D
2393%D So we've got:
2394%D
2395%D \showsetup{setupbodyfont}
2396%D \showsetup{switchtobodyfont}
2397%D
2398%D Both macros look alike. The second one also has to take all kind of keywords into
2399%D account.
2400
2401\ifx\saveinterlinespace   \undefined \let\saveinterlinespace   \relax \fi
2402\ifx\restoreinterlinespace\undefined \let\restoreinterlinespace\relax \fi
2403
2404% \newtoks \everysetupbodyfont
2405% \newtoks \everyswitchtobodyfont
2406
2407\unexpanded\def\setupbodyfont
2408  {\doifelsenextoptionalcs\font_basics_setupbodyfont_yes\font_basics_setupbodyfont_nop}
2409
2410\def\font_basics_setupbodyfont_nop
2411  {\restoreglobalbodyfont
2412   \saveinterlinespace}
2413
2414\def\font_basics_setupbodyfont_yes[#specification]%
2415  {\doifsomething{#specification}
2416     {\font_helpers_set_font\plusone{#specification}%
2417      \globalbodyfontsize\localbodyfontsize
2418      \normalizebodyfontsize\normalizedglobalbodyfontsize\globalbodyfontsize
2419      \let\globalfontstyle\fontstyle
2420      \ifproductionrun
2421        \the\everybodyfont
2422        \the\everyglobalbodyfont
2423        \saveinterlinespace
2424      \fi
2425      \the\everysetupbodyfont}}
2426
2427\unexpanded\def\font_basics_switchtobodyfont#specification%
2428  {\edef\m_font_step{\font_bodyfontvariable{#specification}}%
2429   \ifx\m_font_step\empty
2430     \font_helpers_set_font\zerocount{#specification}%
2431   \else
2432     \font_helpers_switch_bodyfont_step % so we have a fast [small] switch
2433   \fi
2434   \the\everybodyfont
2435   \the\everyswitchtobodyfont}
2436
2437\unexpanded\def\switchtobodyfont[#specification]% could become an ifx
2438  {\doifsomething{#specification}{\font_basics_switchtobodyfont{#specification}}}
2439
2440\unexpanded\def\usebodyfontparameter#1%
2441  {\edef\m_font_bodyfont_asked{#1\c!bodyfont}%
2442   \ifx\m_font_bodyfont_asked\empty\else
2443     \font_basics_switchtobodyfont\m_font_bodyfont_asked
2444   \fi}
2445
2446\def\font_helpers_switch_bodyfont_step
2447  {\font_basics_switch_points\m_font_step
2448   \font_basics_switch_style \fontstyle}
2449
2450%D The following alternative is meant for math||to||text switching and will be
2451%D optimized.
2452
2453\unexpanded\def\fastswitchtobodyfont#name%
2454  {\ifcsname\??fontenvironments\normalizedbodyfontsize#name\endcsname
2455    %\edef\futurebodyfontsize{\csname\??fontenvironments\normalizedbodyfontsize#name\endcsname}%
2456     \edef\futurebodyfontsize{\lastnamedcs}%
2457     \ifcsname\??fontbodyknown\futurebodyfontsize\endcsname
2458       \font_basics_complete_switch\futurebodyfontsize
2459       \localbodyfontsize\futurebodyfontsize\relax
2460     \fi
2461   \fi
2462   \csname\??fontstyle\fontstyle\endcsname
2463   \the\everybodyfont}
2464
2465%D \starttyping
2466%D $\cases{& \ccaron}$ $x=\hbox{\ccaron $x=\hbox{\ccaron}$}$
2467%D \stoptyping
2468
2469%D \macros
2470%D   {usebodyfont}
2471%D
2472%D This looks nicer then a switch in the preamble
2473%D
2474%D \starttyping
2475%D \usebodyfont[pagella,10pt]
2476%D \usebodyfont[termes,10pt]
2477%D \usebodyfont[dejavu,10pt]
2478%D
2479%D \setupbodyfont[dejavu]
2480%D
2481%D \starttext
2482%D     test
2483%D \stoptext
2484%D \stoptyping
2485
2486% \unexpanded\def\usebodyfont[#1]%
2487%   {\push_macro_fontclass
2488%    \switchtobodyfont[#1]%
2489%    \pop_macro_fontclass
2490%    \ifx\fontclass\empty\else\setupbodyfont\relax\fi}
2491
2492% \unexpanded\def\usebodyfont[#1]%
2493%   {\push_macro_fontclass
2494%    \font_helpers_set_font\zerocount{#1}%
2495%    \pop_macro_fontclass
2496%    \ifx\fontclass\empty \else
2497%      \font_basics_setupbodyfont_nop
2498%    \fi}
2499
2500\unexpanded\def\usebodyfont[#1]%
2501  {\ifx\fontclass\empty
2502     \setupbodyfont[#1]%
2503   \else
2504     \switchtobodyfont[#1]%
2505     \fullrestoreglobalbodyfont
2506   \fi}
2507
2508\unexpanded\def\showbodyfontstate
2509  {\dontleavehmode
2510   \start
2511   \infofont
2512   [fontclass: \fontclass,\space
2513    fontbody:  \fontbody ,\space
2514    fontface:  \fontface ,\space
2515    fontsize:  \fontsize ]%
2516   \stop}
2517
2518%D Handy for manuals:
2519
2520%D The \type {\tochar} commmand takes a specification:
2521%D
2522%D \starttabulate[|l|l|l|]
2523%D \NC e \NC entity                   \NC e:eacute \NC \NR
2524%D \NC x \NC hexadecimal unicode      \NC x:013D   \NC \NR
2525%D \NC d \NC decimal unicode          \NC d:123    \NC \NR
2526%D \NC s \NC hexadecimal index (slot) \NC s:210D   \NC \NR
2527%D \NC i \NC decimal index            \NC i:456    \NC \NR
2528%D \NC n \NC name                     \NC n:eight  \NC \NR
2529%D \NC c \NC name                     \NC c:x      \NC \NR
2530%D \NC u \NC unicode descriptions     \NC u:dog    \NC \NR
2531%D \NC a \NC all (also descriptions)  \NC a:rewind \NC \NR
2532%D \stoptabulate
2533%D
2534%D This is an expandable command!
2535
2536\unexpanded\def\fontchar       #character{\clf_fontchar{#character}}
2537\unexpanded\def\fontcharbyindex    #index{\clf_fontcharbyindex#index\relax}
2538           \def\tochar    #specifications{\clf_tochar{#specifications}} % expanded (also used in edef)
2539
2540%D The next auxilliary macro is an alternative to \type {\fontname}.
2541
2542\def\purefontname#font{\clf_purefontname{\fontname#font}}
2543
2544%D \macros
2545%D   {switchstyleonly}
2546%D
2547%D For switching a style but keeping the alternative, there
2548%D is:
2549%D
2550%D \starttyping
2551%D {\bf text \switchstyleonly\ss text}
2552%D {\bf text \switchstyleonly[ss]text}
2553%D {\sl text \switchstyleonly[sansserif]text}
2554%D \stoptyping
2555
2556\unexpanded\def\switchstyleonly
2557  {\doifelsenextoptionalcs\font_basics_switch_style_only_opt\font_basics_switch_style_only_arg}
2558
2559\def\font_basics_switch_style_only_arg#name% stupid version
2560  {\font_helpers_set_current_font_style{\csname\??fontshortstyle\checkedstrippedcsname#name\endcsname}%
2561   \the\everybodyfont} % needed ?
2562
2563\def\font_basics_switch_style_only_opt[#name]% todo : check
2564  {\font_helpers_set_current_font_style{\csname\??fontshortstyle#name\endcsname}%
2565   \the\everybodyfont} % needed ?
2566
2567%D \macros
2568%D   {definebodyfontswitch}
2569%D
2570%D \PLAIN\ \TEX\ defines some macro's like \type {\tenpoint} to switch to a specific
2571%D bodyfontsize. Just for the sake of compatibility we can define them like:
2572%D
2573%D \starttyping
2574%D \definebodyfontswitch [twelvepoint] [12pt]
2575%D \stoptyping
2576%D
2577%D We don't support language specific synonyms here.
2578
2579\unexpanded\def\definebodyfontswitch
2580  {\dodoubleargument\font_basics_define_bodyfont_switch}
2581
2582\def\font_basics_define_bodyfont_switch[#command][#specification]% no longer a commalist (not useful)
2583  {\setvalue{#command}{\switchtobodyfont[#specification]}}%
2584
2585%D \macros
2586%D   {setsmallbodyfont,setmainbodyfont,setbigbodyfont}
2587%D
2588%D When we're typesetting at for instance 10pt, we can call for the \type {small} as
2589%D well as the \type {big} alternative, related to this main size, using \type
2590%D {\switchtobodyfont[small]}. The three alternatives can be activated by the next
2591%D three system calls and are defined by the bodyfontenvironment.
2592
2593\newmacro\m_font_step
2594
2595\def\font_helpers_set_bodyfont_step#step%
2596  {\edef\m_font_step{\font_bodyfontvariable{#step}}% not always \cs
2597   \font_basics_switch_points\m_font_step
2598   \font_basics_switch_style \fontstyle}
2599
2600\unexpanded\def\setsmallbodyfont{\font_helpers_set_bodyfont_step\v!small\the\everybodyfont}
2601\unexpanded\def\setbigbodyfont  {\font_helpers_set_bodyfont_step\v!big  \the\everybodyfont}
2602
2603\unexpanded\def\setmainbodyfont
2604  {\font_basics_switch_points\normalizedbodyfontsize
2605   \font_basics_switch_style\fontstyle
2606   \the\everybodyfont
2607   \the\everyglobalbodyfont
2608   \saveinterlinespace}
2609
2610%D \macros
2611%D   {restoreglobalbodyfont}
2612%D
2613%D Users can set whatever font available while typesetting text. Pagenumbers,
2614%D footers, headers etc. however must be typeset in the main bodyfont and style of
2615%D the document. Returning to the global state can be done with the next macro:
2616%D
2617%D This macro has to be called when entering the pagebody handling routine as well
2618%D as the footnote insert routine. Users can access this feature |<|for instance
2619%D when one wants to typeset tables and alike in the main bodyfont and style while
2620%D the running text is temporary set to a smaller one|>| by saying \type
2621%D {\switchtobodyfont [global]}.
2622
2623\let\globalfontstyle\s!rm
2624
2625\unexpanded\def\fullrestoreglobalbodyfont
2626  {\let\fontsize\defaultfontsize
2627   \let\fontbody\defaultfontbody
2628   \let\fontface\defaultfontface
2629   \currentxfontsize\zerocount
2630   \let\fontclass\globalfontclass
2631   \font_basics_switch_points\normalizedglobalbodyfontsize
2632   \font_basics_switch_style\globalfontstyle
2633   \redoconvertfont % just in case a pagebreak occurs
2634   \tf
2635   \the\everybodyfont
2636   \the\everyglobalbodyfont
2637   \saveinterlinespace}
2638
2639\unexpanded\def\partialrestoreglobalbodyfont
2640  {\let\fontsize\defaultfontsize
2641   \let\fontbody\defaultfontbody
2642   \let\fontface\defaultfontface
2643   \currentxfontsize\zerocount
2644   \redoconvertfont
2645   \tf
2646   \the\everybodyfont % indeed needed
2647   \the\everyglobalbodyfont % indeed needed
2648   \saveinterlinespace}
2649
2650\unexpanded\def\restoreglobalbodyfont % ook style etc
2651  {\ifx\fontclass\globalfontclass
2652     \ifx\fontstyle\globalfontstyle
2653       \ifx\normalizedbodyfontsize\normalizedglobalbodyfontsize
2654         \partialrestoreglobalbodyfont
2655       \else
2656         \fullrestoreglobalbodyfont
2657       \fi
2658     \else
2659       \fullrestoreglobalbodyfont
2660     \fi
2661   \else
2662     \fullrestoreglobalbodyfont
2663   \fi}
2664
2665% in case of troubles: \let\restorebodyfont\fullrestoreglobalbodyfont
2666
2667%D Here are some fast variants that can be used in cases where no font system is
2668%D needed and where fonts are frozen:
2669%D
2670%D \starttyping
2671%D \definefont   [TestA][Serif at 10pt]
2672%D \predefinefont[TestB][Serif at 20pt]
2673%D
2674%D \testfeatureonce{1000}{{\TestA}}                         %   .312
2675%D \testfeatureonce{1000}{{\TestB}}                         % < .016
2676%D \testfeatureonce{1000}{{\definedfont[Serif at 30pt]}}    %   .312
2677%D \testfeatureonce{1000}{{\predefinedfont[Serif at 40pt]}} % < .016
2678%D \stoptyping
2679
2680\installcorenamespace{predefinedfont}
2681
2682\unexpanded\def\predefinefont[#1]#2[#3]% global !
2683  {\setugvalue{#1}{\font_basics_predefine{#1}{#3}}}
2684
2685\unexpanded\def\predefinedfont[#1]% global !
2686  {\ifcsname\??predefinedfont#1\endcsname
2687     \lastnamedcs
2688   \else
2689     \font_basics_predefined{#1}%
2690   \fi}
2691
2692\unexpanded\def\font_basics_predefine#1#2%
2693  {\font_basics_defined_font_yes[#2]%
2694   \expandafter\glet\csname#1\expandafter\endcsname\csname\v_font_identifier_basic\endcsname}
2695
2696\unexpanded\def\font_basics_predefined#1%
2697  {\font_basics_predefine{\??predefinedfont#1}{#1}}
2698
2699%D Handy helper:
2700
2701\unexpanded\def\savedefinedfont[#1]%
2702  {\bgroup
2703   \definedfont[#1]%
2704   \xdef\saveddefinedfontid  {\number\fontid\font}%
2705   \xdef\saveddefinedfontname{\fontname\font}%
2706   \egroup}
2707
2708\def\saveddefinedfontid  {\number\fontid\font}
2709\def\saveddefinedfontname{\fontname\font}
2710
2711%D Ugly helper:
2712
2713\unexpanded\def\saverunningstyleandcolor
2714  {\unexpanded\edef\restorerunningstyleandcolor
2715     {\setfontid          \number\fontid\font
2716      \c_attr_colormodel  \the\c_attr_colormodel
2717      \c_attr_color       \the\c_attr_color
2718      \c_attr_transparency\the\c_attr_transparency
2719      \relax}}
2720
2721\let\restorerunningstyleandcolor\relax
2722
2723%D Handy for defining additional glyphs:
2724
2725\let\getprivateglyphslot\clf_getprivateglyphslot % kind of private macro
2726
2727\let\getprivatechar     \clf_getprivatechar     % gives back a utf !
2728\let\getprivatemathchar \clf_getprivatemathchar % gives back a utf !
2729\let\getprivateslot     \clf_getprivateslot     % companion to fonts.helpers.addprivate
2730
2731% \unexpanded\def\getprivatemathchar#1%
2732%   {\begingroup\the\textfont\zerocount\getprivatechar{#1}\endgroup}
2733
2734\def\privatechar % the text variant gets expanded to utf
2735  {\ifmmode
2736     \expandafter\getprivatemathchar
2737   \else
2738     \expandafter\getprivatechar
2739   \fi}
2740
2741%D Some fonts can have color specifiers:
2742%D
2743%D \starttyping
2744%D \definefontfeature[seguiemj-cl][default][colr=yes,ccmp=yes,dist=yes]
2745%D \definefontsynonym[emoji][seguiemj*seguiemj-cl]
2746%D
2747%D \definecolor[emoji-red] [r=.4]
2748%D \definecolor[emoji-gray][s=1,t=.5,a=1]
2749%D
2750%D %definefontcolorpalette [emoji-r] [emoji-red,emoji-gray,textcolor] % bad
2751%D \definefontcolorpalette [emoji-r] [emoji-red,emoji-gray]           % okay
2752%D
2753%D \definefontfeature[seguiemj-r][ccmp=yes,dist=yes,colr=emoji-r]
2754%D
2755%D \definefont[MyEmojiR][seguiemj*seguiemj-r @ 100pt]
2756%D
2757%D \startTEXpage[offset=10pt]
2758%D     \MyEmojiR\resolvedemoji{triangular ruler}
2759%D \stopTEXpage
2760%D \stoptyping
2761
2762\unexpanded\def\definefontcolorpalette
2763  {\dodoubleargument\font_define_color_palette}
2764
2765\def\font_define_color_palette[#1][#2]%
2766  {\clf_definefontcolorpalette{#1}{#2}}
2767
2768% yes or no:
2769
2770% \let\font_basics_check_text_bodyfont_slow\font_basics_check_text_bodyfont
2771%
2772% \unexpanded\def\font_basics_check_text_bodyfont
2773%   {\ifproductionrun
2774%      % not per se \s!..'s
2775%      \glet\font_basics_check_text_bodyfont     \font_basics_check_text_bodyfont_slow
2776%      \glet\font_basics_check_text_bodyfont_fast\relax
2777%      \expandafter\font_basics_check_text_bodyfont
2778%    \else
2779%      \expandafter\font_basics_check_text_bodyfont_fast
2780%    \fi}
2781%
2782% \def\font_basics_check_text_bodyfont_fast#style#alternative#size% size can be empty (checking needed as \bf is already defined)
2783%   {\setugvalue{#style#size}% \rma
2784%      {\let\fontstyle#style%
2785%       \let\fontsize #size%
2786%       \font_helpers_check_big_math_synchronization % double? better in everymath?
2787%       \font_helpers_synchronize_font}%
2788%    \setugvalue{#alternative#size}% \sla
2789%      {\let\fontalternative#alternative%
2790%       \let\fontsize       #size%
2791%       \font_helpers_check_big_math_synchronization % double? better in everymath?
2792%       \font_helpers_synchronize_font}%
2793%    \setugvalue{#style#alternative#size}% \rmsla
2794%      {\let\fontstyle      #style%
2795%       \let\fontalternative#alternative%
2796%       \let\fontsize       #size%
2797%       \font_helpers_check_big_math_synchronization % double? better in everymath?
2798%       \font_helpers_synchronize_font}%
2799%    \ifcsname\s!normal#style\endcsname % text/math check
2800%      \expandafter\let\csname#style\expandafter\endcsname\csname\s!normal#style\endcsname
2801%    \else
2802%      \setugvalue{#style}% \rm
2803%        {\let\fontstyle#style%
2804%         \font_typescripts_inherit_check\fontstyle
2805%         \ifmmode\mr\fi % otherwise \rm not downward compatible ... not adapted yet
2806%         \font_helpers_synchronize_font}%
2807%    \fi
2808%    \ifcsname\s!normal#alternative\endcsname % text/math check
2809%      \expandafter\let\csname#alternative\expandafter\endcsname\csname\s!normal#alternative\endcsname
2810%    \else
2811%      \setugvalue{#alternative}% \sl
2812%        {\let\fontalternative#alternative%
2813%         \font_helpers_synchronize_font}%
2814%    \fi
2815%    \setugvalue{#style\s!x}% \rmx
2816%      {\csname#style\endcsname\tx}%
2817%    \setugvalue{#style\s!xx}% \rmxx
2818%      {\csname#style\endcsname\txx}%
2819%    \setugvalue{#alternative\s!x}% \slx
2820%      {\font_helpers_check_nested_x_fontsize
2821%       \ifmmode
2822%          \scriptstyle
2823%       \else
2824%         \let\fontface\!!plusfour
2825%         \let\fontalternative#alternative%
2826%         \font_helpers_synchronize_font
2827%       \fi
2828%       \currentxfontsize\plusone
2829%       \let\tx\txx}%
2830%    \setugvalue{#alternative\s!xx}% \slxx
2831%      {\font_helpers_check_nested_x_fontsize
2832%       \ifmmode
2833%          \scriptscriptstyle
2834%       \else
2835%         \let\fontface\!!plusfive
2836%         \let\fontalternative#alternative%
2837%         \font_helpers_synchronize_font
2838%       \fi
2839%       \currentxfontsize\plustwo
2840%       \let\tx\empty
2841%       \let\txx\empty}%
2842%    \setugvalue{#style#alternative}% \rmsl
2843%      {\let\fontstyle      #style%
2844%       \let\fontalternative#alternative%
2845%       \font_helpers_synchronize_font}}
2846
2847%D \macros
2848%D   {addfontpath}
2849%D
2850%D A way to add a path at runtime (no need to generate database):
2851
2852\unexpanded\def\usefontpath[#1]%
2853  {\clf_addfontpath{#1}}
2854
2855%D NO select discs:
2856
2857\ifdefined\discretionaryligaturemode
2858    \discretionaryligaturemode\plusone
2859\fi
2860
2861\protect \endinput
2862