summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/plain/pdcmac/maamac.dtx
blob: a4398caa417b68db30ff59cfc58d9a350df09aa8 (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
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
% maamac.dtx -- documentation & source for maamac.tex -*-tex-*-
        
%%%@TeX-document-file {
%%% title 	= "MAAMAC -- Malvern A Macros",
%%% filename 	= "$texmf/doc/plain/pdcmac/maamac.dtx",
%%% version 	= "$Revision: 1.5 $",
%%% package 	= "pdcmac 1.0",
%%% date 	= "$Date: 1995/04/06 13:33:44 $",
%%% author	= "P. Damian Cugley",
%%% email	= "damian.cugley@comlab.ox.ac.uk",
%%% address	= "Oxford University Computing Laboratory,"
%%%                Parks Road, Oxford  OX1 3QD, UK",
%%% abstract	= "This document describes and is the source code for 
%%%                the TeX definitions file maamac.tex.
%%%                Running plain TeX on this file produces both the
%%%                definitions file and the printed documentation.",
%%% copyright	= "Copyright (c) 1991-1995 P. Damian Cugley",
%%% copying	= "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.",
%%% notice	= "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.",
%%% notice	= "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.",
%%% codetable	= "USASCII",
%%% dependencies = "pdccode.tex"
%%%}

%{{{ maamac
%{{{  preamble

\relax
\input pdccode

\document
\rcs$Id: maamac.dtx,v 1.5 1995/04/06 13:33:44 pdc Exp $\endrcs

\newcount\chcda \newcount\chcdc \newcount\chcdn
\def\changecodes#1#2#3#4{%
    \chcda#2\relax \chcdc#3\relax \chcdn#4\relax
    \loop \ifnum\chcdn>0
	#1\chcda\chcdc
	\advance\chcda1 \advance\chcdc1 \advance\chcdn-1
    \repeat
}
\changecodes\mathcode{`a}{"7461}{26}

\codefile{maamac.tex}
%}}}  preamble
%{{{  introduction
	
\author{P. Damian Cugley}
\title{MAAMAC---Malvern A Macros}
\advance\seccount-1
\section{Introduction}
	
	This document describes |maamac.tex|, a collection of formatting
	macros for plain \TeX\ documents using fonts with the Malvern~A
	encoding.  For example, it defines commands for making composite
	letters and special symbols.

\subsec{About this document}

	The definitions file and this printed documentation are both in
	|maamac.dtx|, a `documented \TeX\ macros' file\footnote*{The
	\LaTeX~2e distribution uses files with the `|dtx|' suffix for
	similar purposes.}  which, when processed by plain \TeX,
	generates a fresh copy of |maamac.tex| in the current directory
	in addition to the |dvi| file.  This ensures that the printed
	documentation and the code it describes are identical.  The
	|dtx| file uses the macros in |pdccode.tex|.

\subsec{What is in MAAMAC?}

	The definitions in |maamac.tex| fall into three sections:
\smallskip
\item{\S1} Building {\it composite letters} like `\'e' from {\it
	marks} like `\'{}' and {\it base letters} like `e'.  This gives
	new definitions for commands like |\'| and |\"|.
\item{\S2} Symbols and  special letters: replacements for existing
	commands like |\P| (\P) and |\ae| (\ae), and new commands like
	|\registered| and |\pounds|.
\item{\S3} Switching between alphabets.  The Malvern~A encoding includes
	separate small capital and medium capital alphabets in addition
	to the usual capitals and lower case.  This section defines
	commands for transliterating a list of tokens from one alphabet
	to another.

\smallskip\noindent
	The first two sections make changes to commands described in
	{\it\TeX book} Chapter~9 (and a few maths symbols from
	Chapter~16) and defined in Appendix~B.
	
%}}}  introduction
%{{{  File identification
\subsec{File identification}
	
	Nowadays, macro files start with some comments identifying the
	file.

\code
	\|\% maamac.tex \fileversion~\filedate~-- Malvern A Macros
	|
	|%%%@TeX-definition-file {
	|%%% filename       = "$texmf/tex/plain/pdcmac/maamac.tex",
	\|\%\%\% version~~~~~~~~= "\fileversion",
	\|\%\%\% date~~~~~~~~~~~= "\filedate",
	|%%% package        = "pdcmac 1.0",
	|%%% author         = "P. Damian Cugley",
	|%%% email          = "damian.cugley@comlab.ox.ac.uk",
	|%%% address        = "Oxford University Computing Laboratory,
	|%%%                   Parks Road, Oxford  OX1 3QD, UK",
	|%%% codetable      = "USASCII",
	|%%% keywords       = "TeX, plain TeX, macros",
	|%%% supported      = "Maybe",
	|%%% abstract       = "Macros for using the Malvern-A font coding
	|%%%                   scheme in plain TeX documents.
	|%%%                   This file was generated by running
	\|\%\%\%~~~~~~~~~~~~~~~~~~~plain TeX on \jobname.dtx",
	|%%% copyright      = "Copyright (c) 1991-1995 P. Damian Cugley",
	|%%% copying        = "DO NOT DISTRIBUTE THIS FILE.
	\|\%\%\%~~~~~~~~~~~~~~~~~~~Distribute \jobname.dtx only as part of the
	|%%%                   package it came in.",
	|%%% dependencies   = "",
	|%%% }
	|
	\|\\message\{\fileversion~<pdc \filedate>\}
	|
\endcode

%}}}
%{{{  building composite letters
\section{Building composite letters}

	THis section redefines commands listed at the start of Chapter~9
	of the {\it\TeX book}: |\'|, |\"|, etc.  The main difference is
	that these now use `medium capitals' and differently-drawn marks
	to make composite capital letters.

	I~also define \<chardef tokens> called |\acuteglyph|,
	|\twodotsglyph| which may be used to print these marks in a
	document: `the acute mark ``\'{}''\dots' might be typeset with
	`|the acute mark ``\acuteglyph''|\dots'.  Also, if you don't
	like the way my macros look, you can say `|\accent\acuteglyph
	E|' rather than having to look up its glyph number.

%{{{   utility macros

\subsec{Utility macros}

	First some nicknames for scratch registers.
\code
	|\dimendef\dimena0  \dimendef\dimenb2
	|\toksdef\toksa0
	|\countdef\counta255
	|\ifx\countb\UNDEFINED \csname newcount\endcsname\countb \fi
	|\ifx\countc\UNDEFINED \csname newcount\endcsname\countc \fi
\endcode

	A macro to find the code in \TeX's internal encoding for a
	character.  The character might be represented by (1)~a
	character with category code~11 or~12, (2)~a token defined with
	|\chardef|, or (3)~the token |\char| followed by a \<number>.
\code
	|\def\code#1{%
	|    \ifcat#1a%
	|        `#1
	|    \else\ifcat#1+%
	|        `#1
	|    \else\ifx\char#1
\endcode
\hbox{\hskip6\fontdimen6\tentt 
	\% If the first token is |\char| the rest is the
	\<number> we want.}
\code
	|    \else
	|        #1%
	|    \fi\fi\fi
	|}
\endcode

	So as to make conditional macros that can be skipped over if
	they appear nested inside another conditional, we make include
	the token |\then| amongst the arguments, making this the `if-'
	token to match the |\else| and |\fi| following it.  This way we
	write, for example 
$$\hbox{|\ifcap|\<character> |\then| \<true text>
	|\else| \<false text> |\fi|}$$
\code
	|\let\then=\iffalse
\smallbreak
	|\def\ifcap#1\then{\expandafter\ifcapnum\code{#1}\then}
	|\def\ifcapnum#1\then{\ifnum\lccode#1=#1}
\smallbreak
	|\def\iflower#1\then{\expandafter\iflowernum\code{#1}\then}
	|\def\iflowernum#1\then{\ifnum\uccode#1=#1}
\endcode

	A macro to extract the slant-per-point parameter of a font in
	toe form of a \TeX\ \<factor>.
\code
	|\def\fontslant#1{\expandafter\stripPT\the\fontdimen1#1}
\smallbreak
	|\begingroup \uccode`2=`p \uccode`3=`t \uppercase{\toksa{\endgroup
	|    \def\\#123{#1}
	|}} \the\toksa
	|\let\stripPT=\\
\endcode
%}}}   utility macros
%{{{   macros for placing marks
	
\subsec{Macros for placing marks}

	This simple macro places the text |#3| at displaced
	$(\hbox{|#1|},\hbox{|#2|})$ from current position:
\code
	|\def\putxy#1#2#3{\leavevmode\rlap{\hskip#1\raise#2\hbox{#3}}}
\endcode

	Now we have a generic mark-placement macro.  It is similar to
	the |\accent| primitive, but takes two extra parameters:
$$ 
 	\hbox{|\putmarkxy|\arg{$xf$}\arg{$dy$}\arg{$mark$}\arg{$base$}}
$$ 
 	The horizontal position $xf$ of the optical centre of the base
	letter (ignoring slant) is expressed as a \<factor> (i.e.,
	decimal fraction of the width of the base glyph).  The vertical
	displacement $dy$ is expressed as a fragment of \TeX\ code that
	will calculate $dy$.  The code is expanded after setting box~0
	to contain the base glyph, and must put the result in |\dimena|.
	For example, we could define
$$
 	\hbox{|\def\fakeaccent{\putmarkxy{0.5}{\dimena\ht0
	\advance\dimena-1ex }}|}
$$
 	This produces an approximation to the primitive |\accent|
	command.

	Given the $x$-factor $xf$, a base glyph with width $wd$, a font
	with slant $s$, the horizontal displacement $dx$ is given by
$$
 	dx = xf \times wd + s \times dy\quad.
$$
 	In this macro it is stored in |\dimenb|.
\code
	|\def\putmarkxy#1#2#3#4{{%
	|    \setbox0=\hbox{#4}#2\relax
	|    \dimenb#1\wd0 \advance\dimenb\fontslant\font\dimena
	|    \leavevmode
	|    \putxy{\dimenb}{\dimena}{\hbox to 0pt{\hss\char#3\hss}}%
	|    \box0
	|}}
\smallbreak
	|\def\putmarky{\putmarkxy{0.5}}
\endcode
%}}}   macros for placing marks
%{{{   type I marks
	
\subsec{Type~I Marks}
	
	A Type~I mark is one which does not have any scope for being
	`squashed' to go over capital letters---for example, the
	two-dots mark `\"{}' and macron `\={}'.  
	
	Here's a macro for placing a Type~I mark given by |#1| (a
	\<number>) over base glyph |#2| (which is anything that |\code|
	understands).  The difference between this macro and simply
	using |\accent| is (1)~if presented with a capital letter it
	will use the corresponding medium capital letter and (2)~the the
	mark is raised by an amount intended to centre it vertically
	between the top of the base letter and the top of the
	body-height---assuming it was original centered between
	body-height and $x$-height.

	If $H$ is the body height, $h$ the height of the base glyph, 
$$ \mathcode`/="202F 
    \eqalign{dy &= { H + h \over   2 } - { H + 1\,{\rm
		ex} \over 2}\cr
	&= \textstyle { 1\over2}h - {1\over2}\,{\rm ex}\cr}
$$
\code
	|\def\typeImark#1#2{{%
	|    \setbox2=\hbox{#2}%
	|    \ifdim \ht2=1ex
	|        \accent#1\relax#2%
	|    \else
	|        \counta\code{#2}%
	|        \ifnum\counta>64 \ifnum\counta<96
	|            \advance\counta 128
	|        \fi \fi
	|        \putmarky{\dimena0.5\ht0 \advance\dimena-0.5ex }
	|                {#1}{\char\counta}%
	|    \fi
	|}}
\endcode

	Finally we define the composite-letter-building commands.
\code
	|\chardef\dotglyph22     \def\.{\typeImark\dotglyph}
	|\chardef\twodotsglyph23 \def\"{\typeImark\twodotsglyph}
	|\chardef\macronglyph150 \def\={\typeImark\macronglyph}
	|\chardef\longmacronglyph151 
	|        \def\longmacronmark{\typeImark\longmacronglyph}
\endcode
%}}}   type I marks
%{{{   type II marks
	
\subsec{Type~II Marks}

	These marks have an alternative glyph for use of capital and
	medium capital letters.  As with |\typeImark|, |#1| is a
	\<number> and |#2| is anything understood by |\code|.
\code
	|\def\typeIImark#1#2{{%
	|    \counta#1\relax \countb\code{#2}%
	|    \ifcap{#2}\then
	|        \ifnum \counta<128 \advance\counta 128 \fi
	|        \ifnum \countb<128 \advance\countb 128 \fi
	|    \fi
	|    \accent\counta \char\countb
	|}}
\smallbreak
	|\chardef\acuteglyph8      \def\'{\typeIImark\acuteglyph}
	|\chardef\graveglyph9      \def\`{\typeIImark\graveglyph}
	|\chardef\circumglyph10    \def\^{\typeIImark\circumglyph}
	|\chardef\tildeglyph11     \def\~{\typeIImark\tildeglyph}
	|\chardef\ringglyph12      \def\ringmark{\typeIImark\ringglyph}
	|\chardef\caronglyph13     \def\v{\typeIImark\caronglyph}
	|\chardef\breveglyph14     \def\u{\typeIImark\breveglyph}
	|\chardef\hungarglyph15 \def\H{\typeIImark\hungarglyph}
\endcode
	I have abbreviated `circumflex' as `circum' (consistent with
	Adobe's `|asciicircum|').  I~have called the hook `\v{}'
	`|caron|' because that is its name as used by ISO and Adobe.
	I~have called the long Hungarian umlaut `\H{}' `|hungar|' for
	want of a better name (it's shorter than |hungarumlaut|)..
%}}}   type II marks
%{{{   cedilla ogonek
	
\subsec{Cedilla and ogonek}

	The cedilla and ogonek each have a variant intended for capital
	letters (in this case the variant is larger not smaller).
\code
	|\def\cedillalike#1#2#3{{%
	|    \setbox0=\hbox{#3}%
	|    \ifdim\ht0>1ex
	|        \ooalign{\hidewidth\char#2\relax\hidewidth\crcr\unhbox0 }%
	|    \else
	|        \accent#1 #3%
	|    \fi
	|}}
\smallbreak
	|\chardef\cedillaglyph6 \chardef\Cedillaglyph134
	|\def\c{\cedillalike\cedillaglyph\Cedillaglyph}
\smallbreak
	|\chardef\ogonekglyph7 \chardef\Ogonekglyph135
	|\def\k{\cedillalike\ogonekglyph\Ogonekglyph}
\endcode
%}}}   cedilla ogonek
%}}}
%{{{  symbols
\section{Symbols and  special letters}
%{{{   special letters

\subsec{Special letters}

	The letters defined here that are not included in Chapter~9 of
	the {\it\TeX book} are the Icelandic thorn (|\TH|, |\th|) and
	eth\footnote*{Also called `edh'.} (|\DH|, |\dh|), the Polish
	{\it a} and {\it e} with ogonek (|\A|, |\a|, |\E|, |\e|), and
	the Sami eng\footnote\dag{Also called `ing' or `ng'.}  (|\NG|,
	|\ng|).

	We also give replacements for {\it d}, {\it t} and {\it l} with
	hook (which are usually drawn with a apostrophe-like mark), and
	the Esperanto letter {\it hho} (\^h).
\code
	|\chardef\TH"00  \chardef\th"10	 \chardef\DH"04  \chardef\dh"14
	|\chardef\A "01  \chardef\a "11	 \chardef\E "05  \chardef\e "15
	|\chardef\NG"02  \chardef\ng"12  \chardef\L "03  \chardef\l "13
	|\chardef\AE"5E  \chardef\ae"7E  \chardef\OE"5F  \chardef\oe"7F
	|\chardef\O "5C  \chardef\o "7C	
\smallbreak
	|\chardef\vd"9C  \chardef\vt"9D  \chardef\h "9E  \chardef\vl"9F
	|\chardef\ss"18  \chardef\i "19  \chardef\j "1A  
\smallbreak
	|\def\aa{\ringmark a} \def\AA{\ringmark A}
\endcode

\code
\smallbreak
	|\chardef\orda"98 \chardef\ordo"99 \def\No{N\ordo} \def\no{n\ordo}
	|\chardef\csuperior"98 \def\Mc{M\csuperior} 
\endcode
	The command |\Mc| is used for forming names like
	M\flushtop{\the\scriptfont\fam \b c}Donald.
%}}}   special letters
%{{{   text syms
	
\subsec{Other symbols used in text}

	There are several new symbols here.  Note that |\trademark| is
	what you will get if you use the ASCII double quote character
	`|"|' in your manuscript.
\code
        |\chardef\trademark "22 
	|\chardef\copyright "FB  \chardef\registered"FD
        |\chardef\careof    "9A  \chardef\Box       "A0
        |\chardef\cents     "A2  \chardef\pounds    "A3
        |\chardef\currency  "A4  \chardef\permille  "A5
        |\chardef\yen       "A8  \chardef\florin    "A9
	|\chardef\dag       "AA  \chardef\ddag      "AB
	|\chardef\gbdecimal "AE  \chardef\minus     "AF
	|\chardef\S         "BA  \chardef\P         "BB
	|\chardef\degrees   "C0
	|\chardef\lguillemet"BC  \chardef\rguillemet"BE
\endcode
	The |\careof| sign ($\rm ^c\!/\!_o$) is an abbreviation for
	`care of' in English-language addresses (actually, Australians
	traditionally write `$\rm ^c\!/\!_-$').  The raised dot
	|\gbdecimal| is the British decimal point (I~usually do
	|\mathcode`.=\gbdecimal| and let maths mode do all the work).
	The |\degrees| sign replaces \TeX's |$^\circ$|.

	The guillemets can also be obtained with the ligatures |<<| and
	|>>|.


%}}}   text syms
%{{{   maths syms
	
\subsec{Symbols used in maths}

	I have stuck with the plain \TeX\ conventions as much as
	possible---even though |\bullet| is more often used in text than
	maths.
\code
	|\mathcode`\,"602C  \mathcode`\-"20AF
	|\mathcode`\."002E  \mathcode`\/"002F
\smallbreak
	|\mathchardef\bullet   "2020  \mathchardef\times    "20A6
	|\mathchardef\backslash"005B  \mathchardef\setminus "205B
	|\mathchardef\cdot     "20AE  \mathchardef\cdotp    "60AE
\smallbreak
	|\def\langle{\delimiter"40DB30A }  \delcode`\<"0DB30A
	|\def\rangle{\delimiter"50DD30B }  \delcode`\>"0DD30B
	|\def\lbrace{\delimiter"407B308 }  \let\{\lbrace  \mathcode`\{"407B
	|\def\rbrace{\delimiter"507D309 }  \let\}\rbrace  \mathcode`\}"407D
\endcode
	
%}}}   maths syms
%}}}  symbols
%{{{  switching alphabets
\section{Switching between alphabets}

	This is one of the strange ideas that went into the design of
	the Malvern font---I wanted to have small capitals and medium
	capitals treated as separate alphabets rather than as a
	different style, just as I treat old-style and ranging numerals
	as separate symbols.  These extra alphabets are present in all
	Malvern~A encodings\footnote*{Fonts with the Malvern~A encoding
	but made from normal PostScript fonts will have medium capitals
	replaced with full capitals, and old-style numerals replaced
	with ranging numerals.}

	These extra alphabets are obtained by transliterating a sequence
	of letters using the |\uppercase| and |\lowercase|
	commands.\footnote\dag{Alas! this task would be so much easier
	and more efficient if it were possible to declare new
	alphabet-switching tables styled after the |\uccode| and
	|\lccode| tables which make |\uppercase| and |\lowercase| work.
	Then all this nonsense could happen in \TeX's mouth, which has
	some advantages.  I~can imagine commands |\newchartable| (used
	to create a token which can be used in the same way as
	|\uccode|) and |\usechartable| (used to defined macros that work
	like |\uppercase|).  E\TeX\ hackers take note!}  For example, to
	transliterate capitals into small capitals (the |\sc| command),
	we first make assignments so that, for example, |\lccode`a| is
	set to the code for small-capital $\scriptstyle A$, then apply
	|\lowercase| to the token list.

\subsec{Setting upper and lower case codes for special letters}

	These entries in the |\uucode| and |\lccode| tables are used by
	the composite-letter-building commands rather then the
	alphabet-switchign commands, but they are included here to be
	near the other code-hackery.

\code
	|\uccode\th\TH  \lccode\TH\th  \uccode\TH\TH  \lccode\th\th
	|\uccode\a \A   \lccode\A \a   \uccode\A \A   \lccode\a \a 
	|\uccode\ng\NG  \lccode\NG\ng  \uccode\NG\NG  \lccode\ng\ng
	|\uccode\l \L   \lccode\L \l   \uccode\L \L   \lccode\l \l 
	|\uccode\dh\DH  \lccode\DH\dh  \uccode\DH\DH  \lccode\dh\dh
	|\uccode\e \E   \lccode\E \e   \uccode\E \E   \lccode\e \e 
	|\uccode\o \O   \lccode\O \o   \uccode\O \O   \lccode\o \o
	|\uccode\ae\AE  \lccode\AE\ae  \uccode\AE\AE  \lccode\ae\ae
	|\uccode\oe\OE  \lccode\OE\oe  \uccode\OE\OE  \lccode\oe\oe
\smallbreak
	|\uccode\i`I    \uccode\j`J	\lccode\i\i	\lccode\j\j
	|\uccode\csuperior`C
\endcode


\subsec{A macro for changing character codes}

	The |\changecodes| command is used to change those segments of
	character tables that are contiguous and map onto a contiguous
	segment in the range.  It is invoked as
$$
 	\hbox{\it |\changecodes| command x y n}
$$ 
 	(where $\it command$ is a token like |\uccode| or |\mathcode|
	and $x$, $y$, and $n$ are \<number>s), and does the equivalent
	of
$$
 	{\it command}\;i\mathrel{\hbox{\tt=}}
	j\qquad \hbox{for all $\cases{x \le i < x + n\cr
					         y \le j < y + n\cr}$}
$$

\code
	|\def\changecodes#1#2#3#4{%
	|    \counta#2\relax \countb#3\relax \countc#4\relax
	|    \loop
	|    \ifnum\countc>0
	|        #1\counta\countb
	|        \advance\counta 1
	|        \advance\countb 1
	|        \advance\countc-1
	|    \repeat
	|}
\endcode

	We can use this immediately to arrange that lowercasing medium caps
	makes lower case, and uppercasing small caps makes full caps:
\code
	|\changecodes\uccode{"E1}{`A}{26}
	|\changecodes\uccode{"C1}{"C1}{26}
	|\changecodes\lccode{"E1}{"E1}{26}
	|\changecodes\lccode{"C1}{`a}{26}
\endcode

	We also make old-style numerals behave as lower case for ranging
	numerals, and also arrange that maths mode uses ranging figures.
\code
	|\changecodes\lccode{"B0}{`0}{10}
	|\changecodes\uccode{`0}{"B0}{10}
\endcode

	In maths mode (1)~we use text italic for letters, since CM MAth
	Italic will not match the body text and (2)~we use ranging
	figures.
\code
	|\changecodes\mathcode{`a}{"7461}{26}
	|\changecodes\mathcode{`A}{"7441}{26}
	|\changecodes\mathcode{`0}{"70B0}{10}
\endcode

\subsec{Changing the alphabet for special letters got with commands}

	When applying |\uppercase| or |\lowercase| to a token list,
	macros will be unaffected (|\ae| will still generate `ae').  To
	get around this we define macros that redefine these control
	sequences.  They each take as parameters hex digits used to make
	character codes.
\code
	|\def\capspecials#1#2{%
	|    \chardef\TH"#10 \chardef\A "#11 \chardef\NG"#12
	|    \chardef\L "#13 \chardef\DH"#14 \chardef\E "#15
	|    \chardef\O "#2C \chardef\AE"#2E \chardef\OE"#2F 
	|}
\smallbreak
	|\def\lcspecials#1#2#3{%
	|    \chardef\th"#10 \chardef\a "#11 \chardef\ng"#12
	|    \chardef\l "#13 \chardef\dh"#14 \chardef\e "#15
	|    \chardef\o "#2C \chardef\ae"#2E \chardef\oe"#2F
	|    \def\ss{\char"#23 \char"#23 }\chardef\i"#39 \chardef\j"#3A 
	|}
\endcode
\subsec{Pulling it all together}
	Now we can define the user macros that do the work. These take
	one argument, a piece of text to transliterate: |\sc{OX1~3QD}|
	produces a small-capital `${\rm\scriptstyle OX}{\mit 1\
	3}{\rm\scriptstyle QD}$';
	|\csc{ABCdef}| produces caps and small caps
	`ABC{\the\scriptfont0 DEF}'.
\code
	|\def\sc#1{{%
	|    \changecodes\lccode{`A}{"E1}{26}\capspecials9F\lowercase{#1}%
	|}}
\smallbreak
	|\def\mc#1{{%
	|    \changecodes\lccode{`A}{"C1}{26}\capspecials8D\lowercase{#1}%
	|}}
\smallbreak
	|\def\csc#1{{%
	|    \changecodes\uccode{`a}{"E1}{26}\lcspecials9FE\uppercase{#1}%
	|}}
\smallbreak
	|\def\allcaps#1{{%
	|    \lcspecials054\uppercase{#1}%
	|}}
\smallbreak
	|\def\alllc#1{{%
	|    \capspecials17\lowercase{#1}%
	|}}
\endcode
%}}}  switching alphabets
\endcodefile
\enddocument
\bye
%}}} maamac


% Local variables:
% fold-folded-p: t
% fill-prefix: "\t"
% End: