summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/sfmath/sfmath.sty
blob: 566070f49e04a4c4357691d33272da82c37337b4 (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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
% sfmath.sty, copyright 2001-2007 by Olaf Dietrich (olaf@dtrx.de)
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
% of this license or (at your option) any later version.
% The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3 or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Olaf Dietrich.
%
% This work consists of the file sfmath.sty.


\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{sfmath}[2007/08/27 v0.8 sans serif maths]


% This is a simple package for sans serif maths in documents.
%
% Usage: \usepackage{sfmath} or \usepackage[OPTIONS]{sfmath}
%
% After including the package sfmath.sty, all maths of the current
% document is displayed with sans serif fonts; there is no way to
% switch back to the original behavior.
%
% The default sans serif font for maths is the sans serif font
% selected for sans serif text (i.e., \sfdefault) when sfmath.sty
% is loaded. Therefore, you must include sfmath.sty after having
% changed \sfdefault, e.g., by a package such as helvet.sty or
% manually. Alternatively, use one of the font options described
% below (cm, helvet, cmbright, tx, px, or lm) in order to override
% the default sans serif font.
%
% Package OPTIONS (options marked with (+) are experimental):
%
% * slantedGreek: for slanted uppercase Greek letters
%
% * cm: use Computer Modern (cmss) for maths (explicitly)
% * helvet: use Postscript Helvetica (phv) for maths (explicitly)
% * cmbright: use CM-Bright fonts (cmbr) for maths (explicitely)
% * tx: use Postscript txfonts (tx) for maths (explicitly)
% * px: use Postscript pxfonts (tx) for maths (explicitly)
% * lm: use Latin Modern (lmss) for maths (explicitly) (+)
%
% * T1experimental: use T1 font encoding for standard maths (+)
% * AlphT1experimental: use T1 font encoding for \math*{...} commands (+)
%
% * mathrmOrig: do not change the behavior of the \mathrm command
% * mathbfOrig: do not change the behavior of the \mathbf command
% * mathitOrig: do not change the behavior of the \mathit command
% * mathsfOrig: do not change the behavior of the \mathsf command
%
% (+): Known limitations of experimental options:
%      T1experimental produces a warning about the encoding of the
%                     operators font.
%      AlphT1experimental DOES NOT WORK with uppercase Greek letters
%                     within the \math*{...} command!
%      These options should only be used with the ec fonts.
%
%      lm includes T1experimental and AlphT1experimental with the
%      limitations mentioned above.
%
%      RECOMMENDATION:
%           use the fix-cm package instead of the experimental
%           T1 options: with fix-cm.sty, the chosen ec fonts
%           harmonize much better with the cm sans serif math fonts.
%           Add \RequirePackage{fix-cm} _before_ \documentclass{...}.
%
%
% Some new macros are defined by sfmath.sty:
%
% * \mathsl{...}: A new math alphabet that is by default identical
%   with \mathit{...}; useful in combination with the option mathitOrig.
%
% * \upOmega, \upDelta: upright versions of \Omega and \Delta;
%   useful when the option slantedGreek is selected.
%
%
% More documentation can currently be found at:
% <URL:http://dtrx.de/od/tex/sfmath.html>


% CHANGES:
%
% v0.8:
%
% * Update documentation and add license details for CTAN upload.
%
%
% v0.7:
%
% * Add (experimental) support for latin modern (lmodern) fonts.
%
%
% v0.6:
%
% * Add some artificial intelligence to use slanted bold letters
%   if available (e.g., for phv, txfonts, or pxfonts).
%   Add options to select txfonts, pxfonts, and cmbright (probably
%   not very useful) explicitely.
%   (Thanks to Alberto Lusiani who asked for slanted bold letters.)
%
%
% v0.5:
%
% * Add experimental options for T1 font encoding of maths fonts.
%   Using these options can be useful with ec fonts which look
%   slightly different from the standard cm maths fonts (especially
%   at large font size). About limitations see above.
%
%
% v0.4:
%
% * Add \upDelta, \upOmega command (to be a little more compatible
%   with other packages that provide the slantedGreek option)
%
%
% v0.3:
%
% * Add sans serif shapes for "," and ".", "\ldotp"
%
% * Modified documentation
%
%
% v0.2:
%
% * New option slantedGreek for slanted greek capitals
%
% * Options helvet and cm to select explicitly the sans serif font
%   for maths. Without any of these options, the current \sfdefault
%   is chosen.
%
% * Options mathxxOrig: don't change the alphabet command \mathxx;
%   available for \mathrm, \mathbf, \mathit, and \mathsf
%
% * Provide dotlessi and dotlessj (if available)
%


% BUGS/LIMITATIONS/PROBLEMS:
%
% * Functionality is limited by the intention to work without
%   additionally defined (virtual) fonts; instead, only standard
%   fonts are used.
%
% * The font metrics are not adjusted to maths usage (this may
%   result in typographically unsatisfying results).
%
% * In many constellations with Postscript fonts (helvet.sty,
%   pslatex.sty, ...) the upper-case greek letters are not chosen
%   correctly within \mathrm, \mathbf, \mathit, ... (because
%   they should be part of OT1-encoded fonts but are not included
%   in these standard postscript fonts).
%
% * Bold math symbols are not always available (e.g. with pslatex.sty)
%   or at least not slanted (e.g. with cmss fonts), so better don't
%   use bold maths with this package. (This has been partially improved
%   in version 0.6.)
%
% * There is a visual difference between the ec sans serif text fonts
%   and the cm sans serif maths fonts, especially at larger font sizes.
%   The fix-cm package might help to reduce the ugliness of the ec
%   sans serif fonts and the differences between the ec text fonts
%   and the cm math fonts.
%   Alternatively, the experimental options T1experimental and
%   AlphT1Experimental might help by using the ec fonts for maths as well.
%
% * The txfonts and pxfonts are reported to have several deficiencies
%   with respect to font metrics and macro implementation; using
%   these fonts is not recommended by the package author.
%
% * The set symbols \mathbb{N} or \mathbbm{N} (from bbm.sty) are not
%   changed. You might like to use \mathbbmss{N} (from bbm.sty).
%
% * Some symbols have serifish shapes (\sum, \prod, probably more) and
%   are not changed.
%
% * Lower-case greek letters are not available in sans serif shape
%   (they don't have real serifs, but cannot be expected to harmonize
%   with the sans serif latin letters).
%
%
% TODO:
%
% * Improve documentation.
%
% * Provide LaTeX .ins/.dtx files instead of naked .sty file.
%


% HERE WE GO:

% Declare options and defaults and process options

\DeclareOption{slantedGreek}{%
  \renewcommand{\greek@shape}{sl}%
  \renewcommand{\greek@bold@shape}{\greek@bold@sl}%
}

\DeclareOption{cm}{\renewcommand{\math@sfdefault}{cmss}}
\DeclareOption{lm}{\renewcommand{\math@sfdefault}{lmss}}
\DeclareOption{helvet}{\renewcommand{\math@sfdefault}{phv}}
\DeclareOption{cmbright}{\renewcommand{\math@sfdefault}{cmbr}}
\DeclareOption{tx}{\renewcommand{\math@sfdefault}{txss}}
\DeclareOption{px}{\renewcommand{\math@sfdefault}{pxss}}

\DeclareOption{T1experimental}{\renewcommand{\math@encoding}{T1}}
\DeclareOption{AlphT1experimental}{\renewcommand{\math@lph@encoding}{T1}}

\DeclareOption{mathrmOrig}{\renewcommand{\mathrm@lph}{cmr}}
\DeclareOption{mathbfOrig}{\renewcommand{\mathbf@lph}{cmr}}
\DeclareOption{mathitOrig}{\renewcommand{\mathit@lph}{cmr}}
\DeclareOption{mathsfOrig}{\renewcommand{\mathsf@lph}{cmss}}


\newcommand{\math@sfdefault}{\sfdefault}
\newcommand{\math@encoding}{OT1}
\newcommand{\math@lph@encoding}{OT1}

\newcommand{\mathrm@lph}{\math@sfdefault}
\newcommand{\mathbf@lph}{\math@sfdefault}
\newcommand{\mathit@lph}{\math@sfdefault}
\newcommand{\mathsf@lph}{\math@sfdefault}


% \math@sfGreek: Font for capital greeks: cmss or other?
% \greek@shape: Capital greeks: normal or slanted? [slantedGreek]
% \greek@bold@shape: Bold capital greeks: normal or slanted? [slantedGreek]
% \greek@bold@sl: Bold capital greeks: "sl" if slanted possible
%
% \mathnormal@bold@shape: Bold letters: normal or slanted? (always bold)
% \mathit@bold@series: Bold \mathit (\mathsl): medium or bold? (always slanted)

\newcommand{\math@sfGreek}{cmss}
\newcommand{\greek@shape}{n}
\newcommand{\greek@bold@shape}{n}
\newcommand{\greek@bold@sl}{n}
\newcommand{\mathnormal@bold@shape}{n}
\newcommand{\mathit@bold@series}{m}



\ProcessOptions



% check the current value of \math@sfdefault

\edef\tmp@sfdefault{\math@sfdefault}

\def\tmp@compare{cmss}
\ifx\tmp@sfdefault\tmp@compare
  % \sfdefault is cmss
  % no slanted bold letters
  % no slanted bold capital Greeks
  \renewcommand{\math@sfGreek}{cmss}
  \renewcommand{\greek@bold@sl}{n}
  \renewcommand{\mathnormal@bold@shape}{n}
  \renewcommand{\mathit@bold@series}{m}
\fi

\def\tmp@compare{phv}
\ifx\tmp@sfdefault\tmp@compare
  % \sfdefault is phv (helvet.sty)
  % slanted bold letters
  % no capital Greeks
  \renewcommand{\math@sfGreek}{cmss}
  \renewcommand{\greek@bold@sl}{n}
  \renewcommand{\mathnormal@bold@shape}{sl}
  \renewcommand{\mathit@bold@series}{bx}
\fi

\def\tmp@compare{txss}
\ifx\tmp@sfdefault\tmp@compare
  % \sfdefault is txss (txfonts.sty)
  % slanted bold letters
  % slanted bold capital Greeks
  \renewcommand{\math@sfGreek}{txss}
  \renewcommand{\greek@bold@sl}{sl}
  \renewcommand{\mathnormal@bold@shape}{sl}
  \renewcommand{\mathit@bold@series}{bx}
\fi

\def\tmp@compare{pxss}
\ifx\tmp@sfdefault\tmp@compare
  % \sfdefault is pxss (pxfonts.sty)
  % slanted bold letters
  % slanted bold capital Greeks
  \renewcommand{\math@sfGreek}{pxss}
  \renewcommand{\greek@bold@sl}{sl}
  \renewcommand{\mathnormal@bold@shape}{sl}
  \renewcommand{\mathit@bold@series}{bx}
\fi

\def\tmp@compare{cmbr}
\ifx\tmp@sfdefault\tmp@compare
  % \sfdefault is cmbr (cmbright.sty)
  % no slanted bold letters
  % no slanted bold capital Greeks
  \renewcommand{\math@sfGreek}{cmbr}
  \renewcommand{\greek@bold@sl}{n}
  \renewcommand{\mathnormal@bold@shape}{n}
  \renewcommand{\mathit@bold@series}{m}
\fi

\def\tmp@compare{lmss}
\ifx\tmp@sfdefault\tmp@compare
  % \sfdefault is lmss (lmodern.sty sans serif)
  % T1 encoding only
  % slanted bold letters
  % no slanted bold capital Greeks
  \renewcommand{\math@encoding}{T1}
  \renewcommand{\math@lph@encoding}{T1}
  \renewcommand{\math@sfGreek}{cmss}
  \renewcommand{\greek@bold@sl}{n}
  \renewcommand{\mathnormal@bold@shape}{sl}
  \renewcommand{\mathit@bold@series}{bx}
\fi



% Change font for digits and "operators" (\sin, \exp, ...)
% to default sans serif font

\SetSymbolFont{operators}{normal}{\math@encoding}{\math@sfdefault}{m}{n}
\SetSymbolFont{operators}{bold}{\math@encoding}{\math@sfdefault}{bx}{n}


% Most special math symbols remain unmodified (and many of those
% don't have serifs); however all letters (A-Z, a-z) are
% explicitely changed to the sans serif version (again
% default sans serif font).
%
% Unfortunately, there is no standard slanted+bold sans serif font
% available (as Postscript Type 1 font), so try an upright
% version (may be better than nothing).

\DeclareSymbolFont{SFMath}{\math@encoding}{\math@sfdefault}{m}{sl}
\SetSymbolFont{SFMath}{normal}{\math@encoding}{\math@sfdefault}{m}{sl}
\SetSymbolFont{SFMath}{bold}{\math@encoding}{\math@sfdefault}{bx}{\mathnormal@bold@shape}
\DeclareMathSymbol{A}{\mathalpha}{SFMath}{`A}
\DeclareMathSymbol{B}{\mathalpha}{SFMath}{`B}
\DeclareMathSymbol{C}{\mathalpha}{SFMath}{`C}
\DeclareMathSymbol{D}{\mathalpha}{SFMath}{`D}
\DeclareMathSymbol{E}{\mathalpha}{SFMath}{`E}
\DeclareMathSymbol{F}{\mathalpha}{SFMath}{`F}
\DeclareMathSymbol{G}{\mathalpha}{SFMath}{`G}
\DeclareMathSymbol{H}{\mathalpha}{SFMath}{`H}
\DeclareMathSymbol{I}{\mathalpha}{SFMath}{`I}
\DeclareMathSymbol{J}{\mathalpha}{SFMath}{`J}
\DeclareMathSymbol{K}{\mathalpha}{SFMath}{`K}
\DeclareMathSymbol{L}{\mathalpha}{SFMath}{`L}
\DeclareMathSymbol{M}{\mathalpha}{SFMath}{`M}
\DeclareMathSymbol{N}{\mathalpha}{SFMath}{`N}
\DeclareMathSymbol{O}{\mathalpha}{SFMath}{`O}
\DeclareMathSymbol{P}{\mathalpha}{SFMath}{`P}
\DeclareMathSymbol{Q}{\mathalpha}{SFMath}{`Q}
\DeclareMathSymbol{R}{\mathalpha}{SFMath}{`R}
\DeclareMathSymbol{S}{\mathalpha}{SFMath}{`S}
\DeclareMathSymbol{T}{\mathalpha}{SFMath}{`T}
\DeclareMathSymbol{U}{\mathalpha}{SFMath}{`U}
\DeclareMathSymbol{V}{\mathalpha}{SFMath}{`V}
\DeclareMathSymbol{W}{\mathalpha}{SFMath}{`W}
\DeclareMathSymbol{X}{\mathalpha}{SFMath}{`X}
\DeclareMathSymbol{Y}{\mathalpha}{SFMath}{`Y}
\DeclareMathSymbol{Z}{\mathalpha}{SFMath}{`Z}
\DeclareMathSymbol{a}{\mathalpha}{SFMath}{`a}
\DeclareMathSymbol{b}{\mathalpha}{SFMath}{`b}
\DeclareMathSymbol{c}{\mathalpha}{SFMath}{`c}
\DeclareMathSymbol{d}{\mathalpha}{SFMath}{`d}
\DeclareMathSymbol{e}{\mathalpha}{SFMath}{`e}
\DeclareMathSymbol{f}{\mathalpha}{SFMath}{`f}
\DeclareMathSymbol{g}{\mathalpha}{SFMath}{`g}
\DeclareMathSymbol{h}{\mathalpha}{SFMath}{`h}
\DeclareMathSymbol{i}{\mathalpha}{SFMath}{`i}
\DeclareMathSymbol{j}{\mathalpha}{SFMath}{`j}
\DeclareMathSymbol{k}{\mathalpha}{SFMath}{`k}
\DeclareMathSymbol{l}{\mathalpha}{SFMath}{`l}
\DeclareMathSymbol{m}{\mathalpha}{SFMath}{`m}
\DeclareMathSymbol{n}{\mathalpha}{SFMath}{`n}
\DeclareMathSymbol{o}{\mathalpha}{SFMath}{`o}
\DeclareMathSymbol{p}{\mathalpha}{SFMath}{`p}
\DeclareMathSymbol{q}{\mathalpha}{SFMath}{`q}
\DeclareMathSymbol{r}{\mathalpha}{SFMath}{`r}
\DeclareMathSymbol{s}{\mathalpha}{SFMath}{`s}
\DeclareMathSymbol{t}{\mathalpha}{SFMath}{`t}
\DeclareMathSymbol{u}{\mathalpha}{SFMath}{`u}
\DeclareMathSymbol{v}{\mathalpha}{SFMath}{`v}
\DeclareMathSymbol{w}{\mathalpha}{SFMath}{`w}
\DeclareMathSymbol{x}{\mathalpha}{SFMath}{`x}
\DeclareMathSymbol{y}{\mathalpha}{SFMath}{`y}
\DeclareMathSymbol{z}{\mathalpha}{SFMath}{`z}

\DeclareMathSymbol{\imath}{\mathalpha}{SFMath}{"10}
\DeclareMathSymbol{\jmath}{\mathalpha}{SFMath}{"11}


% The symbols ",", ".", and "\ldotp" should be sans serif
% but upright.

\DeclareSymbolFont{SFMathUp}{\math@encoding}{\math@sfdefault}{m}{n}
\SetSymbolFont{SFMathUp}{normal}{\math@encoding}{\math@sfdefault}{m}{n}
\SetSymbolFont{SFMathUp}{bold}{\math@encoding}{\math@sfdefault}{bx}{n}
\DeclareMathSymbol{,}{\mathpunct}{SFMathUp}{`,}
\DeclareMathSymbol{.}{\mathord}{SFMathUp}{`.}
\DeclareMathSymbol{\ldotp}{\mathord}{SFMathUp}{`.}


% Take capital greek letters from cmss or [tp]xss; other sans serif fonts
% like helvetica don't have capital greeks, so here cmss is
% taken instead of \sfdefault. Unfortunately, this does not work
% within the alphabet commands \mathrm, \mathsf, ...

\DeclareSymbolFont{SFMathGreek}{OT1}{\math@sfGreek}{m}{\greek@shape}
\SetSymbolFont{SFMathGreek}{normal}{OT1}{\math@sfGreek}{m}{\greek@shape}
\SetSymbolFont{SFMathGreek}{bold}{OT1}{\math@sfGreek}{bx}{\greek@bold@shape}

\DeclareMathSymbol{\Gamma}{\mathalpha}{SFMathGreek}{"00}
\DeclareMathSymbol{\Delta}{\mathalpha}{SFMathGreek}{"01}
\DeclareMathSymbol{\Theta}{\mathalpha}{SFMathGreek}{"02}
\DeclareMathSymbol{\Lambda}{\mathalpha}{SFMathGreek}{"03}
\DeclareMathSymbol{\Xi}{\mathalpha}{SFMathGreek}{"04}
\DeclareMathSymbol{\Pi}{\mathalpha}{SFMathGreek}{"05}
\DeclareMathSymbol{\Sigma}{\mathalpha}{SFMathGreek}{"06}
\DeclareMathSymbol{\Upsilon}{\mathalpha}{SFMathGreek}{"07}
\DeclareMathSymbol{\Phi}{\mathalpha}{SFMathGreek}{"08}
\DeclareMathSymbol{\Psi}{\mathalpha}{SFMathGreek}{"09}
\DeclareMathSymbol{\Omega}{\mathalpha}{SFMathGreek}{"0A}


\DeclareSymbolFont{SFMathUpGreek}{OT1}{\math@sfGreek}{m}{n}
\SetSymbolFont{SFMathUpGreek}{normal}{OT1}{\math@sfGreek}{m}{n}
\SetSymbolFont{SFMathUpGreek}{bold}{OT1}{\math@sfGreek}{bx}{n}

\DeclareMathSymbol{\upDelta}{\mathalpha}{SFMathUpGreek}{"01}
\DeclareMathSymbol{\upOmega}{\mathalpha}{SFMathUpGreek}{"0A}


% Define new behavior for math alphabet commands


\SetMathAlphabet{\mathnormal}{normal}{\math@lph@encoding}{\math@sfdefault}{m}{sl}
\SetMathAlphabet{\mathnormal}{bold}{\math@lph@encoding}{\math@sfdefault}{bx}{\mathnormal@bold@shape}

\SetMathAlphabet{\mathrm}{normal}{\math@lph@encoding}{\mathrm@lph}{m}{n}
\SetMathAlphabet{\mathrm}{bold}{\math@lph@encoding}{\mathrm@lph}{bx}{n}

\SetMathAlphabet{\mathbf}{normal}{\math@lph@encoding}{\mathbf@lph}{bx}{n}
\SetMathAlphabet{\mathbf}{bold}{\math@lph@encoding}{\mathbf@lph}{bx}{n}

\SetMathAlphabet{\mathit}{normal}{\math@lph@encoding}{\mathit@lph}{m}{sl}
\SetMathAlphabet{\mathit}{bold}{\math@lph@encoding}{\mathit@lph}{\mathit@bold@series}{sl}

\SetMathAlphabet{\mathsf}{normal}{\math@lph@encoding}{\mathsf@lph}{m}{n}
\SetMathAlphabet{\mathsf}{bold}{\math@lph@encoding}{\mathsf@lph}{bx}{n}



% Define new math alphabet command \mathsl

\DeclareMathAlphabet{\mathsl}{\math@lph@encoding}{\math@sfdefault}{m}{sl}
\SetMathAlphabet{\mathsl}{bold}{\math@lph@encoding}{\math@sfdefault}{\mathit@bold@series}{sl}


\endinput