summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/iwonamath/iwonamath.dtx
blob: 020c8d6ad08cb60441de04e4f7f451eb0c868637 (plain)
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
% \iffalse meta-comment
%
% File: iwonamath.dtx
% Copyright 2023 by Boris Veytsman
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version.  The latest version
% of this license is in the file
%
%    https://www.latex-project.org/lppl.txt
%
%<*driver>
\documentclass{l3doc}
\usepackage{iwonamath}
\usepackage{natbib, booktabs}
\usepackage[tableposition=top]{caption}
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \GetFileInfo{iwonamath.sty}
% \title{\pkg{iwonamath}---a scaled version of Iwona math fonts}
% \date{\fileversion, \filedate}
% \author{Boris
% Veytsman\thanks{\href{mailto:borisv@lk.net}{borisv@lk.net},
% \href{mailto:boris@varphi.com}{boris@varphi.com}}}
% \maketitle
% \begin{abstract}
%   \LaTeX\ support for scaled Iwona math fonts for mixing with sans
%   serif text fonts.
% \end{abstract}
% \begin{documentation}
%
%\section{User manual}
%\label{sec:ug}
%
%
% Iwona is a sans serif typeface by Janusz Marian Nowacki.  It has a
% very good math support~\citep{iwona}.  Package \pkg{iwona} integrates
% text and math fonts.  However, the math fonts may provide
% interesting companions for other text fonts.  To enable the
% combination, this package separates math fonts and provides tools
% for the package writers to mix and match them with text.
%
% \begin{variable}{
%   options/light,
%   options/condensed,
%   options/scale,
%   options/Scale,
%   options/delimitershack,
%   options/standardversion}
% The package has the following options:
% \begin{description}
% \item[light] whether the math fonts use the light version of Iwona,
% either |true| or |false| (default)
% \item[condensed] whether the math fonts use the condensed version of
% Iwona, either |true| or |false| (default).
% \item[scale] the scale of the fonts, a number (by default 1).  The
% title cased |Scale| is the synonym for this key.
% \item[delimitershack] whether to use the hack to get \cs{lVert} and
% \cs{rVert} delimiters, absent in the original font (see
% \citep[\S~12.5.5]{TLC3}), either |true| (default) or |false|.
% \item[standardversions] whether to define standard versions |normal|
% and |bold|, either |true| (default) or |false|.  If |false|, then
% the package does not define any math fonts, and it is up to the user
% to deploy \cmd{\DefineIwonaMathVersion} do define them.  
% \end{description}
% \end{variable}
%
%
% \begin{function}{\DefineIwonaMathVersion}
%   \begin{syntax}
%     \cs{DefineIwonaMathVersion}\Arg{key/value pairs}
%   \end{syntax}
%   The main function of the package,
%   \cmd{\DefineIwonaMathVersion} defines a new
%   math version based on Iwona fonts.  
% \end{function}
% The keys are the following (the defaults, where applicable,
% correspond to the package options):
% \begin{variable}{main/name,
%   main/light,
%   main/condensed,
%   main/bold}
%   \begin{description}
%   \item[name] the name of the version.  By default, either |normal|
%   or |bold| depending on the |bold| key described below.
%   \item[light] whether the math fonts use the light version of
%   Iwona, either |true| or |false|
% \item[condensed] whether the math fonts use the condensed version of
% Iwona, either |true| or |false|.
%   \item[bold] whether we define a bold version, either |true| or
%   |false| (default)
%   \end{description}
% \end{variable}
%
% For the boolean keys the setting |=true| can be omitted, so
% |\DefineIwonaMathVersion{light=true}| and
% |\DefineIwonaMathVersion{light}| are equivalent
%
% Note that in the current implementation the parameters |scale| and
% |delimitershack| are the same for all versions defined.
%
% For example, the following invocation defines four math versions,
% |normal|, |bold|, |condensed| and |boldcondensed|, based on Iwona
% light, scaled 1.2:
% \begin{verbatim}
% \usepackage[scale=1.2, light]{iwonamath}
% \DefineIwonaMathVersion{name=condensed, 
%                          condensed=true}
% \DefineIwonaMathVersion{name=boldcondensed, 
%                          bold=true, condensed=true}
% \end{verbatim}
%
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{Implementation}
% \label{sec:impl}
%
% 
%
%\subsection{Setting up}
%\label{sec:settingup}
%
%
% 
% First, we declare who we are:
%    \begin{macrocode}
%<@@=iwonamath>
%<package>\ProvidesExplPackage {iwonamath}
%<fd>\ProvidesExplFile
%<ot1m>{ot1_FAMILY_m.fd}
%<ot1>{ot1_FAMILY_.fd}
%<oml>{oml_FAMILY_.fd}
%<oms>{oms_FAMILY_.fd}
%<omx>{omx_FAMILY_.fd}
%<cmsy>{omsiwonamathcmsy.fd}
%<package|fd>{2023-08-31} {1.0}
%<package|fd>{Scaled Iwona math fonts}
%<*package>
%    \end{macrocode}
%
%
%
%
%\subsection{Options}
%\label{sec:optionSetting}
%
%
% 
% \begin{variable}{\l_@@_scale_tl,
%                  \l_@@_mainlight_bool,
%                  \l_@@_maincondensed_bool,
%                  \l_@@_delimitershack_bool,
%                  \l_@@_standardversions_bool,
%                  options/light,
%                  options/condensed,
%                  options/scale,
%                  options/Scale,
%                  options/delimitershack,
%                  options/standardversion}
%    \begin{macrocode}
\keys_define:nn { iwonamath/options }
{
  scale .tl_set:N = \l_@@_scale_tl,
  Scale .tl_set:N = \l_@@_scale_tl,
  light .bool_set:N = \l_@@_mainlight_bool,
  light .default:n = true,
  condensed .bool_set:N = \l_@@_maincondensed_bool,
  condensed .default:n = true,
  delimitershack .bool_set:N = \l_@@_delimitershack_bool,
  delimitershack .default:n = true,
  standardversions .bool_set:N = \l_@@_standardversions_bool,
  standardversions .default:n = true,
}

