Debian Codegraph @

texmf-dist/source/fontinst/base/ficommon.dtx

raw
1 % \CheckSum{2283}
2 % \iffalse meta-comment
3 %
4 % Copyright 1993, 1994, 1995, 1996 Alan Jeffrey,
5 % hacked and maintained 1997, 1998 Sebastian Rahtz,
6 % copyright 1998, 1999, 2000, 2001 the fontinst maintenance team and
7 % any individual authors listed elsewhere in this file.
8 % All rights reserved.
9 %
10 % This file is part of the fontinst system version 1.9.
11 % -----------------------------------------------------
12 %
13 % It may be distributed under the terms of the LaTeX Project Public
14 % License, as described in lppl.txt in the base LaTeX distribution.
15 % Either version 1.2 or, at your option, any later version.
16 %
17 %%% From file: ficommon.dtx
18 %
19 %<*driver>
20 \documentclass{ltxdoc}
21 \usepackage{fisource}
22 \title{The \package{fontinst} utility}
23 \author{Alan Jeffrey, Sebastian Rahtz, Ulrik Vieth, Lars Hellstr\"om}
24 \begin{document}
25 \maketitle
26 \tableofcontents
27 \DocInput{ficommon.dtx}
28 \end{document}
29 %</driver>
30 % \fi
31 %
32 % \StopEventually{}
33 %
34 %
35 % \section{General commands}
36 % \changes{1.916}{2000/12/27}{Moved Section \thesection\ to
37 % \texttt{ficommon.dtx}. (LH)}
38 %
39 % \changes{1.916}{2001/01/02}{\emph{Major} overhaul of \package{fontdoc}
40 % mechanisms for integer and string expressions completed. (LH)}
41 % There are roughly five types of arguments that \package{fontinst}
42 % commands can take. These are
43 % \begin{itemize}
44 % \item integer expressions,
45 % \item string expressions,
46 % \item dimensions,
47 % \item commands (i.e., \TeX\ control sequences), and
48 % \item other (pretty much ``none of the above'').
49 % \end{itemize}
50 % The most common form of an integer expression is simply a \TeX\
51 % \meta{number} and the most common form of a string expression is
52 % simply a sequence of character tokens, but there are more complicated
53 % forms. Dimensions are simply \TeX\ \meta{dimen}s; their use is rather
54 % limited. Common to integer expressions, string expressions, and
55 % dimensions is that these argument types get expanded during
56 % evaluation (in the case of string expressions, this expansion
57 % \emph{is} the evaluation), which means one can use macros in
58 % arguments of these types.
59 %
60 % Command arguments do not get expanded---they are mainly used with
61 % commands that modify the definitions of other commands. As for the
62 % ``other'' arguments one cannot give any rules: they might get
63 % expanded, but it could also happen that they won't.
64 %
65 %
66 % \subsection{String expressions}
67 %
68 % The first problem with string expressions is to typeset the values.
69 % The character strings that appear in ETX and MTX files usually consist
70 % only of immediately printable characters, but there are a few
71 % characters (such as underscore) which may be used even though they
72 % aren't directly printable. This subsection defines commands which deal
73 % with this problem by replacing non-printable characters by commands.
74 % The implementation is based on the implementation of the
75 % |\MakeHarmless| command in the \package{xdoc} package.
76 %
77 % \subsubsection{Typesetting problematic characters}
78 %
79 % \begin{macro}{\PrintChar}
80 % \begin{macro}{\InvisibleCharPrefix}
81 % \begin{macro}{\InvisibleCharSuffix}
82 % The |\PrintChar| command has the syntax
83 % \begin{quote}
84 % |\PrintChar|\marg{8-bit number}
85 % \end{quote}
86 % where \meta{8-bit number} is a \TeX\ number in the range 0--255.
87 % For arguments in the range 0--31, |\PrintChar| prints
88 % `\textit{\ttfamily\string^\string^@}'--`\textit{\ttfamily
89 % \string^\string^_}'. For an argument in the range 32--126,
90 % |\PrintChar| calls |\Print|\-|Visible|\-|Char| which typesets the
91 % corresponding ASCII character (similar to |\char|, but it takes the
92 % path via the \LaTeX\ internal representation so that it works with
93 % non-typewriter \texttt{OT1} fonts); in particular, |\PrintChar{32}|
94 % prints a ``visible space'' character. |\PrintChar{127}| prints
95 % `\textit{\ttfamily\string^\string^?}'. For arguments in the range
96 % 128--255, |\PrintChar| prints
97 % `\textit{\ttfamily\string^\string^80}'--`\textit{\ttfamily
98 % \string^\string^ff}'.
99 % The |\PrintChar| command is robust.
100 %
101 % The macros |\InvisibleCharPrefix| and |\InvisibleCharSuffix| begin
102 % and end a |^^|-sequence. |\InvisibleCharPrefix| should print the
103 % actual |^^|, but it may also for example select a new font for
104 % the |^^|-sequence (such font changes are restored at the end of
105 % |\PrintChar|).
106 % \begin{macrocode}
107 %<*doc>
108 \DeclareRobustCommand\PrintChar[1]{%
109 \leavevmode
110 \begingroup
111 \count@=#1\relax
112 \ifnum \@xxxii>\count@
113 \advance \count@ 64%
114 \InvisibleCharPrefix
115 \PrintVisibleChar\count@
116 \InvisibleCharSuffix
117 \else\ifnum 127>\count@
118 \PrintVisibleChar\count@
119 \else
120 \InvisibleCharPrefix
121 \ifnum 127=\count@ \PrintVisibleChar{63}\else
122 \@tempcnta=\count@
123 \divide \count@ \sixt@@n
124 \@tempcntb=\count@
125 \multiply \count@ \sixt@@n
126 \advance \@tempcnta -\count@
127 \advance \@tempcntb \ifnum 9<\@tempcntb 87\else 48\fi
128 \advance \@tempcnta \ifnum 9<\@tempcnta 87\else 48\fi
129 \char\@tempcntb \char\@tempcnta
130 \fi
131 \InvisibleCharSuffix
132 \fi\fi
133 \endgroup
134 }
135 % \end{macrocode}
136 % \begin{macrocode}
137 \newcommand\InvisibleCharPrefix{%
138 \/\em
139 \PrintVisibleChar{`\^}\PrintVisibleChar{`\^}%
140 }
141 \newcommand\InvisibleCharSuffix{\/}
142 % \end{macrocode}
143 % \end{macro}\end{macro}\end{macro}
144 %
145 % \begin{macro}{\PrintVisibleChar}
146 % The |\PrintVisibleChar| command should print the visible ASCII
147 % character whose character code is given in the argument. The
148 % definition given here translates every character code to the
149 % corresponding \LaTeX\ internal representation, which is necessary
150 % if the current font is e.g.\ an \texttt{OT1}-encoded non-typewriter
151 % font. If the current font is known to be \texttt{T1}-encoded then
152 % one can do just as well with |\char#1 | as the replacement text.
153 % \begin{macrocode}
154 \newcommand\PrintVisibleChar[1]{%
155 \ifcase #1%
156 \or\or\or\or\or\or\or\or \or\or\or\or\or\or\or\or
157 \or\or\or\or\or\or\or\or \or\or\or\or\or\or\or\or
158 % "20
159 \textvisiblespace \or!\or\textquotedbl \or\#\or\textdollar
160 \or\%\or\&\or\textquoteright\or(\or)\or*\or+\or,\or-\or.\or/%
161 \or % "30
162 0\or1\or2\or3\or4\or5\or6\or7\or8\or9\or:\or;\or
163 \textless\or=\or\textgreater\or?%
164 \or % "40
165 @\or A\or B\or C\or D\or E\or F\or G\or
166 H\or I\or J\or K\or L\or M\or N\or O%
167 \or % "50
168 P\or Q\or R\or S\or T\or U\or V\or W\or X\or Y\or Z\or [\or
169 \textbackslash \or]\or\textasciicircum \or\textunderscore
170 \or % "60
171 \textquoteleft \or a\or b\or c\or d\or e\or f\or g\or h\or
172 i\or j\or k\or l\or m\or n\or o%
173 \or % "70
174 p\or q\or r\or s\or t\or u\or v\or w\or x\or y\or z\or
175 \textbraceleft \or\textbar \or\textbraceright \or\textasciitilde
176 \fi
177 }
178 % \end{macrocode}
179 % \end{macro}
180 %
181 % \begin{macro}{\textvisiblespace}
182 % The |\textvisiblespace| command, which is heavily used in names of
183 % coding schemes, unfortunately has a default definition which lacks
184 % leading on the right side. This redefinition attempts to improve
185 % things.
186 % \changes{1.921}{2002/03/27}{Redefinition added. (LH)}
187 % \begin{macrocode}
188 \DeclareTextCommandDefault{\textvisiblespace}{%
189 \makebox[\fontdimen\tw@\font]{%
190 \hfil
191 \vrule \@height.3ex%
192 \vbox{\hrule \@width .66\fontdimen\tw@\font}%
193 \vrule \@height.3ex%
194 \hfil
195 }%
196 }
197 % \end{macrocode}
198 % \end{macro}
199 %
200 % \begin{macro}{\FD@quoted@PrintChar}
201 % One sometimes wants to use a printable character string as part of a
202 % control sequence name. If the normal definition of |\PrintChar| is
203 % in force at such times then each |\PrintChar| in the string would
204 % produce lots of errors, which is why |\FD@quoted@PrintChar| has
205 % been defined. This macro is an alternative definition of
206 % |\PrintChar| which expands to |"|\meta{number}|"|, which can be part
207 % of a macro name.
208 % \begin{macrocode}
209 \def\FD@quoted@PrintChar#1{"\number#1"}
210 % \end{macrocode}
211 % \end{macro}
212 %
213 %
214 % \subsubsection{Converting character strings}
215 %
216 % Replacing all problematic characters with |\PrintChar| calls certainly
217 % makes the strings easier to manage, but actually making those
218 % replacements is a rather complicated task. This subsubsection
219 % contains the macros necessary for doing these replacements.
220 %
221 % The first problem is how to efficiently recognise the problematic
222 % characters. One might think that it is sufficient to look at their
223 % |\catcode|, but that will fail for characters like |<| whose normal
224 % catcode is 12 but do not appear in the \texttt{OT1} encoding. Because
225 % of this, I have chosen a brute strength solution: build a table
226 % (indexed by character code) that gives the printable form of
227 % every character. This table is stored in the
228 % \describecsfamily{FD@printable@\meta{code}}^^A
229 % |\FD@printable@|\meta{code} family of control sequences, where the
230 % \meta{code} is in the range |32|--|126|. The printable form of
231 % characters outside this range is always the |\PrintChar| form.
232 % \begin{macrocode}
233 \count@=32
234 \begingroup
235 \catcode\z@=12\relax
236 \@firstofone{%
237 \endgroup
238 \loop
239 \if \ifnum 11=\catcode\count@ 1\else \ifnum 12=\catcode\count@
240 1\else 0\fi\fi 1%
241 \uccode\z@=\count@
242 \uppercase{\def\@tempa{^^@}}%
243 \else
244 \edef\@tempa{\noexpand\PrintChar{\the\count@}}%
245 \fi
246 \x@cs\let{FD@printable@\the\count@}=\@tempa
247 \advance \count@ \@ne
248 \ifnum 127>\count@ \repeat
249 }
250 % \end{macrocode}
251 % This loop hasn't caught all non-printable characters, so a few
252 % entries have to be set explicitly.
253 % \begin{macrocode}
254 \@namedef{FD@printable@34}{\PrintChar{34}} % "
255 \@namedef{FD@printable@60}{\PrintChar{60}} % <
256 \@namedef{FD@printable@62}{\PrintChar{62}} % >
257 % \end{macrocode}
258 %
259 %
260 % \begin{macro}{\MakePrintable}
261 % To render a character string harmless, you do
262 % \begin{quote}
263 % |\MakePrintable|\marg{macro}\marg{flag}\marg{string}
264 % \end{quote}
265 % This locally assigns to \meta{macro} the printable character string
266 % which corresponds to \meta{string}. Furthermore the control sequence
267 % |\if|\meta{flag} is locally let to |\iftrue| or |\iffalse|
268 % depending on whether the printable string is simple (only consists
269 % of character tokens and |\PrintChar| commands) or not.
270 %
271 % During the conversion the converted part of the string is stored in
272 % |\toks@| and the |@tempswa| switch keeps track of whether the string
273 % so far is simple (yes when |false|), but those are both local to
274 % |\MakePrintable|.
275 % \begin{macrocode}
276 \def\MakePrintable#1#2#3{%
277 \begingroup
278 \toks@={}%
279 \escapechar=`\\%
280 \@tempswafalse
281 \FD@printable@#3\protect\FD@printable@
282 \toks@=\expandafter{%
283 \expandafter\let \csname if#2\expandafter\endcsname
284 \csname if\if@tempswa false\else true\fi \expandafter\endcsname
285 \expandafter\def \expandafter#1\expandafter{\the\toks@}%
286 }%
287 \expandafter\endgroup \the\toks@
288 }
289 % \end{macrocode}
290 % \end{macro}
291 %
292 % \begin{macro}{\FD@printable@iii}
293 % \begin{macro}{\FD@printable@iv}
294 % \begin{macro}{\FD@printable@v}
295 % \begin{macro}{\FD@printable@vi}
296 % What one has to be most careful about when making strings printable
297 % are the space tokens, since many of \TeX's primitives gladly
298 % snatches an extra space (or more) where you don't want them to in
299 % this case. Macro parameters can be particularly dangerous, as \TeX\
300 % will skip any number of spaces while looking for the replacement
301 % text for an undelimited macro argument. Therefore the algorithm for
302 % rendering a character token harmless consists begins
303 % (|\FD@printable@iii|) with |\string|ing the next token in the
304 % string---this preserves the character code and sets the category to
305 % 12 for all characters except the ASCII space, which gets category 10
306 % (space)---and then |\futurelet| is used to peek at the next token. If
307 % it is a space token (|\FD@printable@iv|) then the character code
308 % is 32 and the actual space can be gobbled (|\FD@printable@v|), and
309 % if it isn't then the next token can be grabbed in a undelimited macro
310 % argument (|\FD@printable@vi|). In either case, the harmless form
311 % is given by the |\FD@printable@|\meta{code} table entry
312 % (in |\FD@printable@v| or |\FD@printable@vi|).
313 % \begin{macrocode}
314 \def\FD@printable@iii{%
315 \expandafter\futurelet \expandafter\@let@token
316 \expandafter\FD@printable@iv \string
317 }
318 % \end{macrocode}
319 % \begin{macrocode}
320 \def\FD@printable@iv{%
321 \ifx \@let@token\@sptoken
322 \expandafter\FD@printable@v
323 \else
324 \expandafter\FD@printable@vi
325 \fi
326 }
327 % \end{macrocode}
328 % ^^A Hack:
329 % \begingroup
330 % \expandafter\def \expandafter\MakePrivateLetters \expandafter{^^A
331 % \MakePrivateLetters
332 % \catcode`3=11
333 % \catcode`2=11
334 % }
335 % \begin{macrocode}
336 \begingroup
337 \catcode`3=\catcode`a
338 \catcode`2=\catcode`a
339 \@firstofone{\gdef\FD@printable@v} {%
340 \toks@=\expandafter{\the \expandafter\toks@ \FD@printable@32}%
341 \FD@printable@
342 }
343 \endgroup
344 % \end{macrocode}
345 % \endgroup
346 % \begin{macrocode}
347 \def\FD@printable@vi#1{%
348 \if \ifnum `#1<\@xxxii 1\else \ifnum `#1>126 1\else 0\fi\fi 1%
349 \toks@=\expandafter{\the\expandafter\toks@
350 \expandafter\PrintChar \expandafter{\number`#1}%
351 }%
352 \else
353 \toks@=\expandafter{\the\expandafter\expandafter\expandafter\toks@
354 \csname FD@printable@\number`#1\endcsname}%
355 \fi
356 \FD@printable@
357 }
358 % \end{macrocode}
359 % \end{macro}\end{macro}\end{macro}\end{macro}
360 %
361 % \begin{macro}{\FD@printable@}
362 % \begin{macro}{\FD@printable@i}
363 % \begin{macro}{\FD@printable@ii}
364 % \begin{macro}{\FD@printable@vii}
365 % But that is not all |\MakePrintable| can do. One must also deal
366 % with things in the string that are not simply characters, but more
367 % complex items (for example |\str| and |\strint| constructions). When
368 % control sequences that start such complex items are fed to
369 % |\MakePrintable| they must be preceeded by a |\protect| (they will
370 % be if the original command is defined using \LaTeX's
371 % |\Declare|\-|Robust|\-|Command| command and the string has been fed
372 % through a |\protected@edef|, which happens to be the case); this
373 % |\protect| is taken as a signal that the next token should get
374 % special processing. Control sequences that are not preceeded by a
375 % |\protect| are simply |\string|ed.
376 %
377 % To accommodate for this, |\FD@printable@| (which is the first step
378 % in converting a token) always begins by checking (in |\FD@|\-^^A
379 % |printable@i|) whether the next token is a control sequence. If it
380 % is and that control sequence is |\protect| then it is checked (in
381 % |\FD@printable@ii|) whether the control sequence
382 % \describecsfamily{FD@printable\PrintChar{`\\}\meta{cs-name}}^^A
383 % |\FD@printable\|\meta{cs-name}, where \meta{cs-name} is the name
384 % without |\| (and with any spaces removed) of the control sequence
385 % encountered, is defined. If it is defined then control is handed
386 % over to |\FD@printable\|\meta{cs-name} which should process the
387 % arguments (if any) of |\|\meta{cs-name} and add a suitable
388 % representation to |\toks@|, but if |\FD@printable\|\meta{cs-name}
389 % isn't defined then this is considered to be an error.
390 %
391 % If the next token isn't a control sequence then control is handed
392 % over to |\FD@printable@ii|. If the next token is a control sequence
393 % but not |\protect| then that token is |\string|ed (in
394 % |\FD@printable@vii|) and control is handed over to
395 % |\FD@printable@vi|.
396 % \begin{macrocode}
397 \def\FD@printable@{\futurelet\@let@token \FD@printable@i}
398 % \end{macrocode}
399 % \begin{macrocode}
400 \def\FD@printable@i{%
401 \csname FD@printable@%
402 \ifcat \noexpand\@let@token \noexpand\FD@printable@
403 \ifx \@let@token\protect ii\else vii\fi
404 \else iii\fi
405 \endcsname
406 }
407 % \end{macrocode}
408 % \begin{macrocode}
409 \def\FD@printable@ii\protect#1{%
410 \@ifundefined{FD@printable\expandafter\zap@space\string#1 \@empty}{%
411 \PackageError{fontdoc}{Command \protect#1 not allowed in string}%
412 \@eha
413 }{\csname FD@printable\expandafter\zap@space\string#1 \@empty
414 \endcsname}%
415 }
416 % \end{macrocode}
417 % \begin{macrocode}
418 \def\FD@printable@vii{\expandafter\FD@printable@vi \string}
419 % \end{macrocode}
420 % \end{macro}\end{macro}\end{macro}\end{macro}
421 %
422 % \begin{macro}{\FD@printable\FD@printable@}
423 % A control sequence |\FD@printable\|\meta{cs-name} is responsible for
424 % interpreting the string item that begins with the control sequence
425 % |\|\meta{cs-name} and appending a printable representation of it to
426 % |\toks@|. Normal |\FD@printable\|\meta{cs-name} control sequences
427 % must also end by inserting |\FD@printable@| in front of what remains
428 % of the string after the complex string item has been removed. This
429 % sees to that the rest of the string is also made printable. The only
430 % such control sequence which does not insert |\FD@printable@| is
431 % |\FD@printable\FD@printable@|, but that is as it should be since
432 % |\MakePrintable| itself appends a |\FD@printable@| to every character
433 % string it should convert to mark the end of it.
434 % \begin{macrocode}
435 \expandafter\let
436 \csname FD@printable\string\FD@printable@\endcsname \@empty
437 % \end{macrocode}
438 % \end{macro}
439 %
440 % \begin{macro}{\FD@printable\PrintChar}
441 % It is occasionally convenient to use a |\PrintChar| command as part
442 % of a string that is to be made harmless instead of using the raw
443 % character. The definition is very similar to that of
444 % |\FD@printable@vi|.
445 % \begin{macrocode}
446 \@namedef{FD@printable\string\PrintChar}#1{%
447 \if \ifnum #1<\@xxxii 1\else \ifnum #1>126 1\else 0\fi\fi 1%
448 \toks@=\expandafter{\the\expandafter\toks@
449 \expandafter\PrintChar \expandafter{\number#1}%
450 }%
451 \else
452 \toks@=\expandafter{\the\expandafter\expandafter\expandafter\toks@
453 \csname FD@printable@\number#1\endcsname}%
454 \fi
455 \FD@printable@
456 }
457 % \end{macrocode}
458 % \end{macro}
459 %
460 %
461 % \begin{macro}{\ExpandAndMakePrintable}
462 % The |\ExpandAndMakePrintable| command is an abbreviation for a
463 % common use of |\MakePrintable|, namely to first feed the string
464 % through a |\protected@edef| to get rid of all the simple macros.
465 % \begin{macrocode}
466 \newcommand*\ExpandAndMakePrintable[3]{%
467 \protected@edef\@tempa{{#2}{#3}}%
468 \expandafter\MakePrintable \expandafter#1\@tempa
469 }
470 %</doc>
471 % \end{macrocode}
472 % \end{macro}
473 %
474 %
475 % \subsubsection{Evaluating string expressions}
476 %
477 % In string expressions, the only available operation is juxtaposition
478 % (fancy name for putting things next to each other) and thus the
479 % syntax for a string expression is
480 % \begin{quote}
481 % \meta{string expression} \(\longrightarrow\) $\emptyset \mid$
482 % \meta{string atom}\meta{string expression}
483 % \end{quote}
484 % where $\emptyset$ denotes the empty string. A \meta{string atom} is
485 % one of
486 % \begin{quote}
487 % \meta{character token}\\
488 % |\str|\marg{string expression}\\
489 % |\strint|\marg{string expression}
490 % \end{quote}
491 % The meaning of a \meta{character token} is explained
492 % in~\cite{TeXbook}. The |\str| and |\strint| forms of
493 % \marg{string atom} refer to the respective values of the string and
494 % integer variables (see Subsection~\ref{Ssec:Variables}) whose names
495 % are given in the argument of |\str| or |\strint| respectively. Since
496 % the names of variables are themselves string expressions, |\str| and
497 % |\strint| may themselves be used in names of variables.
498 %
499 % It should be noted that most of \package{fontinst}'s string
500 % expressions sooner or later end up between a |\csname| and the
501 % corresponding |\endcsname|. This places significant restrictions on
502 % what may occur in string expressions.
503 %
504 % \begin{macro}{\str}
505 % \begin{macro}{\strint}
506 % \changes{1.909}{1999/10/19}{Change to stop it from gobbling a
507 % following space if the integer is stored in a macro. (LH)}
508 % In \package{fontinst} the only macros needed for dealing with string
509 % expressions are |\str| and |\strint|.
510 % \begin{macrocode}
511 %<*pkg>
512 \def\str#1{\csname~s-#1\endcsname}
513 \def\strint#1{\expandafter\identity_one\expandafter{\number\int{#1}}}
514 %</pkg>
515 % \end{macrocode}
516 % \end{macro}\end{macro}
517 %
518 % \package{fontdoc} mainly uses \TeX's text mode for typesetting string
519 % expressions because not all characters are available in math mode;
520 % it's easier to switch to text mode than to augment the math setup. One
521 % kind of material is however typeset in math mode, namely
522 % ``string-valued functions'': the name and functional parenthesis of
523 % such material is typeset in math mode to get a mathematical look.
524 %
525 % \begin{macro}{\FD@string@func}
526 % The |\FD@string@func| macro has the syntax
527 % \begin{quote}
528 % |\FD@string@func|\marg{name}\marg{argument}
529 % \end{quote}
530 % It is used for typesetting the \meta{name}$($\meta{argument}$)$ of a
531 % string-valued function (e.g.\ the value-of-string-variable function
532 % $\mathrm{s}$). It should only be used in horizontal mode.
533 %
534 % |\FD@string@func| includes a bit of extra spacing around the typeset
535 % text, but not at the beginning or end of a string and neither
536 % between two string-valued functions. As a flag for this is used
537 % that the value of |\spacefactor| is 1; when it is one should proceed
538 % as if this extra spacing is already present.
539 % \begin{macrocode}
540 %<*doc>
541 \def\FD@string@func#1#2{%
542 \relax
543 \ifnum \spacefactor=\@ne $\mkern1mu\else$\fi
544 \mathrm{#1}($%
545 #2%
546 \ifnum \spacefactor=\@ne $\mkern-1mu\else $\fi)\mkern1mu$%
547 \spacefactor=\@ne
548 }
549 % \end{macrocode}
550 % \end{macro}
551 %
552 % \begin{macro}{\TypesetStringExpression}
553 % \begin{macro}{\FD@typeset@string}
554 % \begin{macro}{\ifFD@swa}
555 % In \package{fontdoc} the string expressions must be typeset, and
556 % that is not trivial due to that (i) not all character tokens have
557 % catcode 11 or 12 and (ii) not all characters are available in all
558 % fonts. Furthermore the non-character string atoms should be given
559 % special treatment in character strings!
560 %
561 % Because of this, string expressions that are to be typeset are
562 % handed to a special command |\TypesetStringExpression|, which takes
563 % the string to typeset as its only argument. This string may contain
564 % user-defined macros.
565 % \begin{macrocode}
566 \newcommand\TypesetStringExpression[1]{%
567 \protected@edef\@tempa{%
568 \noexpand\MakePrintable \noexpand\@tempa {FD@swa}{#1}%
569 }%
570 \@tempa
571 \FD@typeset@string{\@tempa}%
572 }
573 % \end{macrocode}
574 % Actually typesetting the string is handled in |\FD@typeset@string|,
575 % but strings handed to this macro must be preprocessed by a full
576 % protected expansion and a |\MakeHarmless|.
577 % \begin{macrocode}
578 \def\FD@typeset@string#1{%
579 \mbox{%
580 \normalfont\ttfamily
581 \spacefactor=\@ne
582 #1%
583 \ifnum \spacefactor=\@ne $\mkern-1mu\m@th$\fi
584 }%
585 }
586 % \end{macrocode}
587 % The |\ifFD@swa| control sequence is often |\let| to |\iftrue| or
588 % |\iffalse| by |\Make|\-|Printable|, and then it is used as a
589 % conditional. Since that assignment sometimes takes place in
590 % conditional text however, one must make sure that |\ifFD@swa|
591 % always is some conditional.
592 % \begin{macrocode}
593 \let\ifFD@swa\iffalse
594 % \end{macrocode}
595 % \end{macro}\end{macro}\end{macro}
596 %
597 % \begin{macro}{\str}
598 % \begin{macro}{\FD@printable\str}
599 % The processing of the |\str| macro in \package{fontdoc} is far from
600 % straightforward. |\str| has to be robust, but apart from that its
601 % defintion has no effect on how its argument is processed. That is
602 % instead controlled by |\FD@printable\str|, which happens to use
603 % |\str| as an auxiliary formatting macro.
604 %
605 % Most of the complexity below is however due to the processing
606 % needed to determine whether the string variable accessed has been
607 % assigned a value. See |\Set|\-|String|\-|Variable| for more
608 % information.
609 % \begin{macrocode}
610 \DeclareRobustCommand\str[1]{\FD@string@func{s}{#1}}
611 \@namedef{FD@printable\string\str}#1{%
612 \MakePrintable\@tempa{FD@swa}{#1}%
613 \begingroup
614 \let\PrintChar=\FD@quoted@PrintChar
615 \if \ifFD@swa \@ifundefined{FD@s-\@tempa}{0}{1}\else 0\fi 1%
616 \expandafter
617 \endgroup
618 \csname FD@s-\@tempa\endcsname
619 \else
620 \endgroup
621 \toks@=\expandafter{\the\expandafter\toks@
622 \expandafter\str \expandafter{\@tempa}}%
623 \@tempswatrue
624 \fi
625 \FD@printable@
626 }
627 % \end{macrocode}
628 % \end{macro}\end{macro}
629 %
630 %
631 % \begin{macro}{\strint}
632 % \begin{macro}{\FD@printable\strint}
633 % |\strint| is handled similarly to |\str|.
634 % \begin{macrocode}
635 \DeclareRobustCommand\strint[1]{\FD@string@func{int}{#1}}
636 \@namedef{FD@printable\string\strint}#1{%
637 \MakePrintable\@tempa{FD@swa}{#1}%
638 \protected@edef\@tempa{%
639 \ifFD@swa \protect\FD@simple@int \else \strint \fi{\@tempa}%
640 }
641 \toks@=\expandafter{\the\expandafter\toks@ \@tempa}%
642 \@tempswatrue
643 \FD@printable@
644 }
645 % \end{macrocode}
646 % \end{macro}\end{macro}
647 %
648 % \begin{macro}{\macroparameter}
649 % \changes{1.916}{2001/01/06}{Command added. (LH)}
650 % \begin{macro}{\FD@printable\macroparameter}
651 % The |\macroparameter| command can be used in string and integer
652 % expressions as a sort of ``macro parameter placeholder''. It is not
653 % defined in \package{fontinst}, but in \package{fontdoc} one
654 % occationally writes comments which say things like ``XXX is short
655 % for ASDFSKADN'', and in those cases one can use |\macroparameter|
656 % as a placeholder for an argument. The syntax is
657 % \begin{quote}
658 % |\macroparameter|\marg{digit}
659 % \end{quote}
660 % where \meta{digit} should be a decimal digit between |1| and |9|
661 % inclusive.
662 %
663 % The definition in |\macroparameter| handles uses of the command in
664 % integer expressions, whereas |\FD@printable\macroparameter| takes
665 % care of uses in string expressions.
666 % \begin{macrocode}
667 \DeclareRobustCommand\macroparameter[1]{%
668 \gdef\FD@expression{\text{\normalfont\itshape\##1}}%
669 \global\chardef\FD@priority=5%
670 \global\FD@bracket@level=\z@
671 \FD@evaluate@false
672 }
673 \@namedef{FD@printable\string\macroparameter}#1{%
674 \toks@=\expandafter{\the\toks@\textrm{\emph{\##1}}}%
675 \@tempswatrue
676 \FD@printable@
677 }
678 %</doc>
679 % \end{macrocode}
680 % \end{macro}\end{macro}
681 %
682 %
683 %
684 % \subsection{Integer expressions}
685 %
686 % An \meta{integer expression} is one of the following:
687 % \begin{quote}
688 % \meta{number}\\
689 % |\int|\marg{string expression}\\
690 % |\neg|\marg{integer expression}\\
691 % |\add|\marg{integer expression}\marg{integer expression}\\
692 % |\sub|\marg{integer expression}\marg{integer expression}\\
693 % |\max|\marg{integer expression}\marg{integer expression}\\
694 % |\min|\marg{integer expression}\marg{integer expression}\\
695 % |\mul|\marg{integer expression}\marg{integer expression}\\
696 % |\div|\marg{integer expression}\marg{integer expression}\\
697 % |\half|\marg{integer expression}\\
698 % |\otherhalf|\marg{integer expression}\\
699 % |\scale|\marg{integer expression}\marg{integer expression}\\
700 % |\width|\marg{string expression}\\
701 % |\height|\marg{string expression}\\
702 % |\depth|\marg{string expression}\\
703 % |\italic|\marg{string expression}\\
704 % |\kerning|\marg{string expression}\marg{string expression}
705 % \end{quote}
706 % \meta{number} is any \TeX\ number, as defined in~\cite{TeXbook}. The
707 % \meta{string expression} in the argument of |\int| must be the name of
708 % an integer variable which is currently set, i.e., the condition
709 % \begin{quote}
710 % |\ifisint|\marg{string expression}|\then|
711 % \end{quote}
712 % must evaluate to true. Likewise the \meta{string expression} in the
713 % argument of |\width|, |\height|, |\depth|, and |\italic| must be the
714 % name of a glyph which is currently set, i.e., the condition
715 % \begin{quote}
716 % |\ifisglyph|\marg{string expression}|\then|
717 % \end{quote}
718 % must evaluate to true.
719 %
720 % \begin{macro}{\eval_expr}
721 % \begin{macro}{\eval_expr_to}
722 % \begin{macro}{\g_eval_expr_to}
723 % \begin{macro}{\result}
724 % The only thing \package{fontinst} does with integer expressions is
725 % evaluating them. The macro
726 % \begin{quote}
727 % |\eval_expr|\marg{integer expression}
728 % \end{quote}
729 % globally assigns |\result| to the value of
730 % \meta{integer expression}, and changes the value of no other
731 % counters.
732 %
733 % The macro
734 % \begin{quote}
735 % |\eval_expr_to|\marg{\TeX\ integer variable}^^A
736 % \marg{integer expression}
737 % \end{quote}
738 % locally assigns the value of \meta{integer expression} to
739 % \meta{\TeX\ integer variable} (which is an integer variable as
740 % defined in~\cite{TeXbook}).
741 % |\g_eval_expr_to| does the same globally.
742 %
743 % \begin{macrocode}
744 %<*pkg>
745 \newcount\result
746 \def\eval_expr#1{\global\result=#1\x_relax}
747 \def\eval_expr_to#1#2{\eval_expr{#2}#1=\result}
748 \def\g_eval_expr_to#1#2{\eval_expr{#2}\global#1=\result}
749 %</pkg>
750 % \end{macrocode}
751 % \end{macro}\end{macro}\end{macro}\end{macro}
752 %
753 %
754 % \begin{macro}{\TypesetIntegerExpression}
755 % In \package{fontdoc} the main task is instead to typeset the
756 % expression as a mathematical formula, but in some cases one wants to
757 % know its value as well (if possible). Therefore things get a bit
758 % more complex in that context. The top-level command there is
759 % \begin{quote}
760 % |\TypesetIntegerExpression|\marg{integer expression}
761 % \end{quote}
762 % which typesets the \meta{integer expression} by first forming (in the
763 % |\FD@expression| macro) code for typesetting the integer expression.
764 % |\Typeset|\-|Integer|\-|Expression| should be only be used in math
765 % mode.
766 %
767 % Most of the work in |\TypesetIntegerExpression| is carried out by
768 % the |\FD@eval@expr| macro and hence |\TypesetIntegerExpression| sets
769 % a couple of other variables as explained below. Apart from the fact
770 % that |\FD@eval@expr| doesn't actually typeset anything, the main
771 % difference between it and |\Typeset|\-|Integer|\-|Expression| is that
772 % the latter also accepts code that after expansion will become integer
773 % expressions, whereas the former requires that all such macros have
774 % first been expanded.
775 % \begin{macrocode}
776 %<*doc>
777 \newcommand\TypesetIntegerExpression[1]{%
778 \protected@edef\@tempa{#1}%
779 \expandafter\FD@eval@expr \expandafter{\@tempa}%
780 \FD@expression
781 }
782 % \end{macrocode}
783 % \end{macro}
784 %
785 % \begin{macro}{\FD@expression}
786 % \begin{macro}{\FD@result}
787 % \begin{macro}{\FD@priority}
788 % \begin{macro}{\FD@bracket@level}
789 % \begin{switch}{FD@evaluate@}
790 % The |\FD@expression| macro, |\FD@result| and |\FD@bracket@level|
791 % count registers, the |\FD@priority| chardef token, and the
792 % |FD@evaluate@| switch are used by \package{fontdoc} when formatting
793 % and evaluating an integer expression. They are all assigned globally.
794 %
795 % The |\FD@expression| macro contains code for typesetting an
796 % expression. |\FD@priority| is a chardef token whose numerical value
797 % specifies the priority of the outermost operation in
798 % |\FD@expression| according to the following table:
799 % \begin{enumerate}
800 % \item[0]
801 % Outermost operation is $+$ or $-$.
802 % \item[1]
803 % Outermost operation is explicit multiplication ($\cdot$) or
804 % division $/$. If it is one of the factors in a product then
805 % that multiplication must be explicit.
806 % \item[2]
807 % Outermost operation is explicit multiplication. If it is to be
808 % the right factor in a product, then the multiplication must be
809 % made explicit too.
810 % \item[3]
811 % Outermost operation is explicit multiplication. It
812 % does not need to be explicitly multiplied.
813 % \item[4]
814 % Outermost operation is implicit multiplication (juxtaposition),
815 % unary prefix (unary $-$) or something which is bracketed anyway.
816 % If it is to be the right factor in a product, then that
817 % multiplication should be made explicit too. A typical example
818 % of this kind of thing is an explicit negative number.
819 % \item[5]
820 % Outermost operation is implicit multiplication (juxtaposition)
821 % or something which is bracketed anyway. It does not need to be
822 % explicitly multiplied.
823 % \item[6]
824 % The expression is an explicit non-negative number. If it is to
825 % be the right factor in a product, then the multiplication
826 % should be made explicit.
827 % \end{enumerate}
828 % |\FD@bracket@level| keeps track of what parenthesis size one must
829 % use to cover the expression in |\FD@expression|: 0 is the normal
830 % size, 1 is |\big| size, 2 is |\Big| size, etc. The |FD@evaluate@|
831 % switch specifies whether |\FD@eval@expr| should try to (upon entry)
832 % or managed to (after it is completed) evaluate the integer
833 % expression (true is evaluate, false is don't bother). When the value
834 % has been evaluated, it is returned in |\FD@result|.
835 % \begin{macrocode}
836 \newcount\FD@result
837 \newcount\FD@bracket@level
838 \def\FD@evaluate@true{\global\let\ifFD@evaluate@\iftrue}
839 \def\FD@evaluate@false{\global\let\ifFD@evaluate@\iffalse}
840 \FD@evaluate@false
841 % \end{macrocode}
842 % \end{switch}\end{macro}\end{macro}\end{macro}\end{macro}
843 %
844 % \begin{macro}{\FD@eval@expr}
845 % The |\FD@eval@expr| macro has the syntax
846 % \begin{quote}
847 % |\FD@eval@expr|\marg{integer expression}
848 % \end{quote}
849 % It puts code for typesetting the \meta{integer expression} in the
850 % |\FD@expression| macro, sets |\FD@bracket@level| to the
851 % corresponding value, and if |FD@evaluate@| is true it also tries to
852 % evaluate the expression and put the result in |\FD@result|.
853 %
854 % More precisely, |\FD@eval@expr| only handles the \meta{\TeX~number}
855 % cases of integer expression. In the other cases the first token in
856 % the integer expression is a robust command which should take care of
857 % building the expression as needed.
858 % \begin{macrocode}
859 \def\FD@eval@expr#1{%
860 \expandafter\expandafter \expandafter\ifx
861 \expandafter\@car#1\x@relax\@nil \protect
862 #1%
863 \else\ifcat \expandafter\noexpand \@car#1\x@relax\@nil 0%
864 \global\FD@result=#1\x@relax
865 \xdef\FD@expression{\the\FD@result}%
866 \global\chardef\FD@priority=\ifnum \FD@result<\z@ 4\else 6\fi
867 \global\FD@bracket@level=\z@
868 \else
869 \begingroup
870 \MakePrintable\@tempa{FD@swa}{#1}%
871 \global\FD@bracket@level=\ifFD@swa\z@\else\@ne\fi
872 \protected@xdef\FD@expression{\protect\mbox{\texttt{\@tempa}}}%
873 \endgroup
874 \global\chardef\FD@priority=5%
875 \FD@evaluate@false
876 \fi\fi
877 }
878 %</doc>
879 % \end{macrocode}
880 % Note: It is important that all groups that are started or ended
881 % during the evaluation of an integer expression are of |\begingroup|
882 % type, since |\bgroup| groups affect spacing in math mode.
883 % \end{macro}
884 %
885 % \begin{macro}{\add}
886 % The |\add| command has the syntax
887 % \begin{quote}
888 % |\add|\marg{integer expression}\marg{integer expression}
889 % \end{quote}
890 % It represents the sum of the two \meta{integer expression}s.
891 % \begin{macrocode}
892 %<*pkg>
893 \def\add#1#2{
894 #1
895 \bgroup
896 \a_count=\result
897 \eval_expr{#2}
898 \global\advance \result \a_count
899 \egroup
900 }
901 %</pkg>
902 %<*doc>
903 \DeclareRobustCommand\add[2]{%
904 \begingroup
905 \FD@eval@expr{#1}%
906 \let\@tempa=\FD@expression
907 \ifFD@evaluate@ \a@count=\FD@result \fi
908 \b@count=\FD@bracket@level
909 \FD@eval@expr{#2}%
910 \protected@xdef\FD@expression{\@tempa+\FD@expression}%
911 \ifFD@evaluate@ \global\advance \FD@result \a@count \fi
912 \ifnum \FD@bracket@level<\b@count
913 \global\FD@bracket@level=\b@count
914 \fi
915 \global\chardef\FD@priority=\z@
916 \endgroup
917 }
918 %</doc>
919 % \end{macrocode}
920 % \end{macro}
921 %
922 % \begin{macro}{\sub}
923 % The |\sub| command has the syntax
924 % \begin{quote}
925 % |\sub|\marg{integer expression}\marg{integer expression}
926 % \end{quote}
927 % It represents the difference between the two \meta{integer
928 % expression}s.
929 % \begin{macrocode}
930 %<*pkg>
931 \def\sub#1#2{
932 #1
933 \bgroup
934 \a_count=\result
935 \eval_expr{#2}
936 \advance \a_count -\result
937 \global\result=\a_count
938 \egroup
939 }
940 %</pkg>
941 %<*doc>
942 \DeclareRobustCommand\sub[2]{%
943 \begingroup
944 \FD@eval@expr{#1}%
945 \let\@tempa=\FD@expression
946 \ifFD@evaluate@ \a@count=\FD@result \fi
947 \b@count=\FD@bracket@level
948 \FD@eval@expr{#2}%
949 \ifnum \FD@priority<\@ne \FD@bracket@expression \fi
950 \protected@xdef\FD@expression{\@tempa-\FD@expression}%
951 \ifFD@evaluate@
952 \advance \a@count -\FD@result
953 \global\FD@result=\a@count
954 \fi
955 \ifnum \FD@bracket@level<\b@count
956 \global\FD@bracket@level=\b@count
957 \fi
958 \global\chardef\FD@priority=\z@
959 \endgroup
960 }
961 % \end{macrocode}
962 % \end{macro}
963 %
964 % \begin{macro}{\FD@subexpression}
965 % \begin{macro}{\FD@commapenalty}
966 % The |\FD@subexpression| macro has the syntax
967 % \begin{quote}
968 % |\FD@subexpression|\marg{math mode material}
969 % \end{quote}
970 % It should only be used in math mode and produces results very
971 % similar to \meta{math mode material}, but it locally increases all
972 % the math-related penalties by |\FD@commapenalty| for when the math
973 % mode material is converted to a horizontal list. This allows
974 % linebreaking to take notice of logical nesting in expressions.
975 %
976 % |\FD@commapenalty| is used as a companion of |\relpenalty| and
977 % |\binoppenalty|, but which is used after commas (where \TeX\ doesn't
978 % insert penalties automatically).
979 % \begin{macrocode}
980 \def\FD@subexpression#1{${%
981 \advance \binoppenalty \FD@commapenalty
982 \advance \relpenalty \FD@commapenalty
983 \advance \FD@commapenalty \FD@commapenalty
984 $#1$}$%
985 }
986 \newcount\FD@commapenalty
987 \FD@commapenalty=\binoppenalty
988 \advance \FD@commapenalty \relpenalty
989 % \end{macrocode}
990 % \end{macro}\end{macro}
991 %
992 % \begin{macro}{\FD@bracket@expression}
993 % The |\FD@bracket@expression| brackets the expression currently in
994 % |\FD@expression| by the suitable size of parentheses and updates
995 % |\FD@bracket@level| and |\FD@priority| accordingly.
996 % \begin{macrocode}
997 \def\FD@bracket@expression{%
998 \protected@xdef\FD@expression{%
999 \ifcase\FD@bracket@level \or \protect\bigl \or \protect\Bigl \or
1000 \protect\biggl \else \protect\Biggl \fi (%
1001 \protect\FD@subexpression{\FD@expression}%
1002 \ifcase\FD@bracket@level \or \protect\bigr \or \protect\Bigr \or
1003 \protect\biggr \else \protect\Biggr \fi )%
1004 }%
1005 \global\chardef\FD@priority=5%
1006 \global\advance \FD@bracket@level \@ne
1007 }
1008 %</doc>
1009 % \end{macrocode}
1010 % \end{macro}
1011 %
1012 %
1013 % \begin{macro}{\int}
1014 % \changes{1.909}{1999/10/19}{\package{fontdoc} implementation
1015 % changed to using \cs{typeset@integer}. (LH)}
1016 % \begin{macro}{\FD@simple@int}
1017 % The |\int| command has the syntax
1018 % \begin{quote}
1019 % |\int|\marg{string expression}
1020 % \end{quote}
1021 % It is used to represent the value of the \package{fontinst} integer
1022 % whose name is the value of the \meta{string expression} in integer
1023 % expressions.
1024 %
1025 % The |\FD@simple@int| macro take the printable string form of the
1026 % name of an integer variable as its argument and typesets the
1027 % printed representation of this integer, but it should only be used
1028 % when the argument is a simple string expression. When the argument
1029 % is not a simple string expression, |\FD@integer@func| should be
1030 % used instead. |\FD@simple@int| should only be called in horizontal
1031 % mode.
1032 % \begin{macrocode}
1033 %<pkg>\def\int#1{\csname i-#1 \endcsname}
1034 %<*doc>
1035 \DeclareRobustCommand\int[1]{%
1036 \begingroup
1037 \MakePrintable\@tempa{FD@swa}{#1}%
1038 \protected@xdef\FD@expression{%
1039 \ifFD@swa
1040 \text{\protect\FD@simple@int{\@tempa}}%
1041 \else
1042 \protect\FD@integer@func{int}{\@tempa}%
1043 \fi
1044 }%
1045 \global\chardef\FD@priority=5%
1046 \global\FD@bracket@level=\ifFD@swa\z@\else\@ne\fi
1047 \FD@evaluate@false
1048 \endgroup
1049 }
1050 \def\FD@simple@int#1{{\normalfont\itshape #1\/}}
1051 % \end{macrocode}
1052 % \end{macro}\end{macro}
1053 %
1054 % \begin{macro}{\FD@integer@func}
1055 % The |\FD@integer@func| macro has the syntax
1056 % \begin{quote}
1057 % |\FD@integer@func|\marg{name}\marg{argument}
1058 % \end{quote}
1059 % It is used for typesetting the \meta{name}$($\meta{argument}$)$
1060 % of an integer-valued function which takes a string expression as
1061 % argument (e.g.\ the width-of-glyph function $\mathrm{w}$). It
1062 % should only be used in math mode.
1063 %
1064 % The empty group in the argument of |\mathop| is there to ensure
1065 % that the nucleus of the mathop atom isn't simply a symbol, since
1066 % \TeX\ in that case centers it vertically.
1067 % \begin{macrocode}
1068 \def\FD@integer@func#1#2{%
1069 \mathop{\mathrm{#1}{}}(\text{\FD@typeset@string{#2}})%
1070 }
1071 %</doc>
1072 % \end{macrocode}
1073 % \end{macro}
1074 %
1075 %
1076 % \begin{macro}{\neg}
1077 % The |\neg| command has the syntax
1078 % \begin{quote}
1079 % |\neg|\marg{integer expression}
1080 % \end{quote}
1081 % It represents the negative of the \meta{integer expression}.
1082 % \begin{macrocode}
1083 %<pkg>\def\neg#1{#1 \global\result=-\result}
1084 %<*doc>
1085 \DeclareRobustCommand\neg[1]{%
1086 \FD@eval@expr{#1}%
1087 \ifnum 5>\FD@priority \FD@bracket@expression \fi
1088 \protected@xdef\FD@expression{-\FD@expression}%
1089 \global\chardef\FD@priority=4%
1090 \ifFD@evaluate@ \global\FD@result=-\FD@result \fi
1091 }
1092 %</doc>
1093 % \end{macrocode}
1094 % \end{macro}
1095 %
1096 % \begin{macro}{\mul}
1097 % The |\mul| command has the syntax
1098 % \begin{quote}
1099 % |\mul|\marg{integer expression}\marg{integer expression}
1100 % \end{quote}
1101 % It represents the product of the two \meta{integer expression}s.
1102 % \begin{macrocode}
1103 %<*pkg>
1104 \def\mul#1#2{
1105 #1
1106 \bgroup
1107 \a_count=\result
1108 \eval_expr{#2}
1109 \global\multiply \result \a_count
1110 \egroup
1111 }
1112 %</pkg>
1113 % \end{macrocode}
1114 %
1115 % The main problem in the \package{fontdoc} definition of |\mul| is
1116 % to determine whether the multiplication should be made explicit or
1117 % not, and what priority code the resulting expression should be
1118 % given. It turns out that if the right factor has priority 1 (it is
1119 % a quotient or a product that ends with a quotient) then the
1120 % combined expression will be too, whereas if it isn't but the left
1121 % factor has priority 1 then the combined expression will get
1122 % priority 2. The remaining cases will be explicit or implicit
1123 % depending on the parity of the priority of the right expression, and
1124 % priority will be odd or even depending on the parity of the priority
1125 % of the left expression.
1126 % \begin{macrocode}
1127 %<*doc>
1128 \DeclareRobustCommand\mul[2]{%
1129 \begingroup
1130 \FD@eval@expr{#1}%
1131 \ifnum \FD@priority<\@ne \FD@bracket@expression \fi
1132 \let\@tempa=\FD@expression
1133 \ifFD@evaluate@ \a@count=\FD@result \fi
1134 \b@count=\FD@bracket@level
1135 \let\FD@left@priority=\FD@priority
1136 \FD@eval@expr{#2}%
1137 \ifnum \FD@priority<\@ne \FD@bracket@expression \fi
1138 \protected@xdef\FD@expression{%
1139 \@tempa
1140 \if \ifnum \FD@left@priority=\@ne e%
1141 \else\ifnum \FD@priority<\thr@@ e%
1142 \else\ifodd \FD@priority i\else e\fi\fi\fi e%
1143 \cdot
1144 \fi
1145 \FD@expression
1146 }%
1147 \ifFD@evaluate@ \global\multiply \FD@result \a@count \fi
1148 \ifnum \FD@bracket@level<\b@count
1149 \global\FD@bracket@level=\b@count
1150 \fi
1151 \a@count=%
1152 \ifnum \FD@priority=\@ne 1%
1153 \else\ifnum \FD@left@priority=\@ne 2%
1154 \else\ifodd\FD@left@priority
1155 \ifodd\FD@priority 5\else 3\fi
1156 \else
1157 \ifodd\FD@priority 4\else 2\fi
1158 \fi\fi\fi
1159 \global\chardef\FD@priority=\a@count
1160 \endgroup
1161 }
1162 %</doc>
1163 % \end{macrocode}
1164 % \end{macro}
1165 %
1166 % \begin{macro}{\div}
1167 % The |\div| command has the syntax
1168 % \begin{quote}
1169 % |\div|\marg{integer expression}\marg{integer expression}
1170 % \end{quote}
1171 % It represents the quotient of the two \meta{integer expression}s, as
1172 % computed by \TeX's |\divide| command: non-integer quotients are
1173 % rounded towards zero.
1174 % \begin{macrocode}
1175 %<*pkg>
1176 \def\div#1#2{
1177 #1
1178 \bgroup
1179 \a_count=\result
1180 \eval_expr{#2}
1181 \divide \a_count \result
1182 \global\result=\a_count
1183 \egroup
1184 }
1185 %</pkg>
1186 %<*doc>
1187 \DeclareRobustCommand\div[2]{%
1188 \begingroup
1189 \FD@eval@expr{#1}%
1190 \ifnum \FD@priority<\@ne \FD@bracket@expression \fi
1191 \let\@tempa=\FD@expression
1192 \ifFD@evaluate@ \a@count=\FD@result \fi
1193 \b@count=\FD@bracket@level
1194 \FD@eval@expr{#2}%
1195 \ifnum 4>\FD@priority \FD@bracket@expression \fi
1196 \ifnum \FD@bracket@level<\b@count
1197 \global\FD@bracket@level=\b@count
1198 \fi
1199 \protected@xdef\FD@expression{%
1200 \@tempa
1201 \ifcase\FD@bracket@level \or \protect\big \or \protect\Big \or
1202 \protect\bigg \else \protect\Bigg \fi /%
1203 \FD@expression
1204 }%
1205 \ifFD@evaluate@
1206 \divide \a@count \FD@result
1207 \global\FD@result=\a@count
1208 \fi
1209 \global\chardef\FD@priority=\@ne
1210 \endgroup
1211 }
1212 % \end{macrocode}
1213 % \end{macro}
1214 %
1215 % \begin{macro}{\FD@eval@spec@expr}
1216 % The |\FD@eval@spec@expr| macro has the syntax
1217 % \begin{isyntax}
1218 % |\FD@eval@spec@expr|\marg{integer expression}^^A
1219 % \discretionary{}{}{}\marg{spec-command}^^A
1220 % \discretionary{}{}{}\marg{rep-command}
1221 % \end{isyntax}
1222 % It does pretty much the same thing as |\FD@eval@expr|, but if the
1223 % first token in the \meta{integer expression} is the
1224 % \meta{spec-command} then it will do
1225 % \begin{quote}
1226 % \meta{rep-command}\meta{integer expression}
1227 % \end{quote}
1228 % instead of the normal activities. This is useful for operations that
1229 % are normally denoted as $n$-ary operations rather that binary ones,
1230 % i.e., for |\max| and |\min|.
1231 % \begin{macrocode}
1232 \def\FD@eval@spec@expr#1#2#3{%
1233 \expandafter\ifx \@car#1\x@relax\@nil #2%
1234 #3#1%
1235 \else
1236 \FD@eval@expr{#1}%
1237 \fi
1238 }
1239 %</doc>
1240 % \end{macrocode}
1241 % \end{macro}
1242 %
1243 % \begin{macro}{\max}
1244 % The |\max| command has the syntax
1245 % \begin{quote}
1246 % |\max|\marg{integer expression}\marg{integer expression}
1247 % \end{quote}
1248 % It represents the maximum of the two \meta{integer expression}s.
1249 % \begin{macrocode}
1250 %<*pkg>
1251 \def\max#1#2{
1252 #1
1253 \bgroup
1254 \a_count=\result
1255 \eval_expr{#2}
1256 \ifnum \a_count>\result \global\result=\a_count \fi
1257 \egroup
1258 }
1259 %</pkg>
1260 %<*doc>
1261 \DeclareRobustCommand\max[2]{%
1262 \begingroup
1263 \toks@={}%
1264 \a@count=-\maxdimen
1265 \b@count=\z@
1266 \FD@eval@spec@expr{\max{#1}{#2}}{\max}{\FD@maxmin@comma}%
1267 \ifnum \a@count>\FD@bracket@level
1268 \global\FD@bracket@level=\a@count
1269 \fi
1270 \protected@xdef\FD@expression{%
1271 \protect\plainmax
1272 \ifcase\FD@bracket@level \protect\@firstofone \or \protect\bigl
1273 \or \protect\Bigl \or \protect\biggl \else \protect\Biggl
1274 \fi{\{}%
1275 \the\toks@
1276 \protect\FD@subexpression{\FD@expression}%
1277 \ifcase\FD@bracket@level \protect\@firstofone \or \protect\bigl
1278 \or \protect\Bigl \or \protect\biggl \else \protect\Biggl
1279 \fi{\}}%
1280 }%
1281 \ifFD@evaluate@
1282 \ifnum \a@count>\FD@result \global\FD@result=\a@count \fi
1283 \fi
1284 \global\chardef\FD@priority=5%
1285 \global\advance \FD@bracket@level \@ne
1286 \endgroup
1287 }
1288 %</doc>
1289 % \end{macrocode}
1290 % \end{macro}
1291 %
1292 % \begin{macro}{\min}
1293 % The |\min| command has the syntax
1294 % \begin{quote}
1295 % |\min|\marg{integer expression}\marg{integer expression}
1296 % \end{quote}
1297 % It represents the minimum of the two \meta{integer expression}s.
1298 % \begin{macrocode}
1299 %<*pkg>
1300 \def\min#1#2{
1301 #1
1302 \bgroup
1303 \a_count=\result
1304 \eval_expr{#2}
1305 \ifnum \a_count<\result \global\result=\a_count \fi
1306 \egroup
1307 }
1308 %</pkg>
1309 %<*doc>
1310 \DeclareRobustCommand\min[2]{%
1311 \begingroup
1312 \toks@={}%
1313 \a@count=\maxdimen
1314 \b@count=\z@
1315 \FD@eval@spec@expr{\min{#1}{#2}}{\min}{\FD@maxmin@comma}%
1316 \ifnum \a@count>\FD@bracket@level
1317 \global\FD@bracket@level=\a@count
1318 \fi
1319 \protected@xdef\FD@expression{%
1320 \protect\plainmin
1321 \ifcase\FD@bracket@level \protect\@firstofone \or \protect\bigl
1322 \or \protect\Bigl \or \protect\biggl \else \protect\Biggl
1323 \fi{\{}%
1324 \the\toks@
1325 \protect\FD@subexpression{\FD@expression}%
1326 \ifcase\FD@bracket@level \protect\@firstofone \or \protect\bigl
1327 \or \protect\Bigl \or \protect\biggl \else \protect\Biggl
1328 \fi{\}}%
1329 }%
1330 \ifFD@evaluate@
1331 \ifnum \a@count<\FD@result \global\FD@result=\a@count \fi
1332 \fi
1333 \global\chardef\FD@priority=5%
1334 \global\advance \FD@bracket@level \@ne
1335 \endgroup
1336 }
1337 % \end{macrocode}
1338 % \end{macro}
1339 %
1340 % \begin{macro}{\FD@maxmin@comma}
1341 % The |\FD@maxmin@comma| macro does most of the work for |\max| and
1342 % |\min| in \package{fontdoc}. In some sense it inserts the commas
1343 % between the operands, but it also takes care of evaluating the
1344 % maximum\slash minimum and determining the proper bracketing level.
1345 %
1346 % The sequence of arguments (separated by commas) is compiled in
1347 % |\toks@|. The greatest\slash least value of an argument found so
1348 % far is kept in |\a@count|, and the greatest bracketing level found
1349 % is kept in |\b@count|.
1350 % \begin{macrocode}
1351 \def\FD@maxmin@comma#1#2#3{%
1352 \FD@eval@spec@expr{#2}{#1}{\FD@maxmin@comma}%
1353 \toks@=\expandafter{\the\expandafter\toks@
1354 \expandafter\protect \expandafter\FD@subexpression
1355 \expandafter{\FD@expression}%
1356 ,\penalty\FD@commapenalty\,%
1357 }
1358 \ifFD@evaluate@
1359 \ifnum \a@count \ifx\max#1<\else>\fi \FD@result
1360 \a@count=\FD@result
1361 \fi
1362 \fi
1363 \ifnum \b@count<\FD@bracket@level \b@count=\FD@bracket@level \fi
1364 \FD@eval@spec@expr{#3}{#1}{\FD@maxmin@comma}%
1365 }
1366 %</doc>
1367 % \end{macrocode}
1368 % \end{macro}
1369 %
1370 % \begin{macro}{\half}
1371 % \begin{macro}{\otherhalf}
1372 % \multchanges{\cs{half}\cs{otherhalf}}{1.916}{2000/12/31}{Macros
1373 % added. (LH)}
1374 % The |\half| and |\otherhalf| macros have the syntaxes
1375 % \begin{quote}
1376 % |\half|\marg{integer expression}\\
1377 % |\otherhalf|\marg{integer expression}
1378 % \end{quote}
1379 % They both represent one half of the \meta{integer expression}, but
1380 % they don't round it the same way. |\half| does rounding as
1381 % specified in~\cite[p.~237]{TAOCP2} (towards even integers) whereas
1382 % |\otherhalf| does it the other way (towards odd integers). This
1383 % means that
1384 % \begin{quote}
1385 % |\add{\half{|\meta{IE}|}}{\otherhalf{|\meta{IE}|}}|
1386 % \end{quote}
1387 % will always sum up to precisely the same as the \meta{IE} integer
1388 % expression.
1389 % \begin{macrocode}
1390 %<*pkg>
1391 \def\half#1{
1392 #1\x_relax
1393 \ifodd\result
1394 \global\advance \result \@ne
1395 \global\divide \result \tw@
1396 \ifodd\result \global\advance \result \m@ne \fi
1397 \else
1398 \global\divide \result \tw@
1399 \fi
1400 }
1401 \def\otherhalf#1{
1402 #1\x_relax
1403 \ifodd\result
1404 \global\advance \result \@ne
1405 \global\divide \result \tw@
1406 \ifodd\result \else \global\advance \result \m@ne \fi
1407 \else
1408 \global\divide \result \tw@
1409 \fi
1410 }
1411 %</pkg>
1412 %<*doc>
1413 \DeclareRobustCommand\half[1]{%
1414 \begingroup
1415 \FD@eval@expr{#1}%
1416 \ifnum \FD@priority<\@ne \FD@bracket@expression \fi
1417 \a@count=%
1418 \ifnum \FD@priority=\@ne 1%
1419 \else\ifodd\FD@priority 5%
1420 \else 3\fi\fi
1421 \global\chardef\FD@priority=\a@count
1422 \protected@xdef\FD@expression{%
1423 \protect\frac{1}{2}%
1424 \ifnum \FD@priority>\thr@@ \else \cdot \fi
1425 \FD@expression
1426 }%
1427 \ifFD@evaluate@
1428 \ifodd \FD@result
1429 \global\advance \FD@result \@ne
1430 \global\divide \FD@result \tw@
1431 \ifodd\FD@result \global\advance \FD@result \m@ne \fi
1432 \else
1433 \global\divide \FD@result \tw@
1434 \fi
1435 \fi
1436 \endgroup
1437 }
1438 \DeclareRobustCommand\otherhalf[1]{%
1439 \begingroup
1440 \FD@eval@expr{#1}%
1441 \ifnum \FD@priority<\@ne \FD@bracket@expression \fi
1442 \a@count=%
1443 \ifnum \FD@priority=\@ne 1%
1444 \else\ifodd\FD@priority 5%
1445 \else 3\fi\fi
1446 \global\chardef\FD@priority=\a@count
1447 \protected@xdef\FD@expression{%
1448 \protect\frac{1}{2}%
1449 \ifnum \FD@priority>\thr@@ \else \cdot \fi
1450 \FD@expression
1451 }%
1452 \ifFD@evaluate@
1453 \ifodd \FD@result
1454 \global\advance \FD@result \@ne
1455 \global\divide \FD@result \tw@
1456 \ifodd\FD@result\else \global\advance \FD@result \m@ne \fi
1457 \else
1458 \global\divide \FD@result \tw@
1459 \fi
1460 \fi
1461 \endgroup
1462 }
1463 %</doc>
1464 % \end{macrocode}
1465 % \end{macro}\end{macro}
1466 %
1467 % \begin{macro}{\scale}
1468 % The |\scale| command has the syntax
1469 % \begin{quote}
1470 % |\scale|\marg{integer expression}\marg{integer expression}
1471 % \end{quote}
1472 % It represents the result of multiplying the first \meta{integer
1473 % expression} by as many thousands as is specified by the second
1474 % \meta{integer expression}. In practice, |\scale|\marg{ie1}\marg{ie2}
1475 % is very similar to
1476 % \begin{quote}
1477 % |\div{\mul|\marg{ie1}\marg{ie2}|}{1000}|
1478 % \end{quote}
1479 % but |\scale| also tries to do proper rounding (note however that
1480 % |\scale|ing by 500 is not rounded properly; use |\half| instead).
1481 % \begin{macrocode}
1482 %<*pkg>
1483 \def\scale#1#2{
1484 #1
1485 \bgroup
1486 \a_count=\result
1487 \eval_expr{#2}
1488 \global\multiply \result \a_count
1489 \rounded_thousandths
1490 \egroup
1491 }
1492 %</pkg>
1493 % \end{macrocode}
1494 %
1495 % The second (scaling factor) argument of |\scale| is usually very
1496 % simple, and in that case the |\scale| will be formatted as a
1497 % fraction (containing the second argument) multiplied by the first
1498 % argument.
1499 % \begin{macrocode}
1500 %<*doc>
1501 \DeclareRobustCommand\scale[2]{%
1502 \begingroup
1503 \FD@eval@expr{#1}%
1504 \ifnum \FD@priority<\@ne \FD@bracket@expression \fi
1505 \let\@tempa=\FD@expression
1506 \ifFD@evaluate@ \a@count=\FD@result \fi
1507 \b@count=\FD@bracket@level
1508 \let\FD@left@priority=\FD@priority
1509 \FD@eval@expr{#2}%
1510 \if \ifnum \FD@bracket@level<\@ne \ifnum \FD@priority>\thr@@
1511 1\else 0\fi\else 0\fi 1%
1512 \protected@xdef\FD@expression{%
1513 \protect\frac{\FD@expression}{1000}%
1514 \if \ifnum \FD@left@priority<\thr@@ e\else
1515 \ifodd \FD@left@priority i\else e\fi\fi e%
1516 \cdot
1517 \fi
1518 \@tempa
1519 }
1520 \global\chardef\FD@priority=%
1521 \ifnum \FD@left@priority=\@ne 1\else
1522 \ifodd\FD@left@priority 5\else 3\fi\fi
1523 \global\FD@bracket@level=\b@count
1524 \else
1525 \ifnum \FD@priority<\@ne \FD@bracket@expression \fi
1526 \protected@xdef\FD@expression{%
1527 \@tempa
1528 \if \ifnum \FD@left@priority=\@ne e%
1529 \else\ifnum \FD@priority<\thr@@ e%
1530 \else\ifodd \FD@priority i\else e\fi\fi\fi e%
1531 \cdot
1532 \fi
1533 \FD@expression
1534 \ifcase\FD@bracket@level \or \protect\big \or \protect\Big
1535 \or \protect\bigg \else \protect\Bigg \fi /1000%
1536 }%
1537 \ifnum \FD@bracket@level<\b@count
1538 \global\FD@bracket@level=\b@count
1539 \fi
1540 \global\chardef\FD@priority=\@ne
1541 \fi
1542 \ifFD@evaluate@
1543 \global\multiply \FD@result \a@count
1544 \global\divide \FD@result 500
1545 \ifodd \FD@result
1546 \global\advance \FD@result \ifnum 0>\FD@result - \fi \@ne
1547 \fi
1548 \global\divide \FD@result \tw@
1549 \fi
1550 \endgroup
1551 }
1552 %</doc>
1553 % \end{macrocode}
1554 % \end{macro}
1555 %
1556 % \begin{macro}{\rounded_thousandths}
1557 % \changes{1.901}{1999/03/06}{Macro added. \cs{scale} changed to
1558 % use it. (LH)}
1559 % \begin{macro}{\l_rounded_thousandths}
1560 % The |\rounded_thousandths| macro divides |\result|
1561 % by 1000 and rounds the result to the nearest integer. This is
1562 % different from
1563 % \begin{quote}
1564 % |\global\divide \result \one_thousand|
1565 % \end{quote}
1566 % since the latter always rounds positive numbers downwards and
1567 % negative numbers upwards.
1568 %
1569 % |\l_rounded_thousandths| does the same thing, but to the register
1570 % passed as parameter \#1 and is assigned locally.
1571 % \changes{1.913}{2000/03/04}{Macro added. (LH)}
1572 % \begin{macrocode}
1573 %<*pkg>
1574 \def\rounded_thousandths{
1575 \global\divide \result \five_hundred
1576 \ifodd \result
1577 \global\advance \result by \ifnum 0>\result - \fi 1
1578 \fi
1579 \global\divide \result \tw@
1580 }
1581 % \end{macrocode}
1582 % \begin{macrocode}
1583 \def\l_rounded_thousandths#1{
1584 \divide #1 \five_hundred
1585 \ifodd #1
1586 \advance #1 by \ifnum 0>#1 - \fi\@ne
1587 \fi
1588 \divide #1 \tw@
1589 }
1590 % \end{macrocode}
1591 % \end{macro}\end{macro}
1592 %
1593 % \begin{macro}{\l_inv_scale}
1594 % \changes{1.913}{2000/03/11}{Macro added. (LH)}
1595 % The |\l_inv_scale| takes two arguments: as \#1 a count register,
1596 % and as \#2 a \TeX\ number. |\l_inv_scale| scales \#1 by the inverse
1597 % of \#2, if the value in \#1 is $n$ and the value in \#2 is $m$ then
1598 % |\l_inv_scale| computes
1599 % $$
1600 % \left[ \frac{1000n}{m} \right] \mbox{,}
1601 % $$
1602 % where the brackets denote rounding to the nearest integer, and
1603 % assigns this number to \#1 locally.
1604 % \begin{macrocode}
1605 \def\l_inv_scale#1#2{
1606 \multiply #1 \two_thousand
1607 \divide #1 #2\x_relax
1608 \ifodd#1 \advance #1 \ifnum 0>#1 - \fi\@ne \fi
1609 \divide #1 \tw@
1610 }
1611 % \end{macrocode}
1612 % \end{macro}
1613 %
1614 % \multchanges{\cs{priority}}{1.909}{1999/10/20}{Changed condition for
1615 % \cs{ifnum}, so that expressions with equal priority will not get
1616 % bracketed when nested. (LH)}
1617 % \multchanges{\cs{expression}\cs{priority}\cs{identity}^^A
1618 % \cs{bracket}}{1.916}{2001/01/01}{Macros removed. (LH)}
1619 %
1620 % \begin{macro}{\ifnumber}
1621 % \changes{1.900}{1999/02/15}{Command added. (LH)}
1622 % The call
1623 % \begin{quote}
1624 % |\ifnumber|\marg{integer expression}\meta{rel}^^A
1625 % \marg{integer expression}|\then|
1626 % \end{quote}
1627 % can be used to compare the two integer expressions. \meta{rel} may
1628 % be |<|, |=|, or |>|.
1629 % \begin{macrocode}
1630 \def\ifnumber#1#2#3\then{
1631 \eval_expr_to\a_count{#1}
1632 \eval_expr{#3}
1633 \ifnum \a_count#2\result
1634 \expandafter\if_true
1635 \else
1636 \expandafter\if_false
1637 \fi
1638 }
1639 %</pkg>
1640 % \end{macrocode}
1641 %
1642 % Like the other conditionals, |\ifnumber| is treated as being true by
1643 % \package{fontdoc}.
1644 % \begin{macrocode}
1645 %<*doc>
1646 \def\ifnumber#1#2#3\then{%
1647 \FD@evaluate@false
1648 \generic@if{%
1649 $\TypesetIntegerExpression{#1}#2\TypesetIntegerExpression{#3}$%
1650 }%
1651 }
1652 %</doc>
1653 % \end{macrocode}
1654 % \end{macro}
1655 %
1656 %
1657 %
1658 % \subsection{Setting variables}
1659 % \label{Ssec:Variables}
1660 %
1661 % \meta{int}, \meta{str}, and \meta{dim} below are string expressions.
1662 % \meta{command} can be any control sequence.
1663 %
1664 % \DescribeMacro{\setint}
1665 % \DescribeMacro{\setstr}
1666 % \DescribeMacro{\setdim}
1667 % \DescribeMacro{\setcommand}
1668 % The macros:
1669 % \begin{quote}
1670 % |\setint|\marg{int}\marg{integer expression}\\
1671 % |\setstr|\marg{str}\marg{string}\\
1672 % |\setdim|\marg{dim}\marg{dimension}\\
1673 % |\setcommand|\meta{command}\meta{definition}
1674 % \end{quote}
1675 % define new macros
1676 % \describecsfamily{i-\meta{int}}|\i-|\meta{int},
1677 % \describecsfamily{s-\meta{str}}|\s-|\meta{str},
1678 % \describecsfamily{d-\meta{dim}}|\d-|\meta{dim}, or
1679 % \meta{command}.
1680 %
1681 % \DescribeMacro{\resetint}
1682 % \DescribeMacro{\resetstr}
1683 % \DescribeMacro{\resetdim}
1684 % \DescribeMacro{\resetcommand}
1685 % The macros:
1686 % \begin{quote}
1687 % |\resetint|\marg{int}\marg{integer expression}\\
1688 % |\resetstr|\marg{str}\marg{string}\\
1689 % |\resetdim|\marg{dim}\marg{dimension}\\
1690 % |\resetcommand|\meta{command}\meta{definition}
1691 % \end{quote}
1692 % redefine the macros |\i-|\meta{int}, |\s-|\meta{str}, |\d-|\meta{dim} or
1693 % \meta{command}.
1694 %
1695 % \DescribeMacro{\int}
1696 % \DescribeMacro{\str}
1697 % \DescribeMacro{\dim}
1698 % The macros:
1699 % \begin{quote}
1700 % |\int|\marg{int}\\
1701 % |\str|\marg{str}\\
1702 % |\dim|\marg{dim}\\
1703 % \meta{command}
1704 % \end{quote}
1705 % return the values of |\i-|\meta{int}, |\s-|\meta{str}, |\d-|\meta{dim},
1706 % or \meta{command}.
1707 %
1708 % \DescribeMacro{\strint}
1709 % The macro
1710 % \begin{quote}
1711 % |\strint|\marg{int}
1712 % \end{quote}
1713 % returns the value of |\i-|\meta{int} as a string.
1714 %
1715 % \DescribeMacro{\ifisint}
1716 % \DescribeMacro{\ifisstr}
1717 % \DescribeMacro{\ifisdim}
1718 % \DescribeMacro{\ifiscommand}
1719 % The macros:
1720 % \begin{quote}
1721 % |\ifisint|\marg{int}|\then|\\
1722 % |\ifisstr|\marg{str}|\then|\\
1723 % |\ifisdim|\marg{dim}|\then|\\
1724 % |\ifiscommand|\meta{command}|\then|
1725 % \end{quote}
1726 % return |\if_true| if |\i-|\meta{int}, |\s-|\meta{str},
1727 % |\d-|\meta{dim}, or \meta{command} respectively have been defined,
1728 % and |\if_false| otherwise.
1729 %
1730 % \DescribeMacro{\unsetint}
1731 % \DescribeMacro{\unsetstr}
1732 % \DescribeMacro{\unsetdim}
1733 % \DescribeMacro{\unsetcommand}
1734 % The macros:
1735 % \begin{quote}
1736 % |\unsetint|\marg{int}\\
1737 % |\unsetstr|\marg{str}\\
1738 % |\unsetdim|\marg{dim}\\
1739 % |\unsetcommand|\meta{command}
1740 % \end{quote}
1741 % undefine |\i-|\meta{int}, |\s-|\meta{str}, |\d-|\meta{dim}, or
1742 % \meta{command}.
1743 %
1744 % \DescribeMacro{\x_setint}
1745 % \DescribeMacro{\x_resetint}
1746 % \DescribeMacro{\x_setstr}
1747 % The macros |\x_setint|, |\x_resetint|, and |\x_setstr| are ``private''
1748 % versions of |\setint|, |\resetint|, and |\setstr| respectively. They
1749 % have been included to reduce the problems in case a user turns off one
1750 % of these commands and forgets to turn it on again.
1751 %
1752 % \changes{1.900}{1999/02/07}{Replaced internal \cs{setint},
1753 % \cs{resetint}, and \cs{setstr} by \cs{x_setint}, \cs{x_resetint},
1754 % and \cs{x_setstr} respectively, to make the public versions
1755 % possible to turn off. (LH)}
1756 %
1757 % Integers are kept as |\mathchardef|s if possible; a comparision of
1758 % doing this versus not doing this appears in
1759 % Subsection~\ref{Ssec: ASAJ tests}.
1760 %
1761 % \begin{macro}{\setsomething_global}
1762 % The |\setsomething_global| control sequence should be either
1763 % |\relax| or |\global|. It appears before the central assignments in
1764 % all the |\set|\textellipsis, |\reset|\textellipsis, and
1765 % |\unset|\textellipsis\ commands. The normal value is |\relax|, so
1766 % that these assignments are local.
1767 %
1768 % When there is counter-intuitive grouping, and it could seem that
1769 % \TeX\ should not be inside a group at all---i.e., between
1770 % |\installfonts| and |\endinstallfonts|---one can make the basic
1771 % assignment commands act more logical by setting
1772 % |\setsomething_global| to |\global|.
1773 %
1774 % \changes{1.912}{2000/01/15}{Control sequence introduced and added
1775 % to all \cs{set}\dots, \cs{reset}\dots, and \cs{unset}\dots\
1776 % commands, as well as \cs{offcommand} and \cs{oncommand}. (LH)}
1777 % \begin{macrocode}
1778 %<*pkg>
1779 \let\setsomething_global=\x_relax
1780 % \end{macrocode}
1781 % \end{macro}
1782 %
1783 % \begin{macro}{\x_setint}
1784 % \begin{macro}{\setint}
1785 % \begin{macro}{\x_setstr}
1786 % \begin{macro}{\setstr}
1787 % \begin{macro}{\setdim}
1788 % \begin{macro}{\setcommand}
1789 % \changes{1.909}{1999/10/17}{Since \package{fontdoc} adds some
1790 % grouping, \cs{setcommand} must set its argument globally there.
1791 % (LH)}
1792 % \changes{1.912}{2000/01/15}{Settings of a command already defined
1793 % is diverted to \cs{a_macro}; it used to be \cs{a_command}. Saves
1794 % one hash table position. (LH)}
1795 %
1796 % \begin{macrocode}
1797 \def\x_setint#1#2{
1798 \x_cs\ifx{i-#1}\x_relax
1799 \x_resetint{#1}{#2}
1800 \fi
1801 }
1802 \let\setint=\x_setint
1803 \def\x_setstr#1#2{
1804 \x_cs\ifx{s-#1}\x_relax
1805 \setsomething_global\x_cs\edef{s-#1}{#2}
1806 \fi
1807 }
1808 \let\setstr=\x_setstr
1809 \def\setdim#1#2{
1810 \x_cs\ifx{d-#1}\x_relax
1811 \a_dimen=#2\x_relax
1812 \setsomething_global\x_cs\edef{d-#1}{\the\a_dimen}
1813 \fi
1814 }
1815 \def\setcommand#1{
1816 \ifx#1\undefined_command
1817 \setsomething_global \expandafter\def \expandafter#1
1818 \else
1819 \expandafter\def \expandafter\a_macro
1820 \fi
1821 }
1822 %</pkg>
1823 % \end{macrocode}
1824 %
1825 % In \package{fontdoc}, |\setint|, |\setstr|, and |\setdim| print
1826 % headings. There is no need for the private forms |\x_setint| and
1827 % |\x_setstr|. |\setcommand|, finally, does the same thing as in
1828 % \package{fontinst}; the assignment is global because of grouping
1829 % not present in \package{fontinst}.
1830 % \begin{macrocode}
1831 %<*doc>
1832 \newcommand\setint[2]{%
1833 \Bheading{Default} \(\TypesetIntegerExpression{\int{#1}}\) =
1834 \(\TypesetIntegerExpression{#2}\)%
1835 }
1836 \newcommand\setstr[2]{%
1837 \Bheading{Default} \TypesetStringExpression{\str{#1}} =
1838 \TypesetStringExpression{#2}%
1839 }
1840 \newcommand\setdim[2]{%
1841 \a@dimen=#2\relax
1842 \Bheading{Default} \TypesetStringExpression{#1} dimen = \the\a@dimen
1843 }
1844 \def\setcommand#1{\ifx#1\undefined@command
1845 \expandafter\gdef\expandafter#1\else
1846 \expandafter\gdef\expandafter\a@command\fi}
1847 %</doc>
1848 % \end{macrocode}
1849 % \end{macro} \end{macro} \end{macro} \end{macro} \end{macro}
1850 % \end{macro}
1851 %
1852 % \begin{macro}{\x_resetint}
1853 % \begin{macro}{\resetint}
1854 % \begin{macro}{\resetstr}
1855 % \begin{macro}{\resetdim}
1856 % \begin{macro}{\resetcommand}
1857 % \changes{1.909}{1999/10/17}{Since \package{fontdoc} adds some
1858 % grouping, \cs{resetcommand} must set its argument globally there.
1859 % (LH)}
1860 % \begin{macrocode}
1861 %<*pkg>
1862 \def\x_resetint#1#2{
1863 \eval_expr{#2}
1864 \setsomething_global
1865 \ifnum\result<\max_mathchardef
1866 \ifnum 0>\result
1867 \x_cs\edef{i-#1}{\the\result}
1868 \else
1869 \x_cs\mathchardef{i-#1}=\result
1870 \fi
1871 \else
1872 \x_cs\edef{i-#1}{\the\result}
1873 \fi
1874 }
1875 \let\resetint=\x_resetint
1876 \def\resetstr#1#2{\setsomething_global\x_cs\edef{s-#1}{#2}}
1877 \def\resetdim#1#2{
1878 \a_dimen=#2
1879 \setsomething_global\x_cs\edef{d-#1}{\the\a_dimen}
1880 }
1881 \def\resetcommand#1{\setsomething_global\def#1}
1882 %</pkg>
1883 % \end{macrocode}
1884 %
1885 % In \package{fontdoc}, |\resetint|, |\resetstr|, and |\resetdim|
1886 % print headings. There is no need for the private form |\x_resetint|.
1887 % |\resetcommand|, finally, does the same thing as in
1888 % \package{fontinst}.
1889 %
1890 % \begin{macrocode}
1891 %<*doc>
1892 \newcommand\resetint[2]{%
1893 \Bheading{Value} \(\TypesetIntegerExpression{\int{#1}}\) =
1894 \(\TypesetIntegerExpression{#2}\)%
1895 }
1896 \newcommand\resetstr[2]{%
1897 \Bheading{Value} \TypesetStringExpression{\str{#1}} =
1898 \TypesetStringExpression{#2}%
1899 }
1900 \newcommand\resetdim[2]{%
1901 \a@dimen=#2\relax
1902 \Bheading{Value} \TypesetStringExpression{#1} dimen = \the\a@dimen
1903 }
1904 \def\resetcommand#1{\gdef#1}
1905 %</doc>
1906 % \end{macrocode}
1907 % \end{macro} \end{macro} \end{macro} \end{macro} \end{macro}
1908 %
1909 %
1910 % \begin{macro}{\dim}
1911 % \begin{macrocode}
1912 %<pkg>\def\dim#1{\csname~d-#1\endcsname}
1913 % \end{macrocode}
1914 % \missing{doc}{\dim}
1915 % \end{macro}
1916 %
1917 % \multchanges{\cs{typeset@integer}\cs{typeset@string}^^A
1918 % \cs{typeset@dimen}}{1.916}{2000/01/02}{Macros removed. (LH)}
1919 %
1920 % \begin{macro}{\ifisint}
1921 % \begin{macro}{\ifisstr}
1922 % \begin{macro}{\ifisdim}
1923 % \multchanges{\cs{ifisint}\cs{ifisstr}\cs{ifisdim}}{1.912}
1924 % {2000/02/10}{Reimplemented using \cs{if_defined}. (LH)}
1925 % \begin{macro}{\ifiscommand}
1926 % \begin{macrocode}
1927 %<*pkg>
1928 \def\ifisint#1\then{\if_defined i-#1\then}
1929 \def\ifisstr#1\then{\if_defined s-#1\then}
1930 \def\ifisdim#1\then{\if_defined d-#1\then}
1931 \def\ifiscommand#1\then{
1932 \ifx#1\undefined_command
1933 \expandafter\if_false
1934 \else
1935 \expandafter\if_true
1936 \fi
1937 }
1938 %</pkg>
1939 % \end{macrocode}
1940 %
1941 % In \package{fontdoc}, all conditionals are handled through
1942 % |\generic@if|, which by default expands to |\iftrue|.
1943 % \changes{1.909}{1999/10/17}{Changed one fontdoc definition of
1944 % \cs{ifisglyph} to a definition of \cs{ifiscommand}, which was
1945 % missing from fontdoc.}
1946 % \begin{macrocode}
1947 %<*doc>
1948 \def\ifisint#1\then{%
1949 \generic@if{integer $\TypesetIntegerExpression{\int{#1}}$ set}%
1950 }
1951 \def\ifisstr#1\then{%
1952 \generic@if{string \TypesetStringExpression{#1} set}%
1953 }
1954 \def\ifisdim#1\then{%
1955 \generic@if{dimension \TypesetStringExpression{#1} set}%
1956 }
1957 \def\ifiscommand#1\then{%
1958 \generic@if{command \normalfont{\ttfamily\string#1} set}%
1959 }
1960 %</doc>
1961 % \end{macrocode}
1962 % \end{macro}
1963 % \end{macro}
1964 % \end{macro}
1965 % \end{macro}
1966 %
1967 % \begin{macro}{\unsetint}
1968 % \begin{macro}{\unsetstr}
1969 % \begin{macro}{\unsetdim}
1970 % \begin{macro}{\unsetcommand}
1971 % \begin{macrocode}
1972 %<*pkg>
1973 \def\unsetint#1{\setsomething_global\x_cs\let{i-#1}\x_relax}
1974 \def\unsetstr#1{\setsomething_global\x_cs\let{s-#1}\x_relax}
1975 \def\unsetdim#1{\setsomething_global\x_cs\let{d-#1}\x_relax}
1976 \def\unsetcommand#1{\setsomething_global\let#1=\undefined_command}
1977 %</pkg>
1978 % \end{macrocode}
1979 % \missing{doc}{\unsetint}
1980 % \missing{doc}{\unsetstr}
1981 % \missing{doc}{\unsetdim}
1982 % \missing{doc}{\unsetcommand}
1983 % \begin{macrocode}
1984 %<*doc>
1985 %</doc>
1986 % \end{macrocode}
1987 % \end{macro}\end{macro}\end{macro}\end{macro}
1988 %
1989 % \begin{macro}{\offcommand}
1990 % \begin{macro}{\oncommand}
1991 % \multchanges{\cs{offcommand}\cs{oncommand}}{1.900}{1999/02/07}
1992 % {Commands added. (LH)}
1993 % The calls
1994 % \begin{quote}
1995 % |\offcommand|\meta{command}\\
1996 % |\oncommand|\meta{command}
1997 % \end{quote}
1998 % can be used to turn a command off (make it simply absorb its
1999 % arguments but expand to nothing) or on (return it to normal)
2000 % respectively. Their primary use is for ignoring some of the
2001 % commands in \texttt{.mtx} files that \package{fontinst} generates
2002 % from \texttt{.afm}, \texttt{.pl}, or other \texttt{.mtx} files.
2003 %
2004 % \describecsfamily{saved-\meta{\textbackslash command}}
2005 % The normal definition of a command that has been turned off
2006 % is saved as the control sequence |\saved-|\meta{command}. If the
2007 % syntax of a command is tricky---not all arguments are read by the
2008 % base command or its parameter text contains tokens that are not
2009 % parameters---or if simply making it do nothing is not the expected
2010 % `off' behaviour, then the automatic off-turning may not work. In such
2011 % cases a handtooled off definition of the command \meta{command}
2012 % may be provided as the control sequence |\off-|\meta{command}.^^A
2013 % \describecsfamily{off-\meta{\textbackslash command}}
2014 %
2015 % Nothing happens if |\offcommand| is called for a command that is
2016 % not on. Nothing happens if |\oncommand| is called for a command
2017 % that is not off.
2018 % \begin{macrocode}
2019 %<*pkg>
2020 \def\offcommand#1{
2021 \x_cs\ifx{saved-\string#1}\x_relax
2022 \setsomething_global\x_cs\let{saved-\string#1}#1
2023 \x_cs\ifx{off-\string#1}\x_relax
2024 \generate_off_command{#1}
2025 \else
2026 \setsomething_global \expandafter\let \expandafter#1
2027 \csname off-\string#1\endcsname
2028 \fi
2029 \fi
2030 }
2031 % \end{macrocode}
2032 % \begin{macrocode}
2033 \def\oncommand#1{
2034 \x_cs\ifx{saved-\string#1}\x_relax \else
2035 \setsomething_global \expandafter\let \expandafter#1
2036 \csname saved-\string#1\endcsname
2037 \setsomething_global\x_cs\let{saved-\string#1}\x_relax
2038 \fi
2039 }
2040 %</pkg>
2041 % \end{macrocode}
2042 % \multchanges{\cs{offcommand}\cs{oncommand}}{1.914}{2000/05/28}
2043 % {\package{fontdoc} definitions added. (LH)}
2044 % \begin{macrocode}
2045 %<*doc>
2046 \def\offcommand#1{\Bheading{Turn off} \texttt{\string#1}}
2047 \def\oncommand#1{\Bheading{Turn on} \texttt{\string#1}}
2048 %</doc>
2049 % \end{macrocode}
2050 % \end{macro}\end{macro}
2051 %
2052 % \begin{macro}{\generate_off_command}
2053 % \begin{macro}{\count_hashes}
2054 % \begin{macro}{\gobble_to_xrelax}
2055 % |\generate_off_command|\meta{command} converts \meta{command} to
2056 % an ``off'' version of itself by counting the number of arguments
2057 % and defining it to gobble that many arguments. It cannot cope with
2058 % commands whose parameter texts are not simply of the type
2059 % \begin{quote}
2060 % |#1#2|\textellipsis|#|$n$
2061 % \end{quote}
2062 % \begin{macrocode}
2063 %<*pkg>
2064 \def\generate_off_command#1{
2065 \a_count=0
2066 \let\next=\count_hashes
2067 \expandafter\next\meaning#1~->\x_relax
2068 \b_count=0
2069 \a_toks={}
2070 \loop \ifnum \b_count<\a_count
2071 \advance \b_count 1
2072 \a_toks=\expandafter{\the\expandafter\a_toks \expandafter####
2073 \the\b_count}
2074 \repeat
2075 \setsomething_global \expandafter\def \expandafter#1 \the\a_toks {}
2076 }
2077 % \end{macrocode}
2078 % \begin{macrocode}
2079 \def\count_hashes#1#2{
2080 \if \hash_char#1
2081 \advance \a_count 1
2082 \else
2083 \if -#1
2084 \if >#2
2085 \let\next=\gobble_to_xrelax
2086 \fi\fi
2087 \fi
2088 \next#2
2089 }
2090 \def\gobble_to_xrelax#1\x_relax{}
2091 %</pkg>
2092 % \end{macrocode}
2093 % \end{macro}\end{macro}\end{macro}
2094 %
2095 %
2096 % Control sequences of the form
2097 % \begin{quote}
2098 % \describecsfamily{FD@s-\meta{name}}|\FD@s-|\meta{name}
2099 % \end{quote}
2100 % are used by \package{fontdoc} to store the values of string variables
2101 % which have been assigned values; \meta{name} is the name of the string
2102 % variable. Unlike the case in \package{fontinst}, the
2103 % \package{fontdoc} |\setstr| command does not assign values to string
2104 % variables, but |\SetStringVariable| does.
2105 %
2106 % The contents of the |\FD@s-|\meta{name} macros aren't really the
2107 % string values, but code that will append the printable form of the
2108 % corresponding string expression to |\toks@| and update other variables
2109 % used by |\MakePrintable| accordingly. Typically it might look
2110 % something like
2111 % \begin{quote}
2112 % |\toks@=\expandafter{\the\toks@ ab}|
2113 % \end{quote}
2114 % when the value of the string is |ab|.
2115 %
2116 % \begin{macro}{\SetStringVariable}
2117 % \changes{1.916}{2001/01/24}{Command added. (LH)}
2118 % The |\SetStringVariable| command has the syntax
2119 % \begin{quote}
2120 % |\SetStringVariable|\marg{variable name}\marg{new value}
2121 % \end{quote}
2122 % where \meta{variable name} and \meta{new value} are both string
2123 % expressions. The \meta{variable name} must furthermore be a simple
2124 % string expression. The command globally defines the corresponding
2125 % |\FD@s-|\meta{name} control sequence to add the printable form of
2126 % the \marg{new value} string to the |\toks@| token list register and,
2127 % in case the \meta{new value} string is non-simple, sets the |@tempswa|
2128 % switch to true.
2129 %
2130 % The control sequence |\@tempa| can be used as part of \meta{new
2131 % value}, but not in the \meta{variable name}.
2132 % \begin{macrocode}
2133 %<*doc>
2134 \newcommand\SetStringVariable[2]{%
2135 \protected@edef\@tempa{\noexpand\MakePrintable \noexpand\@tempa
2136 {FD@swa}{#2}}%
2137 \@tempa
2138 \protected@edef\@tempa{%
2139 \toks@=\noexpand\expandafter{\noexpand\the \toks@ \@tempa}%
2140 \ifFD@swa \noexpand\@tempswatrue \fi
2141 }%
2142 \protected@edef\@tempb{\noexpand\MakePrintable \noexpand\@tempb
2143 {FD@swa}{#1}}%
2144 \@tempb
2145 \ifFD@swa
2146 \begingroup
2147 \let\PrintChar=\FD@quoted@PrintChar
2148 \global\expandafter\let \csname FD@s-\@tempb\endcsname \@tempa
2149 \endgroup
2150 \else
2151 \PackageError{fontdoc}{Names of string variables must be
2152 simple\MessageBreak if they are to be assigned values}\@eha
2153 \fi
2154 }
2155 %</doc>
2156 % \end{macrocode}
2157 % \end{macro}
2158 %
2159 %
2160 %
2161 %
2162 %
2163 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2164 %
2165 % \subsection{For loops}
2166 %
2167 %
2168 % \begin{macro}{\for}
2169 % \begin{macro}{\endfor}
2170 % \multchanges{\cs{for}\cs{endfor}}{1.900}{1999/02/16}{Commands
2171 % added. (LH)}
2172 % The command sequence
2173 % \begin{quote}
2174 % |\for|\parg{name}\marg{start}\marg{stop}\marg{step}\\
2175 % \vadjust{}\quad\meta{body code}\\
2176 % |\endfor|\parg{name}
2177 % \end{quote}
2178 % will cause the \meta{body code} to be repeated some number of times.
2179 % How many depends on the values of \meta{start}, \meta{stop}, and
2180 % \meta{step}, which are integer expressions.
2181 %
2182 % As a precaution, the \meta{body code} is not allowed to contain any
2183 % empty lines (|\par| tokens). If you want to have the visual
2184 % separation (for sakes of legibility or otherwise), put a |%|
2185 % somewhere on the line---that makes it nonempty.
2186 %
2187 % \meta{name} is used as the name of an integer variable. This
2188 % variable gets reset to the value of \meta{start} before the first
2189 % repetition of \meta{body code}. After each repetition but the last,
2190 % it is incremented by \meta{step}. \meta{body code} gets repeated if
2191 % the value of \meta{name} has not gotten past that of \meta{stop}. To
2192 % get past means to be bigger if \meta{step} is positive and to be
2193 % smaller if \meta{step} is negative. In the case that \meta{step} is
2194 % zero, the entire construction above will be equivalent to
2195 % \begin{quote}
2196 % |\resetint|\marg{name}\marg{start}\\
2197 % \meta{body code}
2198 % \end{quote}
2199 %
2200 % |\for| \textellipsis\ |\endfor| constructions can be nested.
2201 % \meta{name} is used by |\for| to identify its matching |\endfor|, so
2202 % they need to be identical in |\for| and |\endfor|.
2203 %
2204 % \multchanges{\cs{for}\cs{for_i}\cs{foreach}}{1.914}{2000/05/21}
2205 % {\cs{setsomething_global} added to assignments of the
2206 % \cs{for-\meta{name}} and \cs{body-\meta{name}} control
2207 % sequences. (LH)}
2208 % \begin{macrocode}
2209 %<*pkg>
2210 \def\for(#1)#2#3#4{
2211 \eval_expr_to\a_count{#2}
2212 \x_resetint{#1}{\a_count}
2213 \eval_expr{#4}
2214 \ifnum 0=\result \else
2215 \c_count=\result
2216 \eval_expr_to\b_count{#3}
2217 \setsomething_global\x_cs\edef{for-#1}{
2218 \the\c_count \x_relax
2219 \noexpand\ifnum \gobble_one\fi
2220 \the\b_count \ifnum 0>\c_count > \else < \fi
2221 }
2222 \def\next##1##2##3\endfor(#1){##2\for_i{##1}{##3}}
2223 \next{#1}
2224 \fi
2225 }
2226 % \end{macrocode}
2227 %
2228 % The macro \describecsfamily{for-\meta{name}}|\for-|\meta{name}
2229 % will contain
2230 % \begin{quote}
2231 % \meta{step}|\x_relax\ifnum|\meta{stop}\meta{rel}
2232 % \end{quote}
2233 % \meta{step} is the value of the \meta{step} parameter of |\for|,
2234 % computed when the loop was entered and now expressed in digits.
2235 % \meta{stop} is likewise for the \meta{stop} parameter. \meta{rel}
2236 % is |>| or |<|, depending on whether \meta{step} is positive or
2237 % negative respectively. The reason for this curious definition will
2238 % be appearent in the light of the definition of |\for_ii|.
2239 %
2240 % |\for_i| is expanded in the context
2241 % \begin{quote}
2242 % |\for_i|\marg{name}\marg{body code}
2243 % \end{quote}
2244 % Also remember, when reading the definition below, that |\ifnum|
2245 % keeps on expanding tokens until it has found a
2246 % \begin{quote}
2247 % \meta{number}\meta{relation}\meta{number}
2248 % \end{quote}
2249 % structure. It is therefore possible to nest |\ifnum|s like this!
2250 %
2251 % \begin{macrocode}
2252 \def\for_i#1#2{
2253 \setsomething_global\x_cs\def{body-#1}{#2}
2254 \ifnum \b_count \ifnum0>\c_count >\else<\fi \a_count
2255 \expandafter\gobble_two
2256 \else
2257 \csname body-#1 \expandafter\endcsname
2258 \fi
2259 \for_ii{#1}
2260 }
2261 % \end{macrocode}
2262 %
2263 % The macro \describecsfamily{body-\meta{name}}|\body-|\meta{name}
2264 % expands to the \meta{body code}.
2265 %
2266 % |\for_ii| executes the following code:
2267 % \begin{quote}
2268 % |\a_count=\int|\marg{name}\\
2269 % |\advance \a_count |\meta{step}|\x_relax|\\
2270 % |\ifnum |\meta{stop}\meta{rel}|\a_count|\\
2271 % | \expandafter\gobble_two|\\
2272 % |\else|\\
2273 % | \resetint|\marg{name}|\a_count|\\
2274 % | \csname body-|\meta{name}| \expandafter\endcsname|\\
2275 % |\fi|\\
2276 % |\for_ii|\marg{name}
2277 % \end{quote}
2278 % \meta{step}, \meta{stop}, and \meta{rel} are in |\for-|\meta{name},
2279 % and since there only are two other tokens between \meta{step} and
2280 % \meta{rel} in the above, one might as well include them in
2281 % |\for-|\meta{name} as well. Doing that requires that a matching
2282 % hole---that will be filled in by |\for-|\meta{name}---is made in the
2283 % definition of |\for_ii| and that is the reason for its somewhat
2284 % curious definition.
2285 %
2286 % \begin{macrocode}
2287 \def\for_ii#1{
2288 \a_count=\int{#1}
2289 \advance \a_count \csname for-#1\endcsname \a_count
2290 \expandafter\gobble_two
2291 \else
2292 \x_resetint{#1}\a_count
2293 \csname body-#1 \expandafter\endcsname
2294 \fi
2295 \for_ii{#1}
2296 }
2297 % \end{macrocode}
2298 %
2299 % |\endfor| just gobbles its argument, so that the \meta{step}${}=0$
2300 % case will work right.
2301 %
2302 % \begin{macrocode}
2303 \def\endfor(#1){}
2304 %</pkg>
2305 % \end{macrocode}
2306 % \missing{doc}{\for}
2307 % \missing{doc}{\endfor}
2308 % \begin{macrocode}
2309 %<*doc>
2310 %</doc>
2311 % \end{macrocode}
2312 % \end{macro}\end{macro}
2313 %
2314 %
2315 % \begin{macro}{\foreach}
2316 % \changes{1.901}{1999/03/07}{Command added. (LH)}
2317 % \changes{1.916}{2001/01/24}{\package{fontdoc} definition added. (LH)}
2318 % \begin{macro}{\foreach_i}
2319 % The command sequence
2320 % \begin{quote}
2321 % |\foreach|\parg{name}\marg{csep-list}\\
2322 % \vadjust{}\quad\meta{body code}\\
2323 % |\endfor|\parg{name}
2324 % \end{quote}
2325 % will cause the \meta{body code} to be repeated one time for each item
2326 % in the \meta{csep-list}. \meta{csep-list} is a comma-separated list
2327 % of strings.
2328 %
2329 % As a precaution, the \meta{body code} is not allowed to contain any
2330 % empty lines (|\par| tokens). If you want to have the visual
2331 % separation (for sakes of legibility or otherwise), put a |%|
2332 % somewhere on the line---that makes it nonempty.
2333 %
2334 % \meta{name} is used as the name of a string variable. Before each
2335 % repetition of the \meta{body code}, this variable will get reset to
2336 % the next item in the \meta{csep-list}.
2337 %
2338 % |\foreach|\textellipsis\ |\endfor| constructions can be nested.
2339 % \meta{name} is used by |\foreach| to identify its matching |\endfor|,
2340 % so they need to be identical in |\foreach| and |\endfor|.
2341 %
2342 % \begin{macrocode}
2343 %<*pkg>
2344 \def\foreach(#1)#2{
2345 \def\next##1\endfor(#1){
2346 \setsomething_global\x_cs\def{body-#1}{##1}
2347 \process_csep_list{\foreach_i{#1}}#2,\process_csep_list,
2348 }
2349 \next
2350 }
2351 \def\foreach_i#1#2{
2352 \resetstr{#1}{#2}
2353 \csname body-#1\endcsname
2354 }
2355 %</pkg>
2356 %<*doc>
2357 \def\foreach(#1)#2{%
2358 \def\next##1\endfor(#1){%
2359 \@for\@tempa:=#2\do{%
2360 \SetStringVariable{#1}{\@tempa}%
2361 ##1%
2362 }%
2363 }%
2364 \next
2365 }
2366 %</doc>
2367 % \end{macrocode}
2368 % \end{macro} \end{macro}
2369 %
2370 %
2371 %
2372 % \subsection{Comments}
2373 %
2374 % \changes{1.911}{1999/11/30}{Comment commands included in
2375 % \texttt{finstmsc.sty}. (LH)}
2376 %
2377 % \begin{macro}{\comment}
2378 % In \package{fontinst}, |\comment| simply gobbles its argument.
2379 % \begin{macrocode}
2380 %<pkg>\let\comment=\gobble_one
2381 % \end{macrocode}
2382 %
2383 % In \package{fontdoc}, |\comment| starts a new text paragraph and
2384 % leaves the argument to be typeset. Note that the argument group
2385 % thus survives; some commands make use of this fact.
2386 % \begin{macrocode}
2387 %<*doc>
2388 \def\comment{\par\noindent}
2389 %</doc>
2390 % \end{macrocode}
2391 % \end{macro}
2392 %
2393 %
2394 % \begin{macro}{\begincomment}
2395 % \changes{1.900}{1999/02/07}{Command added. (LH)}
2396 % \begin{macro}{\endcomment}
2397 % \changes{1.900}{1999/02/07}{Command added. (LH)}
2398 % Since |\comment| cannot be used for a comment longer than one
2399 % paragraph, we also provide the means of introducing longer comments,
2400 % by writing
2401 % \begin{quote}
2402 % |\begincomment| \meta{any amount of text} |\endcomment|
2403 % \end{quote}
2404 % The names are admittedly not nice from a \LaTeX\ point of view, but
2405 % it is hardly worth the cost to implement some kind of environment
2406 % processing in \package{fontinst}, just for the sake of this command.
2407 % \begin{macrocode}
2408 %<pkg>\let\begincomment=\iffalse
2409 %<doc>\let\begincomment=\iftrue
2410 %<pkg|doc>\let\endcomment=\fi
2411 % \end{macrocode}
2412 % \end{macro} \end{macro}
2413 %
2414 % \Finale
2415 %
2416 \endinput