Debian Codegraph @

TeX/elstob.sty

raw
1 %% Elstob.sty
2 %% Copyright 2023 by Peter S. Baker
3 %
4 % This work may be distributed and/or modified under the
5 % conditions of the LaTeX Project Public License, either version 1.3c
6 % of this license or (at your option) any later version.
7 % The latest version of this license is at
8 % https://www.latex-project.org/lppl.txt
9 %
10 % This work consists of the files elstob.sty and elstob.lua.
11
12 \ProvidesPackage{elstob}[%
13 2023/12/16 (Peter Baker) Supports the Elstob variable font for LuaLaTeX.]
14
15 \RequirePackage{ifluatex,xkeyval,fontspec}
16
17 \RequireLuaTeX
18
19 % FIGURES (default is OldStyle Proportional)
20
21 \newif\ifelstob@lining \elstob@liningfalse
22 \newif\ifelstob@tabular \elstob@tabularfalse
23
24 \DeclareOptionX{lining}{\elstob@liningtrue}
25 \DeclareOptionX{tabular}{\elstob@tabulartrue}
26 \DeclareOptionX{proportional}{\elstob@tabularfalse}
27 \DeclareOptionX{oldstyle}{\elstob@liningfalse}
28
29 % WEIGHT OPTIONS
30
31 \newcommand*{\elstob@regidx}{1}
32 \DeclareOptionX{extralight}{\renewcommand{\elstob@regidx}{4}}
33 \DeclareOptionX{light}{\renewcommand{\elstob@regidx}{2}}
34 \DeclareOptionX{medium}{\renewcommand{\elstob@regidx}{3}}
35 \newcommand*{\elstob@boldidx}{1}
36 \DeclareOptionX{semibold}{\renewcommand{\elstob@boldidx}{2}}
37 \DeclareOptionX{extrabold}{\renewcommand{\elstob@boldidx}{3}}
38
39 \newcommand*{\wghtadj}{0}
40 \DeclareOptionX{wghtadjust}{\renewcommand*{\wghtadj}{#1}}
41 \DeclareOptionX{weightadjustment}{\renewcommand*{\wghtadj}{#1}}
42
43 % OLD-STYLE SPACING; OPTICAL SIZE; ITALIC SLANT
44
45 \newif\ifelstob@oldspacing \elstob@oldspacingfalse
46 \DeclareOptionX{oldspacing}{\elstob@oldspacingtrue}
47
48 \newcommand*{\opszadj}{0}
49 \DeclareOptionX{opszadjust}{\renewcommand*{\opszadj}{#1}}
50 \DeclareOptionX{opticalsizeadjustment}{\renewcommand*{\opszadj}{#1}}
51
52 \newcommand*{\elstob@Islnt}{8}
53 \DeclareOptionX{slant}{\renewcommand*{\elstob@Islnt}{#1}}
54
55 % MAIN TEXT OPTIONS
56
57 \newcommand*{\MainDef}{}
58 \newcommand*{\MainRegDef}{}
59 \newcommand*{\MainItalicDef}{}
60 \newcommand*{\MainBoldDef}{}
61 \newcommand*{\MainBoldItalicDef}{}
62
63 \DeclareOptionX{MainFeatures}{\renewcommand*{\MainDef}{#1,}}
64 \DeclareOptionX{MainRegularFeatures}{\renewcommand*{\MainRegDef}{#1,}}
65 \DeclareOptionX{MainItalicFeatures}{\renewcommand*{\MainItalicDef}{#1,}}
66 \DeclareOptionX{MainBoldFeatures}{\renewcommand*{\MainBoldDef}{#1,}}
67 \DeclareOptionX{MainBoldItalicFeatures}{\renewcommand*{\MainBoldItalicDef}{#1,}}
68
69 \DeclareOptionX{MainRegularSizeFeatures}{\newcommand*{\MainRegSizeDef}{\directlua{mksizecommand({#1})}}}
70 \DeclareOptionX{MainItalicSizeFeatures}{\newcommand*{\MainItalicSizeDef}{\directlua{mksizecommand({#1})}}}
71 \DeclareOptionX{MainBoldSizeFeatures}{\newcommand*{\MainBoldSizeDef}{\directlua{mksizecommand({#1})}}}
72 \DeclareOptionX{MainBoldItalicSizeFeatures}{\newcommand*{\MainBoldItalicSizeDef}{\directlua{mksizecommand({#1})}}}
73
74 % ALTERNATE STYLES
75
76 \directlua{dofile("Elstob.lua")
77 mkaltcommands()}
78
79 % PROCESS OPTIONS
80
81 \DeclareOptionX*{\PackageWarning{Elstob}{Unknown option `\CurrentOption' ignored}}
82 \ProcessOptionsX\relax
83
84 % APPLY OPTICAL SIZE ADJUSTMENT AND GENERATE opsz COMMANDS
85
86 \def\mkopszcommands#1{%
87 \directlua{adjustment = #1
88 mkopszcommands(adjustment)}}
89
90 \mkopszcommands{\opszadj}
91
92 % APPLY WEIGHT ADJUSTMENT AND GENERATE wght COMMANDS
93
94 \def\mkregwghtcommands#1#2{%
95 \directlua{wtidx = #1
96 adjustment = #2
97 mkregcommands(wtidx, adjustment)}}
98
99 \def\mkboldwghtcommands#1#2{%
100 \directlua{wtidx = #1
101 adjustment = #2
102 mkboldcommands(wtidx, adjustment)}}
103
104 \mkregwghtcommands{\elstob@regidx}{\wghtadj}
105
106 \mkboldwghtcommands{\elstob@boldidx}{\wghtadj}
107
108 % SET SS18 AND SPAC AXIS IF OLD-STYLE SPACING
109
110 \def\elstob@spac{0}
111 \ifelstob@oldspacing
112 % Append StylisticSet=18 to existing \MainDef (which may be empty).
113 \let\tttemp\MainDef
114 \renewcommand*{\MainDef}{\tttemp StylisticSet=18,}
115 \def\elstob@spac{1}
116 \fi
117
118 % GENERATE SizeFeatures FOR THE FOUR MAIN STYLES
119 % (won't be done if user has supplied custom SizeFeatures)
120
121 \@ifundefined{MainRegSizeDef}{
122 \typeout{Constructing MainRegSizeDef}
123 \newcommand*{\MainRegSizeDef}{
124 SizeFeatures={
125 {Size={-6.5}, RawFeature={axis={wght=\elstob@RwghtOne, opsz=\elstob@RopszOne, SPAC=\elstob@spac}}},
126 {Size={6.5-7.5}, RawFeature={axis={wght=\elstob@RwghtTwo, opsz=\elstob@RopszTwo, SPAC=\elstob@spac}}},
127 {Size={7.5-8.5}, RawFeature={axis={wght=\elstob@RwghtThree, opsz=\elstob@RopszThree, SPAC=\elstob@spac}}},
128 {Size={8.5-9.5}, RawFeature={axis={wght=\elstob@RwghtFour, opsz=\elstob@RopszFour, SPAC=\elstob@spac}}},
129 {Size={9.5-10.5}, RawFeature={axis={wght=\elstob@RwghtFive, opsz=\elstob@RopszFive, SPAC=\elstob@spac}}},
130 {Size={10.5-11.5}, RawFeature={axis={wght=\elstob@RwghtSix, opsz=\elstob@RopszSix, SPAC=\elstob@spac}}},
131 {Size={11.5-12.5}, RawFeature={axis={wght=\elstob@RwghtSeven, opsz=\elstob@RopszSeven, SPAC=\elstob@spac}}},
132 {Size={12.5-13.5}, RawFeature={axis={wght=\elstob@RwghtEight, opsz=\elstob@RopszEight, SPAC=\elstob@spac}}},
133 {Size={13.5-14.5}, RawFeature={axis={wght=\elstob@RwghtNine, opsz=\elstob@RopszNine, SPAC=\elstob@spac}}},
134 {Size={14.5-15.5}, RawFeature={axis={wght=\elstob@RwghtTen, opsz=\elstob@RopszTen, SPAC=\elstob@spac}}},
135 {Size={15.5-16.5}, RawFeature={axis={wght=\elstob@RwghtEleven, opsz=\elstob@RopszEleven, SPAC=\elstob@spac}}},
136 {Size={16.5-17.5}, RawFeature={axis={wght=\elstob@RwghtTwelve, opsz=\elstob@RopszTwelve, SPAC=\elstob@spac}}},
137 {Size={17.5-}, RawFeature={axis={wght=\elstob@RwghtThirteen, opsz=\elstob@RopszThirteen, SPAC=\elstob@spac}}}
138 }
139 }
140 }{\typeout{Using predefined MainRegSizeDef}}
141
142 \@ifundefined{MainItalicSizeDef}{
143 \newcommand*{\MainItalicSizeDef}{
144 SizeFeatures={
145 {Size={-6.5}, RawFeature={axis={wght=\elstob@IwghtOne,opsz=\elstob@IopszOne,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
146 {Size={6.5-7.5}, RawFeature={axis={wght=\elstob@IwghtTwo,opsz=\elstob@IopszTwo,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
147 {Size={7.5-8.5}, RawFeature={axis={wght=\elstob@IwghtThree,opsz=\elstob@IopszThree,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
148 {Size={8.5-9.5}, RawFeature={axis={wght=\elstob@IwghtFour,opsz=\elstob@IopszFour,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
149 {Size={9.5-10.5}, RawFeature={axis={wght=\elstob@IwghtFive,opsz=\elstob@IopszFive,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
150 {Size={10.5-11.5}, RawFeature={axis={wght=\elstob@IwghtSix,opsz=\elstob@IopszSix,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
151 {Size={11.5-12.5}, RawFeature={axis={wght=\elstob@IwghtSeven,opsz=\elstob@IopszSeven,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
152 {Size={12.5-13.5}, RawFeature={axis={wght=\elstob@IwghtEight,opsz=\elstob@IopszEight,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
153 {Size={13.5-14.5}, RawFeature={axis={wght=\elstob@IwghtNine,opsz=\elstob@IopszNine,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
154 {Size={14.5-15.5}, RawFeature={axis={wght=\elstob@IwghtTen,opsz=\elstob@IopszTen,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
155 {Size={15.5-16.5}, RawFeature={axis={wght=\elstob@IwghtEleven,opsz=\elstob@IopszEleven,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
156 {Size={16.5-17.5}, RawFeature={axis={wght=\elstob@IwghtTwelve,opsz=\elstob@IopszTwelve,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
157 {Size={17.5-}, RawFeature={axis={wght=\elstob@IwghtThirteen,opsz=\elstob@IopszThirteen,SPAC=\elstob@spac,slnt=\elstob@Islnt}}}
158 }
159 }
160 }{}
161
162 \@ifundefined{MainBoldSizeDef}{
163 \newcommand*{\MainBoldSizeDef}{
164 SizeFeatures={
165 {Size={-6.5}, RawFeature={axis={wght=\elstob@BwghtOne,opsz=\elstob@BopszOne,SPAC=\elstob@spac}}},
166 {Size={6.5-7.5}, RawFeature={axis={wght=\elstob@BwghtTwo,opsz=\elstob@BopszTwo,SPAC=\elstob@spac}}},
167 {Size={7.5-8.5}, RawFeature={axis={wght=\elstob@BwghtThree,opsz=\elstob@BopszThree,SPAC=\elstob@spac}}},
168 {Size={8.5-9.5}, RawFeature={axis={wght=\elstob@BwghtFour,opsz=\elstob@BopszFour,SPAC=\elstob@spac}}},
169 {Size={9.5-10.5}, RawFeature={axis={wght=\elstob@BwghtFive,opsz=\elstob@BopszFive,SPAC=\elstob@spac}}},
170 {Size={10.5-11.5}, RawFeature={axis={wght=\elstob@BwghtSix,opsz=\elstob@BopszSix,SPAC=\elstob@spac}}},
171 {Size={11.5-12.5}, RawFeature={axis={wght=\elstob@BwghtSeven,opsz=\elstob@BopszSeven,SPAC=\elstob@spac}}},
172 {Size={12.5-13.5}, RawFeature={axis={wght=\elstob@BwghtEight,opsz=\elstob@BopszEight,SPAC=\elstob@spac}}},
173 {Size={13.5-14.5}, RawFeature={axis={wght=\elstob@BwghtNine,opsz=\elstob@BopszNine,SPAC=\elstob@spac}}},
174 {Size={14.5-15.5}, RawFeature={axis={wght=\elstob@BwghtTen,opsz=\elstob@BopszTen,SPAC=\elstob@spac}}},
175 {Size={15.5-16.5}, RawFeature={axis={wght=\elstob@BwghtEleven,opsz=\elstob@BopszEleven,SPAC=\elstob@spac}}},
176 {Size={16.5-17.5}, RawFeature={axis={wght=\elstob@BwghtTwelve,opsz=\elstob@BopszTwelve,SPAC=\elstob@spac}}},
177 {Size={17.5-}, RawFeature={axis={wght=\elstob@BwghtThirteen,opsz=\elstob@BopszThirteen,SPAC=\elstob@spac}}}
178 }
179 }
180 }{}
181
182 \@ifundefined{MainBoldItalicSizeDef}{
183 \newcommand*{\MainBoldItalicSizeDef}{
184 SizeFeatures={
185 {Size={-6.5}, RawFeature={axis={wght=\elstob@BIwghtOne,opsz=\elstob@BIopszOne,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
186 {Size={6.5-7.5}, RawFeature={axis={wght=\elstob@BIwghtTwo,opsz=\elstob@BIopszTwo,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
187 {Size={7.5-8.5}, RawFeature={axis={wght=\elstob@BIwghtThree,opsz=\elstob@BIopszThree,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
188 {Size={8.5-9.5}, RawFeature={axis={wght=\elstob@BIwghtFour,opsz=\elstob@BIopszFour,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
189 {Size={9.5-10.5}, RawFeature={axis={wght=\elstob@BIwghtFive,opsz=\elstob@BIopszFive,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
190 {Size={10.5-11.5}, RawFeature={axis={wght=\elstob@BIwghtSix,opsz=\elstob@BIopszSix,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
191 {Size={11.5-12.5}, RawFeature={axis={wght=\elstob@BIwghtSeven,opsz=\elstob@BIopszSeven,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
192 {Size={12.5-13.5}, RawFeature={axis={wght=\elstob@BIwghtEight,opsz=\elstob@BIopszEight,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
193 {Size={13.5-14.5}, RawFeature={axis={wght=\elstob@BIwghtNine,opsz=\elstob@BIopszNine,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
194 {Size={14.5-15.5}, RawFeature={axis={wght=\elstob@BIwghtTen,opsz=\elstob@BIopszTen,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
195 {Size={15.5-16.5}, RawFeature={axis={wght=\elstob@BIwghtEleven,opsz=\elstob@BIopszEleven,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
196 {Size={16.5-17.5}, RawFeature={axis={wght=\elstob@BIwghtTwelve,opsz=\elstob@BIopszTwelve,SPAC=\elstob@spac,slnt=\elstob@Islnt}}},
197 {Size={17.5-}, RawFeature={axis={wght=\elstob@BIwghtThirteen,opsz=\elstob@BIopszThirteen,SPAC=\elstob@spac,slnt=\elstob@Islnt}}}
198 }
199 }
200 }{}
201
202 % GENERATE NUMBER STRINGS (fontspec style)
203
204 \def\elstob@figurestyle{Lowercase}
205 \ifelstob@lining\def\elstob@figurestyle{Uppercase}\fi
206 \def\elstob@figurealign{Proportional}
207 \ifelstob@tabular\def\elstob@figurealign{Monospaced}\fi
208
209 % SET UP THE MAIN FONT.
210
211 \setmainfont{Elstob}[
212 ItalicFont = {*-Italic},
213 BoldFont = {*},
214 BoldItalicFont = {*-Italic},
215 Renderer = HarfBuzz,
216 Numbers = {\elstob@figurealign,\elstob@figurestyle},
217 \MainDef
218 UprightFeatures = {\MainRegDef
219 \MainRegSizeDef},
220 BoldFeatures = {\MainBoldDef
221 \MainBoldSizeDef},
222 ItalicFeatures = {\MainItalicDef
223 \MainItalicSizeDef},
224 BoldItalicFeatures = {\MainBoldItalicDef
225 \MainBoldItalicSizeDef}
226 ]
227
228 % GENERATE THE ALTERNATE STYLES
229
230 % #1 Name of the face; #2 Elstob or Elstob-Italic;
231 % #3 general features; #4 SizeFeatures
232 \newcommand*{\elstob@newfont}[4]{
233 \setfontface#1{#2}[
234 Renderer = HarfBuzz,
235 Numbers = {\elstob@figurealign,\elstob@figurestyle},
236 SmallCapsFont = {*},
237 SmallCapsFeatures = {Letters=SmallCaps},
238 #3
239 #4
240 ]
241 }
242
243 \directlua{mkfontcommands()}
244
245 % CONVENIENCE COMMANDS FOR ACCESS TO ELSTOB'S OT FEATURES
246
247 % Character Variants
248
249 \newcommand*{\textcv}[3][0]{{\addfontfeature{CharacterVariant=#2:#1}#3}}
250 \newcommand*{\ecv}[2][0]{\addfontfeature{CharacterVariant=#2:#1}}
251
252 % Stylistic Sets.
253
254 \newcommand*{\AltThornEth}{\addfontfeature{StylisticSet=1}} % ss01
255 \newcommand*{\textAltThornEth}[1]{{\addfontfeature{StylisticSet=1}#1}}
256 \newcommand*{\InsularLetterForms}{\addfontfeature{StylisticSet=2}} % ss02
257 \newcommand*{\textInsularLetterForms}[1]{{\addfontfeature{StylisticSet=2}#1}}
258 \newcommand*{\AlternateFigures}{\addfontfeature{StylisticSet=3}} % ss03
259 \newcommand*{\textAlternateFigures}[1]{{\addfontfeature{StylisticSet=3}#1}}
260 \newcommand*{\ContextualLongS}{\addfontfeature{StylisticSet=8}} % ss08
261 \newcommand*{\textContextualLongS}[1]{{\addfontfeature{StylisticSet=8}#1}}
262 \newcommand*{\LanguageSpecificVariants}{\addfontfeature{StylisticSet=9}} % ss09
263 \newcommand*{\textLanguageSpecificVariants}[1]{{\addfontfeature{StylisticSet=9}#1}}
264 \newcommand*{\EarlyEnglishFuthorc}{\addfontfeature{StylisticSet=12}} % ss12
265 \newcommand*{\textEarlyEnglishFuthorc}[1]{{\addfontfeature{StylisticSet=12}#1}}
266 \newcommand*{\ElderFuthark}{\addfontfeature{StylisticSet=13}} % ss13
267 \newcommand*{\textElderFuthark}[1]{{\addfontfeature{StylisticSet=13}#1}}
268 \newcommand*{\YoungerFuthark}{\addfontfeature{StylisticSet=14}} % ss14
269 \newcommand*{\textYoungerFuthark}[1]{{\addfontfeature{StylisticSet=14}#1}}
270 \newcommand*{\LongBranchToShortTwig}{\addfontfeature{StylisticSet=15}} % ss15
271 \newcommand*{\textLongBranchToShortTwig}[1]{{\addfontfeature{StylisticSet=15}#1}}
272 \newcommand*{\ContextualRRotunda}{\addfontfeature{StylisticSet=16}} % ss16
273 \newcommand*{\textContextualRRotunda}[1]{{\addfontfeature{StylisticSet=16}#1}}
274 \newcommand*{\OldStylePunctuation}{\addfontfeature{StylisticSet=18}} % ss18
275 \newcommand*{\textOldStylePunctuation}[1]{{\addfontfeature{StylisticSet=18}#1}}
276
277 % Tiny macros for providing mnemonic access to the cvNN features.
278
279 \def\ecvD{7}
280 \def\ecvd{8}
281 \def\ecvF{11}
282 \def\ecvf{12}
283 \def\ecvG{13}
284 \def\ecvg{14}
285 \def\ecvi{18}
286 \def\ecvR{35}
287 \def\ecvr{36}
288 \def\ecvS{37}
289 \def\ecvs{38}
290 \def\ecvT{39}
291 \def\ecvt{40}
292 \def\ecvTironianEt{69}
293 \def\ecvquestion{76}
294