\keys_set:nn {iwonamath/options }
{
  scale = 1,
  light = false,
  condensed = false,
  delimitershack = true,
  standardversions = true,
}
%    \end{macrocode}
%   
% \end{variable}
%
%
% Options processing
%    \begin{macrocode}
\IfFormatAtLeastTF { 2022-06-01 }
  { \ProcessKeyOptions [ iwonamath/options ] }
  {
    \RequirePackage { l3keys2e }
    \ProcessKeysOptions { iwonamath/options }
  }
%    \end{macrocode}% 
%
% \begin{variable}{\l_@@_versionname_tl,
%                  \l_@@_light_bool,
%                  \l_@@_condensed_bool,
%                  \l_@@_bold_bool,
%                  main/name,
%                  main/light,
%                  main/condensed,
%                  main/bold}
% Now the options for the main command
%    \begin{macrocode}
\keys_define:nn { iwonamath/main }
{
  name .tl_set:N = \l_@@_versionname_tl,
  light .bool_set:N = \l_@@_light_bool,
  light .default:n = true,
  condensed .bool_set:N = \l_@@_condensed_bool,
  condensed .default:n = true,
  bold .bool_set:N = \l_@@_bold_bool,
  bold .default:n = true,
}
%    \end{macrocode}
%   
% \end{variable}
%
%
%\subsection{Delimiters hack}
%\label{sec:delimiters}
%
% We add delimiters from |cmsy|, as discussed in
% \citep[\S~12.5.5]{TLC3}).  We predefine the symbols for the standard
% versions just in case.
%    \begin{macrocode}
\bool_if:NTF \l_@@_delimitershack_bool
{
  \DeclareSymbolFont{symbols2}{OMS}{iwonamathcmsy}{m}{n}
  \SetSymbolFont{symbols2}    {bold}{OMS}{cmsy}{b}{n}
  \DeclareMathDelimiter{\lVert}{\mathopen} {symbols2}{"6B}{largesymbols}{"0D}
  \DeclareMathDelimiter{\rVert}{\mathclose}{symbols2}{"6B}{largesymbols}{"0D}
}
{}
%    \end{macrocode}
%
%
%\subsection{The main function}
%\label{sec:main}
%
%
% \begin{macro}{\DefineIwonaMathVersion}
%    \begin{macrocode}
\DeclareDocumentCommand \DefineIwonaMathVersion { m }
{
  \tl_clear:N \l_@@_versionname_tl
  \bool_set_eq:NN \l_@@_light_bool \l_@@_mainlight_bool
  \bool_set_eq:NN \l_@@_condensed_bool \l_@@_maincondensed_bool
  \bool_set_false:N \l_@@_bold_bool 
  \keys_set:nn { iwonamath/main }
  {
    #1
  }

  \tl_if_empty:NTF \l_@@_versionname_tl
  {
    \bool_if:NTF \l_@@_bold_bool
    {
      \tl_set:Nn \l_@@_versionname_tl {bold}
    }
    {
      \tl_set:Nn \l_@@_versionname_tl {normal}
    }
  }
  {}
  
  \tl_set:Nn \l_tmpa_tl {iwonamath}


  \bool_if:NTF \l_@@_light_bool
  {
    \tl_set:Ne \l_tmpa_tl {\l_tmpa_tl l}
  }
  {}
  
  \bool_if:NTF \l_@@_condensed_bool
  {
    \tl_set:Ne \l_tmpa_tl {\l_tmpa_tl c}
  }
  {}

  \DeclareMathVersion{\l_@@_versionname_tl}
  \bool_if:NTF \l_@@_bold_bool
  {
    \SetSymbolFont{operators}{\l_@@_versionname_tl}{OT1}{\l_tmpa_tl m} {b}{n}
    \SetSymbolFont{letters}  {\l_@@_versionname_tl}{OML}{\l_tmpa_tl} {b}{it}
    \SetSymbolFont{symbols}  {\l_@@_versionname_tl}{OMS}{\l_tmpa_tl}{b}{n}
    \SetSymbolFont{largesymbols}{\l_@@_versionname_tl}{OMX}{\l_tmpa_tl}{b}{n}
    \SetMathAlphabet\mathsf{\l_@@_versionname_tl}{OT1}{\l_tmpa_tl}{bx}{n}
    \SetMathAlphabet\mathit{\l_@@_versionname_tl}{OT1}{\l_tmpa_tl}{bx}{it}
    \SetSymbolFont{symbols2}    {\l_@@_versionname_tl}{OMS}{iwonamathcmsy}{b}{n}
  }
  {
    \SetSymbolFont{operators}{\l_@@_versionname_tl}{OT1}{\l_tmpa_tl m}{m}{n}
    \SetSymbolFont{letters}{\l_@@_versionname_tl}{OML}{\l_tmpa_tl} {m}{it}
    \SetSymbolFont{symbols}{\l_@@_versionname_tl}{OMS}{\l_tmpa_tl}{m}{n}
    \SetSymbolFont{largesymbols}{\l_@@_versionname_tl}{OMX}{\l_tmpa_tl}{m}{n}
    \SetMathAlphabet{\mathbf}{\l_@@_versionname_tl}{OT1}{\l_tmpa_tl}{bx}{n}
    \SetMathAlphabet{\mathsf}{\l_@@_versionname_tl}{OT1}{\l_tmpa_tl}{m}{n}
    \SetMathAlphabet{\mathit}{\l_@@_versionname_tl}{OT1}{\l_tmpa_tl}{m}{it}
    \SetMathAlphabet{\mathtt}{\l_@@_versionname_tl}{OT1}{\l_tmpa_tl}{m}{n}
    \SetSymbolFont{symbols2}    {\l_@@_versionname_tl}{OMS}{iwonamathcmsy}{m}{n}
  }

  \bool_if:NTF \l_@@_delimitershack_bool
  {
    
  }
  {}
  
}
%    \end{macrocode}
% \end{macro}
%
%
%
%\subsection{Default versions}
%\label{sec:defaults}
%
% If standard versions are requested, we define them
%    \begin{macrocode}
\bool_if:NTF \l_@@_standardversions_bool
{
  \DefineIwonaMathVersion{}
  \DefineIwonaMathVersion{bold}
}
{}
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
%\subsection{Font definition files}
%\label{sec:fd}
%
%
%
% Now, the fd files.  Sometimes they are defined in special |fdd|
% files; here we use the main |dtx| for this.
%
% First, we check if the size is defined.  If not,
% we define it.
%    \begin{macrocode}
%<*fd>
\tl_if_exist:NTF \l_@@_scale_tl
{}
{
  \tl_new:N \l_@@_scale_tl
  \tl_set:Nn \l_@@_scale_tl {1}
}
%</fd>
%    \end{macrocode}
%
% Our version of |cmsy| just scales the font.  Note that right now the
% scaling is exactly the same as for other iwona math
% characters---maybe we need to fine tune this.
%    \begin{macrocode}
%<*cmsy>
\DeclareFontFamily{OMS}{iwonamathcmsy}{\skewchar\font48 }
\DeclareFontShape{OMS}{iwonamathcmsy}{m}{n}{%
      <-> [\l_@@_scale_tl] cmsy10%
      }{}
