Debian Codegraph @

texmf-dist/doc/latex/relenc/relenc.tex

raw
1 \documentclass[a4paper]{article}
2
3 \usepackage{doc}
4 % Stuff more or less from ltxdoc.cls:
5 \DeclareFontShape{OT1}{cmtt}{bx}{n}{<-> ssub * cmtt/m/n}{}
6 \DeclareFontShape{OT1}{cmss}{m}{it}{<->ssub*cmss/m/sl}{}
7 \DeclareFontFamily{OMS}{cmtt}{\skewchar\font'60}
8 \DeclareFontShape{OMS}{cmtt}{m}{n}{<-> ssub * cmsy/m/n}{}
9 \DeclareFontShape{OMS}{cmtt}{bx}{n}{<-> ssub * cmsy/b/n}{}
10
11 \setlength{\textwidth}{355pt}
12 \addtolength\marginparwidth{30pt}
13 \addtolength\oddsidemargin{20pt}
14 \addtolength\evensidemargin{20pt}
15
16 \makeatletter
17 \def\cmd#1{\cs{\expandafter\cmd@to@cs\string#1}}
18 \def\cmd@to@cs#1#2{\char\number`#2\relax}
19 \DeclareRobustCommand\cs[1]{\texttt{\char`\\#1}}
20 \makeatother
21
22 \setcounter{StandardModuleDepth}{1}
23
24
25 \usepackage{2sidedoc}
26
27 \newcommand\B{\penalty300\relax}
28 \DeclareTextFontCommand{\textcmtt}{\usefont{OT1}{cmtt}{m}{n}}
29 \newcommand\package[1]{\textsf{#1}}
30 \CodelineNumbered
31
32
33 \makeatletter
34 \newenvironment{cmdusage}{%
35 \setbox\z@=\vbox\bgroup
36 \color@begingroup
37 \hsize=0.75\textwidth
38 \parindent=-1em%
39 \everypar={\hangindent=1em\hangafter=0}%
40 \rightskip=\z@ \@plus 1fil\relax
41 \let\par\@@par
42 }{%
43 \color@endgroup
44 \egroup
45 \@@par
46 \medskip
47 \noindent
48 \fbox{\usebox\z@}\@@par
49 \medskip
50 }
51 \makeatother
52
53 \newcommand*{\marg}[1]{%
54 \begingroup\MacroFont\char`\{\endgroup
55 \meta{#1}%
56 \begingroup\MacroFont\char`\}\endgroup
57 }
58 \newcommand*{\oarg}[1]{%
59 \begingroup\MacroFont\char`\[\endgroup
60 \meta{#1}%
61 \begingroup\MacroFont\char`\]\endgroup
62 }
63
64 \MakeShortVerb{\|}
65
66
67 \title{The \package{relenc} package}
68 \author{Lars Hellstr\"om%
69 \thanks{E-mail: \texttt{[email protected]}}%
70 }
71
72 \begin{document}
73
74 \maketitle
75
76 \tableofcontents
77
78 \section{Motivation}
79 \label{Motivation}
80 %
81 This paper is about some shortcomings that, in my humble opinion,
82 exists in the way \LaTeX\ handles fonts. I also point out a way in
83 which these shortcomings can be overcome.
84
85 The primary problem is ligatures, but as there are a few different
86 ligature concepts that are of interest, let me begin with specifying
87 my terms. A \emph{ligature} is a sequence of characters
88 (almost always letters) that have been given an appearance somewhat
89 different from the one the characters would have if simply put side to
90 side, almost always because they would otherwise not look very
91 pleasing to the eye. Despite this difference in appearence, it is
92 still meant to be read as the entire character sequence, not as a
93 completely new character. The canonical example of this is the `fi'
94 ligature.
95
96 In \TeX\ fonts, there is a special mechanism to implement this, and
97 everything that is implemented using this mechanism will be
98 called \emph{font ligatures}. It is almost always the case however,
99 that some font ligartures are not ligatures as defined above, but
100 simply a handy way to type characters that are hard or impossible to
101 type using a standard keyboard; the canonical example of this is the
102 `\texttt{--}' (two hyphens) to `--' (endash) conversion that is
103 present in most \TeX\ fonts. Such nonproper ligatures will be called
104 \emph{syntactic ligatures}, and proper ligatures will sometimes be
105 called \emph{aestetic ligatures} to stress their origin.
106
107 A \emph{font-dependent command} in \LaTeX\ is a command whose
108 actions depend directly or indirectly on which font is the current. (I
109 would not consider a command |\foo| defined by
110 \begin{verbatim}
111 \def\foo{\char65 }
112 \end{verbatim}
113 as a font-dependent command since it always does the same thing.
114 The results need not always be identical, but that is because
115 the command is executed under different conditions.) An example of a
116 font-dependent command is |\"|, which is (roughly) |\accent 127| when
117 the current font is \texttt{OT1}-encoded and |\accent 4| when the
118 current font is \texttt{T1}-encoded. (The dependence is indirect since
119 the command directly depends on a macro which is set during the font
120 selection process, but there is a dependence.)
121
122 For the purposes of this paper, if would also suffice to define a
123 font-dependent command as a command that is defined by some of the
124 commands |\DeclareTextCommand|, |\ProvideTextCommand|,
125 |\DeclareTextSymbol|, |\Declare|\B|Text|\B|Command|\B|Default|,
126 |\Provide|\B|Text|\B|Command|\B|Default|, or |\Declare|\B|TextAccent|.
127 \LaTeX\ documentation uses the term `encoding-specific command' for
128 these, but for reasons that will soon be appearent, that term would be
129 somewhat inappropriate here.
130
131 Thus, with these definitions taken care of, it is now time to get to
132 the point.
133
134 The recommended latin font encoding these days is the
135 \texttt{T1}/`Cork'\slash`Extended \TeX\ text'
136 encoding, and this is rightfully so. It is clearly superior to the old
137 \texttt{OT1} encoding, as it adds more than a hundred accented
138 characters to those which can be used to form a word that \TeX\ can
139 automatically hyphenate, but there is at least one case in which the
140 \texttt{OT1} encoding is preferable. This case is when the font has many
141 ligatures.
142
143 In the \texttt{T1} encoding, there are seven slots available
144 for ligatures, and these have been assigned to the `ff', `fi', `fl',
145 `ffi', `ffl', `IJ', and `ij' ligatures. Since all slots have been
146 assigned to something, there is no place to put an additional ligature,
147 even if it is needed. Thus the conclusion is that if a font is to be
148 \texttt{T1} encoded, it cannot contain any ligatures in addition to the
149 aforemensioned; to put it the other way, if a font design requires the
150 presence of a ligature other than the aforemensioned, it cannot be
151 \texttt{T1} encoded.
152
153 In the \texttt{OT1} encoding, there are only five slots assigned to
154 ligatures, but there are 128 unassigned slots that can be used for
155 anything the font designer wants. Thus having more than five ligatures
156 in an \texttt{OT1} encoded font is no problem, but a recourse to using
157 \texttt{OT1} is not a very good option, as it leaves the hyphenation
158 problem unsolved. The solution, then, would seem to be the creation of
159 a new encoding, and part of it will, but this will not be quite
160 sufficient for reasons I will shortly describe.
161
162 For the moment though, let us, as an intellectual experiment, assume
163 that we shall solve this problem with \texttt{T1} having too few slots
164 for ligatures by creating a new encoding for a hypothetical font that
165 would need more than seven ligatures. Let us also assume that the new
166 encoding shall be a modified version of the \texttt{T1} encoding, where
167 some accented characters will have been left out to make room for the
168 ligatures. Finally, let us assume that we want to be as international
169 as possible and include as many of the accented characters as we can
170 squeeze in. These are three simple assumptions, and there are good
171 reasons for all of them.
172
173 How \emph{many} slots do we need to assign to ligatures, then? This
174 varies, of course, between different font families, but it might vary
175 \emph{even more} between fonts in the same family. The \texttt{it}
176 shapes might need a few more than the \texttt{n} shapes, while the
177 \texttt{sc} shapes might not need any at all (`\textsc{fi}' (|fi|) and
178 `\textsc{f{}i}' (|f{}i|) look exactly the same in most font families).
179 Instead, there are some accents which are harder to put on in the
180 \texttt{sc} shapes (in many font families the ring on \textsc{a} in
181 \textsc{\r{a}} should touch the main letter; this is not what the
182 default definition does), so it appears that the optimal thing to do
183 would be to have slightly different encodings for different fonts, even
184 if they belong to the same family. This is theoretically no problem;
185 \TeX's macro facilities are flexible enough to allow user level
186 commands that do different things in different fonts. It becomes,
187 however, a problem to do this in a reasonably universal way, so that
188 the macros produced work in general and not only for a single font
189 family.
190
191 Standard \LaTeX\ has a mechanism for doing precisely this. Using the
192 commands |\DeclareTextCommand|, |\DeclareTextSymbol|,
193 |\DeclareTextAccent|, or one of their relatives, one can give a
194 definition of a command that is used with one particular font encoding
195 and not with any other. The problem with using this mechanism here is
196 that one might have to have the normal and italic variants declared
197 as having different encoding attributes (as well as different
198 shapes), so one would have to either device a whole new set of font
199 changing commands or redefine \LaTeX's own high-level font changing
200 commands (such as |\textit|) to change encoding as well as shape or
201 series. Neither alternative is good, and one can expect several
202 incompability problems to arise for both of them.
203
204 A better solution starts with recognizing that there are actually two
205 different `encoding' concepts that can be found here. One is the
206 attribute by which fonts are selected in \LaTeX, the other is the
207 actual layout of a font. I will call this latter concept a
208 \emph{coding scheme} and reserve \emph{encoding} for the former.
209 (Formally, one may start by defining a \emph{slot} to be an integer in
210 the range 0--255 and a \emph{glyph} to be a pattern (usually
211 recognicable as a letter, digit, punctuation mark, or some other part
212 of written language, but it need not always be). A coding scheme can
213 then be defined as a mapping of slots to classes of glyphs. A font
214 complies to a particular coding scheme if, for every slot $n$ in the
215 domain of the coding scheme, the glyph occupying slot $n$ of the font
216 is a member of the class that the encoding scheme maps $n$ to. But I
217 digress.) As far as I know, there is no strict defintion of what an
218 encoding is, apart from the operational given in \cite{fntguide} as
219 something that is part of the specification of a font. (The canonical
220 source for such a definition would be \cite{encguide}, but that paper
221 is, according to its author, ``still in an embryo state''.) In font
222 discussions, an encoding is often taken to imply a specific coding
223 scheme, and many encoding definition files seem to be all about listing
224 the coding scheme, but is this implication suitable? I would claim that
225 in this case, it is not.
226
227 A more constructive definition would be to see an encoding as a
228 specification of which font-dependent commands are available to the
229 author. An encoding definition file, on the other hand, is a
230 specification of the interface between \LaTeX\ macros and the
231 information in a \TeX\ font. It does not matter to the author whether
232 \H{o} is |\char174| of the current font, generated as |\accent125o|
233 by \TeX, or whatever. The only thing that matters is that when the
234 author types |Erd\H{o}s|, it comes out as Erd\H{o}s.
235
236 Consequently, there is really no need for the font-dependent commands in
237 \LaTeX\ to do the same thing for any two fonts with the same encoding
238 attribute, it is merely the case that standard \LaTeX\ does not offer
239 an interface for defining font-dependent commands in any other way. The
240 natural remedy for this then, would be to write a package which offers
241 such an interface. This is what I have done; the package is called
242 \package{relenc} and this paper is its documentation. Its usage and
243 implementation are described in the following sections, and the
244 appendices describe some accompanying files.
245
246 I shall however conclude this section by an attempt to elaborate the
247 above view on what an encoding is, or perhaps rather, what it should be.
248
249 The encoding property of a font is a set of rules that determines how
250 the author's manuscript is interpreted---the input character
251 \texttt{q} for example has not the same interpretation in a
252 \texttt{T1} encoded font (where it is the letter `q') as in an
253 \texttt{OT2} encoded font (where it is a cyrillic letter whose closest
254 latin equivalent is the Czech `\v{c}'). An encoding specification should
255 therefore be a formalization of an agreement between the font designer
256 on one hand and the author on the other---it specifies which rules each
257 side must comply with and which results that can then be expected. An
258 example of the author's rules may be to refrain from writing \TeX\ code
259 like |\char 166|, because the font designer may have an option on what
260 to put in that slot. If the author breaks the rules, he or she may find
261 that the manuscript produced contains text whose meaning is not the same
262 if typeset with two different fonts even if they do have the same
263 encoding property. In practice, the author's rules for the standard text
264 encodings are pretty much the same as the rules on how write \TeX\ code
265 we find in every elementary book on the subject, so they are hardly new
266 to us.
267
268 An example of the font designer's rules may be to put an exclamation
269 mark in slot 33, so that \texttt{!} actually print as one, or to
270 include a font ligature that converts two consequtive hyphens to an
271 endash, so that |--| actually will print as an endash, which the
272 author by tradition expects it to do. If the font designer breaks the
273 rules then authors who follow their rules might find that they do not
274 get the right results anyway and such a font designer is likely to get
275 complaints from authors about this. In practice however, the font
276 designer rules are often vaugely specified if specified at all and
277 hence there are gray areas for most encodings where there are no rights
278 and wrongs. The \texttt{OT1} encoding is probably the one most plauged
279 by these; the dollar versus sterling problem (an excellent example of
280 how changing the glyph of a single slot many completely alter the
281 interpretation of a text) is a classic. One of my intentions with
282 writing this text is to work for that these gray areas are shrunken
283 or even completely eliminated, although I do not think there is
284 anything that can be done for the \texttt{OT1} encoding---its
285 irregularities are much too well known and exploited.
286
287 Now if an encoding is (a formalization of) an agreement, how do the
288 parties agree to it? On the font designer's side this happens when
289 the font designer gives a font a specific encoding by writing a font
290 definition file that defines that font with that encoding. On the
291 author's side this happens when the author selects a font with that
292 encoding property.
293
294 So far the informal description, now it is time to get to the
295 formalization. Which exactly are the rules for the author and for the
296 font designer? This varies between different encodings, but only in
297 the details. The areas the encoding specification must cover can be
298 listed and are:
299 \begin{itemize}
300 \item
301 Which input characters that can be used directly to produce
302 some of the font's glyphs in the output and what they will
303 generate. This pertains to the author, who shouldn't use other
304 input characters. The allowed ones do however have well-defined
305 results.
306 \item
307 Which coding scheme the font must comply with. The pertains to
308 the font designer. There are no direct restrictions on the use of
309 slots not listed in this coding scheme.\footnote{There may be
310 indirect restrictions, see below.}
311 \item
312 Which the required syntactic ligatures are. This pertains to both
313 author and font designer. The author cannot trust any in addition
314 to these, the font designer must include them.\footnote{It could
315 well be that there \emph{should not} be any syntactic ligatures
316 in addition to these. I know of no situation where there would be
317 an advantage in adding syntactic ligatures.}
318 \item
319 Which the font-dependent commands are and what they will generate.
320 This pertains to the author in the same manner as does the input
321 character rules.
322 \item
323 Which the required font dimensions are and what they stand for.
324 This pertains to both the author and the font designer in the same
325 manner as does the syntactic ligature rules.\footnote{Even though
326 very few physical authors access any font dimensions, the same
327 does not hold for packages, and these also count as authors in
328 this context.}
329 \end{itemize}
330 After these have been specified, the grey areas should be very small
331 indeed! There are however a few additional twists that must be sorted
332 out.
333
334 If the required coding scheme listed in the encoding specification does
335 not cover all the 256 slots, then one must be aware that in particular
336 the required syntactic ligatures, but also the font-dependent commands,
337 may impose some restrictions on the font's coding scheme in
338 addition to those expressed by the given coding scheme that the font
339 must comply with. These restrictions are then of the form that a
340 glyph from a specific class must be assigned to some slot, but the
341 font designer may freely choose exactly which slot. Thus any single
342 slot not specified by the required coding scheme may be used for just
343 about anything.
344
345 The use of the \package{relenc} package requires that the following
346 area has to be added the ones listed above.
347 \begin{itemize}
348 \item
349 The font designer must see to that for every combination of a
350 variable command and a font, there is a variant that will give the
351 specified result.\footnote{The terms \emph{variable command} and
352 \emph{variant} are explained in Subsubsection~\ref{Tekn.bakgr.}.}
353 \end{itemize}
354 % With encodings that depend on the \package{relenc} package (I call
355 % such encodings \emph{relaxed}),
356 Hyphentation patterns do also offer theoretical problems to the use of
357 the \package{relenc} package, as these refer explicitly to the coding
358 scheme of the font. Problems with these can however not result in
359 anything worse than bad hyphenation, so the interpretation of a text
360 should not be affected. It is furthermore the case that in practice
361 the problems can often be avoided (see Subsection~\ref{Hyph}).
362
363 Finally, there are two font parameters---|\hyphenchar| and
364 |\skewchar|---that do explicitly relate to the coding scheme of the
365 font and which are not stored in the font itself. It is possible that
366 the value of at least one of these should be specified in an
367 encoding specification, but that particular question is not of
368 immediate interest to the \package{relenc} package, as \LaTeX\ itself
369 already provides the font designer with the ability to set these for
370 each font individually (using the sixth argument of
371 |\Declare|\B|Font|\B|Shape|).
372
373
374
375 \section{Usage}
376
377 \subsection{Author usage}
378
379 All the author has to do to use fonts with a relaxed encoding, as
380 opposed to fonts with for example the \texttt{T1} encoding, is to
381 include the command
382 \begin{verbatim}
383 \usepackage{relenc}
384 \end{verbatim}
385 in the preamble and load the encoding definition file, for example
386 using the \package{fontenc} package. It is however important that the
387 \package{relenc} package is loaded \emph{before} the encoding
388 definition file, as the latter uses commands defined in the former.
389
390
391 \subsection{Font designer usage}
392
393 For a font designer, it is important to know at least in broad
394 outline how the mechanisms made available through the \package{relenc}
395 package work, which is why this subsection starts with a description of
396 that. There is however a convention followed in the remainder of this
397 paper that the reader should be aware of and this convention has to do
398 with how control sequences are written.
399
400 In this paper, there are many control sequences with ``strange''
401 names, meaning names that mixes letters and non-letters in pretty
402 arbitrary ways, so that these names cannot be read as one normally
403 reads \TeX\ code. Therefore thin spaces are inserted around names of
404 control sequences, regardless of whether a space character at that
405 place would automatically be skipped by \TeX\ while it is reading the
406 code or not. A space character that is really meant to ``be there'' will
407 be written as a visible space (\textvisiblespace). All control sequences
408 will, as usual, be written with an opening backslash, but this
409 backslash is not part of the name of the control sequence.
410
411 Excepted from the above convention about spaces is the actual \TeX\ %
412 source code for that appear in Section~\ref{Implementation} and onwards
413 (the lines of this is numbered, so it should be easily distinguishable)
414 and some pieces of ``alternative'' source code in the same sections.
415 These exceptions should be easy to recognise for the readers who are
416 interested in that particular material.
417
418
419 \subsubsection{Some technical background}
420 \label{Tekn.bakgr.}
421
422 The main feature added by the \package{relenc} package is that of
423 the \emph{variable commands}; it is through making commands variable
424 that their definition may depend on which font is the current. This is
425 not how \TeX\ would see it, since the definition of a variable
426 command (as a \TeX\ control sequence) actually does not change after
427 the command has been made variable! Rather, a variable command is a
428 macro which expands to different things depending on which the current
429 font is.
430
431 With overwhelming probability, this is something you have encountered
432 before, although you might not have realised it. Under \LaTeXe, all
433 accenting commands and all commands for letters other than a--z (such
434 as \ae, \o, and \ss) are like this. The only difference lies is what
435 will affect the eventual outcome of the command. The \LaTeXe\ kernel
436 only supports dependence on which the current encoding is. The variable
437 command concept makes dependence on the current family, series, and
438 shape possible as well.
439
440 Both systems are quite similar in that they rely on |\csname| lookups.
441 What happens to, for example, the command |\foo| is the following:
442 First it gets |\string|ed. This converts the single control sequence token
443 to the sequence of character tokens which would form the name of the
444 command; in this case to |\|, |f|, |o|, and |o|. Then a piece of text
445 is put in front of that character sequence, and finally the result of
446 that is taken to be the name of a new control sequence. This process
447 mainly generates control sequnces with very peculiar names; if the bit
448 of text is, say, |T1| then the new control sequnce will be |\T1\foo|
449 (this is \emph{one} control sequence). Such names are impossible to type
450 without a lot of trickery, but that is deliberate, since they should
451 not be accessed directly. If the control sequence thus formed is defined,
452 then the definition of that control sequence will be taken as the intended
453 definition of the control sequence |\foo| it all started with.
454
455 The systems differ in what pieces of text they put before the name of
456 the command and what they do if the control sequence formed is not
457 defined. The \LaTeXe\ kernel starts by using the name of the current
458 encoding as the prefix text. If that fails, it tries with |?| instead.
459 If that fails too, an error message is issued. The variable commands
460 defined using the \package{relenc} package have a more general approach.
461
462 This approach relies on the concept of a \emph{search path}, about
463 the structure of which more will be said later. For the moment, it is
464 sufficient to say that it consists of a sequence of \emph{blocks} of
465 text. The looking up process consists of a loop in which the following
466 is done: The first block is removed from the search path, and the text
467 it contains is used to form the name of a control sequence, as described
468 above. The rest of the search path is saved away as the \emph{remaining
469 search path}. If the control sequence formed is defined, then it is used
470 as the definition of the command, and if it is not, then the process
471 is repeated. When the process is repeated however, it starts by
472 removing the first block of the remaining search path, which is the
473 second (or third, or fourth, depending on which iteration of the loop
474 is the current) block of the entire search path, while once again
475 saving the rest as the new remaining search path. Not until the
476 entire search path has been scanned in this way will an error message
477 be issued.
478
479 This means arbitrarily many possibilities can be tested in searching
480 for the definition of a command, but about six is probably a
481 realistic upper bound on how many there will be in practical
482 applications. In many cases it will be even fewer.
483
484 What has been mensioned so far does not mean there necessarily is any
485 dependence on the current font, but it opens the possibility. The
486 trick is that the pieces of text, which are the blocks in the search
487 path, can contain not only characters but also macros (and other
488 expandable stuff)---as long as everything eventually expands to
489 character tokens, everything is fine. The point here is that the
490 control sequences that contains the names of the current encoding,
491 family, series, and shape---|\f@encoding|\footnote{For technical
492 reasons, it is probably better to use \cs{cf@encoding} instead. See page
493 \pageref{Why cf@encoding} for a discussion of this.}, |\f@family|,
494 |\f@series|, and |\f@shape| respectively---are of this kind. Thus
495 making the definition of a variable command depend on these attributes
496 of the current font is simply a matter of making the corresponding
497 control sequences part of the texts in the search path.
498
499 The above might give the impression that the variable commands are
500 ment to be used instead of the encoding-specific commands of standard
501 \LaTeX, but that is not the case. What actually happens is that the
502 control sequences of type |\T1\foo| that the \LaTeXe\ kernel looks up
503 will themselves be variable commands. This means that to \LaTeX, the
504 commands in a relaxed encoding whose definitions depend on the current
505 font are just normal encoding-specific commands, even though they do a
506 lot of peculiar things before they actually generate any typeset
507 material, but on the other hand \LaTeX\ doesn't care what they do, as
508 long as it finds a definition.\footnote{It also saves me a lot of
509 work, since I won't have to bother with trying to make the variable
510 commands robust---\LaTeX\ already makes the encoding-specific commands
511 robust.}
512
513 This has probably been a bit abstract, so an explicit example might be
514 in place. Let's say that the current encoding is \texttt{T1R} (this is
515 an existing relaxed encoding), the current family is \texttt{zcm}
516 (this is an example family\footnote{The \texttt{zcm} font family is
517 described in Appendix \ref{zcm-family}.}), the current series is
518 \texttt{m}, and the current shape is \texttt{n}. Furthermore let's say
519 the user has just issued the font-dependent command |\foo| (this is not
520 really a font-dependent command, but let's assume it is). What will happen?
521
522 \begin{enumerate}
523 \item
524 The actual control sequence |\foo| causes the \LaTeXe\ kernel to start
525 look for a definition. It first tries |\T1R\foo|, then |\?\foo|, and
526 if neither is defined then an error message is given. The case of
527 interest here is that |\T1R\foo| is defined, because then the
528 \LaTeXe\ kernel is content and \TeX\ will act as if |\T1R\foo| was
529 issued instead.
530 \item
531 If the final definition of |\foo| is to depend on family\slash
532 series\slash shape then |\T1R\foo| must be a variable command. The
533 first thing which happens then is that \package{relenc} starts
534 looking for a search path to use. Search paths are stored in
535 macros, and the names of these macros are formed in a manner
536 similar to that in which the other lookup names here are formed.
537
538 The two macros which can contain the search path are
539 |\T1R/zcm-path| and |\T1R-path| (these are still only single
540 control sequences), and they are tried in that order. If none of
541 them exists, then an error message is given. The second of the two
542 is common to all fonts using the \texttt{T1R} encoding and must be
543 defined by the encoding designer. A font designer can choose to
544 define a search path of his or hers own, and that will then be named
545 as the first of the two above. A family specific search path
546 completely overrides the encoding specific (the latter is in that
547 case not even considered), but in many cases the encoding specific
548 will do just fine.
549
550 Let's assume that |\T1R/zcm-path| is defined and consists of
551 \begin{verse}
552 |{|\meta{enc}|/|\meta{family}|/|\meta{series}|/|\meta{shape}|}|\\
553 |{|\meta{enc}|/|\meta{family}|/?/|\meta{shape}|}|\\
554 |{|\meta{enc}|/|\meta{family}|/?/?}|\\
555 |{|\meta{enc}|/?/?/?}|
556 \end{verse}
557 (Each block is written on a separate line. The text of the block is
558 everything between (but not including) the braces, which act as
559 delimiters of the block. \meta{enc}, \meta{family}, \meta{series}, and
560 \meta{shape} denote the \LaTeX\ macros listed above which contain the
561 names of the current encoding, family, series, and shape respectively.)
562 \item
563 Once the search path is found, it is scanned. In this particular
564 case this means that the control sequences |\T1R/zcm/m/n\foo|,
565 |\T1R/zcm/?/n\foo|, |\T1R/zcm/?/?\foo|, and |\T1R/?/?/?\foo| are
566 tried in that order. If none of them is defined, an error message is
567 given, but let's assume that |\T1R/zcm/?/?\foo| is defined and
568 neither |\T1R/zcm/m/n\foo| nor |\T1R/zcm/?/n\foo| are. This
569 corresponds to the case that there is a definition of the variable
570 command that is specific for the family, but not any specific for
571 the shape or series.
572 \item
573 The final stage is that |\T1R/zcm/?/?\foo| gets executed.
574 \end{enumerate}
575
576 There are now only a few more things to sort out before the
577 description of the commands a font designer has available can commence.
578 Firstly, control sequences like the above |\T1R/zcm/?/?\foo|, that hold
579 an actual definition of a variable command, are called \emph{variants}
580 of that command. The processing during the scan of the search path that
581 is connected to one block in the search path is called a \emph{step} in
582 that scan.
583
584 Secondly, there is another thing which might affect the definition of a
585 command, viz.\ the first argument of the command. Commands for which
586 the first argument is checked before the actual definition is determined
587 are called \emph{composite commands}, or are said to be \emph{composed}.
588 The alternative definitions of them are called \emph{compositions}. Each
589 composition is used for exactly one value of the argument, and the main
590 composite command contains a definition which is used for all values for
591 which there is no composition.
592
593 This too is a mechanism that is present in the \LaTeXe\ kernel, what
594 \package{relenc} does is that it introduces some commands to make
595 variable commands composed or vice versa. Very much like variable
596 commands, composite commands rely on |\csname| lookups, but instead of
597 adding a prefix to the command name, the composition mechanism adds a
598 suffix consisting of a hyphen (|-|) and the first token of the first
599 argument (as a precaution, this token is |\string|ed beforehand, to
600 convert it to character tokens if it was not already).
601
602 An example of this, from the \texttt{T1} encoding, is the acute accent
603 command |\'|. The command that actually is composed is |\T1\'|, which
604 holds the definition of |\'| in the \texttt{T1} encoding, and one of
605 its compositions are |\\T1\'-a|. This is a macro which expands to the
606 letter \'{a}, which is the expected result of |\'{a}|. There is no
607 composition for the argument |\ae| in the \texttt{T1} encoding, so if
608 the user issues |\'{\ae}| the lookup mechanism finds nothing and the
609 default definition is used, yielding `\'{\ae}'. Had there been a
610 composition however, it would have called |\\T1\'-\ae|. Cases like
611 these are why the |\string|ing precaution is necessary; most
612 commands generate errors when \TeX\ meets with them inside a |\csname|
613 \textellipsis\ |\endcsname| pair.
614
615 With that description completed, it is now time to describe the usage
616 and purpose of the commands available to the font designer. It should
617 perhaps be pointed out that most of them are about defining variants
618 of commands, as making a command variable lies within the powers of
619 the encoding designer.
620
621
622 \subsubsection{Defining variants of font-dependent commands}
623
624 Among the arguments of every variant defining command is the sequence
625 \marg{encoding}\B\marg{family}\B\marg{series}\B\marg{shape},
626 which specifies which variant of a command is being defined. The
627 arguments should consist of letters and\slash or figures, but any
628 combination of these parameter fields might be left empty. A field
629 left empty signifies that the intended variant may be used regardless
630 of what value that attribute may take. Thus |{T1R}{zcm}{m}{n}| is used
631 when defining a variant specific to this encoding, family, series, and
632 shape, whilst |{T1R}{zcm}{}{}| is used when defining a variant that
633 applies for every font in the \texttt{T1R}-encoded \texttt{zcm} family.
634 Technically, a field left empty will be filled with a question mark.
635 Thus the |{T1R}{zcm}{}{}| variant of |\foo| will be stored in the
636 control sequence |\T1R/zcm/?/?\foo|.
637
638 \DescribeMacro\DefineTextSymbolVariant
639 \DescribeMacro\DefineTextAccentVariant
640 |\DefineTextSymbolVariant| and |\DefineTextAccentVariant| are the two
641 simplest commands for defining a variant. The former makes the variant
642 output a single character, whose slot in the font is given as the
643 argument \meta{slot}. The latter should be used for variants of accent
644 commands, as an accenting command is precisely what it defines. The
645 character used for the accent is the one with slot number
646 \meta{slot}. |\DefineTextSymbolVariant| and
647 |\DefineTextAccentVariant| parallell the commands |\DeclareTextSymbol|
648 and |\DeclareTextAccent| respectively that are found in standard
649 \LaTeX.
650
651 \DescribeMacro\DefineTextCommandVariant
652 If the above are not sufficient for the definition of a variant of
653 some command (they are not, for example, general enough to define any
654 of the accents put \emph{under} letters), complete generality is
655 offered through the |\DefineTextCommandVariant| command, which can be
656 used to define any \TeX\ macro. (It consists simply of a |\gdef| to
657 the control sequence that stores the variant in question.) This means
658 the \meta{parameter text} should be formated as for the |\def|
659 command, without any surrounding braces or such. Also notice that every
660 token in the \meta{parameter text} counts, including spaces and end of
661 lines.
662
663 Apart from the arguments mensioned, all the above commands have an
664 argument \meta{cmd}. This is the name of the base font-dependent command of
665 which you want to define a variant. It is not the name of the actual
666 variable command, so you should write |\foo|, not |\T1R\foo|.
667 The syntaxes of the commands are as follows:
668 \begin{cmdusage}
669 |\DefineTextSymbolVariant| \marg{cmd}
670 \marg{encoding} \marg{family} \marg{series} \marg{shape}
671 \marg{slot}
672
673 |\DefineTextAccentVariant| \marg{cmd}
674 \marg{encoding} \marg{family} \marg{series} \marg{shape}
675 \marg{slot}
676
677 |\DefineTextCommandVariant| \marg{cmd}
678 \marg{encoding} \marg{family} \marg{series} \marg{shape}
679 \meta{parameter~text}~|{|~\meta{replacement~text}~|}|
680 \end{cmdusage}
681 \medskip
682
683 \DescribeMacro\NewTextCommandVariant
684 \DescribeMacro\RenewTextCommandVariant
685 \DescribeMacro\ProvideTextCommandVariant
686 \package{relenc} does also offer some |\newcommand|-style commands for
687 defining variants of font-dependent commands, for font designers who prefer
688 that. They do offer some additional functionality, as they can make
689 commands which take an optional argument, but I am not currently aware
690 of any font-dependent command that uses this feature. One reason the
691 feature is offered is that variable command processing comes before
692 optional argument processing, hence if a variable font-dependent command
693 can have an optional argument then all its variants must be able to cope
694 with that argument when it is present.
695
696 Technically the commands boil down to an application of
697 |\newcommand|, |\renewcommand|, or |\providecommand| respectively
698 (the starred forms, to be exact). Thus you may get error messages
699 if the variant is already defined or not defined, depending on which
700 command you use. As the error messages are the standard \LaTeX\ %
701 error messages, they may be somewhat confusing. Still, a somewhat
702 confusing error message may be better than none at all.
703 \begin{cmdusage}
704 |\NewTextCommandVariant| \marg{cmd}
705 \marg{encoding} \marg{family} \marg{series} \marg{shape}
706 \oarg{numargs} \oarg{default} \marg{replacement text}
707
708 |\RenewTextCommandVariant| \marg{cmd}
709 \marg{encoding} \marg{family} \marg{series} \marg{shape}
710 \oarg{numargs} \oarg{default} \marg{replacement text}
711
712 |\ProvideTextCommandVariant| \marg{cmd}
713 \marg{encoding} \marg{family} \marg{series} \marg{shape}
714 \oarg{numargs} \oarg{default} \marg{replacement text}
715 \end{cmdusage}
716 \medskip
717
718
719 \subsubsection{Defining variants of compositions}
720 \label{Var. of comp.}
721
722 As compositions can be variable, there are commands for defining
723 variants of them. The situation here is simpler than for font-dependent
724 commands in general since compositions cannot have any arguments,
725 consequently there is no need to provide such a large variety of
726 definition commands as for defining command variants.
727
728 \DescribeMacro\DefineTextCompositionVariant
729 \DescribeMacro\DefineTextCompositionVariantCommand
730 The most important is |\DefineTextCompositionVariant| which
731 corresponds to |\DefineTextSymbolVariant|---it makes a variant which
732 simply typesets one of the characters in the font. The most general
733 command is |\DefineText|\B|Composition|\B|VariantCommand| which defines
734 the variant to be a parameterless macro without other restictions.
735
736 \DescribeMacro\DefineTextUncomposedVariant
737 A special, but probably rather common macro to define a variant of a
738 composition to be, is the macro consisting of the noncomposite
739 definition applied on the argument for the composition, because
740 defining the variant this way is probably the easiest way to free a slot
741 in the font for other purposes. Hence there is a special command for
742 doing this: |\DefineTextUncomposedVariant|. It resembles the other
743 two, but there is of course no argument that gives the definition of
744 the variant and there is a special restriction, namely that
745 the \meta{encoding} argument must not be empty!
746
747 The arguments of these commands are as for the commands for defining
748 variants of font-dependent commands, except for one designated
749 \marg{argument}. This is the argument which is passed to the
750 font-dependent command that corresponds to the current composition---the
751 composition of which a variant is to be defined.
752
753 \begin{cmdusage}
754 |\DefineTextCompositionVariant| \marg{cmd}
755 \marg{encoding} \marg{family} \marg{series} \marg{shape}
756 \marg{argument} \marg{slot}
757
758 |\DefineTextCompositionVariantCommand| \marg{cmd}
759 \marg{encoding} \marg{family} \marg{series} \marg{shape}
760 \marg{argument} \marg{replacement text}
761
762 |\DefineTextUncomposedVariant| \marg{cmd}
763 \marg{encoding} \marg{family} \marg{series} \marg{shape}
764 \marg{argument}
765 \end{cmdusage}
766
767
768 \subsubsection{Defining compositions of variants}
769 \label{Comp av var}
770 %
771 Things can be done the other way round too---a variant of a font-dependent
772 command may have compositions. These compositions are then completely
773 independent of any compositions of the base font-dependent command. Unlike
774 compositions of a font-dependent command (which must be \emph{declared}
775 in the encoding definition file and are common to all fonts in a
776 particular encoding), compositions of a variant can be \emph{defined}
777 whenever a variant can be defined. Thus making compositions of variants
778 lies within the powers of the font designer.
779
780 \DescribeMacro\DefineTextVariantComposition
781 \DescribeMacro\DefineTextVariantCompositionCommand
782 There are two commands for defining compositions of variants:
783 |\Define|\B|Text|\B|Variant|\B|Composition| and
784 |\Define|\B|Text|\B|Variant|\B|Composition|\B|Command|. The difference
785 between them is simply that the latter command defines the composition
786 to be a macro with the given replacement text, while the former defines
787 it to be a chardef token for the given slot. What is more interesting is
788 what these commands do if the variant they are to make a composition of
789 is not defined, because in this case they define the default definition
790 to be a macro that resumes the scan of the search path. This means that
791 the font designer can choose to specify some compositions early in the
792 search path and others later---and perhaps more importantly---can give
793 special definitions for some compositions early in the search path
794 without having to copy the default definition to that level.
795
796 As it happens, the names of the control sequences, in which the
797 definitions of compositions of variants and variants of compositions
798 respectively are stored, are slightly different (a backslash appears
799 at different positions). Hence it is possible to have both for exactly
800 the same \meta{encoding} \meta{family} \meta{series} \meta{shape}
801 \meta{argument} combination for a composition of variant and variant
802 of composition without having them overwriting each other, although
803 there is hardly any point in having things set up this way.
804
805 \begin{cmdusage}
806 |\DefineTextVariantComposition| \marg{cmd}
807 \marg{encoding} \marg{family} \marg{series} \marg{shape}
808 \marg{argument} \marg{slot}
809
810 |\DefineTextVariantCompositionCommand| \marg{cmd}
811 \marg{encoding} \marg{family} \marg{series} \marg{shape}
812 \marg{argument} \marg{replacement text}
813 \end{cmdusage}
814
815
816 \subsubsection{Setting the family search path}
817
818 Setting the family search path is pretty straightforward: The search
819 path is the last argument, encoding and family in question the two
820 other. A useful feature here is that inside the search path argument,
821 |@| will be a letter and all spaces and newlines are ignored. This
822 means the example search path from Subsubsection \ref{Tekn.bakgr.} can
823 be set even by a command call as spaced out as the following
824 \begin{verbatim}
825 \SetFamilySearchPath{T1R}{zcm}{
826 { \cf@encoding / \f@family / \f@series / \f@shape }
827 { \cf@encoding / \f@family / ? / \f@shape }
828 { \cf@encoding / \f@family / ? / ? }
829 { \cf@encoding / ? / ? / ? }
830 }
831 \end{verbatim}
832 and even if it appears in the preamble of a document (this is handy when
833 debugging a font family).
834
835 Search paths \emph{must} be set using the |\SetFamilySearchPath| or
836 |\SetEncoding|\B|SearchPath| commands, otherwise the case that no
837 definition of a variable command is found cannot be handled
838 correctly, with the effect that \TeX\ gets hung in an infinite loop.
839
840 \begin{cmdusage}
841 |\SetFamilySearchPath| \marg{encoding} \marg{family}
842 \marg{search~path}
843 \end{cmdusage}
844
845
846 \subsubsection{Where to put it all}
847 %
848 One topic that has not been delt with above is where the font designer
849 is to put all these commands for defining variants and setting search
850 path. In my opinion, there is only one possible place---the font
851 definition file\footnote{I am well aware of the rules for which
852 commands may be used in font definition files that are described in
853 \cite{fntguide}. I have however chosen to disregard from these rules
854 in the case of commands defined by the \package{relenc} package, as
855 this case could hardly have been foreseen by the prescribers of these
856 rules.}. This is also the logical place to put the commands,
857 since this is the file in which the font designer describes his or her
858 font family to \LaTeX. In particular, one cannot expect full
859 functionality if the commands are put in a package, since it is
860 perfectly possible to select a font without using a standard package
861 for this.
862
863 Of course, definition commands can also appear in an encoding
864 definition file and anything that can appear in an encoding definition
865 file may also appear in a package file, even though packages containing
866 such code are often of a rather special nature.
867
868 % There is however a complication of a technical nature with using
869 % commands from the \package{relenc} package in font definition files.
870 % Most of the commands defined in the \package{relenc} package assume
871 % that the value of the \TeX\ parameter |\escapechar| is $92$, denoting
872 % the backslash character (|\|). This is normally the case in \LaTeX,
873 % but unfortunately this is not always the case when a font definition
874 % file is loaded. \LaTeX\ locally sets |\escapechar| to $-1$ during some
875 % important operations, most notably the loading of a new font done in
876 % |\define@newfont|, and it is often at this time that font definition
877 % files get loaded.
878 %
879 % To work around this, include the line
880 % \begin{verbatim}
881 % \begingroup \escapechar=`\\
882 % \end{verbatim}
883 % somewhere in every font definition file using commands from the
884 % \package{relenc} package and put it before the first such command; also
885 % include the line
886 % \begin{verbatim}
887 % \endgroup
888 % \end{verbatim}
889 % somewhere after the last such command. This temporarily resets
890 % |\escapechar| to its normal value. I believe the group is necessary
891 % (and it doesn't harm), since the value of |\escapechar| is not
892 % neccessarily $-1$ at the time a font definition file is loaded. Sigh.
893 %
894 % IMHO, the best way to fix this would be to change \LaTeX\ itself so
895 % that it doesn't change |\escapechar| at this particular
896 % time\footnote{One could easily achieve the same results using a
897 % combination of \cs{expandafter}s and \cs{@gobble}s. This would also
898 % have the positive effect that backslashes will appear where one is
899 % used to see them in the tracing messages \TeX\ writes out if
900 % \cs{tracingcommands} or \cs{tracingmacros} are positive, instead of
901 % being missing inside a neighbourhood of every font change.}, but that
902 % is of course for the \LaTeX3 project team to decide.
903
904
905 \subsection{Encoding designer usage}
906 %
907 The encoding designer's work in making a relaxed encoding is very
908 much like the work in making a normal encoding. There are only two
909 additional steps: It must be decided which commands and compositions
910 that should be variable, and an encoding search path must be set. Both
911 of these are more a matter of planning than writing \TeX\ code, but it
912 seems best to treat the coding first.
913
914 Each of the commands for declaring a variable font-dependent command or
915 composition corresponds to a command for declaring a non-variable
916 font-dependent command which is part of standard \LaTeX, as is shown in the
917 following table. The correspondence is not one to one, but it is pretty
918 close.
919
920 \begin{center}
921 \small\DeleteShortVerb{\|}
922 \begin{tabular}{|ll|}
923 \hline
924 Standard declaration command& Variable declaration command%
925 \\[-0.9\ht\strutbox]
926 \hrulefill&\hrulefill\\
927 \relax\MakeShortVerb{\|}|\DeclareTextCommand|&
928 \relax|\DeclareTextVariableCommand|\\
929 \relax|\DeclareTextCommand|&
930 \relax|\DeclareTextVariableCommandNoDefault|\\
931 \relax|\ProvideTextCommand|&
932 \relax|\ProvideTextVariableCommand|\\
933 \relax|\DeclareTextSymbol|&
934 \relax|\DeclareTextVariableSymbol|\\
935 \relax|\DeclareTextAccent|&
936 \relax|\DeclareTextVariableAccent|\\
937 \relax|\DeclareTextComposite|&
938 \relax|\DeclareVariableTextComposition|\\
939 \relax|\DeclareTextCompositeCommand|&
940 \relax|\DeclareVariableTextComposition|\\
941 \hline
942 \end{tabular}
943 \end{center}
944
945 \DescribeMacro\DeclareTextVariableSymbol
946 \DescribeMacro\DeclareTextVariableCommand
947 \DescribeMacro\ProvideTextVariableCommand
948 \DescribeMacro\DeclareTextVariableAccent
949 The difference between on one hand the commands |\Declare|\B|Text|\B
950 |Variable|\B|Symbol|, |\Declare|\B|Text|\B|Variable|\B|Command|,
951 |\Provide|\B|Text|\B|Variable|\B|Command|, and |\Declare|\B|Text|\B
952 |Variable|\B|Accent| and their non-variable counterparts on the other is
953 that the font-dependent command they declare will become a variable
954 command, while the definitions given will be used to define the
955 encoding-level variant of the command. The arguments are exactly the
956 same as for the commands' non-variable counterparts of standard \LaTeX.
957
958 \DescribeMacro\DeclareTextVariableCommandNoDefault
959 The |\DeclareTextVariableCommandNoDefault| command only declares a
960 font-dependent command and makes it variable, but does not define any of
961 its variants. This can actually be useful if one is writing an encoding
962 that is a relaxed version of another encoding, such as the \texttt{T1R}
963 encoding, since many commands will have the same encoding-level
964 definition in both encodings. It is then possible to include the name of
965 that other encoding in the search path, so that the same control
966 sequence will hold the definition of a command in two different
967 encodings.
968
969 \DescribeMacro\DeclareVariableTextComposition
970 The |\DeclareVariableTextComposition| command declares a composition of
971 a command, like |\Declare|\B|Text|\B|Composite| or
972 |\DeclareTextCompositeCommand|, and makes that composition variable.
973 But it is also like |\Declare|\B|Variable|\B|Text|\B|CommandNo|\B|Default|
974 in that it does not define any variant of the composition. To define a
975 variant, one of the commands in Subsection \ref{Var. of comp.} must be
976 used as well\footnote{I am not sure that this is a good way to organise
977 it. Perhaps there should be commands combining these functions.}.
978 |\DeclareVariableTextComposition| takes three arguments: the command,
979 the encoding, and the argument for which a composition is to be
980 declared.
981
982 \begin{cmdusage}
983 |\DeclareTextVariableSymbol| \marg{cmd} \marg{encoding}
984 \marg{slot}
985
986 |\DeclareTextVariableCommand| \marg{cmd} \marg{encoding}
987 \oarg{arguments} \oarg{default} \marg{replacement~text}
988
989 |\DeclareTextVariableCommandNoDefault| \marg{cmd} \marg{encoding}
990
991 |\ProvideTextVariableCommand| \marg{cmd} \marg{encoding}
992 \oarg{arguments} \oarg{default} \marg{replacement~text}
993
994 |\DeclareTextVariableAccent| \marg{cmd} \marg{encoding}
995 \marg{slot}
996
997 |\DeclareVariableTextComposition| \marg{cmd} \marg{encoding}
998 \marg{argument}
999 \end{cmdusage}
1000 \bigskip
1001
1002 \DescribeMacro\SetEncodingSearchPath
1003 This is very much like |\SetFamilySearchPath|; the main difference to
1004 setting a family search path is that a relaxed encoding \emph{must} set
1005 its encoding search path.
1006
1007 \begin{cmdusage}
1008 |\SetEncodingSearchPath| \marg{encoding} \marg{search~path}
1009 \end{cmdusage}
1010
1011 \medskip
1012
1013 Now to the part which is not coding. As noone, at the time this is
1014 written, is particularly experienced in the creation of relaxed
1015 encodings, this is not a guide of how to do that. This is only a
1016 collection of some observations I made when I created the
1017 \texttt{T1R} encoding and the \package{relenc} package.
1018
1019 \begin{itemize}
1020 \item
1021 When making a relaxed encoding: If you mainly want to free some
1022 slots, so that you can include some new set of glyphs (for example
1023 additional ligatures) in the font, the obvious place to start is to
1024 reduce the number of slots that are assigned to compositions, by
1025 implementing these in a variable way.
1026 \item
1027 When relaxing a composition, there are two ways of doing this:
1028 making the composition variable, or making the command variable
1029 and defining a composition of some variant. The cost (i.e., the
1030 number of special definitions you have to make) is connected to
1031 different things in these methods.
1032
1033 In the case of a composition of a variant, there is a cost
1034 connected to having a composition. In the case of a variable
1035 composition, the cost is rather connected to not using the default
1036 definition for the composition. In the usual case that one either
1037 uses a special glyph for a composition or uses the default
1038 definition of the accenting command, this means that composition of
1039 variant is cheaper if a minority of the compositions uses the
1040 default definition and variable composition is cheaper if a
1041 majority uses the default definition.
1042 \item
1043 In some cases, the default definition of an accenting command
1044 tends to be suitable for some font families, but inappropriate
1045 for others. An example from the \texttt{OT1} encoding is that the
1046 definition of |\c| starts by looking at the \emph{height} (!!!) of
1047 the character it is to put a cedilla under. If the height is
1048 exactly $1\,\textrm{ex}$ then the |\accent| primitive is used,
1049 otherwise the accent is put in place using a |\vtop| construction.
1050 This works fine (I suppose, trusting DEK to have known what he was
1051 doing) for fonts with idealized heights and depths of characters,
1052 such as the Computer Modern family of fonts, but is a pure waste
1053 of time if the heights and depths are computed from the bounding
1054 boxes of the glyphs (like \textit{fontinst} \cite{fontinst} does).
1055
1056 The conclusion of all this is that it might be a good idea to
1057 make accenting commands that have such a specific default definition
1058 variable, regardless of how any compositions of these commands might
1059 be implemented, so that font designers can override the definitions
1060 in case they want to.
1061
1062 \end{itemize}
1063
1064 Apart from this, there is not much advice I can give. It is however
1065 likely to be a good idea to try to make a specification of the
1066 encoding---like described in Section \ref{Motivation} or in some other
1067 way, detailed or only in loose sketches---before starting to do the
1068 coding.
1069
1070
1071 \subsection{Power user commands}
1072 %
1073 This subsection treats some commands that may be useful to advanced
1074 users of the \package{relenc} package (this includes all font and
1075 encoding designers); in any case, the novice author users can do
1076 perfectly well without using the commands described here.
1077
1078 \subsubsection{Debugging assistance}
1079 %
1080 \DescribeMacro\ShowVariantSearchResult
1081 As the way from user level command to definition given is quite long
1082 if the command is variable, there are many instances in which things
1083 can go wrong. |\ShowVariantSearchResult| may help in sorting out what
1084 exactly happened. Its primary function is to print the contents of
1085 all internal variables in \package{relenc} on the terminal and then
1086 wait for a command, just like after the primitive \TeX\ command |\show|.
1087 As an extra service, |\ShowVariantSearchResult| also prints the current
1088 encoding, family, series, and shape.
1089
1090 As most of the processing in \package{relenc} is done in \TeX's mouth,
1091 there is not very much left to show. The most important piece of data
1092 there is is the \emph{remaining search path}. This is the part of the
1093 search path that was \emph{not} scanned in looking for a definition;
1094 by comparing it to the whole of the search path used, one can
1095 determine at which stage a definition was found. The other thing shown
1096 is the definition of |\RE@first@search@item|, which normally is
1097 defined to be a parameterless macro that expands to the first block
1098 in the search path most recently used. There are however two cases
1099 when it is not: (i) If a definition was found in the first stage
1100 of the most recent search, |\RE@first@search@item| is not altered.
1101 (ii) If the search has been restarted (see Subsubsection \ref
1102 {Comp av var}) then |\RE@first@search@item| is a macro with a
1103 parameter.
1104
1105 Despite these reservations, |\ShowVariantSearchResult| provides about
1106 all the information there is to get about what a search has found. It
1107 might also be instructive if you want to understand the inner workings
1108 of the \package{relenc} package in more detail.
1109
1110 \begin{cmdusage}
1111 |\ShowVariantSearchResult|
1112 \end{cmdusage}
1113
1114 Should |\ShowVariantSearchResult| not give you enough information, you
1115 can of course always set |\tracingmacros| to 1 and |\tracingcommands|
1116 to 2 for the time it takes to execute the command you are trying to
1117 debug, this will give you the whole picture of what \package{relenc}
1118 does. Before attempting this drastic action however, you should
1119 familiarise yourself with the implementation of the \package{relenc}
1120 package.
1121
1122
1123 \subsubsection{The `define first' mechanism}
1124 %
1125 The `define first' mechanism, which has not been mensioned until now
1126 because it is not really related to anything else in the package, is
1127 something very few users should ever have to bother with. It can
1128 however speed up the typesetting process, as demonstrated in Table
1129 \ref{Tab:Tid}.
1130
1131 \begin{table}
1132 \begin{center}
1133 \DeleteShortVerb{\|}
1134 \begin{tabular}{|rr@{.}lr@{.}lr@{.}l|}
1135 \hline
1136 &\multicolumn{6}{c|}{Default encoding}\\[-0.9\ht\strutbox]
1137 &\multicolumn{6}{c|}{\hrulefill}\\
1138 & \multicolumn{2}{c}{\texttt{OT1}}&\multicolumn{2}{c}{\texttt{T1}}&
1139 \multicolumn{2}{c|}{\texttt{T1R}}
1140 \\[-0.9\ht\strutbox]
1141 & \multicolumn{2}{c}{\hrulefill}& \multicolumn{2}{c}{\hrulefill}&
1142 \multicolumn{2}{c|}{\hrulefill}\\
1143 \parbox[c]{0.3\columnwidth}{Time taken using \texttt{T1}}&
1144 253&4\,s& 197&5\,s& 255&2\,s\\[1ex]
1145 \parbox[c]{0.3\columnwidth}{Time taken using \texttt{T1R}\\
1146 (DFM on, no FSP)}&
1147 339&7\,s& 349&5\,s& 294&2\,s\\[2ex]
1148 \parbox[c]{0.3\columnwidth}{Time taken using \texttt{T1R}\\
1149 (DFM off, no FSP)}&
1150 446&4\,s& 458&3\,s& 400&5\,s\\[2ex]
1151 \parbox[c]{0.3\columnwidth}{Time taken using \texttt{T1R}\\
1152 (DFM off, has FSP)}&
1153 334&4\,s& 350&9\,s& 293&2\,s\\[2ex]
1154 \parbox[c]{0.3\columnwidth}{Time taken using \texttt{T1R}\\
1155 (DFM on, has FSP)}&
1156 316&7\,s& 327&5\,s& 269&9\,s\\[2ex]
1157 \hline
1158 \end{tabular}%
1159 \MakeShortVerb{\|}
1160 \end{center}\medskip
1161
1162 \begingroup\footnotesize \parindent=1em
1163 DFM = Define First Mechanism
1164
1165 FSP = Family Search Path. The family search path used was
1166 optimised to examine only the levels at which there actually
1167 existed some variant.
1168
1169 The `default encoding' in this table is the encoding whose
1170 encoding definition file was read in last. As explained in
1171 \cite{ltoutenc}, this means that all commands declared in that
1172 encoding will execute somewhat faster when that encoding is the
1173 current.
1174
1175 The test text used consisted of all non-accented letters declared
1176 in the \texttt{T1} encoding (a--z, as well as \ae, \ss, \i, and a
1177 few others) in both upper and lower case, as they are as well as
1178 accented with every accent command available (|\`|, |\'|, |\^|, |\~|,
1179 |\"|, |\H|, |\r|, |\v|, |\u|, |\=|, |\.|, |\b|, |\c|, |\d|, and
1180 |\k|). These 32 lines were then repeated 100 times, to reduce the
1181 relaive amount of time taken to start the process.\par
1182 \endgroup
1183
1184 \caption{A comparision of typesetting speed}\label{Tab:Tid}
1185 \end{table}
1186
1187 What the define first mechanism (DFM) does, when it is active, is
1188 that if a definition is not found in the first step of the search
1189 path scan and a definition is found in some later step, then that
1190 definition is copied to the control sequence scanned in the first step.
1191 Thus the next time that the same command is issued, the scan of the
1192 search path will find a definition in the first step.
1193
1194 This can speed up the search considerably, but there is a price to pay:
1195 More control sequnces gets defined, meaning more of \TeX's memory is
1196 being used for storing definitions of variable commands.\footnote{Or
1197 so it would appear \textellipsis\ Some things I've recently learnt
1198 about how \TeX's internal tables work has made me wonder about whether
1199 it really takes more memory, so I am currently not sure. Perhaps
1200 someone competent in the area of \TeX's memory management will
1201 volunteer to sort things out for me?} If you run out of memory while
1202 typesetting a document with the DFM on, turning it off will lower the
1203 memory requirements. If your \TeX\ is generally low on memory however,
1204 you should probably not be using relaxed encodings at all, since the
1205 basic deal of the entire package is to loosen the restrictions on fonts
1206 for a particular encoding by increasing the number of control sequences
1207 needed for the typesetting process.
1208
1209 But these differences should be seen for what they really are,
1210 differences in speed for one of the many things \TeX\ have to do to
1211 typeset something. \TeX\ does no linebreaking during the tests in
1212 Table \ref{Tab:Tid} (hence no hyphentaing either), does not read any
1213 input after the first five seconds (the entire text is generated through
1214 expanding macros), has a very simple job pagebreaking, and so forth.
1215 In addition, the percentage of letters generated through font-dependent
1216 commands is much greater in the test text than what one would find in
1217 a normal \TeX\ manuscript. This circumstance also reduces the effect
1218 that the tabulated differences in speed will have on the overall
1219 typesetting speed for a normal \TeX\ manuscript.
1220
1221 If you have not noticed that your document is being typeset slower due
1222 to the fact that the encoding used is not the encoding whose definition
1223 file was read in last, then chances are you would not notice any drop
1224 in speed if it was typeset using a relaxed encoding either.
1225
1226 \medskip
1227
1228 \DescribeMacro\ActivateDefineFirst
1229 \DescribeMacro\DeactivateDefineFirst
1230 The DFM is turned on and off using the commands
1231 |\ActivateDefineFirst| and |\DeactivateDefineFirst|, none of which
1232 have any parameters. As it is currently implemented, the activation
1233 state of the DFM is affected by grouping, but the defining it does
1234 is global.
1235
1236 \begin{cmdusage}
1237 |\ActivateDefineFirst|
1238
1239 |\DeactivateDefineFirst|
1240 \end{cmdusage}
1241
1242
1243 % The implementation
1244 % \part{\texttt{relenc.dtx}}
1245 \DocInput{relenc.dtx}\Finale
1246
1247
1248 \appendix
1249
1250 \part*{The \texttt{T1R} encoding}
1251 \addcontentsline{toc}{part}{The \texttt{T1R} encoding}
1252 \DocInput{t1renc.dtx}\Finale
1253
1254 \part*{The \texttt{zcm} example font family}
1255 \addcontentsline{toc}{part}{The \texttt{zcm} example font family}
1256 \DocInput{t1rzcm.fdd}\Finale
1257
1258
1259 \begin{thebibliography}{99}
1260 %
1261 \bibitem{ltoutenc}
1262 Johannes Braams, David Carlisle, Alan Jeffrey, Frank Mittelbach,
1263 Chris Rowley, Rainer Sch\"opf: \texttt{ltoutenc.dtx} (part of the
1264 \LaTeXe\ base distribution).
1265 %
1266 \bibitem{fontinst}
1267 Alan Jeffrey, Rowland McDonnell (manual), Sebastian Rahtz,
1268 Ulrik Vieth: \emph{The fontinst utility} (v\,1.8),
1269 \texttt{fontinst.dtx}, in CTAN at \texttt{ftp:/\slash
1270 ftp.tex.ac.uk\slash tex-archive\slash fonts\slash utilities\slash
1271 fontinst\slash}\textellipsis
1272 %
1273 \bibitem{fntguide}
1274 \LaTeX3 Project Team: \emph{\LaTeXe\ font selection},
1275 \texttt{fntguide.tex} (part of the \LaTeXe\ base distribution).
1276 %
1277 \bibitem{encguide}
1278 Frank Mittelbach [et al. ?]: \texttt{encguide.tex}. To appear as
1279 part of the \LaTeXe\ base distribution. Sometime. Or at least, that
1280 is the intention.
1281 %
1282 \end{thebibliography}
1283
1284
1285 \end{document}