Debian Codegraph @

texmf-dist/source/latex/base/ltfsstrc.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 1993-2025
4 % The LaTeX Project and any individual authors listed elsewhere
5 % in this file.
6 %
7 % This file is part of the LaTeX base system.
8 % -------------------------------------------
9 %
10 % It may be distributed and/or modified under the
11 % conditions of the LaTeX Project Public License, either version 1.3c
12 % of this license or (at your option) any later version.
13 % The latest version of this license is in
14 % https://www.latex-project.org/lppl.txt
15 % and version 1.3c or later is part of all distributions of LaTeX
16 % version 2008 or later.
17 %
18 % This file has the LPPL maintenance status "maintained".
19 %
20 % The list of all files belonging to the LaTeX base distribution is
21 % given in the file `manifest.txt'. See also `legal.txt' for additional
22 % information.
23 %
24 % The list of derived (unpacked) files belonging to the distribution
25 % and covered by LPPL is defined by the unpacking scripts (with
26 % extension .ins) which are part of the distribution.
27 %
28 % \fi
29 %
30 % \iffalse
31 %%% From File: ltfsstrc.dtx
32 %% Copyright (C) 1989-97 by Frank Mittelbach and Rainer Sch\"opf.
33 %% Copyright (C) 1994-97 by LaTeX Project. All rights reserved.
34 %
35 %<package>\NeedsTeXFormat{LaTeX2e}[2021/06/01]
36 %<package>\ProvidesPackage{tracefnt}
37 %<package> [2020/12/22 v3.0n Standard LaTeX package (font tracing)]
38 % \fi
39 % \ProvidesFile{ltfsstrc.dtx}
40 % [2025/06/29 v3.0q LaTeX Kernel (NFSS tracing)]
41 %
42 % \iffalse
43 %<+checkmem>\CHECKMEM
44 % \fi
45 %
46 %
47 %
48 %
49 % \changes{v3.0g}{1995/11/28}
50 % {documentation fixes}
51 % \changes{v3.0f}{1995/10/22}{Added `genb' and `sgenb' size functions
52 % to support new DC font naming scheme.}
53 % \changes{v3.0e}{1995/10/20}
54 % {(DPC) Modify autoload code}
55 % \changes{v3.0d}{1995/10/04}
56 % {(DPC) Modify autoload code}
57 % \changes{v3.0b}{1995/05/24}
58 % {(DPC) Fix \cs{ProvidesFile} usage}
59 % \changes{v3.0a}{1995/05/24}
60 % {(DPC) Make file from previous file, tracefnt 1995/05/16 v2.3o}
61 % \changes{v3.0k}{2015/02/21}
62 % {Removed autoload code}
63 %
64 % \changes{v2.3m}{1994/11/18}
65 % {\cs{next} to \cs{reserved@f}}
66 % \changes{v2.3l}{1994/11/17}
67 % {\cs{@tempa} to \cs{reserved@a}}
68 % \changes{v2.3i}{1994/05/20}{Use new error command names}
69 % \changes{v2.3g}{1994/05/13}{Removed typeouts as
70 % \cs{ProvidesPackage} writes to log.}
71 % \changes{v2.3e}{1994/04/27}{Corrected item that was forgotten
72 % in last change.}
73 % \changes{v2.3d}{1994/04/18}{Changed to new error/warning scheme}
74 % \changes{v2.3a}{1994/01/17}{New math font setup}
75 % \changes{v2.2a}{1993/11/11}{Option concept added for LaTeX2e}
76 % \changes{v2.1j}{1993/09/15}{Corrected spelling of \cs{noxpand}.}
77 % \changes{v2.1i}{1993/09/02}{Corrected name of sgen size function.}
78 % \changes{v2.1h}{1993/07/16}{Changed layout of info messages}
79 % \changes{v2.1b}{1993/03/18}
80 % {Changed all \cs{@tempdimb} in \cs{@tempdimx}
81 % to avoid killing \cs{numberline}}
82 % \changes{v2.1b}{1993/03/18}
83 % {Changed all \cs{@tempdima} in \cs{@tempdimb}
84 % to avoid killing \cs{numberline}}
85 % \changes{v1.0l}{1990/04/01}{Part of code moved to fam.dtx.}
86 % \changes{v1.0k}{1990/03/14}{Added code for TeX3.}
87 % \changes{v1.0h}{1990/01/18}{\cs{tracingfonts} meaning changed.}
88 %
89 % \newcommand\module[1]{\texttt{#1}}
90 % \providecommand{\dst}{\textsc{DocStrip}}
91 % \newcommand\Loption[1]{\texttt{#1}}
92 %
93 % \GetFileInfo{ltfsstrc.dtx}
94 % \title{The \texttt{tracefnt} package\thanks
95 % {This file has version number \fileversion, dated
96 % \filedate.} \\
97 % for use with the new font selection scheme}
98 % \author{Frank Mittelbach \and Rainer Sch\"opf}
99 %
100 %
101 % \MaintainedByLaTeXTeam{latex}
102 % \maketitle
103 %
104 % \section{Introduction}
105 %
106 % This package contains the code for tracing font loading and font
107 % changes. It basically overlays some of the low-level functions of
108 % NFSS with additional code used for tracing.
109 %
110 % The package accepts the following options:
111 % \begin{description}
112 % \item[errorshow] Write all information about font changes etc.\
113 % only to the transcript file unless an error happens. This means
114 % that information about font substitution will not be shown on the
115 % terminal.
116 %
117 % \item[warningshow] Show all NFSS warnings on the terminal. This
118 % setting corresponds to the default behaviour of NFSS if the
119 % \texttt{tracefnt} package is \emph{not} loaded!
120 %
121 % \item[infoshow] Show all NFSS warning and all NFSS info
122 % messages (that are normally only written to the transcript file)
123 % also on the terminal. This is the default if the \texttt{tracefnt}
124 % package is loaded.
125 %
126 % \item[debugshow] In addition to \texttt{infoshow} show also
127 % changing of math fonts as far as possible (this option can produce a
128 % large amount of output).
129 %
130 % \item[loading] Show the name of external fonts when they are
131 % loaded. This option shows only ``newly'' loaded fonts not those
132 % already preloaded in the format or the class file before the
133 % \texttt{tracefnt} package became active.
134 %
135 % \item[pausing]
136 % Turn all font warnings into errors so that \LaTeX{} will stop.
137 %
138 % \end{description}
139 %
140 %
141 % \MaybeStop{}
142 %
143 % \section{A driver for this document}
144 %
145 % The next bit of code contains the documentation driver file for
146 % \TeX{}, i.e., the file that will produce the documentation you
147 % are currently reading. It will be extracted from this file by the
148 % \dst{} program.
149 %
150 % When this file is processed directly by \LaTeX{} this will
151 % produce the documentation as well.
152 %
153 % \begin{macrocode}
154 %<*driver>
155 \documentclass{ltxdoc}
156
157
158 %\OnlyDescription % comment out for implementation details
159
160 \begin{document}
161 \DocInput{ltfsstrc.dtx}
162 \end{document}
163 %</driver>
164 % \end{macrocode}
165 %
166 %
167 % \section{The Implementation}
168 %
169 % \begin{quote}
170 % \textbf{Warning:} Read the macro documentation with a grain of
171 % salt. It is still basically the documentation from the first NFSS
172 % release and therefore in some cases probably not completely
173 % accurate.
174 % \end{quote}
175 %
176 % If we are making a package file it is a good idea to test whether
177 % we are running under 2e.
178 % This code is actually placed at the very beginning of this file
179 % for easier maintenance, thus commented out here.
180 % \begin{macrocode}
181 %<*package>
182 %\NeedsTeXFormat{LaTeX2e}
183 %\ProvidesPackage{tracefnt}[??/??/?? v?.??
184 % Standard LaTeX package (font tracing)]
185 %</package>
186 % \end{macrocode}
187 %
188 %
189 % The \texttt{debug} module makes use of commands contained in a
190 % special package file named \texttt{trace.sty}.\footnote{This package
191 % is not in distribution at the moment (and probably doesn't any
192 % longer work). Think of this part of the code as being historical
193 % artifacts.}
194 % \begin{macrocode}
195 %<+debug> \input trace.sty
196 % \end{macrocode}
197 %
198 %
199 % \section{Handling Options}
200 %
201 % \begin{macro}{\tracingfonts}
202 % Here is the definition of the integer register for the font
203 % trace. As a default in a package file we use $1$ to give error
204 % messages if fonts are substituted. If this code is used for
205 % debugging or tracing reasons in the format file (i.e.\ in
206 % \texttt{fam.dtx}) we use $0$ as the default. But if no font
207 % trace is used we build a definition that will produce a warning
208 % message.
209 % \changes{v1.0l}{1990/04/01}
210 % {Check if \cs{tracingfonts} already defined.}
211 % \changes{v1.0o}{1990/04/01}
212 % {Check if \cs{tracingfonts} defined removed again.}
213 % \begin{macrocode}
214 %<*2ekernel>
215 \message{NFSS tracing,}
216 \def\tracingfonts{%
217 \@font@warning{Command \noexpand\tracingfonts
218 not provided.\MessageBreak
219 Use the `tracefnt' package.\MessageBreak Command found:}%
220 \count@}
221 %</2ekernel>
222 % \end{macrocode}
223 % The |\count@| in the line above will remove the number after
224 % |\tracingfonts|. Note that this definition will be overwritten be
225 % the next line if one of these modules are included.
226 % \begin{macrocode}
227 %<*package,trace,debug>
228 \newcount\tracingfonts
229 \tracingfonts=0
230 %</package,trace,debug>
231 % \end{macrocode}
232 % \end{macro}
233 %
234 %
235 % The option \Loption{errorshow} turns off all warnings so that only
236 % real errors are shown. \Loption{warningshow} corresponds to the
237 % NFSS default (when \texttt{tracefnt} is not loaded).
238 % \Loption{infoshow} is the default for this package here; and
239 % \Loption{debugshow}, \Loption{loading}, and
240 % \Loption{pausing} extend the amount of information even further.
241 % \changes{v2.3o}{1995/05/13}
242 % {Use single hash mark in \cs{DeclareOption}}
243 % \begin{macrocode}
244 %<*package>
245 \DeclareOption{errorshow}{%
246 \def\@font@info#1{%
247 \GenericInfo{(Font)\@spaces\@spaces\@spaces\space\space}%
248 {LaTeX Font Info: \space\space\space#1}}%
249 \def\@font@warning#1{%
250 \GenericInfo{(Font)\@spaces\@spaces\@spaces\space\space}%
251 {LaTeX Font Warning: #1}}%
252 }
253 % \end{macrocode}
254 %
255 % \begin{macrocode}
256 \DeclareOption{warningshow}{%
257 \def\@font@info#1{%
258 \GenericInfo{(Font)\@spaces\@spaces\@spaces\space\space}%
259 {LaTeX Font Info: \space\space\space#1}}%
260 \def\@font@warning#1{%
261 \GenericWarning{(Font)\@spaces\@spaces\@spaces\space\space}%
262 {LaTeX Font Warning: #1}}%
263 }
264 % \end{macrocode}
265 %
266 % \begin{macrocode}
267 \DeclareOption{infoshow}{%
268 \def\@font@info#1{%
269 \GenericWarning{(Font)\@spaces\@spaces\@spaces\space\space}%
270 {LaTeX Font Info: \space\space\space#1}}%
271 \def\@font@warning#1{%
272 \GenericWarning{(Font)\@spaces\@spaces\@spaces\space\space}%
273 {LaTeX Font Warning: #1}}%
274 }
275 % \end{macrocode}
276 %
277 % \begin{macrocode}
278 \DeclareOption{loading}{%
279 \tracingfonts\tw@
280 }
281 % \end{macrocode}
282 %
283 % \begin{macrocode}
284 \DeclareOption{debugshow}{%
285 \ExecuteOptions{infoshow}%
286 \tracingfonts\thr@@
287 }
288 % \end{macrocode}
289 %
290 % \changes{v3.0j}{1997/05/29}{Replaced \texttt{\symbol{92}\symbol{92}}
291 % by \cs{MessageBreak}, as suggested by Donald Arseneau.}
292 % \begin{macrocode}
293 \DeclareOption{pausing}{%
294 \def\@font@warning#1{%
295 \GenericError
296 {(Font)\@spaces\@spaces\@spaces\space\space}%
297 {LaTeX Font Warning: #1}%
298 {See the LaTeX Companion for details.}%
299 {I'll stop for every LaTeX Font Warning because
300 you requested\MessageBreak the `pausing' option
301 to the tracefnt package.}}%
302 }
303 % \end{macrocode}
304 % We make |infoshow| the default, which in turn defines
305 % |\font@warning| and |\font@info|.
306 % \begin{macrocode}
307 \ExecuteOptions{infoshow}
308 \ProcessOptions
309 %</package>
310 % \end{macrocode}
311 %
312 % We also need a default definition inside the kernel:
313 % \begin{macrocode}
314 %<*2ekernel>
315 \def\@font@info#1{%
316 \GenericInfo{(Font)\@spaces\@spaces\@spaces\space\space}%
317 {LaTeX Font Info: \space\space\space#1}}%
318 \def\@font@warning#1{%
319 \GenericWarning{(Font)\@spaces\@spaces\@spaces\space\space}%
320 {LaTeX Font Warning: #1}}%
321 %</2ekernel>
322 % \end{macrocode}
323 %
324 %
325 % \section{Macros common to \texttt{fam.tex} and \texttt{tracefnt.sty}}
326 %
327 % In the first versions of \texttt{tracefnt.dtx} some macros of
328 % \texttt{fam.dtx}\footnote{This file is currently not distributed in
329 % documented form. Its code is part of \texttt{ltfss.dtx}.}
330 % were redefined to included the extra tracing
331 % information. Now these macros are all defined in this file (i.e.\
332 % removed from \texttt{fam.dtx}) and different production versions can
333 % be obtained simply by specifying a different set of modules to
334 % include when generating \texttt{ltfss.dtx}.
335 %
336 %
337 %
338 % \subsection{General font loading}
339 %
340 %
341 % \begin{macro}{\extract@font}
342 %
343 % This macro organizes the font loading.
344 % It first calls |\get@external@font|
345 % which will return in |\external@font| the name of the external
346 % font file (the \texttt{.tfm}) as it was determined by the NFSS
347 % tables.
348 % \begin{macrocode}
349 %<*2ekernel|package>
350 \def\extract@font{%
351 \get@external@font
352 % \end{macrocode}
353 % Then the external font is loaded and assigned to the font
354 % identifier stored inside |\font@name|
355 % (for this reason we need |\expandafter|).
356 % \begin{macrocode}
357 \global\expandafter\font\font@name\external@font\relax
358 % \end{macrocode}
359 % When tracing we typeout the internal and external font name.
360 % \changes{v1.0k}{1990/03/14}{Added code for TeX3.}
361 % \begin{macrocode}
362 %<*trace>
363 \ifnum \tracingfonts >\@ne
364 \@font@info{External font `\external@font'
365 loaded as\MessageBreak \font@name}\fi
366 %</trace>
367 % \end{macrocode}
368 % Finally we call the corresponding ``loading action'' macros to
369 % finish things. First the font is locally selected to allow the
370 % use of |\font| inside the loading action macros.
371 % \begin{macrocode}
372 \font@name \relax
373 % \end{macrocode}
374 % The next two lines execute the ``loading actions'' for the
375 % family and then for the individual font shape.
376 % \begin{macrocode}
377 \csname \f@encoding+\f@family\endcsname
378 \csname\curr@fontshape\endcsname
379 \relax
380 }
381 %</2ekernel|package>
382 % \end{macrocode}
383 % The |\relax| at the end needs to be explained.
384 % This is inserted to prevent \TeX{} from scanning too far
385 % when it is executing the replacement text of the loading
386 % code macros.
387 % \end{macro}
388 %
389 %
390 % \begin{macro}{\get@external@font}
391 % This function tries to find an external font name. It will place
392 % the name into the macro
393 % |\external@font|. If no font is found it will return the one
394 % that was defined via |\DeclareErrorFont|.
395 % \begin{macrocode}
396 %<*2ekernel>
397 \def\get@external@font{%
398 % \end{macrocode}
399 % We don't know the external font name at the beginning.
400 % \begin{macrocode}
401 \let\external@font\@empty
402 \edef\font@info{\expandafter\expandafter\expandafter\string
403 \csname \curr@fontshape \endcsname}%
404 \try@size@range
405 % \end{macrocode}
406 % If this failed, we'll try to substitute another size of the same
407 % font. This is done by the |\try@size@substitution| macro. It
408 % ``knows about'' |\do@extract@font|, |\font@name|, |\f@size|, and
409 % so on.
410 % \begin{macrocode}
411 \ifx\external@font\@empty
412 \try@size@substitution
413 \ifx\external@font\@empty
414 \@latex@error{Font \expandafter \string\font@name\space
415 not found}\@eha
416 \error@fontshape
417 \get@external@font
418 \fi\fi
419 }
420 %</2ekernel>
421 % \end{macrocode}
422 % \end{macro}
423 %
424
425 % \begin{macrocode}
426 %<*2ekernel|latexrelease|package>
427 %<latexrelease>\IncludeInRelease{2021/06/01}%
428 %<latexrelease> {\selectfont}{Add hook to \selectfont}%
429 % \end{macrocode}
430 %
431 %
432 %
433 %
434 % \begin{macro}{\selectfont}
435 % \changes{v1.0j}{1990/02/18}
436 % {Redefine unprotected version \cs{p@selectfont}
437 % instead of \cs{selectfont}.}
438 % \changes{v1.1a}{1989/12/16}{Changed order of calls.}
439 % \changes{v2.3f}{1994/05/12}{Use \cs{DeclareRobustCommand}}
440 % The macro |\selectfont| is called whenever a font change must
441 % take place.
442 % \begin{macrocode}
443 \DeclareRobustCommand\selectfont
444 {%
445 % \end{macrocode}
446 % When \module{debug} is specified we actually want something like
447 % `undebug'. The font selection is now stable so that using
448 % |\tracingall| on some other macros will show us a lot of unwanted
449 % information about font loading. Therefore we disable tracing during
450 % font loading as long as |\tracingfonts| is less than $4$.
451 % \changes{v1.0m}{1990/04/05}
452 % {Call \cs{tracingon} only if \cs{tracingfonts} greater than 3.}
453 % \changes{v1.0n}{1990/05/05}{\cs{tracingon} with new syntax.}
454 % \begin{macrocode}
455 %<+debug> \pushtracing
456 %<+debug> \ifnum\tracingfonts<4 \tracingoff
457 %<+debug> \else \tracingon\p@selectfont \fi
458 % \end{macrocode}
459 % If |\baselinestretch| was redefined by the user it will not
460 % longer match its internal counterpart |\f@linespread|. If so we
461 % call |\set@fontsize| to prepare |\size@update|.
462 % \begin{macrocode}
463 \ifx\f@linespread\baselinestretch \else
464 \set@fontsize\baselinestretch\f@size\f@baselineskip \fi
465 % \end{macrocode}
466 %
467 % The series and shape updates are only prepared by
468 % \cs{fontseries} and \cs{fontshape} but not executed until after
469 % we are ready to change the font face. This way they happen after
470 % a possibly new family is set which is important because they
471 % look at the available font faces in that family and alter the
472 % selection based on availability. Several calls to \cs{fontseries}
473 % or \cs{fontshape} are delayed in the order in which they appear,
474 % so that by switching them one can work around missing
475 % intermediate font faces and avoid substitutions.
476 %
477 % We first attempt to do the merge without any substitution. As we
478 % might end up with a non-existing font face we may have to restart
479 % and therefore save the current values of \cs{f@series} and
480 % \cs{f@shape} before the merge.
481 %
482 % But first we make a quick test to see if there are any delayed
483 % actions, because if not it is pointless to make all the
484 % assignments and try loading a missing fontshape.
485 %
486 % \changes{v3.0n}{2020/12/22}{Execute delayed series and shape updates (gh/444)}
487 % \begin{macrocode}
488 \ifx\delayed@f@adjustment\@empty
489 \else
490 \let\f@shape@saved\f@shape
491 \let\f@series@saved\f@series
492 % \end{macrocode}
493 % Then we run the delayed adjustments (which use the
494 % \cs{..@without@substitution} commands):
495 % \begin{macrocode}
496 \delayed@f@adjustment
497 % \end{macrocode}
498 % We then check if the resulting cominbation is valid but for this
499 % we have to make sure that the appropriate \texttt{.fd} is loaded if
500 % that hasn't happened so far.
501 % \begin{macrocode}
502 \maybe@load@fontshape
503 \ifcsname \f@encoding/\f@family/\f@series/\f@shape \endcsname
504 % \end{macrocode}
505 % If this macro is defined then we are good and no further action
506 % is necessary.
507 %
508 % Otherwise the combination is not valid, so we redo the merge but
509 % this time with substitutions.
510 % \begin{macrocode}
511 \else
512 \let\f@shape\f@shape@saved
513 \let\f@series\f@series@saved
514 \let\delayed@merge@font@shape\merge@font@shape
515 \let\delayed@merge@font@series\merge@font@series
516 \delayed@f@adjustment
517 \let\delayed@merge@font@shape\merge@font@shape@without@substitution
518 \let\delayed@merge@font@series\merge@font@series@without@substitution
519 \fi
520 % \end{macrocode}
521 % Now the series and shape values are updated and we clear
522 % \cs{delayed@f@adjustment}. This is important because on the next
523 % execution of \cs{selectfont} we should not mistakenly redo the
524 % delayed actions if there wasn't any series or shape change.
525 % \begin{macrocode}
526 \let\delayed@f@adjustment\@empty
527 \fi
528 % \end{macrocode}
529 % If the series was forced we should now cancel that in case the
530 % next series change is done with some low-level setting to
531 % \cs{f@series}.
532 % \changes{v3.0o}{2021/04/26}{Unset the forced series boolean when reaching
533 % \cs{selectfont} (gh/444)}
534 % \begin{macrocode}
535 \@forced@seriesfalse
536 % \end{macrocode}
537 % Then we generate the internal name of the font
538 % by concatenating {\em family}, {\em series},
539 % {\em shape}, and current {\em size},
540 % with slashes as delimiters between them.
541 % This is much more readable than standard
542 % \LaTeX's |\twfbf|, etc.
543 % We define |\font@name| globally, as always.
544 % The reason for this is explained later on.
545 % \changes{v2.0b}{1992/07/26}{}
546 % \begin{macrocode}
547 \xdef\font@name{%
548 \csname\curr@fontshape/\f@size\endcsname}%
549 % \end{macrocode}
550 % We call the macro |\pickup@font| which will load the font if
551 % necessary.
552 % \begin{macrocode}
553 \pickup@font
554 % \end{macrocode}
555 % Then we select the font.
556 % \begin{macrocode}
557 \font@name
558 % \end{macrocode}
559 %
560 % After switching fonts we run a hook, so that packages can make
561 % last minute alterations based on the new font (originally provided
562 % in \pkg{everysel} but using a different interface).
563 % \changes{v3.0m}{2020/12/03}{Install a hook in \cs{selectfont} (gh/444)}
564 % \begin{macrocode}
565 \UseHook{selectfont}%
566 % \end{macrocode}
567 % Finally we call |\size@update|. This macro is normally empty but
568 % will contain actions (like setting the |\baselineskip|) that have
569 % to be carried out when the font size, the base |\baselineskip| or
570 % the |\baselinestretch| have changed.
571 % \begin{macrocode}
572 \size@update
573 % \end{macrocode}
574 % A similar function is called to handle anything related to
575 % encoding updates. This one is changed from |\relax| by
576 % |\fontencoding|.
577 % \changes{v2.3h}{1994/05/14}{Added \cs{enc@update}}
578 % \begin{macrocode}
579 \enc@update
580 % \end{macrocode}
581 % Just before ending this macro we have to pop the tracing stack
582 % if it was pushed before.
583 % \begin{macrocode}
584 %<+debug> \poptracing
585 }
586 % \end{macrocode}
587 % \end{macro}
588 %
589 %
590 % \begin{macro}{selectfont}
591 % Declare the hook used in selecfont in the kernel, but not
592 % inside the \pkg{tracefnt} package.
593 % \begin{macrocode}
594 %<-trace>\NewHook{selectfont}
595 % \end{macrocode}
596 % \end{macro}
597 %
598 %
599 % If |\tracingfonts| is
600 % greater than 2 we also show the font switch inside \cs{selectfont}.
601 % We do this by adding this code to the hook in the \pkg{tracefnt} package:
602 % macro might redefine |\font@name|.
603 % \begin{macrocode}
604 %<*trace>
605 \AddToHook{selectfont}
606 {\ifnum \tracingfonts>\tw@
607 \@font@info{Switching to \font@name}\fi}
608 %</trace>
609 % \end{macrocode}
610 %
611 %
612 % \begin{macrocode}
613 %</2ekernel|latexrelease|package>
614 %<latexrelease>\EndIncludeInRelease
615 % \end{macrocode}
616 %
617 % With \cs{selectfont} having different definitions in different
618 % kernels we also have to provide them in the \texttt{tracefnt}
619 % package to support rollback. In packages that works a bit
620 % differently and therefore we have to provide an empty block there.
621 % \begin{macrocode}
622 %<package>\IncludeInRelease{2021/06/01}%
623 %<package> {\selectfont}{Add hook to \selectfont}%
624 %<package>\EndIncludeInRelease
625 % \end{macrocode}
626 %
627 % \begin{macrocode}
628 %<latexrelease|package>\IncludeInRelease{0000/00/00}%
629 %<latexrelease|package> {\selectfont}{Add hook to \selectfont}%
630 %<latexrelease|package>
631 %<latexrelease|package>\DeclareRobustCommand\selectfont
632 %<latexrelease|package> {%
633 %<latexrelease|package> \ifx\f@linespread\baselinestretch \else
634 %<latexrelease|package> \set@fontsize\baselinestretch\f@size\f@baselineskip \fi
635 %<latexrelease|package> \xdef\font@name{%
636 %<latexrelease|package> \csname\curr@fontshape/\f@size\endcsname}%
637 %<latexrelease|package> \pickup@font
638 %<latexrelease|package> \font@name
639 %<latexrelease|package> \size@update
640 %<latexrelease|package> \enc@update
641 %<latexrelease|package> }
642 %<latexrelease|package>
643 %<latexrelease|package>\EndIncludeInRelease
644 % \end{macrocode}
645 %
646 %
647 %
648 % \begin{macro}{\set@fontsize}
649 % The macro |\set@fontsize| does the actual work. First it assigns
650 % new values to |\f@size|, |\f@baselineskip| and |\f@linespread|.
651 % \begin{macrocode}
652 %<*2ekernel|package>
653 \def\set@fontsize#1#2#3{%
654 \@defaultunits\@tempdimb#2pt\relax\@nnil
655 \edef\f@size{\strip@pt\@tempdimb}%
656 \@defaultunits\@tempskipa#3pt\relax\@nnil
657 \edef\f@baselineskip{\the\@tempskipa}%
658 \edef\f@linespread{#1}%
659 % \end{macrocode}
660 % For backward compatibility and for later testing within
661 % |\selectfont| the internal value of |\f@linespread| is passed
662 % back to |\baselinestretch|.
663 % \begin{macrocode}
664 \let\baselinestretch\f@linespread
665 % \end{macrocode}
666 % Additional processing will happen within |\selectfont|. For this
667 % reason the macro |\size@update| (which will be called in
668 % |\selectfont|) will be defined to be:
669 % \begin{macrocode}
670 \def\size@update{%
671 % \end{macrocode}
672 % First calculate the new |\baselineskip| and also store it in
673 % |normalbaselineskip|
674 % \begin{macrocode}
675 \baselineskip\f@baselineskip\relax
676 \baselineskip\f@linespread\baselineskip
677 \normalbaselineskip\baselineskip
678 % \end{macrocode}
679 % then to set up a new |\strutbox|
680 % \begin{macrocode}
681 \setbox\strutbox\hbox{%
682 \vrule\@height.7\baselineskip
683 \@depth.3\baselineskip
684 \@width\z@}%
685 % \end{macrocode}
686 % We end with a bit of tracing information.
687 % \begin{macrocode}
688 %<*trace>
689 \ifnum \tracingfonts>\tw@
690 \ifx\f@linespread\@empty
691 \let\reserved@a\@empty
692 \else
693 \def\reserved@a{\f@linespread x}%
694 \fi
695 \@font@info{Changing size to \f@size/\reserved@a
696 \f@baselineskip}%
697 \aftergroup\type@restoreinfo \fi
698 %</trace>
699 % \end{macrocode}
700 % When all this is processed |\size@update| redefines itself to
701 % |\relax| so that in later calls of |\selectfont| no extra code
702 % will be executed.
703 % \begin{macrocode}
704 \let\size@update\relax}%
705 }
706 % \end{macrocode}
707 % Instead of defining this macro internally we might speed things
708 % up by placing the code into a separate macro and use |\let|!
709 % \end{macro}
710 %
711 %
712 % \begin{macro}{\size@update}
713 % Normally this macro does nothing; it will be redefined by
714 % |\set@fontsize| to initiate an update.
715 % \begin{macrocode}
716 \let\size@update\relax
717 % \end{macrocode}
718 % \end{macro}
719 %
720 %
721 % \begin{macro}{\type@restoreinfo}
722 % This macro produces some info when a font size and/or baseline
723 % change will get restored.
724 % \changes{1.0r}{1990/08/27}{Some extra tracing info.}
725 % \begin{macrocode}
726 %<*trace>
727 \def\type@restoreinfo{%
728 \ifx\f@linespread\@empty
729 \let\reserved@a\@empty
730 \else
731 \def\reserved@a{\f@linespread x}%
732 \fi
733 \@font@info{Restoring size to
734 \f@size/\reserved@a\f@baselineskip}}
735 %</trace>
736 % \end{macrocode}
737 % \end{macro}
738 %
739 % \begin{macro}{\glb@settings}
740 % \begin{macro}{\glb@currsize}
741 % \changes{v2.3a}{1994/01/17}{New math font setup}
742 % \changes{v2.3k}{1994/11/06}{New implementation}
743 % The macro |\glb@settings| globally selects
744 % all math fonts for the current size if necessary.
745 % \begin{macrocode}
746 \def\glb@settings{%
747 % \end{macrocode}
748 % When |\glb@settings| gains control a size
749 % change was requested and all previous font assignments need to
750 % be replaced.
751 % Therefore the old values of the fonts are no longer needed.
752 % For every {\em math group\/} the new assignments are appended to
753 % |\math@fonts|.
754 % But this happens only if the |math@fonts| switch
755 % is set to true.
756 % However, we always set up the correct math sizes for script and
757 % scriptscript fonts since they may be needed even if we don't set
758 % up the whole math machinery.
759 %
760 % Here we set the math size, script size and scriptscript size.
761 % If the |S@|\ldots{} macro is not defined we have to first
762 % calculate the three sizes.
763 % \begin{macrocode}
764 \expandafter\ifx\csname S@\f@size\endcsname\relax
765 \calculate@math@sizes
766 \fi
767 % \end{macrocode}
768 % The effect of this is that |\calculate@math@sizes|
769 % may or may not define the |S@|\ldots{} macro. In the
770 % first case the next time the same size is requested
771 % this macro is used, otherwise |\calculate@math@sizes| is
772 % called again.
773 % This also sets the |math@fonts| switch.
774 % If it is true we must switch the math fonts.
775 % \begin{macrocode}
776 \csname S@\f@size\endcsname
777 \ifmath@fonts
778 %<*trace>
779 \ifnum \tracingfonts>\tw@
780 \@font@info{Setting up math fonts for
781 \f@size/\f@baselineskip}\fi
782 %</trace>
783 % \end{macrocode}
784 % Inside a group we execute the macro for the current math {\em
785 % version}. This sets |\math@fonts| to a list of
786 % |\textfont|\dots{} assignments. |\getanddefine@fonts| (which may
787 % be called at this point) needs the |\escapechar| parameter to be
788 % set to $-1$.
789 % \begin{macrocode}
790 \begingroup
791 \escapechar\m@ne
792 \csname mv@\math@version \endcsname
793 % \end{macrocode}
794 % Then we set |\globaldefs| to 1 so that all following changes are
795 % done globally. The math font assignments recorded in
796 % |\math@fonts| are executed and |\glb@currsize| is set equal to
797 % |\f@size|. This signals that the fonts for math in this size are
798 % set up.
799 % \begin{macrocode}
800 \globaldefs\@ne
801 \math@fonts
802 \let \glb@currsize \f@size
803 \endgroup
804 % \end{macrocode}
805 % Finally we execute any code that is supposed to happen
806 % whenever the math font setup changes. This register will
807 % be executed in local mode which means that everything that is
808 % supposed to have any effect should be done globally inside.
809 % We can't execute it within |\globaldefs\@ne| as we don't know
810 % what ends up inside this register, e.g., it might contain
811 % calculations which use some local registers to calculate the
812 % final (global) value.
813 % \begin{macrocode}
814 \the\every@math@size
815 % \end{macrocode}
816 % Otherwise we announce that the math fonts are not set up for this
817 % size.
818 % \begin{macrocode}
819 %<*trace>
820 \else
821 \ifnum \tracingfonts>\tw@
822 \@font@info{No math setup for
823 \f@size/\f@baselineskip}\fi
824 %</trace>
825 \fi
826 }
827 %</2ekernel|package>
828 % \end{macrocode}
829 % \end{macro}
830 % \end{macro}
831 %
832 %
833 % \begin{macro}{\baselinestretch}
834 % \changes{v1.0o}{1990/06/24}{Moved to tracefnt.dtx.}
835 % In |\selectfont| we used |\baselinestretch| as
836 % a factor when assigning a value to |\baselineskip|.
837 % We use 1 as a default (i.e.\ no stretch).
838 % \begin{macrocode}
839 %<*2ekernel>
840 \def\baselinestretch{1}
841 % \end{macrocode}
842 % \end{macro}
843 %
844 % \begin{macro}{\every@math@size}
845 % \changes{v1.0u fam.dtx}{1989/12/05}{Hook \cs{every@size} added.}
846 % \changes{v23.k}{1994/10/23}{Renamed to \cs{every@math@size}}
847 % We must still define the hook |\every@math@size| we used in
848 % |\glb@settings|. We initialize it to nothing. It is important to
849 % remember that everything that goes into this hook should to global
850 % updates, local changes will have weird effects.
851 % \begin{macrocode}
852 \newtoks\every@math@size
853 \every@math@size={}
854 %</2ekernel>
855 % \end{macrocode}
856 % \end{macro}
857 %
858 %
859 %
860 % \subsection{Math fonts setup}
861 %
862 %
863 % \subsubsection{Outline of algorithm for math font sizes}
864 %
865 % \TeX{} uses the math fonts that are current when the end of a
866 % formula is reached. If we don't want to keep font setups local to
867 % every formula (which would result in an enormous overhead), we have
868 % to be careful not to end up with the wrong setup in case formulas
869 % are nested, e.g., we need to be able to handle
870 % \begin{verbatim}
871 % $ a=b+c \mbox{ \small for all $b$ and $c\in Z$}$
872 %\end{verbatim}
873 % Here the inner formulae |b| and |c\in Z| are typeset in |\small| but
874 % we have to return to |\normalsize| before we reach the
875 % closing |$| \iffalse$\fi
876 % of the outer formula.
877 %
878 % This is handled in the following way:
879 % \begin{enumerate}
880 % \item At any point in the document the global variable
881 % |\gbl@currsize| contains the point size for which the math fonts
882 % currently are set up.
883 %
884 % \item \label{it:everymath} Whenever we start a formula we compare
885 % its value with the local variable |\f@size| that describes the
886 % current text font size.
887 %
888 % \item If both are the same we assume that we can use the current
889 % math font setup without adjustment.
890 %
891 % \item \label{it:everymathend} If they differ we call |\gbl@settings|
892 % which changes the math font setup and updates |\gbl@currsize|.
893 % \begin{enumerate}
894 % \item If we are recursively inside another formula (|\if@inmath|) we
895 % ensure that |\gbl@settings| is executed again in the outer
896 % formula, so that the old setup is automatically restored.
897 % \item Otherwise, we set the switch |@inmath| locally to |true| so
898 % that all nested formulae will be able to detect that they are
899 % nested in some outer formula.
900 % \end{enumerate}
901 % \end{enumerate}
902 %
903 %
904 % The above algorithm has the following features:
905 % \begin{itemize}
906 % \item For sizes which are not containing any formula no math setup
907 % is done. Compared to the original algorithm of NFSS this results
908 % in the following savings:
909 % \begin{itemize}
910 % \item No unnecessary loading of math fonts for sizes that are not
911 % used to typeset any math formulae (explicit or implicit ones).
912 % \item No time overhead due to unnecessary changes of the math font
913 % setup on entrance and exit of the text font size.
914 % \end{itemize}
915 %
916 % \item Math font setup changes for top-level formulae will survive
917 % (there is no restoration after the formula) thus any following
918 % formula in the same size will be directly typesetable. Compared to
919 % original implementation in NFSS2
920 % the new algorithm has the overhead of one test per formula
921 % to see if the current math setup is valid (in the original
922 % algorithm the setup was always valid, thus no test was necessary).
923 %
924 % \item In nested formulae the math font setup is restored in the
925 % outer formula by a series of |\aftergroup| commands and checks.
926 % Compared to the original algorithm this involves additional checks
927 % ($2 \times \langle\mbox{non-math levels}\rangle$ per inner
928 % formula).
929 % \end{itemize}
930 %
931 % \subsubsection{Code for math font size setting}
932 %
933 % \begin{macro}{\check@mathfonts}
934 % \changes{v2.3a}{1994/01/17}{New math font setup}
935 % \changes{v2.3c}{1994/01/26}{Correct trace info placement}
936 % In the |\check@mathfonts| macros we implement the steps
937 % \ref{it:everymath} to \ref{it:everymathend} except that instead
938 % of a switch the macro |\init@restore@glb@settings| is used.
939 % \begin{macrocode}
940 %<*2ekernel|package>
941 \def\check@mathfonts{%
942 \ifx \glb@currsize \f@size
943 %<*trace>
944 \ifnum \tracingfonts>\thr@@
945 \@font@info{*** MATH: no change \f@size\space
946 curr/global (\curr@math@size/\glb@currsize)}\fi
947 %</trace>
948 \else
949 %<*trace>
950 \ifnum \tracingfonts>\thr@@
951 \@font@info{*** MATH: setting up \f@size\space
952 curr/global (\curr@math@size/\glb@currsize)}\fi
953 %</trace>
954 \glb@settings
955 \init@restore@glb@settings
956 \fi
957 \let\curr@math@size\f@size
958 \def\init@restore@glb@settings{\aftergroup\restglb@settings}%
959 }
960 % \end{macrocode}
961 % \end{macro}
962 %
963 %
964 %
965 %
966 % \begin{macro}{\init@restore@glb@settings}
967 % \changes{v3.0i}{1996/07/26}{macro added replacing \cs{if@inmath} switch}
968 % This macros does by default nothing but get redefined inside
969 % |\check@mathfonts| to initiate fontsize restoring in nested
970 % formulas.
971 % \begin{macrocode}
972 %<-trace>\let\init@restore@glb@settings\relax
973 %<*trace>
974 \def\init@restore@glb@settings{%
975 \ifnum \tracingfonts>\thr@@
976 \@font@info{*** MATH: no resetting (not in
977 nested math)}\fi
978 }
979 %</trace>
980 % \end{macrocode}
981 % \end{macro}
982 %
983 %
984 % \begin{macro}{\restglb@settings}
985 % \changes{v2.3a}{1994/01/17}{New math font setup}
986 % \changes{v2.3c}{1994/01/26}{Correct trace info placement}
987 % This macro will be executed the first time after the current
988 % formula.
989 % \begin{macrocode}
990 \def\restglb@settings{%
991 %<*trace>
992 \ifnum \tracingfonts>\thr@@
993 \@font@info{*** MATH: restoring}\fi
994 %</trace>
995 \begingroup
996 \let\f@size\curr@math@size
997 \ifx\glb@currsize \f@size
998 %<*trace>
999 \ifnum \tracingfonts>\thr@@
1000 \@font@info{*** MATH: ... already okay (\f@size)}\fi
1001 %</trace>
1002 \else
1003 %<*trace>
1004 \ifnum \tracingfonts>\thr@@
1005 \@font@info{*** MATH: ... to \f@size}\fi
1006 %</trace>
1007 \glb@settings
1008 \fi
1009 \endgroup
1010 }
1011 % \end{macrocode}
1012 % \end{macro}
1013 %
1014 %
1015 % \subsubsection{Other code for math}
1016 %
1017 %
1018 % \begin{macro}{\use@mathgroup}
1019 % \changes{v1.2b}{1990/01/21}{Macro added to allow cleaner interface.}
1020 % \changes{v1.2h}{1990/03/30}{Third argument removed (see
1021 % \cs{math@egroup}).}
1022 % The |\use@mathgroup| macro should be used in user
1023 % macros to select a math group. Depending on whether or not the
1024 % \texttt{margid} option is in force it has two or three arguments.
1025 % For this reason it should be called as the last macro.
1026 %
1027 % First we test if we are inside math mode since we don't want to
1028 % apply a useless definition.
1029 % \changes{v1.1a}{1989/12/16}{Usage of `\quotechar=' macro added.}
1030 % \changes{v1.1a}{1989/12/16}{Redefinition of alphabet now simpler.}
1031 % \begin{macrocode}
1032 \def\use@mathgroup#1#2{\relax\ifmmode
1033 % \end{macrocode}
1034 % \changes{v1.0o}{1990/06/24}{Tracing code added.}
1035 % \changes{v1.0q}{1990/07/07}{Group number added to tracing.}
1036 % \begin{macrocode}
1037 %<*trace>
1038 \ifnum \tracingfonts>\tw@
1039 \count@#2\relax
1040 \@font@info{Using \noexpand\mathgroup
1041 (\the\count@) #2}\fi
1042 %</trace>
1043 % \end{macrocode}
1044 % If so we first call the `=' macro (i.e.\ argument three) to set
1045 % up special things for the selected math group. Then we call
1046 % |\mathgroup| to select the group given by argument two and
1047 % finally we place |#1| (i.e., the argument of the \meta{math
1048 % alphabet identifier}) at the end. This part of the code is
1049 % surrounded by two commands which behave like |\begingroup|
1050 % and |\endgroup| if we want \meta{math alphabet identifier}s
1051 % but will expand into |\@empty| if we want simply switches to
1052 % a new math group.
1053 % \changes{v1.0p}{1990/06/30}{Added \cs{relax} after math group number.}
1054 % Since argument number $2$ may be a digit instead of a control
1055 % sequence we add a |\relax|.
1056 % Otherwise something like |\mit{1}| would switch to math group
1057 % $11$ (and back) instead of printing an oldstyle $\mit {1}$.
1058 % \changes{v2.0b}{1992/07/26}{}
1059 % \begin{macrocode}
1060 \math@bgroup
1061 \expandafter\ifx\csname M@\f@encoding\endcsname#1\else
1062 #1\fi
1063 \mathgroup#2\relax
1064 % \end{macrocode}
1065 % Before we reinsert the swallowed token (arg.\ three) into the
1066 % input stream, in the case that the \meta{math alphabet
1067 % identifier} isn't called in math mode, we remove the |\fi|
1068 % with the |\expandafter| trick. This is necessary if the
1069 % token is actually an macro with arguments. In such a case the
1070 % |\fi| will be misinterpreted as the first argument which
1071 % would be disastrous.
1072 % \changes{v1.0f}{1989/12/13}
1073 % {\cs{expandafter} added before final \cs{fi}.}
1074 % \begin{macrocode}
1075 \expandafter\math@egroup\fi}%
1076 % \end{macrocode}
1077 % The surrounding macros equal |\begingroup| and |\endgroup|. But
1078 % using internal names makes it possible to overwrite their meaning
1079 % in certain cases. This is for example used in \AmSTeX{} macros
1080 % for placing accents.
1081 % \end{macro}
1082 %
1083 % \begin{macro}{\math@egroup}
1084 % \changes{v1.0q}{1990/07/07}{Tracing code added.} If the
1085 % \texttt{margid} option is in force (which can be tested by
1086 % looking at the definition of |\math@bgroup|) we change the
1087 % |\math@egroup| command a bit to display the current \meta{math
1088 % group number} after it closes the scope of \meta{math alphabet}
1089 % with |\endgroup|.
1090 % \changes{v3.0h}{1996/05/08}{Use \cs{bgroup} instead of \cs{begingroup}
1091 % to match a kernel change made in 1994!!!!}
1092 % \begin{macrocode}
1093 %<*trace>
1094 \ifx\math@bgroup\bgroup
1095 \def\math@egroup#1{#1\egroup
1096 \ifnum \tracingfonts>\tw@
1097 \@font@info{Restoring \noexpand\mathgroup
1098 (\ifnum\mathgroup=\m@ne default\else \the\mathgroup \fi)%
1099 }\fi}
1100 \fi
1101 %</trace>
1102 % \end{macrocode}
1103 % \end{macro}
1104 %
1105 % \begin{macro}{\getanddefine@fonts}
1106 % \changes{v1.0o}{1990/06/24}{\cs{Macro} moved from fam.dtx.}
1107 % |\getanddefine@fonts| has two arguments: the \meta{math
1108 % group number} and the {\em family/series/shape\/} name as a
1109 % control sequence.
1110 % \begin{macrocode}
1111 \def\getanddefine@fonts#1#2{%
1112 % \end{macrocode}
1113 % First we turn of tracing when |\tracingfonts| is less than $4$.
1114 % \changes{v1.0o}{1990/06/24}{Adding debug code.}
1115 % \changes{v1.0r}{1990/08/27}
1116 % {Correcting missing name after \cs{tracingon}.}
1117 % \begin{macrocode}
1118 %<+debug> \pushtracing
1119 %<+debug> \ifnum\tracingfonts<4 \tracingoff
1120 %<+debug> \else \tracingon\getanddefine@fonts \fi
1121 % \end{macrocode}
1122 % \changes{v1.0o}{1990/06/24}{\cs{Adding} tracing code.}
1123 % \changes{v1.0q}{1990/07/07}{Group number added to tracing.}
1124 % \changes{v2.1a}{1992/09/22}{Introduced \cs{tf@size} for math size.}
1125 % \changes{v3.0q}{2025/06/29}{Introduced \cs{transform@scriptfont} for script fonts.}
1126 % \begin{macrocode}
1127 %<*trace>
1128 \ifnum \tracingfonts>\tw@
1129 \count@#1\relax
1130 \@font@info{\noexpand\mathgroup (\the\count@) #1 :=\MessageBreak
1131 \string#2 \tf@size/\sf@size/\ssf@size}\fi
1132 %</trace>
1133 % \end{macrocode}
1134 % We append the current |\tf@size| to |#2| to obtain the font
1135 % name.\footnote{One might ask why this expansion does not generate
1136 % a macro name that starts with an additional \texttt{\bslash}
1137 % character. The solution is that \texttt{\bslash escapechar} is
1138 % set to $-1$ before \texttt{\bslash getanddefine@fonts} is
1139 % called.} Again, |font@name| is defined globally, for the reasons
1140 % explained in the description of |\wrong@fontshape|.
1141 % \begin{macrocode}
1142 \xdef\font@name{\csname \string#2/\tf@size\endcsname}%
1143 % \end{macrocode}
1144 % Then we call |\pickup@font| to load it if necessary.
1145 % We remember the internal name as |\textfont@name|.
1146 % \begin{macrocode}
1147 \pickup@font \let\textfont@name\font@name
1148 % \end{macrocode}
1149 % Same game for |\scriptfont| and |\scriptscriptfont|, but here we additionally
1150 % transform the fontname through |\transform@scriptfont| to allow different
1151 % family names in math scripts.
1152 % \begin{macrocode}
1153 \xdef\font@name{\csname \transform@scriptfont {sf}{#2}/\sf@size\endcsname}%
1154 \pickup@font \let\scriptfont@name\font@name
1155 \xdef\font@name{\csname \transform@scriptfont {ssf}{#2}/\ssf@size\endcsname}%
1156 \pickup@font
1157 % \end{macrocode}
1158 % Then we append the new |\textfont|\ldots{} assignments to
1159 % the |\math@fonts|.
1160 % \begin{macrocode}
1161 \edef\math@fonts{\math@fonts
1162 \textfont#1\textfont@name
1163 \scriptfont#1\scriptfont@name
1164 \scriptscriptfont#1\font@name}%
1165 % \end{macrocode}
1166 % Just before ending this macro we have to pop the tracing stack
1167 % if it was pushed before.
1168 % \begin{macrocode}
1169 %<+debug> \poptracing
1170 }
1171 % \end{macrocode}
1172 % \end{macro}
1173 %
1174 % \begin{macro}{\transform@scriptfont}
1175 % |\transform@scriptfont| has two arguments: the name of the script size we transform
1176 % the font for (always |sf| or |ssf|) and the \emph{family/series/shape\/} name as a csname.
1177 % It expands to a new \emph{family/series/shape\/} name which will be used for this
1178 % script.
1179 % For this |\transform@scriptfont| mostly delegates to |\__nfss_transform_scriptfont:nw|, which
1180 % searches for a replacement marker
1181 % |\__nfss_mapped_scriptfont_family_|\meta{scriptsize}|_|\meta{encoding}|/|\meta{family}
1182 % with a remapped encoding and family.
1183 % \begin{macrocode}
1184 \ExplSyntaxOn
1185 \cs_set:Npn \transform@scriptfont #1 #2 {
1186 \exp_last_unbraced:Nno
1187 \__nfss_transform_scriptfont:nw
1188 {#1}
1189 {\token_to_str:N #2}
1190 }
1191 \cs_set:Npn \__nfss_transform_scriptfont:nw #1 #2 / #3 / {
1192 \cs_if_exist_use:cF { __nfss_mapped_scriptfont_family_ #1 _ #2 / #3 } { #2 / #3 }
1193 /
1194 }
1195 % \end{macrocode}
1196 % \end{macro}
1197 %
1198 % \begin{macro}{\DeclareMathScriptfontMapping}
1199 % |\DeclareMathScriptfontMapping| can be used to define replacement font families which will be used
1200 % for math subscripts or subsubscripts when a specific font family is used as the main math font.
1201 % For this |\DeclareMathScriptfontMapping| takes three pairs of encoding and family names as arguments: The first pair identifies the base font for which associated script and scriptscript variants should be declared.
1202 % The second pair describes the family which should be used as scriptfonts (e.g.\ in subscripts).
1203 % Finally the third pair describes the family which should be used as scriptscriptfonts (e.g.\ in nested subscripts).
1204 % \begin{macrocode}
1205 \cs_set:Npn \DeclareMathScriptfontMapping #1 #2 #3 #4 #5 #6 {
1206 \cs_set:cpn { __nfss_mapped_scriptfont_family_sf_ #1 / #2 } { #3 / #4 }
1207 \cs_set:cpn { __nfss_mapped_scriptfont_family_ssf_ #1 / #2 } { #5 / #6 }
1208 }
1209 \ExplSyntaxOff
1210 %</2ekernel|package>
1211 % \end{macrocode}
1212 % \end{macro}
1213 %
1214 %
1215 % \section{Scaled font extraction}
1216 %
1217 % \begin{macro}{\ifnot@nil}
1218 % We begin with a simple auxiliary macro. It checks
1219 % whether its argument is the token |\@nil|. If so,
1220 % it expands to |\@gobble| which discards the following
1221 % argument, otherwise it expands to |\@firstofone| which
1222 % reproduces it argument.
1223 % \changes{v2.3n}{1995/05/08}{Use \cs{@firstofone}}
1224 % \begin{macrocode}
1225 %<*2ekernel>
1226 \def\ifnot@nil#1{\def\reserved@a{#1}%
1227 \ifx\reserved@a\@nnil \expandafter\@gobble
1228 \else \expandafter\@firstofone\fi}
1229 % \end{macrocode}
1230 % \end{macro}
1231 %
1232 %
1233 % \begin{macro}{\remove@to@nnil}
1234 % \begin{macro}{\remove@angles}
1235 % \begin{macro}{\remove@star}
1236 % Three other auxiliary macros will be needed in the following:
1237 % |\remove@to@nnil| gobbles up everything up to, and including,
1238 % the next |\@nnil| token, and |\remove@angles| and |\remove@star|
1239 % do the same
1240 % for the character |>| and |*|, respectively, instead of |\@nnil|.
1241 % \begin{macrocode}
1242 \def\remove@to@nnil#1\@nnil{}
1243 \def\remove@angles#1>{\set@simple@size@args}
1244 \def\remove@star#1*{#1}
1245 % \end{macrocode}
1246 % \end{macro}
1247 % \end{macro}
1248 % \end{macro}
1249 % \changes{v3.0c}{1995/08/24}{Macro \cs{gobble@font@spec} removed}
1250 %
1251 % \begin{macro}{\extract@sizefn}
1252 % This macro takes a size specification and parses it into size
1253 % function and the optional and mandatory arguments.
1254 % \begin{macrocode}
1255 \def\extract@sizefn#1*#2\@nil{%
1256 \if>#2>\set@size@funct@args#1\@nil
1257 \let\sizefn@info\@empty
1258 \else\expandafter\set@size@funct@args\remove@star#2\@nil
1259 \def\sizefn@info{#1}\fi
1260 }
1261 % \end{macrocode}
1262 % \end{macro}
1263 %
1264 %
1265 % \begin{macro}{\try@simple@size}
1266 % This function tries to extract the given size (specified by
1267 % |\f@size|) for the requested font shape. The font information
1268 % must already be present in |\font@info|.
1269 % The central macro that does the real work is |\extract@fontinfo|.
1270 % We will first give a simple example how this macro works, and
1271 % describe it in full generality later.
1272 %
1273 % Assume that the requested parameters are: {\em encoding scheme\/}
1274 % `OT1', {\em family\/} `cm', {\em series\/} `sansserif',
1275 % {\em shape\/} `normal', and {\em size\/} `$12$'.
1276 % The corresponding font definitions have already been
1277 % extracted from the macro |\OT1/cm/sansserif/normal| and
1278 % stored in |font@info|.
1279 % (Otherwise |\extract@fontinfo| doesn't get called.)
1280 % This information consists of a token list made of characters
1281 % of category code $12$ of the form
1282 % \begin{verbatim}
1283 % <10*>cmss10<12*>cmss12<17*>cmss17
1284 %\end{verbatim}
1285 % For reasonable packages one usually needs more sizes but this is
1286 % sufficient to get the flavour.
1287 % We will define a macro |\extract@fontinfo| to find
1288 % the external font name (`cmss12') for us:
1289 % \begin{verbatim}
1290 % \def\extract@fontinfo#1<12*#2>#3<#4\@nnil{%
1291 % \set@simple@size@args#3<#4\@nnil
1292 % \execute@size@function{#2}}
1293 %\end{verbatim}
1294 % so that when it gets called via
1295 % \begin{verbatim}
1296 % \extract@fontinfo<10*>cmss10<12*>cmss12<17*>cmss17\@nnil
1297 %\end{verbatim}
1298 % |#1| will contain all characters before |<12*>|,
1299 % |#2| will be empty, |#3| will be exactly |cmss12|,
1300 % and |#3| will be |17>cmss17|.
1301 % The expansion is therefore
1302 % \begin{verbatim}
1303 % \set@simple@size@args cmss12<17*>cmss17\@nnil
1304 % \execute@size@function{}
1305 %\end{verbatim}
1306 % This means: the default (empty) size function will be executed,
1307 % with its optional argument set to empty and its mandatory
1308 % argument set to |cmss12| by |\set@simple@size@args|.
1309 % As we discussed earlier, the effect of the default size function
1310 % is to load the given external font (cmss12) at the specified size
1311 % (12)---which is exactly what was intended.
1312 %
1313 % But this is only part of the whole story.
1314 % It may be that the size requested does not occur
1315 % in the token list |\font@info|.
1316 % And the simple definition of |\extract@fontinfo| we gave
1317 % above does not allow to specify give more than one
1318 % size specification in front of the external font name.
1319 %
1320 % Let's address these two problems separately. The first one
1321 % is solved with the following trick:
1322 % We define |\extract@fontinfo| as follows:
1323 % \begin{verbatim}
1324 % \def\extract@fontinfo#1<12*#2>#3<#4\@nnil{%
1325 % \ifnot@nil{#3}%
1326 % {\set@simple@size@args#3<#4\@nnil
1327 % \execute@size@function{#2}%
1328 % }}%
1329 %\end{verbatim}
1330 % How does this work?
1331 % We call |\extract@fontinfo| via
1332 % \begin{verbatim}
1333 % \expandafter\extract@fontinfo\font@info<12*>\@nil<\@nnil
1334 %\end{verbatim}
1335 % i.e. by appending |<12*>\@nil<\@nnil|.
1336 % If the size (`12' in this case) appears in |\font@info|
1337 % everything works as explained above, the only difference being
1338 % that argument |#4| of |\extract@fontinfo|
1339 % additionally gets the tokens |<12*>\@nil<\@nnil|.
1340 % However, if the size is not found everything up to the final
1341 % |<12*>| is in argument |#1|,
1342 % |#3| gets |\@nil|,
1343 % and |#2| and |#4| are empty.
1344 % The macro |\ifnot@nil| will discard the calls to
1345 % |\set@simple@size@args| and |execute@size@function|, and
1346 % hence |\font@info| will continue to be equal to |\@empty|.
1347 % This means that no simple size specification matching the
1348 % requested size could be found.
1349 %
1350 % The second problem (more than one simple size specification
1351 % for one external font name) will be addressed in
1352 % |\set@simple@size@args| below.
1353 %
1354 % The macros are hidden inside other control sequences
1355 % so that we have to build |\extract@fontinfo| in
1356 % several steps.
1357 %
1358 % So here's the actual definition of |\extract@font| in
1359 % |\try@simple@size|.
1360 % \begin{macrocode}
1361 % % this could be replaced by \try@size@range making the subst slower!
1362 \def\try@simple@size{%
1363 % \end{macrocode}
1364 % |\reserved@a| is made an abbreviation for the head of the
1365 % definition of the macro |\extract@fontinfo|.
1366 % \begin{macrocode}
1367 \def\reserved@a{\def\extract@fontinfo####1}%
1368 % \end{macrocode}
1369 % Now we can define |\extract@fontinfo|. Here we handle a small
1370 % but convenient variation: in case of the default (empty) size
1371 % function it is allowed to omit the |*| character.
1372 % \changes{v2.0b}{1992/07/26}{}
1373 % \changes{v2.0c}{1992/09/19}{}
1374 % \begin{macrocode}
1375 \expandafter\reserved@a\expandafter<\f@size>##2<##3\@nnil{%
1376 \ifnot@nil{##2}%
1377 {\set@simple@size@args##2<##3\@nnil
1378 \execute@size@function\sizefn@info
1379 }}%
1380 % \end{macrocode}
1381 % \changes{v2.0b}{1992/07/26}{}
1382 % Now we call |\extract@fontinfo|. Note the |<\@nil| \textsf{tokens}
1383 % at the end.
1384 % \begin{macrocode}
1385 \expandafter\expandafter
1386 \expandafter\extract@fontinfo\expandafter\font@info
1387 \expandafter<\f@size>\@nil<\@nnil
1388 }
1389 % \end{macrocode}
1390 % \end{macro}
1391 %
1392 % \begin{macro}{\set@simple@size@args}
1393 % As promised above, the macro |\set@simple@size@args| will handle
1394 % the case of several size specifications in a row.
1395 % If another size specification follows, the very first token of
1396 % its argument list is the character |<|.
1397 % By starting the definition as follows,
1398 % \begin{macrocode}
1399 \def\set@simple@size@args#1<{%
1400 % \end{macrocode}
1401 % parameter |#1| is empty in this case, and contains the size
1402 % function's arguments otherwise. We distinguish these two cases
1403 % (Note that the character |<| cannot appear in |#1|) by calling
1404 % |\remove@angles| for empty |#1| and |\extract@sizefn|
1405 % otherwise. In the latter case we have to take care of the
1406 % remaining character tokens and discard them. This is done by
1407 % |\remove@to@nnil|. Note also the use of Kabelschacht's method.
1408 % \begin{macrocode}
1409 \if<#1<%
1410 \expandafter\remove@angles
1411 \else
1412 \extract@sizefn#1*\@nil
1413 \expandafter\remove@to@nnil
1414 \fi}
1415 % \end{macrocode}
1416 % \end{macro}
1417 %
1418 %
1419 % Now, we are through with the case of a simple size, except for
1420 % calling the size function. This will be handled later, as it is
1421 % the same mechanism for all types of size specification. We will
1422 % now proceed to macros for extraction of size range specification.
1423 %
1424 %
1425 %
1426 % \begin{macro}{\extract@rangefontinfo}
1427 % |\extract@rangefontinfo| goes through a font shape definition
1428 % in the input until it recognizes the tokens |<\@nil->|.
1429 % It looks for font ranges with font size functions. It's operation
1430 % is rather simple: it discards everything up to the next size
1431 % specification and passes this on to |\is@range| for inspection.
1432 % The specification (parameter |#2|) is inserted again, in case
1433 % it is needed later.
1434 % \begin{macrocode}
1435 \def\extract@rangefontinfo#1<#2>{%
1436 \is@range#2->\@nil#2>}
1437 % \end{macrocode}
1438 % \end{macro}
1439 %
1440 % \begin{macro}{\is@range}
1441 % |\is@range| is again a sort of dispatcher macro: if the size
1442 % specification it is looking at is not a range specification
1443 % it discards it and calls |\extract@rangefontinfo| to continue
1444 % the search. Otherwise it calls |\check@range| to check the
1445 % requested size against the specified range.
1446 %
1447 % From the way |\is@range| is called inside |\extract@rangefontinfo|
1448 % we see that |#2| is the character |>| if the size specification
1449 % found is a simple one (that does not contain a |-| character).
1450 % This is checked easily enough and |\extract@rangefontinfo|
1451 % called again. Note that the extra tokens inserted after the
1452 % |\@nil| in the call to |\is@range| appear at the beginning of
1453 % the first argument to |\extract@rangefontinfo| and are hence
1454 % ignored.
1455 % \begin{macrocode}
1456 \def\is@range#1-#2\@nil{%
1457 \if>#2\expandafter\check@single\else
1458 \expandafter\check@range\fi}
1459 % \end{macrocode}
1460 % \end{macro}
1461 %
1462 %
1463 % \begin{macro}{\check@range}
1464 % |\check@range| takes lower bound as parameter |#1|, upper bound
1465 % as |#2|, size function as |#3| and the size function's arguments
1466 % as |#4|. If |#3| is the special token |\@nil| |\font@info| is
1467 % exhausted and we can stop searching.
1468 % \begin{macrocode}
1469 \def\check@range#1-#2>#3<#4\@nnil{%
1470 \ifnot@nil{#3}{%
1471 % \end{macrocode}
1472 % If |#3| wasn't |\@nil| we have a range. We start by assuming that
1473 % we have to recurse. Note that we have to reinsert an |<| as it
1474 % was already removed by scanning.
1475 % \begin{macrocode}
1476 \def\reserved@f{\extract@rangefontinfo<#4\@nnil}%
1477 % \end{macrocode}
1478 % We have to make sure that both boundaries are present, if not we
1479 % have to set them. Here we check the upper bound. If |\upper@bound|
1480 % is zero after the assignment we set it to |\maxdimen| (upper open
1481 % range). We need to use a \meta{dimen} register for the scan since
1482 % we may have a decimal number as the boundary.
1483 % \begin{macrocode}
1484 \upper@bound0#2\p@
1485 \ifdim\upper@bound=\z@ \upper@bound\maxdimen\fi
1486 % \end{macrocode}
1487 % Now we check the upper boundary against |\f@size|.
1488 % If it is larger or equal than |\f@size| this
1489 % range is no good and we have to recurse.
1490 % \begin{macrocode}
1491 \ifdim \f@size \p@<\upper@bound
1492 % \end{macrocode}
1493 % Otherwise we have to check the lower bound. This time it is not
1494 % necessary to scan the boundary value into a register because if
1495 % it is empty we get zero as desired. We could even omit the |0|
1496 % which would result in |1pt| as default lower boundary. If
1497 % |\f@size| is smaller than the boundary we have to recurse.
1498 % \begin{macrocode}
1499 \lower@bound0#1\p@
1500 \ifdim \f@size \p@<\lower@bound
1501 \else
1502 % \end{macrocode}
1503 % If both tests are passed we can try executing the size function.
1504 % \begin{macrocode}
1505 \set@simple@size@args#3<#4\@nnil
1506 \execute@size@function\sizefn@info
1507 % \end{macrocode}
1508 % If the function was successful it should have left an external
1509 % font name in |\external@font|. We use this to see if we can stop
1510 % scanning. Otherwise we recurse.
1511 % \begin{macrocode}
1512 \ifx\external@font\@empty
1513 \else
1514 \let\reserved@f\@empty
1515 \fi
1516 \fi
1517 \fi
1518 \reserved@f}}
1519 % \end{macrocode}
1520 % \end{macro}
1521 %
1522 % \begin{macro}{\lower@bound}
1523 % \begin{macro}{\upper@bound}
1524 % We use two dimen registers |\lower@bound| and |\upper@bound|
1525 % to store the lower and upper endpoints of the range we found.
1526 % \begin{macrocode}
1527 \newdimen\lower@bound
1528 \newdimen\upper@bound
1529 % \end{macrocode}
1530 % \end{macro}
1531 % \end{macro}
1532 %
1533 %
1534 % \begin{macro}{\check@single}
1535 % |\check@single| takes the size as parameter |#1|, size function
1536 % as |#2| and the size function's arguments as |#3|. We can assume
1537 % that there is always something in the pipeline since the very
1538 % last entry is a faked range (see above).
1539 % \begin{macrocode}
1540 \def\check@single#1>#2<#3\@nnil{%
1541 % \end{macrocode}
1542 % We start by assuming that
1543 % we have to recurse. Note that we have to reinsert an |<| as it
1544 % was already removed by scanning.
1545 % \begin{macrocode}
1546 \def\reserved@f{\extract@rangefontinfo<#3\@nnil}%
1547 % \end{macrocode}
1548 % Now we check the size against |\f@size|. If it is not equal
1549 % |\f@size| it is no good and we have to recurse.
1550 % \begin{macrocode}
1551 \ifdim \f@size \p@=#1\p@
1552 % \end{macrocode}
1553 % Otherwise if this test is passed we can try executing the size
1554 % function.
1555 % \begin{macrocode}
1556 \set@simple@size@args#2<#3\@nnil
1557 \execute@size@function\sizefn@info
1558 % \end{macrocode}
1559 % If the function was successful it should have left an external
1560 % font name in |\external@font|. We use this to see if we can stop
1561 % scanning. Otherwise we recurse.
1562 % \begin{macrocode}
1563 \ifx\external@font\@empty
1564 \else
1565 \let\reserved@f\@empty
1566 \fi
1567 \fi
1568 \reserved@f}
1569 % \end{macrocode}
1570 % \end{macro}
1571 %
1572 %
1573 % \begin{macro}{\set@size@funct@args}
1574 % \begin{macro}{\set@size@funct@args@}
1575 % This macro sets the optional and mandatory arguments for a size
1576 % function. If the optional argument is not present it is set to
1577 % the empty token list. The mandatory argument is delimited by the
1578 % token |\@nil|.
1579 % \begin{macrocode}
1580 \def\set@size@funct@args{\@ifnextchar[%
1581 \set@size@funct@args@{\set@size@funct@args@[]}}
1582 % \end{macrocode}
1583 %
1584 % \begin{macrocode}
1585 \def\set@size@funct@args@[#1]#2\@nil{%
1586 \def\mandatory@arg{#2}%
1587 \def\optional@arg{#1}}
1588 %</2ekernel>
1589 % \end{macrocode}
1590 % \end{macro}
1591 % \end{macro}
1592 %
1593 %
1594 % \begin{macro}{\DeclareSizeFunction}
1595 % This function defines a new size function hiding the internal
1596 % from the designer. The body of the size function may use
1597 % |\optional@arg| and |\mandatory@arg| denoting the optional and
1598 % mandatory argument that may follow the size specification |<...>|.
1599 % \changes{v2.1c}{1993/03/18}{Added all args to avoid blanks problems}
1600 % \begin{macrocode}
1601 %<*2ekernel>
1602 \def\DeclareSizeFunction#1#2{\@namedef{s@fct@#1}{#2}}
1603 \@onlypreamble\DeclareSizeFunction
1604 %</2ekernel>
1605 % \end{macrocode}
1606 % \end{macro}
1607 %
1608 %
1609 % \begin{macro}{\execute@size@function}
1610 % This macro is very simple. The only point worth noting
1611 % is that calling an undefined size function will do nothing
1612 % (actually execute a |\relax|).
1613 % \begin{macrocode}
1614 %<*2ekernel|package>
1615 \def\execute@size@function#1{%
1616 %<*trace>
1617 \@ifundefined{s@fct@#1}%
1618 {\errmessage{Undefined font size function #1}%
1619 \s@fct@}%
1620 {\csname s@fct@#1\endcsname}%
1621 %</trace>
1622 %<-trace> \csname s@fct@#1\endcsname
1623 }
1624 %</2ekernel|package>
1625 % \end{macrocode}
1626 % \end{macro}
1627 %
1628 % \changes{v2.3j}{1994/05/23}{Removed def of \cs{f@warn@break}}
1629 %
1630 %
1631 % \begin{macro}{\try@size@range}
1632 % This macro tries to find a suitable range for requested size
1633 % (specified by |\f@size|) in |\font@info|. All the relevant
1634 % action is done in |\extract@rangefontinfo|. All that needs
1635 % to be done is to stuff in the token list in |\font@info| so
1636 % that |\extract@rangefontinfo| can inspect it.
1637 % Note the |<-*\@nil><| token at the end to stop scanning.
1638 % \changes{v2.0b}{1992/07/26}{}
1639 % \begin{macrocode}
1640 %<*2ekernel>
1641 \def\try@size@range{%
1642 \expandafter\extract@rangefontinfo\font@info <-*>\@nil<\@nnil
1643 }
1644 % \end{macrocode}
1645 % \end{macro}
1646 %
1647 %
1648 % \begin{macro}{\try@size@substitution}
1649 % \changes{v2.3k}{1994/11/06}{New implementation}
1650 % This is the last thing that can be tried. If the desired |\f@size|
1651 % is found neither among the simple size specifications nor in one
1652 % of the ranges the whole list of size specifications is searched for
1653 % a nearby simple size.
1654 % \begin{macrocode}
1655 \gdef\try@size@substitution{%
1656 % \end{macrocode}
1657 % First we do some initializations. |\@tempdimb|
1658 % will hold the difference between the wanted size and the best
1659 % solution found so far, so we initialise it with |\maxdimen|.
1660 % The macro |\best@size| will hold the best size found, nothing
1661 % found is indicated by the empty value.
1662 % \begin{macrocode}
1663 \@tempdimb \maxdimen
1664 \let \best@size \@empty
1665 % \end{macrocode}
1666 % Now we loop over the specification
1667 % \begin{macrocode}
1668 \expandafter \try@simples \font@info <\number\@M>\@nil<\@nnil
1669 }
1670 % \end{macrocode}
1671 % \end{macro}
1672 %
1673 %
1674 % \begin{macro}{\font@submax}
1675 % \changes{v2.3d}{1994/04/18}{Changed dimen to macro}
1676 % \begin{macro}{\fontsubfuzz}
1677 % \changes{v2.3d}{1994/04/18}{Changed dimen to macro}
1678 % The macro |\font@submax| records the maximal deviation from the
1679 % desired size encountered so far. Its value is used in a warning
1680 % message at |\end{document}|. The macro
1681 % |\fontsubfuzz| contains the amount that will not cause terminal
1682 % warnings (warnings still go into the transcript file).
1683 % \begin{macrocode}
1684 \def\font@submax{0pt}
1685 \def\fontsubfuzz{.4pt}
1686 %</2ekernel>
1687 %<+package>\def\fontsubfuzz{0pt}
1688 % \end{macrocode}
1689 % \end{macro}
1690 % \end{macro}
1691 %
1692 %
1693 %
1694 % \begin{macro}{\try@simples}
1695 % \changes{v2.3k}{1994/11/06}{New implementation}
1696 % |\try@simples| goes through a font shape definition
1697 % in the input until it recognizes the tokens |<*\@nil><|.
1698 % It looks for simple sizes to determine the two closest sizes.
1699 % It is assumed that simple sizes are in increasing order.
1700 % \begin{macrocode}
1701 %<*2ekernel>
1702 \gdef\try@simples#1<#2>{%
1703 \tryif@simple#2->\tryif@simple}
1704 % \end{macrocode}
1705 % \end{macro}
1706 %
1707 % \begin{macro}{\tryis@simple}
1708 % \changes{v2.3k}{1994/11/06}{New implementation}
1709 % |\tryis@simple| is similar to |\is@range|. If it sees a simple size,
1710 % it checks it against the value of |\f@size| and sets
1711 % |\lower@font@size| or |\higher@font@size|. In the latter case, it
1712 % stops the iteration. By adding |<\number\@M>| at the end of the
1713 % line we always have an end point. This is a hack which probably
1714 % should be corrected.
1715 %
1716 % First it checks whether it is finished already, then whether the
1717 % size specification in question is a simple one.
1718 % \begin{macrocode}
1719 \gdef\tryif@simple#1-#2\tryif@simple{%
1720 % \end{macrocode}
1721 % Most common case for |\reserved@f| first:
1722 % \begin{macrocode}
1723 \let \reserved@f \try@simples
1724 \if>#2%
1725 % \end{macrocode}
1726 % If so, it compares it to the value of |\f@size|. This is done using
1727 % a dimen register since there may be fractional numbers.
1728 % \begin{macrocode}
1729 \dimen@ #1\p@
1730 \ifdim \dimen@<\@M\p@
1731 % \end{macrocode}
1732 % If |\dimen@| is |\@M\p@| we have reached the end of the fontspec
1733 % (hopefully) otherwise we compare the value with |\f@size| and
1734 % compute in |\@tempdimc| the absolute value of the difference
1735 % between the two values.
1736 % \begin{macrocode}
1737 \ifdim \f@size\p@<\dimen@
1738 \@tempdimc \dimen@
1739 \advance\@tempdimc -\f@size\p@
1740 \else
1741 \@tempdimc \f@size\p@
1742 \advance\@tempdimc -\dimen@
1743 \fi
1744 % \end{macrocode}
1745 % The result is then compared with the smallest difference we have
1746 % encountered, if the new value (in |\@tempdimc| is smaller) we
1747 % have found a size which is a better approximation so we make it
1748 % the |\best@size| and adjust |\@tempdimb|.
1749 % \begin{macrocode}
1750 \ifdim \@tempdimc<\@tempdimb
1751 \@tempdimb \@tempdimc
1752 \def \best@size{#1}%
1753 \fi
1754 % \end{macrocode}
1755 % When we have reached the end of the fontspec we substitute the
1756 % best size found (if any). We code this inline to save macro
1757 % space; in the past this was done by a macro called |\subst@size|.
1758 % \begin{macrocode}
1759 \else
1760 % \end{macrocode}
1761 %
1762 %
1763 % \begin{macro}{\subst@size}
1764 % This macro substitutes the size recorded in |\best@size| for
1765 % the unavailable size |\f@size|. |\font@submax| records the maximum
1766 % difference between desired size and selected size in the
1767 % whole run.
1768 % \changes{v2.3d}{1994/04/18}{\cs{font@submax} and \cs{fontsubfuzz}
1769 % now macros}
1770 % \begin{macrocode}
1771 % %\subst@size %% coded inline
1772 % %\def\subst@size{%
1773 \ifx \external@font\@empty
1774 \ifx \best@size\@empty
1775 \else
1776 \ifdim \@tempdimb>\font@submax \relax
1777 \xdef \font@submax {\the\@tempdimb}%
1778 \fi
1779 \let \f@user@size \f@size
1780 \let \f@size \best@size
1781 \ifdim \@tempdimb>\fontsubfuzz\relax
1782 \@font@warning{Font\space shape\space
1783 `\curr@fontshape'\space in\space size\space
1784 <\f@user@size>\space not\space available\MessageBreak
1785 size\space <\f@size>\space substituted}%
1786 \fi
1787 \try@simple@size
1788 \do@subst@correction
1789 \fi
1790 \fi
1791 % %}
1792 % \end{macrocode}
1793 % \end{macro}
1794 %
1795 % This brings us back into the main part of |\tryif@simple|.
1796 % Finally we get rid of any rubbish left over on the input stack.
1797 %
1798 % \changes{v3.0c}{1995/08/24}{}
1799 % \begin{macrocode}
1800 \let \reserved@f \remove@to@nnil
1801 \fi
1802 \fi
1803 % \end{macrocode}
1804 % If it's a range iterate also.
1805 % \begin{macrocode}
1806 \reserved@f}
1807 % \end{macrocode}
1808 % \end{macro}
1809 %
1810 %
1811 %
1812 % \subsection{Sizefunctions}
1813 %
1814 % In the following we define some useful size functions.
1815 %
1816 %
1817 % \begin{macro}{\s@fct@}
1818 % This is the default size function. Mandatory argument is an
1819 % external font name, optional argument a scale factor.
1820 % The font is scaled
1821 % to |\f@size| if no optional argument is present, and to
1822 % |\f@size| multiplied by the optional argument otherwise.
1823 % \changes{v2.0b}{1992/07/26}{}
1824 % \begin{macrocode}
1825 \DeclareSizeFunction{}{\empty@sfcnt\@font@warning}
1826 \DeclareSizeFunction{s}{\empty@sfcnt\@font@info}
1827 % \end{macrocode}
1828 %
1829 % \begin{macrocode}
1830 \def\empty@sfcnt#1{%
1831 \@tempdimb \f@size\p@
1832 \ifx\optional@arg\@empty
1833 \else
1834 \@tempdimb \optional@arg\@tempdimb
1835 #1{Font\space shape\space `\curr@fontshape'\space
1836 will\space be\MessageBreak
1837 scaled\space to\space size\space \the\@tempdimb}%
1838 \fi
1839 \edef\external@font{\mandatory@arg\space at\the\@tempdimb}}
1840 % \end{macrocode}
1841 % \end{macro}
1842 %
1843 %
1844 %
1845 % \begin{macro}{\s@fct@gen}
1846 % \begin{macro}{\s@fct@sgen}
1847 % This size function generates the external name from the mandatory
1848 % argument and the requested user size, and thus can be used for
1849 % external names where the size is encoded in the font name. The
1850 % optional argument a scale factor. The font is scaled to |\f@size|
1851 % if no optional argument is present, and to |\f@size| multiplied
1852 % by the optional argument otherwise.
1853 % \begin{macrocode}
1854 \DeclareSizeFunction{gen}{\gen@sfcnt\@font@warning}
1855 \DeclareSizeFunction{sgen}{\gen@sfcnt\@font@info}
1856 % \end{macrocode}
1857 %
1858 % \begin{macrocode}
1859 \def\gen@sfcnt{%
1860 \edef\mandatory@arg{\mandatory@arg\f@size}%
1861 \empty@sfcnt}
1862 % \end{macrocode}
1863 % \end{macro}
1864 % \end{macro}
1865 %
1866 %
1867 %
1868 % \begin{macro}{\s@fct@genb}
1869 % \begin{macro}{\s@fct@sgenb}
1870 % This size function is similar to |gen|, but for fonts where the
1871 % size is encoded in the font name in centipoints, as in the DC
1872 % fonts version 1.2. The font is scaled to |\f@size|
1873 % if no optional argument is present, and to |\f@size| multiplied
1874 % by the optional argument otherwise.
1875 % \begin{macrocode}
1876 \DeclareSizeFunction{genb}{\genb@sfcnt\@font@warning}
1877 \DeclareSizeFunction{sgenb}{\genb@sfcnt\@font@info}
1878 % \end{macrocode}
1879 %
1880 % \begin{macrocode}
1881 \def\genb@sfcnt{%
1882 \edef\mandatory@arg{\mandatory@arg\expandafter\genb@x\f@size..\@@}%
1883 \empty@sfcnt}
1884 % \end{macrocode}
1885 % \end{macro}
1886 % \end{macro}
1887 %
1888 %
1889 % \begin{macro}{\genb@x}
1890 % \begin{macro}{\genb@y}
1891 % The auxiliary macros |\genb@x| and |\genb@y| are used to convert
1892 % the |\f@size| into centipoints.
1893 % \begin{macrocode}
1894 \def\genb@x#1.#2.#3\@@{\two@digits{#1}\genb@y#200\@@}
1895 \def\genb@y#1#2#3\@@{#1#2}
1896 % \end{macrocode}
1897 % \end{macro}
1898 % \end{macro}
1899 %
1900 %
1901 %
1902 % \begin{macro}{\s@fct@sub}
1903 % This size function handles font substitution.
1904 % The mandatory argument is a family/series/shape combination,
1905 % the optional argument (if present) is ignored. The font encoding
1906 % scheme cannot be changed. Therefore, the first thing we do is to
1907 % prepend the encoding scheme.
1908 % \changes{v2.0b}{1992/07/26}{documentation fixes}
1909 % \begin{macrocode}
1910 \DeclareSizeFunction{sub}{\sub@sfcnt\@font@warning}
1911 \DeclareSizeFunction{ssub}{\sub@sfcnt\@font@info}
1912 % \end{macrocode}
1913 %
1914 % \begin{macrocode}
1915 \def\sub@sfcnt#1{%
1916 \edef\mandatory@arg{\f@encoding/\mandatory@arg}%
1917 % \end{macrocode}
1918 % Next action is split the arg into its individual components and
1919 % allow for a late font shape load.
1920 % \begin{macrocode}
1921 \begingroup
1922 \expandafter\split@name\mandatory@arg/\@nil
1923 \try@load@fontshape
1924 \endgroup
1925 % \end{macrocode}
1926 % Then we record the current |\f@size| since it may get clobbered.
1927 % \begin{macrocode}
1928 \let\f@user@size\f@size
1929 % \end{macrocode}
1930 % Then we check whether this new combination is defined and
1931 % give an error message if not. In this case we also switch to
1932 % |\error@fontshape|.
1933 % \begin{macrocode}
1934 \expandafter
1935 \ifx\csname\mandatory@arg\endcsname\relax
1936 \errmessage{No\space declaration\space for\space
1937 shape\space \mandatory@arg}%
1938 \error@fontshape
1939 \else
1940 % \end{macrocode}
1941 % Otherwise we warn the user about the substitution taking place.
1942 % \begin{macrocode}
1943 #1{Font\space shape\space `\curr@fontshape'\space in\space
1944 size\space <\f@size>\space not\space available\MessageBreak
1945 Font\space shape\space `\mandatory@arg'\space tried\space
1946 instead}%
1947 \expandafter\split@name\mandatory@arg/\@nil
1948 \fi
1949 % \end{macrocode}
1950 % Then we restart the font specification scan by calling
1951 % |\get@external@font|.
1952 % \begin{macrocode}
1953 \edef\f@size{\f@user@size}%
1954 \get@external@font
1955 % \end{macrocode}
1956 % Finally |\do@subst@correction| is called to get the font name
1957 % right.
1958 % \begin{macrocode}
1959 \do@subst@correction
1960 }
1961 % \end{macrocode}
1962 % \end{macro}
1963 %
1964 % \begin{macro}{\@font@aliasinfo}
1965 % \changes{v3.0l}{2019/10/11}{Added 'alias' size function}
1966 % Sometimes a substitution is only done to map a long font name to
1967 % a standard shape or series, e.g.,
1968 %\begin{verbatim}
1969 %\DeclareFontShape{T1}{Roboto-LF}{b}{it}{<-> alias * Roboto-LF/bold/it}{}
1970 %\end{verbatim}
1971 % Using the \texttt{ssub} function in that case will give a strange
1972 % (and incorrect) warning. As an alternative we therefore offer the
1973 % size function \texttt{alias}. It will still add some info into
1974 % the \texttt{.log} file, but no longer complains that the font
1975 % shape is not available. It is implemented by grabbing the default
1976 % warning text and replacing it with a new one.
1977 % \begin{macrocode}
1978 %</2ekernel>
1979 %<*2ekernel|latexrelease>
1980 %<latexrelease>\IncludeInRelease{2020/02/02}%
1981 %<latexrelease> {\@font@aliasinfo}{alias size function}%
1982 \DeclareSizeFunction{alias}{\sub@sfcnt\@font@aliasinfo}
1983 \def\@font@aliasinfo#1{%
1984 \@font@info{Font\space shape\space `\curr@fontshape'\space
1985 aliased\space to\MessageBreak `\mandatory@arg'}%
1986 }
1987 %</2ekernel|latexrelease>
1988 %<latexrelease>\EndIncludeInRelease
1989 %<latexrelease>\IncludeInRelease{0000/00/00}%
1990 %<latexrelease> {\@font@aliasinfo}{alias size function}%
1991 %<latexrelease>\let\s@fct@alias\@undefined
1992 %<latexrelease>\let\@font@aliasinfo\@undefined
1993 %<latexrelease>
1994 %<latexrelease>\EndIncludeInRelease
1995 %<*2ekernel>
1996 % \end{macrocode}
1997 % \end{macro}
1998 %
1999 % \begin{macro}{\s@fct@subf}
2000 % The |subf| size function allows substitution of another font. The
2001 % mandatory argument is the external name of the font to be
2002 % substituted, the optional argument a size scaling factor like
2003 % in the default size function.
2004 % The main difference to the default size function is the warning
2005 % message.
2006 % \begin{macrocode}
2007 \DeclareSizeFunction{subf}{\subf@sfcnt\@font@warning}
2008 \DeclareSizeFunction{ssubf}{\subf@sfcnt\@font@info}
2009 % \end{macrocode}
2010 %
2011 % \begin{macrocode}
2012 \def\subf@sfcnt#1{%
2013 #1{Font\space shape\space `\curr@fontshape'\space in\space
2014 size\space \f@size\space not\space available\MessageBreak
2015 external\space font\space `\mandatory@arg'\space used}%
2016 \empty@sfcnt#1%
2017 }
2018 % \end{macrocode}
2019 % \end{macro}
2020 %
2021 %
2022 % \begin{macro}{\s@fct@fixed}
2023 % The |fixed| size function is for using a font at a different size
2024 % than requested. A warning message is printed, and the external
2025 % font to be used is taken from the mandatory argument.
2026 % If an optional argument is present it is used as the `at'
2027 % size for the font. Otherwise the font is loaded at its design size.
2028 % \begin{macrocode}
2029 \DeclareSizeFunction{fixed}{\fixed@sfcnt\@font@warning}
2030 \DeclareSizeFunction{sfixed}{\fixed@sfcnt\@font@info}
2031 % \end{macrocode}
2032 %
2033 % \begin{macrocode}
2034 \def\fixed@sfcnt#1{%
2035 \ifx\optional@arg\@empty
2036 \let\external@font\mandatory@arg
2037 \else
2038 \edef\external@font{\mandatory@arg\space at\optional@arg pt}%
2039 \fi
2040 #1{External\space font\space `\external@font'\space loaded\space
2041 for\space size\MessageBreak
2042 <\f@size>}%
2043 }
2044 %</2ekernel>
2045 % \end{macrocode}
2046 % \end{macro}
2047 %
2048 % \iffalse
2049 %<+checkmem>\CHECKMEM
2050 % \fi
2051 %
2052 %
2053 % \Finale