Debian Codegraph @

texmf-dist/tex/latex/sansmath/sansmath.sty

raw
1 % LaTeX package sansmath: typeset sans-serif math using `text' fonts.
2 %
3 \ProvidesPackage{sansmath}[2007/02/28 \space ver 1.1 Donald Arseneau]
4 %
5 % Donald Arseneau, [email protected], Vancouver, Canada.
6 %
7 % This package is released to the public domain by me, Donald Arseneau,
8 % the original author, who disclaims all rights. I do not support it,
9 % and request that it be adopted and supported by someone who knows
10 % more about math font issues in LaTeX.
11 %
12 % The point of this package is to allow sans-serif math in the absence
13 % of proper sans math fonts.
14 %
15 % The author was persuaded to use the name `sansmath' in hopes of
16 % working with various text sans fonts (indicated by \sfdefault)
17 % but the only good results seen were with Computer Modern and cmss.
18 % (Helvetica with the `pslatex' package was very poor!)
19 %
20 % INSTRUCTIONS
21 % ~~~~~~~~~~~~
22 % Load this package by inserting `\usepackage{sansmath}' in the
23 % document preamble. This will define a new math version `sans'
24 % and a command `\sansmath', much like `\boldmath'. There is also
25 % an `\unsansmath' defined, but if math is to be sans-serif for
26 % a region of a document, one should declare `\sansmath' in a local
27 % group (perhaps with \begin{sansmath}...\end{sansmath}).
28 % Within the scope of the \sansmath declaration, math characters
29 % will be taken from the text sans-serif family as much as possible.
30 % The actual sans fonts are OT1 encodings of those indicated by the
31 % meaning of \sfdefault WHEN THE PACKAGE WAS LOADED -- not the
32 % meaning at each math environment!
33 %
34 % Since the (OT1) text fonts do not provide the lower-case greek
35 % letters, there is a package option [eulergreek] to take the
36 % lowercase greek from the Euler math fonts.
37 % Since some (many) sans fonts have no uppercase greek letters either
38 % (missing characters from the OT1 encoding), there is an option
39 % [EULERGREEK] to take ALL greek letters from the euler fonts.
40 % One should also investigate using Euler for ALL MATH in the document,
41 % using package `euler' instead of this one!
42 %
43 % OT1 encoding is normally required to get the uppercase greek letters,
44 % but if you use the [EULERGREEK] option or don't use any uppercase greek
45 % letters, then you are welcome to define \sansmathencoding *before*
46 % loading this package. There is also a package option [T1] to perform
47 % that particuler definition. Note the comment above about only cmms
48 % being good; even the T1-encoded ec fonts are poor substitutes.
49 %
50 % This package achieves math-italic by reloading the slanted version
51 % of the text sans-serif font, and changing a fontdimen parameter
52 % (spaceskip). This causes the italic correction to be applied between
53 % letters (good) but does not break up the `fi' and `fl' ligatures (bad)
54 % (Why does a sans font have these ligatures anyway?) At this point,
55 % nothing is done about this bug.
56
57 \providecommand\sansmathencoding{OT1}
58 \DeclareOption{T1}{
59 \def\sansmathencoding{T1}
60 }
61
62 \let\EulGreek\relax
63 \let\EuUCGreek\relax
64 \let\NonEulGreek\relax
65 \DeclareOption{EULERGREEK}{
66 \ExecuteOptions{eulergreek}
67 \def\EuUCGreek{%
68 \@euG\Gamma \@euG\Delta \@euG\Theta \@euG\Lambda \@euG\Xi \@euG\Pi
69 \@euG\Sigma \@euG\Upsilon \@euG\Phi \@euG\Psi \@euG\Omega
70 }}
71 \DeclareOption{eulergreek}{
72 \def\EulGreek{%
73 \ifnum\alpha<\@eugreekOffset % avoid multi-mapping when repeated
74 \EulGreekList
75 \EuUCGreek
76 \let\varrho\rho \let\varsigma\sigma % Euler's missing variants
77 \fi
78 }
79 \def\EulGreekList{\@eug\alpha \@eug\beta \@eug\gamma \@eug\delta
80 \@eug\epsilon \@eug\zeta \@eug\eta \@eug\theta \@eug\iota \@eug\kappa
81 \@eug\lambda
82 \@eug\mu \@eug\nu \@eug\xi \@eug\pi \@eug\rho \@eug\sigma \@eug\tau
83 \@eug\upsilon \@eug\phi \@eug\chi \@eug\psi \@eug\omega
84 \@eug\varepsilon \@eug\vartheta \@eug\varpi \@eug\varphi
85 }
86 \def\NonEulGreek{% Reverse previous mapping
87 \ifnum\alpha>\@eugreekOffset % avoid multi-mapping when repeated
88 \@eugreekOffset=-\@eugreekOffset \@euGREEKOffset=-\@euGREEKOffset
89 \EulGreekList
90 \EuUCGreek
91 \@eugreekOffset=-\@eugreekOffset \@euGREEKOffset=-\@euGREEKOffset
92 \fi
93 }}
94
95 \ProcessOptions
96
97 \DeclareMathAlphabet{\mathsfsl}{\sansmathencoding}{\sfdefault}{m}{sl}
98 \DeclareOldFontCommand{\sfsl}{\normalfont\sffamily\slshape}{\mathsfsl}
99 \DeclareMathAlphabet{\mathsfbf}{\sansmathencoding}{\sfdefault}{bx}{sl}
100 \DeclareOldFontCommand{\sfbf}{\normalfont\sffamily\bfseries}{\mathsfbf}
101
102 \DeclareMathVersion{sans}
103 \SetMathAlphabet{\mathrm} {sans}{\sansmathencoding}{\sfdefault}{m}{n}
104 \SetMathAlphabet{\mathsfsl}{sans}{\sansmathencoding}{\sfdefault}{m}{sl}
105 \SetSymbolFont {operators}{sans}{OT1}{\sfdefault}{m}{n}
106
107 % The cmm and cmsy are too light for cmss. I tried {b} for the next
108 % two lines, but it did not work well (unbold +, bold greek, bad \neq)
109 \SetSymbolFont {letters} {sans}{OML}{cmm} {m}{it}
110 \SetSymbolFont {symbols} {sans}{OMS}{cmsy}{m}{n}
111
112 \SetMathAlphabet{\mathsfbf}{sans}{\sansmathencoding}{\sfdefault}{bx}{n}
113
114 \DeclareMathSymbol{0}{\mathord}{operators}{`0}
115 \DeclareMathSymbol{1}{\mathord}{operators}{`1}
116 \DeclareMathSymbol{2}{\mathord}{operators}{`2}
117 \DeclareMathSymbol{3}{\mathord}{operators}{`3}
118 \DeclareMathSymbol{4}{\mathord}{operators}{`4}
119 \DeclareMathSymbol{5}{\mathord}{operators}{`5}
120 \DeclareMathSymbol{6}{\mathord}{operators}{`6}
121 \DeclareMathSymbol{7}{\mathord}{operators}{`7}
122 \DeclareMathSymbol{8}{\mathord}{operators}{`8}
123 \DeclareMathSymbol{9}{\mathord}{operators}{`9}
124 \DeclareMathSymbol{!}{\mathclose}{operators}{"21}
125 \DeclareMathSymbol{,}{\mathpunct}{operators}{`\,}
126 \DeclareMathSymbol{.}{\mathord}{operators}{`\.}
127 \DeclareMathSymbol{:}{\mathrel}{operators}{`\:}
128 \DeclareMathSymbol{;}{\mathpunct}{operators}{`\;}
129 \DeclareMathSymbol{?}{\mathclose}{operators}{`\?}
130 %\DeclareMathSymbol{+}{\mathbin}{operators}{"2B}
131 %\DeclareMathSymbol{=}{\mathrel}{operators}{`\=}
132
133
134 \ifx\EulGreek\relax\else
135 \DeclareSymbolFont{EulerGreek}{U}{eur}{m}{n}
136 \SetSymbolFont{EulerGreek}{sans}{U}{eur}{m}{n}
137 \DeclareSymbolFontAlphabet\matheug{EulerGreek}
138
139 \newcount\@eugreekOffset
140 \let\@tempa\relax
141 \DeclareMathSymbol{\@tempa}{\mathord}{EulerGreek}{11}
142 \@eugreekOffset\@tempa
143 \advance\@eugreekOffset-\alpha
144
145 \def\@eug#1{\@tempcnta#1\advance\@tempcnta\@eugreekOffset
146 %\message{Change \string#1 from \number#1 to \number\@tempcnta}%
147 \mathchardef#1\@tempcnta}
148
149 \ifx\EuUCGreek\relax\else
150
151 \newcount\@euGREEKOffset
152 \let\@tempa\relax
153 \DeclareMathSymbol{\@tempa}{\mathord}{EulerGreek}{1}
154 \@euGREEKOffset\@tempa
155 \advance\@euGREEKOffset-\Delta
156
157 \def\@euG#1{\@tempcnta#1\advance\@tempcnta\@euGREEKOffset
158 \mathchardef#1\@tempcnta}
159 \fi
160 \fi
161
162 \def\sfMathSwitch{\sfsl
163 \make@math@version@font \textfont \fam \tf@size
164 \make@math@version@font \scriptfont \fam \sf@size
165 \make@math@version@font \scriptscriptfont \fam \ssf@size
166 }
167
168 \def\make@math@version@font #1#2#3{%
169 \begingroup
170 \escapechar\m@ne
171 \xdef\sansm@name{\expandafter\string\the#1#2+}%
172 \endgroup
173 \@ifundefined{\sansm@name}{%
174 \@load@variant@font \sansm@name{#1#2}{#3\p@}}{}%
175 #1#2\csname \sansm@name\endcsname
176 }
177
178 \begingroup
179 \catcode`\A=12 \catcode`\T=12
180 \lowercase{% necessary because \fontname\font produces "at" in catcode 12.
181 \endgroup
182 %
183 \def\@load@variant@font #1#2#3{\expandafter\@do@load@varfont
184 \csname #1\expandafter\endcsname \fontname#2 AT #3 AT \relax }
185 %
186 \def\@do@load@varfont #1#2 AT #3 AT #4\relax{%
187 \dimen@#3\advance\dimen@ 1sp
188 \global\font #1=#2 at \dimen@
189 \fontdimen\tw@#1=\z@}
190 }
191
192 \def\sansmath{%
193 \ifx\mnorm@mathbf\mathbf\else \let\mnorm@mathbf\mathbf \fi
194 \mathversion{sans}%
195 \let\mathbf\mathsfbf
196 \let\sansm@every@math\sfMathSwitch
197 \EulGreek
198 }
199
200 \def\unsansmath{%
201 \mathversion{normal}%
202 \let\mathbf\mnorm@mathbf
203 \let\sansm@every@math\relax
204 \NonEulGreek
205 }
206
207 \expandafter\def\expandafter\check@mathfonts\expandafter{\check@mathfonts
208 \sansm@every@math}
209
210 \let\sansm@every@math\relax
211 \let\mnorm@mathbf\mathbf
212
213 % Repair of a LaTeX bug that has not been fixed in 6 years.
214 % Latex bug: latex/3357
215
216 \def \@fontswitch #1#2{%
217 \ifmmode
218 \let \math@bgroup \relax
219 \def \math@egroup ##1{%
220 \let \math@bgroup \@@math@bgroup
221 \let \math@egroup \@@math@egroup
222 ##1}%
223 #2\relax
224 \else
225 #1%
226 \fi
227 }
228