summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/altfont/altfont.dtx
blob: 093f3cf9cd92ba24fef517b8573ca00ec84b2861 (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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
\def\fileversion{1.1} % ^^A -*-latex-*-
\def\filedate{1996/07/02}
%\iffalse meta-comment
%\altfont: A \LaTeXe\ package for using alternative fonts
%
%Copyright \copyright\ 1996 Sebastian Marius Kirsch\texttt{%
% $\langle$sebastian\_kirsch@kl.maus.de$\rangle$}
%
%This program is free software; you can redistribute it and/or modify
%it under the terms of the GNU General Public License as published by
%the Free Software Foundation; either version 2 of the License, or
%(at your option) any later version.
%
%This program is distributed in the hope that it will be useful,
%but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%GNU General Public License for more details.
%
%You should have received a copy of the GNU General Public License
%along with this program; if not, write to the Free Software
%Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%\fi
%
%\changes{0.9}{1996/06/29}{Based on \texttt{psfont} v1.0d. Not restricted to
%PostScript fonts.} 
%\changes{0.9a}{1996/06/30}{Updating documentation. Throwing out most \PS\ 
%specific parts.}
%\changes{1.0}{1996/06/30}{1st public release}
%\changes{1.0a}{1996/07/01}{\texttt{\textbackslash AvailableFont} can have
%empty arguments}
%\changes{1.0a}{1996/07/01}{Adding new documentation.}
%\changes{1.1}{1996/07/02}{2nd public release }
%
% \CheckSum{236}
%% \CharacterTable
%%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}
%%
%
%\title{\altfont: Using alternative fonts\thanks{This file has version number
%\fileversion, last revised \filedate.}} 
%
%\author{Sebastian Marius Kirsch\\
%  \texttt{sebastian\_kirsch@kl.maus.de}}
%
%\date{\filedate}
%
%\maketitle
%
%\begin{abstract}
%With this package, you can use many alternative fonts with one single
%package. \psNFSS\ and \mfNFSS\ use one file for every font, while I prefer
%having everything in one package. Besides, of you load two of the font
%changing packages, the latter one overwrites the changes of the first
%one. Having all in one package avoids this.
%\end{abstract}
%
%\section{Introduction}
%
%This package is intended as a replacement for some parts of both \psNFSS\ and
%\mfNFSS. It is a replacement for the parts that actually change the default
%fonts. It was originally written as a replacement for \textsf{psfonts} of
%\psNFSS, but I realized that it was not very reasonable to restrict it to
%PostScript fonts. So it is now not focused on any particular PostScript font,
%but can be used for any font, \MF\ or PostScript. I'll discuss this in detail
%in section \ref{sec:psmfnfss}.
%
%\section{Installation}
%
%The actual package is produced by running \TeX\ on |altfont.ins|. This
%produces |altfont.sty|, the style file, and |altfont.cfg|, the configuration
%file. Both files must be moved where \TeX\ can find them.
%
%\subsection{The configuration file}
%
%\DescribeMacro{\AvailableRMFont}
%\DescribeMacro{\AvailableRMFont}
%\DescribeMacro{\AvailableRMFont}
%\DescribeMacro{\AvailableFont}
%All available fonts must declared in the configuration file. This is done
%using the macros |\AvailableRMFont|, |\AvailableSFFont|, |\AvailableTTFont|,
%and |\AvailableFont|. They have the following syntax:
%
%\begin{quote}
% \cmd{\AvailableRMFont}\oarg{additional code}\marg{long name}\marg{\NFSS\ 
% family name}\\
% \cmd{\AvailableSFFont}\oarg{additional code}\marg{long name}\marg{\NFSS\ 
% family name}\\
% \cmd{\AvailableTTFont}\oarg{additional code}\marg{long name}\marg{\NFSS\ 
% family name}\\
% \cmd{\AvailableFont}\oarg{additional code}\marg{symbolic name}%
% \marg{roman font}\texttt{\%}\\\marg{sans serif font}\marg{typewriter font}
%\end{quote}
%
%The first argument contains a symbolic name for the font, while the second
%argument contains the internal name for the family. The symbolic name is to
%be used as an option to the package. (It is easier to remember Times as
%\texttt{times} than as \texttt{ptm}.)
%
%The optional argument contains code that is executed after the font is
%loaded. It can be used to e.~g.\ change the font encoding or to redefine some
%other defaults such as |\bfdefault|.
%
%The macro |\AvailableFont| does the same, but for three font families at
%once. This can be used for font families that have the varinats sans serif
%and typewriter, e.~g.\ the Computer Modern fonts, as well as for managing a
%combination of three fonts under one short name. The arguments can also be
%empty.
%
%Typical commands looks like this:
%
%\begin{verbatim}
%\AvailableRMFont{times}{ptm}
%\AvailableSFFont{helv}{phv}
%\AvailableTTFont{Courier}{pcr}
%\AvailableFont[\altfontenc{T1}]{dco}{cmor}{cmoss}{cmott}
%\end{verbatim}
%
%\DescribeMacro{\DefaultRMFont}
%\DescribeMacro{\DefaultSFFont}
%\DescribeMacro{\DefaultTTFont}
%You can also tell \altfont\ about default \PS\ fonts. If the user calls the
%option |onlyps|, the default fonts are substituted for the fonts he has not
%defined. This is useful when you do not want to supply every font to be used
%in the document, but want your document to contain only \PS\ fonts. The
%syntax of these commands looks like this:
%
%\begin{quote}
%  \cmd{\DefaultRMFont}\marg{\NFSS\ family name}\\
%  \cmd{\DefaultSFFont}\marg{\NFSS\ family name}\\
%  \cmd{\DefaultTTFont}\marg{\NFSS\ family name}
%\end{quote}
%
%\DescribeMacro{\altfontenc}
%If you want to change the font encoding in the \meta{additional code} section
%of any of the |\Available|\ldots|Font| macros, you have to use |\altfontenc|
%instead of a plain |\RequirePackage[|\ldots|]{fontenc}|. The reason for this
%is discussed later. This is the syntax of |\altfontenc|:
%
%\begin{quote}
%  \cmd{\altfontenc}\marg{encoding}
%\end{quote}
%
%Generally, you can neither use commands that have
%optional arguments nor load classes or packages in the \meta{additional code}
%section.
%
%\section{Syntax}
%
%You load the package with |\usepackage[|\ldots|]{altfont}|, as usual, with
%the fonts you want to use in square brackets. Typical commands look like
%this: 
%
%\begin{verbatim}
%\usepackage[palatino,gill,courier]{altfont}
%\usepackage[newcent,onlyps]{altfont}
%\usepackage[dco]{altfont}
%\usepackage[pandora,courier]{altfont}
%\end{verbatim}
%
%\section{\psNFSS\ vs. \mfNFSS}
%\label{sec:psmfnfss}
%
%There are two other popular packages for using alternative fonts with \LaTeX:
%\psNFSS\ by Sebastian Rahtz, which is responsible for \PS\ fonts, and
%\mfNFSS\ by Frank Mittelbach and Rainer Sch\"opf, which focuses on
%\MF\ fonts.
%
%In my opinion, it was not very reasonable to divide the font changing between
%two packages. The fonts look to \LaTeX\ all the same, so why make a
%difference in the packages?
%
%For fonts which are to be used as |\{rm,sf,tt}default| fonts, both packages
%have little style files which change these defaults. But if you load two of
%those packages, the latter overwrites the changes of the first one. These
%packages all do the same, so why not include them into one style file?
%
%Well, I did this, and the result is easier to use and safer than the
%packages from \psNFSS\ and \mfNFSS. Because of these improvements, I would
%like my package to get included into these packages. (I know, I'm
%unselfish. ;-)
%
%Since \psNFSS\ and \mfNFSS\ focuse on particular fonts, while my package can
%be used with any font, it is not very likely to be included in either
%package, though both could make use of it.
%
%\section{Legal rubbish}
%\altfont: A \LaTeXe\ package for using alternative fonts
%
%Copyright \copyright\ 1996 Sebastian Marius Kirsch\texttt{%
% $\langle$sebastian\_kirsch@kl.maus.de$\rangle$}
%
%This program is free software; you can redistribute it and/or modify
%it under the terms of the GNU General Public License as published by
%the Free Software Foundation; either version 2 of the License, or
%(at your option) any later version.
%
%This program is distributed in the hope that it will be useful,
%but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%GNU General Public License for more details.
%
%You should have received a copy of the GNU General Public License
%along with this program; if not, write to the Free Software
%Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
%
%\StopEventually
%
%\section{The \texttt{docstrip} modules}
%
%This file contains three modules to direct \texttt{docstrip} in generating the
%external files:
%
%\begin{tabular}[t]{ll}
%driver & A short driver for producing the documentation\\
%package & The package itself\\
%config & The local configuration file\\
%\end{tabular}
%
%\section{Producing the documentation}
%
%This short driver can be extracted by \texttt{docstrip} to produce the
%documentation.
%
%    \begin{macrocode}
%<*driver>
\documentclass{ltxdoc}

