summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/ofs/ofs.sty
blob: 6bac96bbc5f70b9b41082662dbc3b4ee739f20fc (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

%%% OFS: Olsak's Font System based on NFSS + LaTeX macros
%%% Jul 2001                                   Petr Olsak
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% see ofsdoc.tex for more details

\NeedsTeXFormat{LaTeX2e} % I don't like LaTeX, the plain macro is more clean.
                         % See the variant of my macros ofs.tex for plain.
                         % But, some users ask for LaTeX style files :-((

%\ProvidesPackage{ofs}[2001/07/01 OFS based on NFSS]
%\ProvidesPackage{ofs}[2002/10/24 OFS based on NFSS]
% \addcmd added
\ProvidesPackage{ofs}[2003/02/25 OFS based on NFSS]
% \setfonts {\bgroup \catcode`\-=12 ... by Z. Wagner added

\def\OFSversion{Oct. 2002}
\typeout{OFS (Olsak's Font System) based on NFSS initialized.
     <\OFSversion>}

%%%% \fontusage %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\bgroup \catcode`\#=12 
  \catcode`\{=12 \catcode`}=12 \catcode`\X=1 \catcode`\Z=2
  \catcode`\^^M=14 \catcode`\ =12 \catcode`\|=0\catcode`\\=12%
|gdef|fontusageX
|begingroup
|typeoutX%---------------------------------------------------------------
\fontusage: ============ Olsak's Font System, usage: ===============^^J
\usepackage [sjannon, sdynamo] {ofs} ... for example^^J 
\showfonts  ... shows all loaded font families (by previous \usepackage)^^J
\setfonts [Family/] ... local switch to the new family, after this, the^^J
  \rm, \bf, \it, bi will switch to the variants. The current size is used.^^J
\setfonts [/size] ... local switch to the new size of fonts, the family is^^J 
  not changed. The "size" has the following possible formats:^^J
    at<dimen>       ... the same as \font\something=file at<dimen>^^J
    <dimen>         ... the same as at<dimen>^^J
    <number>        ... the same as at<number>pt^^J
    scaled<number>  ... the same as \font\something=file scaled<number>^^J
    mag<decimal-number> fonts will be magnified by given coefficient^^J
                        depend on current size of the fonts.^^J
\setfonts [Family/size] ... switch to the new family at given size^^J
\setfonts [Family-vr/]  ... switch to the specified font, the current size^^J
  is used. The "vr" is two-letter acronym for variants: rm, bf, it, bi.^^J
\setfonts [Family-vr/size] ... switch to the specified font.^^J
\fontdef\name [Family/size] ... same as \gdef\name{\setfonts[Family/size]}^^J
  The "Family" or "size" parameter may be empty.^^J
\OFSfamily [Family]        ... expands to internal NFSS family name.^^J
\OFSfamilydefault [Family] ... same as \edef\familydefault{\OFSfamily[Family]}
Z%-----------------------------------------------------------------------
|endgroup 
Z
|egroup


%%%% \rm, \bf, \it, bi %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\bi{\fontseries{b}\fontshape{it}\selectfont}
\def\bf{\fontseries{b}\fontshape{n}\selectfont}
\def\it{\fontseries{m}\fontshape{it}\selectfont}
\def\rm{\fontseries{m}\fontshape{n}\selectfont}
\def\bfdefault{b}

%%%% Macros used in declaration files %%%%%%%%%%%%%%%%%%

\def\ofs@listfamilies{}
\def\ofs@messageheader{OFS (l.\the\inputlineno): }
\def\ofs@unknownfam{undefined}

\def\OFSdeclarefamily [#1] #2{%
   \OFSputfamlist {^^J \space\space[#1/]}%
   \expandafter \gdef\csname ofs-fam:#1\endcsname {#2}%
   \expandafter \gdef\csname ofs-fam:#2\endcsname {#2}%
   \bgroup
      \count2=18
      \def\tmpa ##1{\if:##1\let\tmpa=\relax 
                    \else\advance\count2 by-1 \fi\tmpa}\tmpa #1:%
      \def\tmpa {\ifnum\count2>0 \advance\count2 by-1 \OFSputfamlist{ }%
                 \else\let\tmpa=\relax \fi\tmpa}\tmpa     
   \egroup
}
\def\OFSfamily [#1]{%
   \expandafter \ifx\csname ofs-fam:#1\endcsname \relax
      \ofs@unknownfam
   \else \csname ofs-fam:#1\endcsname 
   \fi
}
\def\OFSfamilydefault [#1]{%
   \edef\tmpa{\OFSfamily[#1]}%
   \ifx\tmpa\ofs@unknownfam 
      \typeout{\ofs@messageheader WARNING. The family is not set.^^J 
         The family name [#1] is not known in the list:
         \ofs@listfamilies}%
   \else
      \edef\familydefault{\tmpa}%
   \fi
}      
\def\OFSputfamlist #1{%
   \xdef\ofs@listfamilies {\ofs@listfamilies #1}%
}
\def\OFSextraencoding #1{%
   \expandafter \ifx \csname ofs-enc:#1\endcsname \relax
      \edef\ofs@extraencoding{#1}%
      \lowercase{\input{#1ini.def}}\relax
      \expandafter \def \csname ofs-enc:#1\endcsname {}%
   \fi
}
\def\OFSnormalvariants{\OFSputfamlist{%
  \string\rm, \string\bf, \string\it, \string\bi}}

%%%% Defaults %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\OFSputfamlist {^^Jdefaults:}
\OFSdeclarefamily  [CMRoman]       {cmr}  \OFSnormalvariants
\OFSputfamlist {, \string\sl}

\OFSdeclarefamily  [CMSans]        {cmss}
\OFSputfamlist {\string\rm, \string\bf, \string\it, \space-} 

\OFSdeclarefamily  [CMTypewriter]  {cmtt}
\OFSputfamlist {\string\rm, \space- , \string\it, \space- , \string\sl}

\OFSdeclarefamily  [Times]         {ptm}  \OFSnormalvariants

\OFSdeclarefamily  [Helvetica]     {phv}  \OFSnormalvariants
\OFSputfamlist{, \string\nrm, \string\nbf, \string\nit, \string\nbi}

\OFSdeclarefamily  [Courier]       {pcr}  \OFSnormalvariants

\def\sl{\fontseries{m}\fontshape{sl}\selectfont}
\def\nrm{\fontseries{mc}\fontshape{n}\selectfont}
\def\nbf{\fontseries{bc}\fontshape{n}\selectfont}
\def\nit{\fontseries{mc}\fontshape{it}\selectfont}
\def\nbi{\fontseries{bc}\fontshape{it}\selectfont}


%%%% \showfonts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\showfonts{\typeout{\ofs@messageheader
    The list of known font families:\ofs@listfamilies}}

%%%% \setfonts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\setfonts {\bgroup \catcode`\-=12 \ofs@setfonts}
\def\ofs@setfonts [#1/#2]{\egroup \OFSsetfonts{#1}{#2}}
\DeclareRobustCommand \OFSsetfonts [2]{%
   \edef\tmpa{#1}\expandafter \ofs@readfamvariant\tmpa--:%
   \ifx\famvariant\empty
      \ofs@setfontfamily [#1/#2]%
   \else
      \ofs@setsinglefont [#1/#2]%
   \fi
   \ignorespaces
}
\def\ofs@readfamvariant #1-#2-#3:{\def\tmpb{#1}\def\famvariant{#2}}   

\def\ofs@setfontfamily [#1/#2]{%
   \if |#1|\else
      \edef\tmpa{\OFSfamily[#1]}%
      \ifx\tmpa\ofs@unknownfam 
         \typeout{\ofs@messageheader WARNING. The family is not set.^^J 
            The family name [#1/] is not known in the list:
            \ofs@listfamilies}%
      \else
         \fontfamily{\tmpa}%
      \fi
   \fi
   \if |#2|\else
      \edef\tmpa{#2}\expandafter\ofs@readfontsize \tmpa:%
      \fontsize{\tmpa}{\f@baselineskip}%
   \fi
   \ofs@selectfont
}
\let\ofs@selectfont=\selectfont

\def\ofs@setsinglefont [#1-#2/#3]{%
   \let\ofs@selectfont=\relax
   \ofs@setfontfamily [#1/#3]\let\ofs@selectfont=\selectfont
   \csname #2\endcsname
}
\def\ofs@readfontsize #1#2:{\if a#1\ofs@readfontsizeat #1#2:%
   \else \if s#1\ofs@readfontsizescaled #1#2:%
   \else \if m#1\ofs@readfontsizemag #1#2..:%
   \fi\fi\fi
}
\def\ofs@readfontsizeat at#1:{\def\tmpa{#1}}
\def\ofs@readfontsizescaled scaled#1:{\dimen0=0.01pt \dimen0=#1\dimen0
   \edef\tmpa{\the\dimen0}}
\def\ofs@readfontsizemag mag#1.#2.#3:{\dimen0=\f@size pt 
   \if|#2|\if|#3|%
      \errmessage{OFS: "mag" need the decimal parameter with decimal point}%
   \fi\fi
   \dimen0 =#1.#2 \dimen0
   \advance\dimen0 by7sp % rounding to three digits after decimal point
   \ifdim\dimen0<10pt \edef\tmpa{+\the\dimen0}\else \edef\tmpa{\the\dimen0}\fi
   \dimen0 =\expandafter \ofs@readsixdigits \tmpa :::::|pt
   \edef\tmpa{\the\dimen0}%
}
\def\ofs@readsixdigits #1#2#3#4#5#6#7#8#9|{%
   \if:#5#1#2\else\if:#6#1#2#3\else\if:#7#1#2#3#4\else
   \if:#8#1#2#3#4#5\else#1#2#3#4#5#6\fi\fi\fi\fi
}

%%%% \fontdef %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\fontdef #1[#2/#3]{\def\tmpc{!}%
   \edef\tmpa{#3}\ifx \tmpa\tmpc \edef\tmpa{\f@size}\fi
   \edef\tmpb{#2}\expandafter \ofs@readfamvariant\tmpb--:%
   \ifx \tmpb\tmpc
      \ifx\famvariant\empty
         \xdef #1{\noexpand\setfonts [\f@family/\tmpa]}%
      \else
         \xdef #1{\noexpand\setfonts [\f@family-\famvariant/\tmpa]}%
      \fi
   \else
      \xdef #1{\noexpand\setfonts [#2/\tmpa]}%
   \fi
}

%%%% \ifknownfam %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newif \ifofs@familypresent

\def\ifknownfam [#1]{%
   \expandafter \ifx\csname ofs-fam:#1\endcsname \relax
       \expandafter \ofs@familypresentfalse
   \else
       \expandafter \ofs@familypresenttrue
   \fi
   \ifofs@familypresent
}

%%%% \addcmd %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\addcmd #1#2{\expandafter\def\expandafter\tmpa\expandafter{#1}%
   \def\tmpb{#1}%
   \ifx\tmpa\tmpb % the #1 is not a macro
      \expandafter\let\csname \string#1-original\endcsname =#1%
      \expandafter\def\expandafter #1\expandafter{%
           \csname\string#1-original\endcsname #2}%
   \else          % the #1 is a macro
      \expandafter\def\expandafter #1\expandafter{#1#2}%
   \fi
}

%%%% Extra encoding %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\setextrafont{\ifx\ofs@extraencoding\undefined
   \typeout{\ofs@messageheader WARNING. Extra encoding is no declared by
        \string\OFSextraencoding.}%
   \else \fontencoding{\ofs@extraencoding}\selectfont \fi
}
\def\extchar{\afterassignment\ofs@doextchar \chardef\tmpa=}
\def\ofs@doextchar{{\setextrafont\tmpa}}


%%%% Accents %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\DeclareRobustCommand \accentabove [3]{%
   \def\tmpa{#3}%
   \ifx \tmpa\empty #1\else
      \leavevmode\vbox{%
         \setbox0=\hbox{#3}\setbox2=\hbox{#1}%
         \dimen0=\ht0 \advance\dimen0 by\dp2 \advance\dimen0 by#2\relax 
         \offinterlineskip
         \halign {##\cr
            \hidewidth\slantcorrection{\dimen0}\box2 \hidewidth\cr
            \noalign{\kern#2}\box0 \cr}}%
   \fi
}
\DeclareRobustCommand \accentbelow [3]{%
   \def\tmpa{#3}%
   \ifx \tmpa\empty #1\else
      \leavevmode\vtop{%
         \setbox0=\hbox{#3}\setbox2=\hbox{#1}%
         \dimen0=-\dp0 \advance\dimen0 by-\ht2 \advance\dimen0 by-#2\relax
         \offinterlineskip
         \halign {##\cr \box0 \cr\noalign{\kern#2}%
            \hidewidth \slantcorrection{\dimen0}%
            \dimen0=\dp2 \ifdim\dimen0<.2ex \dimen0=.2ex \fi
            \vbox to\dimen0{\hbox{\box2}\vss}\hidewidth\cr}}%
   \fi
}
\def\slantcorrection #1{\dimen0=#1\relax
    \dimen0 =\strip@pt \fontdimen1\the\font \dimen0
    \kern 2\dimen0
}


%%%% Options = OFS-style files %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\let\OFSprocessoptions=\relax
\DeclareOption *{\input{\CurrentOption.sty}}
\ProcessOptions\relax
\let\OFSprocessoptions=\undefined