forked from latex3/latex2e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathltfssini.dtx
2250 lines (2211 loc) · 82.2 KB
/
ltfssini.dtx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
%
% Copyright (C) 1993-2022
% The LaTeX Project and any individual authors listed elsewhere
% in this file.
%
% This file is part of the LaTeX base system.
% -------------------------------------------
%
% It may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
% https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008 or later.
%
% This file has the LPPL maintenance status "maintained".
%
% The list of all files belonging to the LaTeX base distribution is
% given in the file `manifest.txt'. See also `legal.txt' for additional
% information.
%
% The list of derived (unpacked) files belonging to the distribution
% and covered by LPPL is defined by the unpacking scripts (with
% extension .ins) which are part of the distribution.
%
% \fi
% \iffalse
%%% From File: ltfssini.dtx
%% Copyright (C) 1989-2001 Frank Mittelbach and Rainer Sch\"opf,
%% all rights reserved.
%
%<*driver>
% \fi
%
%
\ProvidesFile{ltfssini.dtx}
[2021/09/10 v3.2i LaTeX Kernel (NFSS Initialisation)]
% \iffalse
\documentclass{ltxdoc}
\begin{document}
\DocInput{ltfssini.dtx}
\end{document}
%</driver>
% \fi
%
% \iffalse
%<+checkmem>\def\CHECKMEM{\tracingstats=2
%<+checkmem> \newlinechar=`\^^J
%<+checkmem> \message{^^JMemory usage: \filename}\shipout\hbox{}}
%<+checkmem>\CHECKMEM
% \fi
%
%
%
% \GetFileInfo{ltfssini.dtx}
% \title{A new font selection scheme for \TeX{} macro packages\\
% (Initialization)\thanks
% {This file has version number
% \fileversion\ dated \filedate}}
%
% \author{Frank Mittelbach \and Rainer Sch\"opf}
%
% \MaintainedByLaTeXTeam{latex}
% \maketitle
%
% This file contains the top level \LaTeX\ interface to the font
% selection scheme commands. See other parts of the \LaTeX\
% distribution, or \emph{The \LaTeX\ Companion} for higher level
% documentation of these commands.
%
% \MaybeStop{}
%
%
% \changes{v3.0i}{1998/08/17}{(RmS) Minor documentation fixes.}
% \changes{v3.0b}{1995/06/28}
% {(DPC) Fix documentation typos}
% \changes{v3.0a}{1995/05/24}
% {(DPC) Make file from previous file, lfonts.dtx 1995/05/23 v2.2e}
% \changes{v3.1b}{2016/10/15}
% {Require e\TeX{}}
% \changes{v3.1d}{2019/08/27}{Make various commands robust}
%
%
% \section{NFSS Initialization}
%
% \iffalse
%<+checkmem>\CHECKMEM
% \fi
%
%
% \changes{v2.2a}{1994/10/14}{New coding for cfg files}
% \changes{v2.1a}{1993/12/03}{update for LaTeX2e}
% \changes{v1.2c}{1992/01/06}{added slitex code}
% \changes{v1.2d}{1992/03/21}{Renamed \cs{text} to \cs{nfss@text}
% to make it internal.}
% \changes{v1.2a}{1991/11/27}{All \cs{family}, \cs{shape} etc. renamed
% to \cs{fontfamily} etc.}
% \changes{v1.1i}{1990/04/02}{\cs{input} of files now handled
% by docstrip.}
% \changes{v1.1g}{1990/02/08}{Protected the commands
% \cs{family}, \cs{series},
% \cs{shape}, \cs{size}, \cs{selectfont}, and \cs{mathversion}.}
% \changes{v1.1c}{1989/12/03}{Some internal macros renamed to make them
% inaccessible.}
% \changes{v1.1b}{1989/12/02}{\cs{rmmath} renamed to \cs{mathrm}}
%
% \changes{v1.0i}{1989/11/07}{All family, series, and shape names
% abbreviated.}
% \changes{v1.0g}{1989/05/22}{Lines shortened to 72 characters}
% \changes{v1.0f}{1989/04/29}{Corrections to \LaTeX\ tabular env.
% added.}
% \changes{v1.0e}{1989/04/27}{Definitions of \LaTeX\ symbols corrected.}
% \changes{v1.0d}{1989/04/26}{\cs{xpt} added.}
% \changes{v1.0c}{1989/04/21}{Changed to conform to fam.tex.}
% \changes{v1.0b}{1989/04/15}{\cs{mathfontset} renamed to
% \cs{mathversion.}}
% \changes{v1.0a}{1989/04/10}{Starting with version numbers!
% \cs{newif} for \cs{@tempswa} added since this switch is
% unknown at the time when this file is read in.
% (latex.tex is loaded later.)
% \cs{math@famname} changed to \cs{math@version.}}
%
%
% \changes{v2.1j}{1994/05/13}{Removed file identification typeout}
%
% Finally, there are six commands that are to be used in \LaTeX{}
% and that we will therefore protect against expansion at the
% wrong point:
% |\fontfamily|, |\fontseries|, |\fontshape|, |\fontsize|,
% |\selectfont|, and |\mathversion|.
%
% \changes{v2.1i}{1994/05/12}{Moved \cs{fontfamily} to fam.dtx}
% \changes{v2.1i}{1994/05/12}{Moved \cs{fontencoding} to fam.dtx}
% \changes{v2.1i}{1994/05/12}{Moved \cs{fontseries} to fam.dtx}
% \changes{v2.1i}{1994/05/12}{Moved \cs{fontshape} to fam.dtx}
% \changes{v2.1i}{1994/05/12}{Moved \cs{fontsize} to fam.dtx}
% \changes{v2.1i}{1994/05/12}{Moved \cs{mathversion} to fam.dtx}
% \changes{v2.1i}{1994/05/12}{Moved \cs{selectfont} to tracefnt.dtx}
%
%
% \begin{macrocode}
%<*2ekernel>
% \end{macrocode}
%
% \subsection{Providing math \emph{versions}}
%
% \LaTeX{} provides two \emph{versions}. We call them
% \textsf{normal} and \textsf{bold}, respectively.
% \begin{macrocode}
\DeclareMathVersion{normal}
\DeclareMathVersion{bold}
% \end{macrocode}
%
%
% Now we define the standard font change commands.
% We don't allow the use of |\rmfamily| etc.\ in math mode.
%
% (Actually most are now defined further down in the file.)
%
% First the changes to another \emph{family}:
% \begin{macrocode}
%\DeclareRobustCommand\rmfamily
% {\not@math@alphabet\rmfamily\mathrm
% \fontfamily\rmdefault\selectfont}
%\DeclareRobustCommand\sffamily
% {\not@math@alphabet\sffamily\mathsf
% \fontfamily\sfdefault\selectfont}
%\DeclareRobustCommand\ttfamily
% {\not@math@alphabet\ttfamily\mathtt
% \fontfamily\ttdefault\selectfont}
% \end{macrocode}
% Then the commands changing the \emph{series}:
% \begin{macrocode}
%\DeclareRobustCommand\bfseries
% {\not@math@alphabet\bfseries\mathbf
% \fontseries\bfdefault\selectfont}
%\DeclareRobustCommand\mdseries
% {\not@math@alphabet\mdseries\relax
% \fontseries\mddefault\selectfont}
\DeclareRobustCommand\upshape
{\not@math@alphabet\upshape\relax
\fontshape\updefault\selectfont}
% \end{macrocode}
% Then the commands changing the \emph{shape}:
% \begin{macrocode}
\DeclareRobustCommand\slshape
{\not@math@alphabet\slshape\relax
\fontshape\sldefault\selectfont}
\DeclareRobustCommand\scshape
{\not@math@alphabet\scshape\relax
\fontshape\scdefault\selectfont}
\DeclareRobustCommand\itshape
{\not@math@alphabet\itshape\mathit
\fontshape\itdefault\selectfont}
% \end{macrocode}
%
%
%
%
% \section{Custom series settings for main document families}
%
% This section was introduced 2020/02/02 and for now we support a
% full rollback (may need splitting later).
% \changes{v3.1e}{2019/12/17}{Provide custom series settings a la mweights}
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2021/11/15}%
%<latexrelease> {\DeclareFontSeriesDefault}{Custom series}%
% \end{macrocode}
%
% One problem with the NFSS approach of handling the series axis
% turned out to be that (especially with respect to ``boldness'')
% different font families implemented different strategies. For
% example, with Computer Modern fonts you normally only have
% \texttt{bx} whereas most PostScript fonts offered only \texttt{b}
% but not \texttt{bx}. As a result \LaTeX's standard setting for
% \cs{bfdefault} didn't work with such fonts, but if it got changed
% to produce \texttt{b}, then that didn't work with Computer Modern
% if the fonts got combined (e.g., using Computer Modern Typewriter
% with such fonts).
%
% The solution back then was to provide substitution rules in the
% font \texttt{.fd} such that if a \texttt{bx} series got requested
% the \texttt{b} series got used. While this works in that
% particular case, it isn't a very
% general solution. For example, if you happen to have a font family that
% has several weights you may want to typeset the whole document
% in a somewhat lighter or darker font but if you then modify
% \cs{mddefault} to allow for this, then of course your change only
% works with that particular family but not with the typewriter
% or sans serif family you also want to use.
%
% A better solution was provided by the \texttt{mweights} package by
% Bob Tennent that offers defaults on the level of the three main
% font families in the document: for ``rm'', ``sf'' and ``tt'' so
% that font packages could define defaults for the sans serif
% document font by providing \cs{bfseries@sf} which then was used
% when \cs{bfseries} got executed and the current family was the
% \cs{sffamily}.
%
% \DescribeMacro\DeclareFontSeriesDefault
% We now support this concept directly from within \LaTeX{} and for
% use in font packages (or the document preamble) we offer
% \cs{DeclareFontSeriesDefault}. This declaration takes three
% arguments:
% \begin{description}
% \item[document family interface:] Can either be \texttt{rm},
% \texttt{sf} or \texttt{tt}. This is optional and if not given the
% overall default.
% \item[document series interface:] Can be \texttt{md} or
% \texttt{bf}.
% \item[series value:] This is the value that is going to be used
% with the combination is requested.
% \end{description}
%
% For example, \verb=\DeclareFontSeriesDefault[rm]{bf}{sb}= would
% use \texttt{sb} (semi-bold) when \cs{rmfamily} \cs{bfseries} is
% asked for.
%
% If used without the optional argument, e.g.,
% \verb=\DeclareFontSeriesDefault{bf}{b}= then this is like
% redefining \cs{bfdefault} or \cs{mddefault}.
%
% If some family specify defaults aren't given, e.g. if there are
% no declarations for, say, \texttt{tt} then the format defaults
% of \cs{mddefault} and \cs{bfdefault} are assumed. If those are
% later changed this is \emph{not} reflected!\footnote{I see no
% easy way to achieve this without compromising compatibility with
% existing packages that currently use \textsf{mweights} and directly
% define (some) of the \cs{mdseries@..} commands but not others.}
%
%
%
% \begin{macro}{\DeclareFontSeriesDefault}
% The command to declare font series defaults for the ``rm'', ``sf'' or
% ``tt'' family.
% \begin{macrocode}
\let\DeclareFontSeriesDefault\@undefined % for rollback
\newcommand\DeclareFontSeriesDefault[3][]{%
% \end{macrocode}
%
% \changes{v3.2i}{2021/09/10}{Do delayed changes to \cs{bfdefault} or
% \cs{mddefault} first (gh/663)}
% \begin{macrocode}
\expand@font@defaults
\maybe@update@bfseries@defaults
\maybe@update@mdseries@defaults
% \end{macrocode}
%
% \begin{macrocode}
\def\reserved@a{#1}%
% \end{macrocode}
% No optional argument: set up general default.
% \changes{v3.1g}{2020/02/05}{Corrected misspelled csname (gh/264)}
% \begin{macrocode}
\ifx\reserved@a\@empty
\ifcsname #2series\endcsname % supported are
% \[md/bf]default
% \end{macrocode}
% Adding \cs{@empty} allows us to detect if the default gets
% redefined with \cs{renewcommand} or \cs{def} by the user.
% \changes{v3.1k}{2020/03/19}{Support legacy use of \cs{bfdefault}
% and \cs{mddefault} (gh/306)}
% \begin{macrocode}
\expandafter\def
\csname #2default\endcsname{#3\@empty}%
\expandafter\def
\csname #2default@previous\endcsname{#3\@empty}%
\else
% \end{macrocode}
%
% \changes{v3.1g}{2020/02/05}{Clarified error text}
% \begin{macrocode}
\@latex@error{Wrong syntax for \string\DeclareFontSeriesDefault}%
{Mandatory first argument must be 'md' or 'bf'.}
\fi
% \end{macrocode}
% Optional argument given, set up specific default.
% \begin{macrocode}
\else
\ifcsname #2series@#1\endcsname % supported are
% \[md/bf]series@[rm/sf/tt]
\expandafter\edef
\csname #2series@#1\endcsname{#3}%
% \end{macrocode}
%
% If the interface is used we remove the frozen kernel
% default. This way, we know that something was explicitly set up
% (even if the setup has the same value as the default).
% \begin{macrocode}
\expandafter\let
\csname #2series@#1@kernel\endcsname\@undefined
\else
\@latex@error{Wrong syntax for \string\DeclareFontSeriesDefault}%
{Optional argument must be 'rm', 'sf', or 'tt'. \MessageBreak
Mandatory first argument must be 'md' or 'bf'.}
\fi
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2020/02/02}%
%<latexrelease> {\DeclareFontSeriesDefault}{Custom series}%
%<latexrelease>
%<latexrelease>\let\DeclareFontSeriesDefault\@undefined % for rollback
%<latexrelease>\newcommand\DeclareFontSeriesDefault[3][]{%
%<latexrelease> \def\reserved@a{#1}%
%<latexrelease> \ifx\reserved@a\@empty
%<latexrelease> \ifcsname #2series\endcsname % supported are
%<latexrelease> % \[md/bf]default
%<latexrelease> \expandafter\def
%<latexrelease> \csname #2default\endcsname{#3\@empty}%
%<latexrelease> \expandafter\def
%<latexrelease> \csname #2default@previous\endcsname{#3\@empty}%
%<latexrelease> \else
%<latexrelease> \@latex@error{Wrong syntax for \string\DeclareFontSeriesDefault}%
%<latexrelease> {Mandatory first argument must be 'md' or 'bf'.}
%<latexrelease> \fi
%<latexrelease> \else
%<latexrelease> \ifcsname #2series@#1\endcsname % supported are
%<latexrelease> % \[md/bf]series@[rm/sf/tt]
%<latexrelease> \expandafter\edef
%<latexrelease> \csname #2series@#1\endcsname{#3}%
%<latexrelease> \expandafter\let
%<latexrelease> \csname #2series@#1@kernel\endcsname\@undefined
%<latexrelease> \else
%<latexrelease> \@latex@error{Wrong syntax for \string\DeclareFontSeriesDefault}%
%<latexrelease> {Optional argument must be 'rm', 'sf', or 'tt'. \MessageBreak
%<latexrelease> Mandatory first argument must be 'md' or 'bf'.}
%<latexrelease> \fi
%<latexrelease> \fi
%<latexrelease>}
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\DeclareFontSeriesDefault}{Custom series}%
%<latexrelease>
%<latexrelease>\let\DeclareFontSeriesDefault\@undefined
%<latexrelease>\let\bfseries@rm\@undefined
%<latexrelease>\let\bfseries@sf\@undefined
%<latexrelease>\let\bfseries@tt\@undefined
%<latexrelease>\let\bfseries@rm@kernel\@undefined
%<latexrelease>\let\bfseries@sf@kernel\@undefined
%<latexrelease>\let\bfseries@tt@kernel\@undefined
%<latexrelease>\let\mdseries@rm\@undefined
%<latexrelease>\let\mdseries@sf\@undefined
%<latexrelease>\let\mdseries@tt\@undefined
%<latexrelease>\expandafter\let\csname [email protected]\endcsname\@undefined
%<latexrelease>
%<latexrelease>\let\@meta@family@list\@undefined
%<latexrelease>\let\prepare@family@series@update\@undefined
%<latexrelease>\let\update@series@target@value\@undefined
%<latexrelease>
% \end{macrocode}
% This is always called in \cs{document} so don't make it undefined.
% \begin{macrocode}
%<latexrelease>\let\init@series@setup\relax
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2020/02/02}%
%<latexrelease> {\mdseries@rm}{Custom series}%
% \end{macrocode}
% \begin{macro}{\mdseries@rm}
% \begin{macro}{\mdseries@sf}
% \begin{macro}{\mdseries@tt}
% \begin{macro}{\bfseries@rm}
% \begin{macro}{\bfseries@sf}
% \begin{macro}{\bfseries@tt}
% We initialize the family specific default at the end of the
% format generation. Later on they may get overwritten in the
% preamble or a package via \cs{DeclareFontSeriesDefault} (or
% possibly directly).
%
% Conceptual change: The \cs{bfdefault} will be \texttt{b} not
% \texttt{bx} because that is what it should be really for nearly
% every font except Computer/Latin Modern.
%
% To account for the fact that by default we typeset in CM or LM we
% set up the \cs{bfseries@..} defaults to use \texttt{bx} instead.
%
% This means that it behaves like before because if the default
% fonts are used then \cs{bfseries@rm} etc kick in and make
% \cs{textbf} use \texttt{bx}. However, if the font gets changed
% then \cs{bfdefault} will get used.
%
% \begin{macrocode}
\def\bfseries@rm{bx}
\def\bfseries@sf{bx}
\def\bfseries@tt{bx}
% \end{macrocode}
%
% Frozen version of the kernel defaults so we can see if they have changed.
% \begin{macrocode}
\let\bfseries@rm@kernel\bfseries@rm
\let\bfseries@sf@kernel\bfseries@sf
\let\bfseries@tt@kernel\bfseries@tt
% \end{macrocode}
%
% The default for the medium series is \texttt{m} and this will be
% interpreted as resetting both weight and width. To reset only one
% of them the virtual value \texttt{?m} and \texttt{m?} are available.
% \begin{macrocode}
\def\mdseries@rm{m}
\def\mdseries@sf{m}
\def\mdseries@tt{m}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
%
% \begin{macro}{\series@change@debug}
% For debugging, but right now none of this code is extracted. The
% idea is to have a separate package with debugging code
% one day.
% \begin{macrocode}
%<*debug>
\let\series@change@debug\typeout
\let\series@change@debug\@gobble
%</debug>
% \end{macrocode}
% \end{macro}
%
%
%
%
% \begin{macro}{\prepare@family@series@update}
% This is core command that prepares for the family update. The big
% difference to the documented code above is that the nested
% \cs{ifx} statements seem to be missing. Instead we loop through
% an internal list that holds the names of the three meta
% families. This approach allows us to extend the mechanism at a
% later stage to allow for additional named meta families.
%
% \begin{macro}{\@meta@family@list}
% Here is the current definition of that list:
% \begin{macrocode}
\def\@meta@family@list{\@elt{rm}\@elt{sf}\@elt{tt}}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
\def\prepare@family@series@update#1#2{%
% \end{macrocode}
%
% \changes{v3.1i}{2020/02/18}{No series auto-update when forced (gh/277)}
% \begin{macrocode}
\if@forced@series
%<+debug> \series@change@debug{No series preparation (forced \f@series)\on@line}%
\fontfamily#2%
\else
%<+debug> \series@change@debug{Preparing for switching to #1 (#2)\on@line}%
\expand@font@defaults
% \end{macrocode}
% We prepare for changing the current series. We have to find it
% before changing the family as discussed above.
% \begin{macrocode}
\let\target@series@value\@empty
\def\target@meta@family@value{#1}%
% \end{macrocode}
% As the very last item in the meta family list we add
% \verb=\@elt{??}= and define this pseudo meta family to be the
% current font family. So if none of the real meta families matched then
% this will match. This will cover the following case:
% \begin{itemize}
% \item \cs{bfseries} is called for a family using \texttt{bx}
% (e.g., CMR)
% \item Switch to a font family that is none of the meta
% families, e.g., via \verb=\fontfamily{ptm}\allowbreak\verb=\selectfont=
% \item Then none of the real meta families, match but the final
% \verb=\@elt{??}= will.
% \item Therefore if the current series is \cs{mddefault} or
% \cs{bfdefault} it will be detected and the corresponding target
% series selected.
% \end{itemize}
% \changes{v3.1i}{2020/02/18}{Recognize current family if it is not a
% ``meta'' family and auto-update series using \cs{bfdefault} (gh/277)}
% \begin{macrocode}
\expandafter\edef\csname ??def@ult\endcsname{\f@family}%
% \end{macrocode}
% To find it we loop over the meta family list with a suitable
% definition of \cs{@elt}.
% \begin{macrocode}
\let\@elt\update@series@target@value
\@meta@family@list
% \end{macrocode}
% Last resort pseudo meta family. Will only be looked at f none of
% the real ones have matched.
% \begin{macrocode}
\@elt{??}%
\let\@elt\relax
% \end{macrocode}
% That will figure out the correct series value to use without updating
% it. Now we can change the family.
% \begin{macrocode}
\fontfamily#2%
% \end{macrocode}
% After that we update the series. That code is again like the one
% above.
% \begin{macrocode}
\ifx\target@series@value\@empty
%<+debug> \series@change@debug{Target series still empty ...}%
\else
\ifx \f@series\target@series@value
%<+debug> \series@change@debug{Target series unchanged:
%<+debug> \f@series \space = \target@series@value}%
\else
\maybe@load@fontshape
%<+debug> \series@change@debug{Target series:
%<+debug> \f@series \space -> \target@series@value}%
% \end{macrocode}
% The \cs{target@series@value} may contain something like
% \texttt{cm} (coming from a default) and so we can't directly
% assign it to \cs{f@series} be have to drop any surplus \texttt{m}
% first.
% \changes{v3.1j}{2020/02/25}{Drop surplus ``m'' from
% \cs{target@series@value} (gh/291)}
% \begin{macrocode}
% \let\f@series\target@series@value
\series@maybe@drop@one@m\target@series@value\f@series
\fi
\fi
\fi
}
% \end{macrocode}
% \end{macro}
%
%
%
% \begin{macro}{\update@series@target@value}
% In this macro used in the look you basically find the nested
% \cs{ifx}s from the outline above. The only difference is that is
% it is parameterized instead of being written out and only for one
% block of tests because the code is called repeatedly when looping
% over the meta family list. From the list we get each meta family
% name in turn.
% \begin{macrocode}
\def\update@series@target@value#1{%
% \end{macrocode}
% There is one additional test at the beginning, because the list
% contains all meta families and we need to ignore the case where
% current one from the list and target one are identical.
% \begin{macrocode}
\def\reserved@a{#1}%
\ifx\target@meta@family@value\reserved@a % rm -> rm do nothing
\else
%<+debug> \series@change@debug{Trying to match #1: \csname#1def@ult\endcsname
%<+debug> \space = \f@family\space ?}%
% \end{macrocode}
% We only ``do'' something if the current font family matches the
% current meta family.
% \begin{macrocode}
\expandafter\ifx\csname#1def@ult\endcsname\f@family
% \end{macrocode}
% If that's the case we know that this is the block that applies
% (only one meta family can match). So to speed things up we
% change \cs{@elt} so that the rest of the loop gets gobbled.
% \begin{macrocode}
\let\@elt\@gobble
% \end{macrocode}
% Then we try to find the right new value for the series (as
% explained above). The two macros defined first are only there
% because we now need to use \cs{csname} and this way the code will
% be a little faster.
% \begin{macrocode}
\expandafter\let\expandafter\reserved@b
\csname mdseries@\target@meta@family@value\endcsname
\expandafter\let\expandafter\reserved@c
\csname bfseries@\target@meta@family@value\endcsname
%<+debug>\series@change@debug{Targets for mdseries and bfseries:
%<+debug> \reserved@b\space and \reserved@c}%
% \end{macrocode}
% This here is now identical to the nested \cs{ifx} block from the
% outline, except that it there appeared twice in
% \cs{rmfamily}. This is now covered by looping and stopping the
% loop when a match was found.
% \begin{macrocode}
% \end{macrocode}
% We have to sanitize the default value first because it may
% contain something like \texttt{mc} and that would never match
% \cs{f@series} because there it would be called \texttt{c} with
% the \texttt{m} dropped. It would be probably better to do that
% differently these days, but it is hard to adjust without causing
% a lot of issues, so we do the dropping in various places instead.
% \changes{v3.1j}{2020/02/25}{Drop surplus ``m'' from \cs{reserved@d}
% (gh/291)}
% \begin{macrocode}
\expandafter\series@maybe@drop@one@m
\csname mdseries@#1\endcsname\reserved@d
\ifx\reserved@d\f@series
%<+debug> \series@change@debug{mdseries@#1 matched -> \reserved@b}%
\let\target@series@value\reserved@b
\else
% \end{macrocode}
% Again do some sanitizing.
% \changes{v3.1j}{2020/02/25}{Drop surplus ``m'' from \cs{reserved@d}
% (gh/291)}
% \begin{macrocode}
\expandafter\series@maybe@drop@one@m
\csname bfseries@#1\endcsname\reserved@d
\ifx\reserved@d\f@series
%<+debug> \series@change@debug{bfseries@#1 matched -> \reserved@c}%
\let\target@series@value\reserved@c
\else\ifx\f@series\mddef@ult \let\target@series@value\reserved@b
%<+debug> \series@change@debug{mddef@ult matched -> \reserved@b}%
\else\ifx\f@series\bfdef@ult \let\target@series@value\reserved@c
%<+debug> \series@change@debug{bfdef@ult matched -> \reserved@c}%
\fi\fi\fi\fi
\fi
\fi
}
% \end{macrocode}
% \end{macro}
%
%
%
%
%
% \begin{macro}{\init@series@setup}
% This is code to be run at begin document \ldots
% \begin{macrocode}
\def\init@series@setup{%
% \end{macrocode}
%
% We only want \texttt{bx} in \cs{bfseries@rm} if the roman font is
% Computer Modern or Latin Modern, otherwise it should be
% \texttt{b}. It was set to \texttt{bx} in the kernel so that any
% font use with the default families in the preamble get this
% value. Now at the real document start we check if the fonts have
% been changed. If there was a \cs{DeclareFontSeriesDefault}
% declaration or \cs{bfseries@rm} was directly altered then it
% differs from \cs{bfseries@rm@kernel} and we do nothing.
% Otherwise we check if \cs{rmdefault} is one of the CM/LM font
% families and if so we keep \texttt{bx} otherwise we change it to
% \texttt{b}.
%
% This approach doesn't cover one case: CM/LM got changed to a
% different family that supports \texttt{bx}, but the support
% package for that family used \verb=\def\bfseries@rm{bx}= instead
% of using \cs{DeclareFontSeriesDefault}. In that case the code
% here changes it to \texttt{b}. Solution: use the
% \cs{DeclareFontSeriesDefault} interface.
% \begin{macrocode}
\ifx\bfseries@rm@kernel\bfseries@rm
\expandafter\in@\expandafter{\rmdefault}%
{cmr,cmss,cmtt,lcmss,lcmtt,lmr,lmss,lmtt}%
\ifin@ \else \def\bfseries@rm{b}\fi\fi
% \end{macrocode}
% Same approach for \cs{bfseries@sf} and \cs{bfseries@tt}:
% \begin{macrocode}
\ifx\bfseries@sf@kernel\bfseries@sf
\expandafter\in@\expandafter{\sfdefault}%
{cmr,cmss,cmtt,lcmss,lcmtt,lmr,lmss,lmtt}%
\ifin@ \else \def\bfseries@sf{b}\fi\fi
\ifx\bfseries@tt@kernel\bfseries@tt
\expandafter\in@\expandafter{\ttdefault}%
{cmr,cmss,cmtt,lcmss,lcmtt,lmr,lmss,lmtt}%
\ifin@ \else \def\bfseries@tt{b}\fi\fi
% \end{macrocode}
%
% If the document preamble has changed the \cs{familydefault} or if
% the if the \cs{rmdefault} contains a new font family, we may have to
% adjust the series defaults accordingly, before starting
% typesetting.
%
% Similarly, if the user has changed the \cs{mddefault} or the
% medium series for the family selected as document font we may
% also have to adjust the \cs{seriesdefault}.
%
% On the other hand if the document font is still CM or LM then
% \cs{bfdefault} is wrong, because it is now saying \texttt{b} and not
% \texttt{bx} as it should for such fonts.
%
% To fix all this we first run \cs{reset@font} (the internal kernel
% name for \cs{normalfont}). This will set up the document encoding,
% family, series and shape based on the current values of
% \cs{encodingdefault}, \cs{familydefault}, \cs{seriesdefault} and
% \cs{shapedefault}.
% However, if the family (from \cs{familydefault}) has special medium
% default we should switch to that (and not use what is current
% value from \cs{seriesdefault}). This can be achieved by afterwards
% calling \cs{mediumseries} and then changing \cs{seriesdefault} to
% the now current series value (in \cs{f@series}).
%
% But what should happen if \cs{seriesdefault} got explicitly
% changed? In that case the explicit change should survive and we
% should not alter \cs{seriesdefault}. This is solved by comparing
% the current value of \cs{seriesdefault} with a kernel version
% saved in the format and if they differ we do not call
% \cs{mdseries} or change \cs{seriesdefault}.
% \changes{v3.1n}{2020/04/13}{Handling \cs{seriesdefault} changes (gh/315)}
% \begin{macrocode}
\reset@font
\ifx\seriesdefault\seriesdefault@kernel
\mdseries
\let\seriesdefault\f@series
\fi
}%
% \end{macrocode}
% \end{macro}
%
%
%
% As the kernel code now implements the same functionality as
% \textsf{mweights}, albeit internally coded slightly differently,
% that package shouldn't be loaded any more. We therefore pretend
% that it already got loaded. Thus, a font package that tries to
% load it and then sets \cs{mdseries@..}, etc.\ will continue to
% work but will now use the kernel code.
%
% Of course, mid-term such package should probably use
% \cs{DeclareFontSeriesDefault} instead of making using low-level
% definitions.
%
% \begin{macrocode}
\expandafter\let\csname [email protected]\endcsname\fmtversion
% \end{macrocode}
%
%
%
% \begin{macrocode}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease> {\mdseries@rm}{Custom series}%
%<latexrelease>
%<latexrelease>\let\bfseries@rm\@undefined
%<latexrelease>\let\bfseries@sf\@undefined
%<latexrelease>\let\bfseries@tt\@undefined
%<latexrelease>\let\bfseries@rm@kernel\@undefined
%<latexrelease>\let\bfseries@sf@kernel\@undefined
%<latexrelease>\let\bfseries@tt@kernel\@undefined
%<latexrelease>\let\mdseries@rm\@undefined
%<latexrelease>\let\mdseries@sf\@undefined
%<latexrelease>\let\mdseries@tt\@undefined
%<latexrelease>\expandafter\let\csname [email protected]\endcsname\@undefined
%<latexrelease>
%<latexrelease>\let\@meta@family@list\@undefined
%<latexrelease>\let\prepare@family@series@update\@undefined
%<latexrelease>\let\update@series@target@value\@undefined
%<latexrelease>
% \end{macrocode}
% This is always called in \cs{document} so don't make it undefined.
% \begin{macrocode}
%<latexrelease>\let\init@series@setup\relax
%<latexrelease>
%<latexrelease>\EndIncludeInRelease
%<*2ekernel>
% \end{macrocode}
%
%
% \begin{macrocode}
%</2ekernel>
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2021/11/15}%
%<latexrelease> {\bfseries}{Custom series with hooks}%
% \end{macrocode}
% \begin{macro}{\bfseries}
% This document command switches to the bold series.
% \begin{macrocode}
\DeclareRobustCommand\bfseries{%
\not@math@alphabet\bfseries\mathbf
% \end{macrocode}
% In the original NFSS definition it then called \cs{fontseries}
% with the value \cs{bfdefault}. In the new scheme we have more
% alternatives and therefore check if the current family
% (\cs{f@family}) is the current \cs{rmdef@ult}, \cs{sfdef@ult} or
% \cs{ttdef@ult} and the select the correct family default in that case.
% \changes{v3.1i}{2020/02/18}{Make the \cs{ifx} selection outside
% of \cs{fontseries} argument so that it is not done several times}
% \changes{v3.2i}{2021/09/10}{Do delayed changes to \cs{bfdefault} in
% a separate macro for better reuse (gh/663)}
% \begin{macrocode}
\expand@font@defaults
\maybe@update@bfseries@defaults
% \end{macrocode}
%
% \begin{macrocode}
\ifx\f@family\rmdef@ult \fontseries\bfseries@rm
\else\ifx\f@family\sfdef@ult \fontseries\bfseries@sf
\else\ifx\f@family\ttdef@ult \fontseries\bfseries@tt
% \end{macrocode}
% If not \cs{bfdefault} is used.
% \begin{macrocode}
\else \fontseries\bfdefault
\fi\fi\fi
% \end{macrocode}
% This hook in contrast is always executed.
% \begin{macrocode}
\UseHook{bfseries}%
\selectfont
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\maybe@update@bfseries@defaults}
%
% If \cs{bfdefault} and \cs{bfdefault@previous} are different then
% the default got changed directly through the legacy interface
% (i.e., via \cs{def} or \cs{renewcommand}. In that case we reset
% all meta family defaults so that the document behaves like it was
% the case before the new mechanism was introduced.
% \changes{v3.1k}{2020/03/19}{Support legacy use of \cs{bfdefault}
% and \cs{mddefault} (gh/306)}
% \changes{v3.2i}{2021/09/10}{Do delayed changes to \cs{bfdefault} in
% a separate macro for better reuse (gh/663)}
% \begin{macrocode}
\def\maybe@update@bfseries@defaults{%
\ifx\bfdefault\bfdefault@previous\else
% \end{macrocode}
% We add \cs{@empty} and then let \cs{bfdefault@previous} to
% \cs{bfdefault} so that we can detect any further change.
% \changes{v3.2d}{2020/09/30}{\cs{bfdefault@previous} not \cs{bfseries@previous}
% (gh/395)}
% \begin{macrocode}
\expandafter\def\expandafter\bfdefault
\expandafter{\bfdefault\@empty}%
\let\bfdefault@previous\bfdefault
% \end{macrocode}
% And we reset the meta family defaults (\cs{bfdef@ult} is an
% expanded version of \cs{bfdefault}.
% \begin{macrocode}
\let\bfseries@rm\bfdef@ult
\let\bfseries@sf\bfdef@ult
\let\bfseries@tt\bfdef@ult
% \end{macrocode}
%
% Formats that set up parallel fonts, e.g., for Japanese, can use
% this hook to add resets here. Not that this hook is only run when
% resets are necessary.
% \changes{v3.1m}{2020/04/06}{Hook added (gh/306)}
% \changes{v3.2b}{2020/08/21}{Integration of new hook management interface}
% \begin{macrocode}
\UseHook{bfseries/defaults}%
\fi
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\mdseries}
% This document command switches to the medium series.
% \changes{v3.1i}{2020/02/18}{Make the \cs{ifx} selection outside
% of \cs{fontseries} argument so that it is not done several times}
% \changes{v3.1k}{2020/03/19}{Support legacy use of \cs{bfdefault}
% and \cs{mddefault} (gh/306)}
% \changes{v3.2d}{2020/09/30}{\cs{mddefault@previous} not \cs{mdseries@previous}
% (gh/395)}
% \changes{v3.2i}{2021/09/10}{Do delayed changes to \cs{mddefault} in
% a separate macro for better reuse (gh/663)}
% \begin{macrocode}
\DeclareRobustCommand\mdseries{%
\not@math@alphabet\mdseries\relax
\expand@font@defaults
\maybe@update@mdseries@defaults
\ifx\f@family\rmdef@ult \fontseries\mdseries@rm
\else\ifx\f@family\sfdef@ult \fontseries\mdseries@sf
\else\ifx\f@family\ttdef@ult \fontseries\mdseries@tt
\else \fontseries\mddefault
\fi\fi\fi
\UseHook{mdseries}%
\selectfont
}
% \end{macrocode}
% \end{macro}
% \begin{macro}{\maybe@update@mdseries@defaults}
%
% \changes{v3.2i}{2021/09/10}{Do delayed changes to \cs{mddefault} in
% a separate macro for better reuse (gh/663)}
% \begin{macrocode}
\def\maybe@update@mdseries@defaults{%
\ifx\mddefault\mddefault@previous\else
\expandafter\def\expandafter\mddefault\expandafter{\mddefault\@empty}%
\let\mddefault@previous\mddefault
\let\mdseries@rm\mddef@ult
\let\mdseries@sf\mddef@ult
\let\mdseries@tt\mddef@ult
% \end{macrocode}
%
% Formats that set up parallel fonts, e.g., for Japanese, can use
% this hook to add resets here.
% \changes{v3.1m}{2020/04/06}{Hook added (gh/306)}
% \changes{v3.2b}{2020/08/21}{Integration of new hook management interface}
% \begin{macrocode}
\UseHook{mdseries/defaults}%
\fi
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{2020/10/01}%
%<latexrelease> {\bfseries}{Custom series with hooks}%
%<latexrelease>
%<latexrelease>\let\maybe@update@bfseries@defaults\@undefined
%<latexrelease>\let\maybe@update@mdseries@defaults\@undefined
%<latexrelease>
%<latexrelease>\DeclareRobustCommand\bfseries{%
%<latexrelease> \not@math@alphabet\bfseries\mathbf
%<latexrelease> \expand@font@defaults
%<latexrelease> \ifx\bfdefault\bfdefault@previous\else
%<latexrelease> \expandafter\def\expandafter\bfdefault
%<latexrelease> \expandafter{\bfdefault\@empty}%
%<latexrelease> \let\bfdefault@previous\bfdefault
%<latexrelease> \let\bfseries@rm\bfdef@ult
%<latexrelease> \let\bfseries@sf\bfdef@ult
%<latexrelease> \let\bfseries@tt\bfdef@ult
%<latexrelease> \UseHook{bfseries/defaults}%
%<latexrelease> \fi
%<latexrelease> \ifx\f@family\rmdef@ult \fontseries\bfseries@rm
%<latexrelease> \else\ifx\f@family\sfdef@ult \fontseries\bfseries@sf
%<latexrelease> \else\ifx\f@family\ttdef@ult \fontseries\bfseries@tt
%<latexrelease> \else \fontseries\bfdefault
%<latexrelease> \fi\fi\fi
%<latexrelease> \UseHook{bfseries}%
%<latexrelease> \selectfont
%<latexrelease>}
%<latexrelease>
%<latexrelease>\DeclareRobustCommand\mdseries{%
%<latexrelease> \not@math@alphabet\mdseries\relax
%<latexrelease> \expand@font@defaults
%<latexrelease> \ifx\mddefault\mddefault@previous\else
%<latexrelease> \expandafter\def\expandafter\mddefault\expandafter{\mddefault\@empty}%
%<latexrelease> \let\mddefault@previous\mddefault
%<latexrelease> \let\mdseries@rm\mddef@ult
%<latexrelease> \let\mdseries@sf\mddef@ult
%<latexrelease> \let\mdseries@tt\mddef@ult
%<latexrelease> \UseHook{mdseries/defaults}%
%<latexrelease> \fi