\usepackage{mflogo}
\providecommand{\MF}{\textsf{METAFONT}} % for those without mflogo.sty

\newcommand*{\NFSS}{\mbox{\textsf{NFSS}}}
\newcommand*{\psNFSS}{\mbox{\textsf{psNFSS}}}
\newcommand*{\mfNFSS}{\mbox{\textsf{mfNFSS}}}
\newcommand*{\altfont}{\textsf{alt\-font}}
\newcommand*{\PS}{Post\-Script}

\begin{document}

\DocInput{altfont.dtx}

\end{document}
%</driver>
%    \end{macrocode}
%
%\section{The Code}
%
%\subsection{Introduction}
%
%First we have to introduce ourselves.
%
%    \begin{macrocode}
%<*package>
\NeedsTeXFormat{LaTeX2e} 
\ProvidesPackage{altfont}%
  [\filedate\space v\fileversion\space loading alternative fonts]
%    \end{macrocode}
%
%\subsection{Switches}
%
%Next, we define some switches. They are used to determine whether some fonts
%have already been loaded, so we can warn the user when he tries to load two
%colliding fonts.
%
%    \begin{macrocode}
\newif\ifrm@set\rm@setfalse
\newif\ifsf@set\sf@setfalse
\newif\iftt@set\tt@setfalse
%    \end{macrocode}
%
%\subsection{Default \PS\ fonts}
%
%\begin{macro}{\DefaultRMFont}
%\begin{macro}{\DefaultSFFont}
%\begin{macro}{\DefaultTTFont}
%These are some commands for changing the default \PS\ fonts.
%
%    \begin{macrocode}
\newcommand{\DefaultRMFont}[1]{\renewcommand{\def@rmfont}{#1}}
\newcommand{\DefaultSFFont}[1]{\renewcommand{\def@sffont}{#1}}
\newcommand{\DefaultTTFont}[1]{\renewcommand{\def@ttfont}{#1}}
\newcommand{\def@rmfont}{}
\newcommand{\def@sffont}{}
\newcommand{\def@ttfont}{}
%    \end{macrocode}
%\end{macro}\end{macro}\end{macro}
%
%\subsection{Declaring the options}
%
%\begin{macro}{\AvailableRMFont}
%\begin{macro}{\AvailableSFFont}
%\begin{macro}{\AvailableTTFont}
%These commands are needed later in the configuration
%file. There is one command for each font family, ie.\ roman, sans serif or
%typewriter.  
%
%They declare their first argument as an option. 
%
%If the option is called, and the font family has already been defined, a
%\cmd{\PackageError} is reported. If not, the second argument is defined as
%the approriate family default.
%
%When the family default has successfully been set, the corresponding switch
%is turned, so it is not redefined anywhere else in this file. 
%
%The optional argument contains some code that is to be executed when the
%defaults have been set. This is a very useful hook, e.~g.\ when a certain
%font family is only available in OT1 or Cork encoding, we can execute a
%|\altfontenc{OT1}| after the font is loaded. This command is a little hack to
%get around some limitations of |\newcommand| and |\DeclareOption| and is
%described in section \ref{sec:altfontenc}. A plain |\usepackage| will not
%work!
%
%    \begin{macrocode}
\newcommand{\AvailableRMFont}[3][]{%
  \DeclareOption{#2}{%
    \ifrm@set\PackageError{altfont}{%
      \protect\rmfamily\space already defined as \rmdefault
      }{%
      You tried to load two roman families at the same time,\MessageBreak
      e.g. times and palatino}
    \else\renewcommand{\rmdefault}{#3}\rm@settrue
    #1
    \fi}
  }
\newcommand{\AvailableSFFont}[3][]{%
  \DeclareOption{#2}{%
    \ifsf@set\PackageError{altfont}{%
      \protect\sffamily\space already defined as \sfdefault
      }{%
      You tried to load two sans serif families at the same time,\MessageBreak
      e.g. gill and helvetica}
    \else\renewcommand{\sfdefault}{#3}\sf@settrue
    #1
    \fi}
  }
\newcommand{\AvailableTTFont}[3][]{%
  \DeclareOption{#2}{%
    \iftt@set\PackageError{altfont}{%
      \protect\ttfamily\space already defined as \ttdefault
      }{%
      You tried to load two typewriter families at the same time,\MessageBreak
      e.g. courier and typewriter}
    \else\renewcommand{\ttdefault}{#3}\tt@settrue
    #1
    \fi}
  }
%    \end{macrocode}
%\end{macro}\end{macro}\end{macro}
%
%\subsection{One command fits all}
%
%\begin{macro}{\AvailableFont}
%With the macro |\AvailableFont|, all three defaults are set with one
%option. This is useful for managing combinations of three fonts under one
%name, as well as for fonts that have the variants sans serif and
%typewriter. (The Computer Modern fonts are one of those, and Lucida, I
%think.)
%
%|\AvailableFont| may also have empty arguments.
%
%    \begin{macrocode}
\newcommand*{\AvailableFont}[5][]{%
  \DeclareOption{#2}{%
    \def\@temprm{#3}\def\@tempsf{#4}\def\@temptt{#5}
    \ifx\empty\@temprm\else
      \ifrm@set\PackageError{altfont}{%
        \protect\rmfamily\space already defined as \rmdefault
        }{%
        You tried to load two roman families at the same time,
        \MessageBreak e.g. times and palatino}
      \else\renewcommand{\rmdefault}{#3}\rm@settrue
      \fi
    \fi
    \ifx\empty\@tempsf\else
      \ifsf@set\PackageError{altfont}{%
        \protect\sffamily\space already defined as \sfdefault
        }{%
        You tried to load two sans serif families at the same time,
        \MessageBreak e.g. gill and helvetica}
      \else\renewcommand{\sfdefault}{#4}\sf@settrue
      \fi
    \fi
    \ifx\empty\@temptt\else
      \iftt@set\PackageError{altfont}{%
        \protect\ttfamily\space already defined as \ttdefault
        }{%
        You tried to load two typewriter families at the same time,
        \MessageBreak e.g. courier and typewriter}
      \else\renewcommand{\ttdefault}{#5}\tt@settrue
      \fi
    \fi
    #1
  }
}
%    \end{macrocode}
%\end{macro}
%
%\subsection{Loading font encodings in \texttt{\textbackslash Available\ldots
%Font}}
%\label{sec:altfontenc}
%
%\begin{macro}{\altfontenc}
%Working on this package, I discovered two limitations of |\newcommand| and
%|\DeclareOption|.
%
%\begin{itemize}
%\item You cannot use a command with an optional argument in the argument of
%  another command.
%\item You cannot load a package with |\RequirePackage| or |\usepackage| in the
%  \meta{code} section of a |\DeclareOption| command.
%\end{itemize}
%
%I wanted to be able to load different font encodings in the optional argument
%of the |\Available|\ldots|Font| command, so I had to work around these
%limitations. The result is this command:
%
%    \begin{macrocode}
\newcommand*{\altfontenc}[1]{\PassOptionsToPackage{#1}{fontenc}%
  \AtEndOfPackage{\RequirePackage{fontenc}}}
%    \end{macrocode}
%\end{macro}
%
%By passing the option to \texttt{fontenc} with |\PassOptionsToPackage|, I
%avoid having an optional argument to |\RequirePackage|. By delaying the
%|\RequirePackage|, I avoid loading a package in an option. Ugly but useful.
%
%\subsection{Loading the configuration file}
%
%Next, the configuration file is loaded. If it is not found, an error is
%issued, because the package is quite useless without it.
%
%    \begin{macrocode}
\InputIfFileExists{altfont.cfg}{}{%
  \PackageError{altfont}{%
    No local configuration file found
    }{%
    The altfont package was loaded without a local\MessageBreak
    configuration file, so it doesn't know which fonts\MessageBreak
    are available.}
  }
%</package>
%    \end{macrocode}
%
%\subsection{The configuration file}
%
%The configuration file looks like this:
%
%\subsubsection{Introduction}
%
%As usual\ldots
%
%    \begin{macrocode}
%<*config>
\NeedsTeXFormat{LaTeX2e}
\ProvidesFile{altfont.cfg}%
  [\filedate\space v\fileversion\space Local configuration for altfont.sty]
%    \end{macrocode}
%
%\subsubsection{Declaring default PostScript fonts}
%
%Here, the default PostScript fonts are defined. They are needed later, if the
%author does not define all fonts he wants to use, but wants his document to
%contain only \PS\ fonts. Strictly spoken, this does not belong to a package
%for \PS\ and \MF\ fonts, but I think it is nonetheless very useful.
%
%    \begin{macrocode}
\DefaultRMFont{ptm}
\DefaultSFFont{phv}
\DefaultTTFont{pcr}
%    \end{macrocode}
%
%\subsubsection{Available fonts}
%
%Now the available fonts are defined. They are divided into three
%categories---roman fonts, sans serif fonts and typewriter fonts, as it is
%done in \LaTeXe\ itself. 
%
%They are defined using the |\Available|\ldots|Font| macros. These macros
%define a symbolic name to be used as an option to the package, and take the
%name of the \NFSS\ font family as a second argument.
%
%    \begin{macrocode}
\AvailableRMFont{times}{ptm}
\AvailableRMFont{palatino}{ppl}
\AvailableRMFont{newcent}{pnc}

\AvailableSFFont{helv}{phv}
\AvailableSFFont{gill}{pgs}

\AvailableTTFont{courier}{pcr}

\AvailableFont[\altfontenc{T1}]{dco}{cmor}{cmoss}{cmott}
\AvailableFont[\altfontenc{OT1}%
  \DeclareFontSubstitution{OT1}{pnr}{m}{n}%
  \renewcommand{\bfdefault}{b}%
  \renewcommand{\itdefault}{sl}]{pandora}{pnr}{pnss}{pntt}
%</config>
%    \end{macrocode}
%
%In case you wonder, the dco fonts are another package I wrote. They consist
%of the regular dc fonts with oldstyle digits. I didn't release it yet,
%contact me if you are interested.
%
%And that's the configuration. Of course one could do much more with this
%configuration file, declaring new options and all. It's probably the biggest
%hook a package could have. :-)
%
%\subsection{\texttt{onlyps}: Using only \PS\ fonts}
%
%\begin{macro}{onlyps}
%This option redefines all other family defaults that have not yet been
%\cmd{\renewcommand}ed to \PS\ fonts. It uses the default fonts as defined in
%the configuration file. If no default fonts have been defined, an error is
%reported.
%
%    \begin{macrocode}
%<*package>
\DeclareOption{onlyps}{
  \ifrm@set\else
    \ifx\empty\def@rmfont
       \PackageWarning{altfont}{No default roman font defined!}
    \else\renewcommand{\rmdefault}{\def@rmfont}\fi
  \fi
  \ifsf@set\else
    \ifx\empty\def@sffont
       \PackageWarning{altfont}{No default sans serif font defined!}
    \else\renewcommand{\sfdefault}{\def@sffont}\fi
  \fi
  \iftt@set\else
    \ifx\empty\def@ttfont
       \PackageWarning{altfont}{No default typewriter font defined!}
    \else\renewcommand{\ttdefault}{\def@ttfont}\fi
  \fi
  }
%    \end{macrocode}
%\end{macro}
%
%\subsection{The end}
%
%At last, the options are processed.
%
%    \begin{macrocode}
\ProcessOptions
%</package>
%    \end{macrocode}
%
%\Finale
\endinput