\DeclareFontShape{OMS}{iwonamathcmsy}{b}{n}{%
      <-> [\l_@@_scale_tl] cmbsy10%
      }{}
%</cmsy>
%    \end{macrocode}
%
% \begin{table}
%   \centering
%   \caption{Naming scheme for iwona fonts}
%   \label{tab:naming}
%   \begin{tabular}{lllll}
%       \toprule
%       Weight/Shape & \multicolumn{4}{c}{Base}\\
%       \cmidrule{2-5}\\
%                      & Regular & Condensed & Light & Light Condensed \\
%       \midrule
%       m/n & iwonar & iwonacr & iwonal & iwonacl \\
%       m/it & iwonari & iwonacri & iwonali & iwonacli \\
%       b/n & iwonab & iwonacb & iwonam & iwonacm \\
%       b/it & iwonabi & iwonacb & iwonami & iwonacmi \\
%       \bottomrule
%     \end{tabular}
% \end{table}
% 
% Now, we need many files in the different weights and
% condensed/regular status.  It would be too tedious to write all
% them.  So we create a template with the special marks and a bash
% script to generate all |fd| files.  Of course, \TeX\ with enough
% trickery can be used instead of bash, but why bother: we employ
% Makefiles anyways\ldots
%
% The naming scheme for Iwona fonts is shown in
% Table~\ref{tab:naming}.  From this table we see we need three marks:
% |_FAMILY_| for the base family, |_MEDIUM_| for medium font and
% |_BOLD_| for bold font.
%
% We have two |OT1| files: one for default letters, one for |\math...|
% commands.
%    \begin{macrocode}
%<*ot1m>
\DeclareFontFamily{OT1}{_FAMILY_m}{}
\DeclareFontShape{OT1}{_FAMILY_m}{m}{n}{<-> [\l_@@_scale_tl] rm-_MEDIUM_}{}
\DeclareFontShape{OT1}{_FAMILY_m}{b}{n}{<-> [\l_@@_scale_tl] rm-_BOLD_}{}
%</ot1m>
%<*ot1>
\DeclareFontFamily{OT1}{_FAMILY_}{}
\DeclareFontShape{OT1}{_FAMILY_}{m}{n}{<-> [\l_@@_scale_tl] rm-_MEDIUM_}{}
\DeclareFontShape{OT1}{_FAMILY_}{m}{it}{<-> [\l_@@_scale_tl] rm-_MEDIUM_i}{}
\DeclareFontShape{OT1}{_FAMILY_}{b}{n}{<-> [\l_@@_scale_tl] rm-_BOLD_}{}
\DeclareFontShape{OT1}{_FAMILY_}{bx}{n}{<-> [\l_@@_scale_tl] rm-_BOLD_}{}
%</ot1>
%<*oml>
\DeclareFontFamily{OML}{_FAMILY_}{}
\DeclareFontShape{OML}{_FAMILY_}{m}{it}{<-> [\l_@@_scale_tl] mi-_MEDIUM_i}{}
\DeclareFontShape{OML}{_FAMILY_}{b}{it}{<-> [\l_@@_scale_tl] mi-_BOLD_i}{}
\DeclareFontShape{OML}{_FAMILY_}{bx}{it}{<-> [\l_@@_scale_tl] mi-_BOLD_i}{}
%</oml>
%<*oms>
\DeclareFontFamily{OMS}{_FAMILY_}{}
\DeclareFontShape{OMS}{_FAMILY_}{m}{n}{<-> [\l_@@_scale_tl] sy-_MEDIUM_z}{}
\DeclareFontShape{OMS}{_FAMILY_}{b}{n}{<-> [\l_@@_scale_tl] sy-_BOLD_z}{}
\DeclareFontShape{OMS}{_FAMILY_}{bx}{n}{<-> [\l_@@_scale_tl] sy-_BOLD_z}{}
%</oms>
%<*omx>
\DeclareFontFamily{OMX}{_FAMILY_}{}
\DeclareFontShape{OMX}{_FAMILY_}{m}{n}{<-> [\l_@@_scale_tl] ex-_MEDIUM_}{}
\DeclareFontShape{OMX}{_FAMILY_}{b}{n}{<-> [\l_@@_scale_tl] ex-_BOLD_}{}
\DeclareFontShape{OMX}{_FAMILY_}{bx}{n}{<-> [\l_@@_scale_tl] ex-_BOLD_}{}
%</omx>
%    \end{macrocode}
% 
% \end{implementation}
%
% \bibliography{iwonamath}
% \bibliographystyle{plainnat}
%
%  \PrintIndex