1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
|
%% auditor.tex of 6-94 (alpha)
%% "audits macro use"
%% By laurent siebenmann, lcs@topo.math.u-psud.fr (comments please!)
%% Used mostly for Plain and amstex; LaTeX use not debugged.
%% Documentation after endinput.
%% Alpha posting on ftp ftp.math.u-psud.fr in pub/TeX/Occam.dir
%% auditor.tex is part of the Occam system for macro management.
%% But it can also be used alone.
\ifx\undefined\auditortex\def\auditortex{}
\else
\immediate\write16{}%
\errmessage{%
The auditor.tex macro \noexpand\Def already loaded\string!}%
\EX@\endinput
\fi
\chardef\auditAt=\catcode`\@
\catcode`\@=11
%%temporarily suppress Plain's logging of allocations
\let\auditorwlog@ld\wlog
\def\wlog#1{\relax}
\def\WrSc@{\immediate\write16}
\def\WrOut@{\immediate\write\unusedout@}
\WrSc@{}%
\WrSc@{%
*** The auditor.tex macro-auditing system}%
\WrSc@{%
*** is being installed for a test run of your typescript.}%
\WrSc@{%
*** Its report will appear after typesetting.}%
\WrSc@{%
*** See documentation in auditor.tex.}%
\WrSc@{%
*** Hit return to get audit.}%
\WrSc@{%
*** Hit \space x \space and return to typeset without audit.}%
\def\temp{\par}%
\read16 to \YourChoice
%\def\YourChoice{\par}%%%%%%%%%% comment out?
\ifx\YourChoice\temp
\def\Modify@Audit{}%
\else
\def\Modify@Audit{\let\Def\def \let\gDef\gdef \let\Let\let
\def\gLet{\global\let}\let\The@Audit@\relax}%
\WrSc@{%
*** Auditor apparatus switched off\string.}%
\fi
\WrSc@{}%
\newwrite \unusedout@
\newtoks\temptoks@
\newtoks\nibbletoks@
\newtoks\resttoks@
\newtoks\deftoks@
\newtoks\mactoks@
\newtoks\unusedtoks@
\newtoks\AuditDepth
\let\EX@\expandafter
\def\Nibbl@#1#2\endNibbl@{\nibbletoks@{#1}\resttoks@{#2}}
\def\gobble#1{}
\def\WrDef@#1{\EX@
\ifx\csname\string_%
\string#1\string_\endcsname\@Used
\else
\EX@\global\EX@\let\csname\string_%
\string#1\string_\endcsname\@Defed
\edef\@tmp@{\global
\noexpand\deftoks@{\the\deftoks@\noexpand#1}}%
\@tmp@
\fi
}
\def\WrDDef@#1{\EX@
\ifx\csname\string_%
\string#1\string_\endcsname\@Used
\else
\EX@\global\EX@\let\csname\string_%
\string#1\string_\endcsname\@DDefed
\edef\@tmp@{\global
\noexpand\deftoks@{\the\deftoks@\noexpand#1}}%
\@tmp@
\fi
}
\def\@UsedMathSym{@UsedMathSym}
\newtoks\Def@toks@
\newtoks\Def@@toks@
\newtoks\Font@toks@
\newtoks\Mathchar@toks@
\newtoks\MATHchar@toks@
\newtoks\MATHchars@toks@
\def\Deff@{%
\edef\@tmp@ {\@d@f\the\Def@toks@ {%\noexpand
\global\let \EX@\noexpand\csname\string_%
\EX@\string\the\nibbletoks@\string_\endcsname
\noexpand\@Used
\the\Def@@toks@ }}%
\@tmp@
\EX@\WrDef@\the\nibbletoks@
}
\def\DDeff@{%
\edef\@tmp@ {\@d@f\the\Def@toks@ {%\noexpand
\global\let \EX@\noexpand\csname\string_%
\EX@\string\the\nibbletoks@\string_\endcsname
\noexpand\@Used
\the\Def@@toks@ }}%
\@tmp@
\EX@\WrDDef@\the\nibbletoks@
}
\def\Def#1#{\Def@toks@{#1}%
\Nibbl@#1\endNibbl@\let\@d@f\def
\afterassignment\Deff@\Def@@toks@
}
\def\DDef#1#{\Def@toks@{#1}%
\Nibbl@#1\endNibbl@\let\@d@f\def
\afterassignment\DDeff@\Def@@toks@
}
\def\gDef#1#{\Def@toks@{#1}%
\Nibbl@#1\endNibbl@\let\@d@f\gdef
\afterassignment\Deff@\Def@@toks@
}
%% \Let \gLet require two *macros* following, without =
%% Only then enhances \let
\def\Let#1#2{%
\EX@\Def\EX@#1\EX@{#2}%
}
\def\gLet#1#2{%
\EX@\gDef\EX@#1\EX@{#2}%
}
\def\WrMATHchardef@{%
\EX@\edef\the\MATHchar@toks@{%
\noexpand\ifx
\csname\string_\EX@\string\the\MATHchar@toks@\string_\endcsname
\noexpand\@UsedMathSym
\noexpand\else
\global\MATHchars@toks@\noexpand\EX@{%
\noexpand\the\MATHchars@toks@\the\MATHchar@toks@}%
\global\let\csname\string_\EX@\string\the\MATHchar@toks@\string_\endcsname
\noexpand\@UsedMathSym
\noexpand\fi
\csname \EX@\string\the\MATHchar@toks@\string_\endcsname}
%\EX@\show\the\MATHchar@toks@
}
\def\MATHchardef#1{\MATHchar@toks@{#1}%
%\showthe\MATHchar@toks@
\afterassignment\WrMATHchardef@
\EX@\mathchardef\csname \string#1\string_\endcsname}
\def\AfterMathchardef@{%
\edef\@@temp@{%
\noexpand\Def\the\Mathchar@toks@{%
\csname \EX@\string\the\Mathchar@toks@\string_\endcsname}}
%\show\@@temp@
\@@temp@}
\def\Mathchardef#1{\Mathchar@toks@{#1}%
\afterassignment\AfterMathchardef@
\EX@\mathchardef\csname \string#1\string_\endcsname}
%%% \Newsymbol, \NEWsymbol for \newsymbol of amssym.def
\def\Newsymbol#1#2#3#4#5{\let\next@\relax
\ifnum#2=\@ne\let\next@\msafam@\else
\ifnum#2=\tw@\let\next@\msbfam@\fi\fi
\Mathchardef#1="#3\next@#4#5}
\def\NEWsymbol#1#2#3#4#5{\let\next@\relax
\ifnum#2=\@ne\let\next@\msafam@\else
\ifnum#2=\tw@\let\next@\msbfam@\fi\fi
\MATHchardef#1="#3\next@#4#5}
\def\@F@nt@{\edef\@@temp@{%
\noexpand\Def\the\Font@toks@{%
\csname \EX@\string\the\Font@toks@\string_\endcsname}}%
\@@temp@}
\def\Font#1{\Font@toks@{#1}\afterassignment\@F@nt@
\EX@\font\csname \string#1\string_\endcsname}
\def\@FF@nt@{\edef\@@temp@{%
\noexpand\DDef\the\Font@toks@{%
\csname \EX@\string\the\Font@toks@\string_\endcsname}}%
\@@temp@}
\def\FFont#1{\Font@toks@{#1}\afterassignment\@FF@nt@
\EX@\font\csname \string#1\string_\endcsname}
\def\Loop@#1\Repeat@{%
\def\Iterate@{#1\EX@\Iterate@\fi}%
\Iterate@}
\bgroup\catcode`\%=12
\global\def\Pct@{ %% }\egroup
\def\WriteToToks@{\edef\@tmp@{\global\noexpand
\unusedtoks@{\the\unusedtoks@\the\nibbletoks@}}%
\@tmp@}
%\def\@Defed{@Defed}
%\def\@Used{@Used}
\def\@Used{\WrOut@{ \the\nibbletoks@}}%
\def\@Defed{\WrOut@{ *\the\nibbletoks@}\WriteToToks@}%
\def\@DDefed{\WrOut@{ **\the\nibbletoks@}\WriteToToks@}%
\let\@Filler\relax
\def\@Tail{@Tail}
\def\List@M@cs{%
\Loop@
%\message{ x }
\EX@\Nibbl@\the\deftoks@\@Tail\endNibbl@
\deftoks@\resttoks@ %\showthe\resttoks@
\edef\@Temp@{\EX@\noexpand\csname\string_%
\EX@\string\the\nibbletoks@\string_\endcsname}%
\EX@\let\EX@\@Temp\@Temp@ %
%% \@Temp is x-equal and let-equal to
%% \@Defed or \@DDefed or \@Used or \@Filler or @
%\showthe\nibbletoks@
%\show\@Temp@
%\show\@Temp
\EX@
\ifx \the\nibbletoks@\@Tail
%% exit if next token \@Tail
\else
\@Temp %% write appropriate stuff to file and log
\Repeat@
}
\newtoks\hrct@
{\catcode`\#=12\gdef\StringSharp{\string#}}
\def\The@Audit@{%\show\patience
\def\AuditSheet@{audit.lst}
%%%
\count255=\time\divide\count255 by 60\relax
\edef\temp@{\the\count255}
\multiply\count255 by -60\relax
\advance\count255 by \time
\immediate\openout\unusedout@ \AuditSheet@
\WrOut@{\Pct@ auditor.tex output, date
\the\day-\the\month-\the\year,
time \temp@\string:\the\count255.}%
\WrOut@{}
\edef\@temp@{\the\MATHchars@toks@}\def\empty{}%
\ifx\@temp@\empty\else
\WrOut@{\Pct@ Math characters defined via \noexpand\MATHchardef }
\WrOut@{\Pct@ or \noexpand\NEWsymbol and really used were\string:}
\WrOut@{\the\MATHchars@toks@}
\WrOut@{\Pct@ Beware lack of wordwrap\string!}
\WrOut@{}
\fi
\WrOut@{\Pct@ Macros (if any) defined by \string\Def, \string\Let, etc.}%
\WrOut@{\Pct@ are listed in order defined\string:}
\WrOut@{\Pct@ *Unused* macros among these are marked by * or \StringSharp.}%
\WrOut@{\Pct@ And **, ***, etc. indicate nesting (hence delayed action).}%
\WrSc@{}%
\WrOut@{}%
\List@M@cs
%\showthe\unusedtoks@
%\showthe\deftoks@
\def\empty{}%
\edef\@tmp@{\the\unusedtoks@}%
\ifx\@tmp@\empty
\EX@\def\EX@\@tmp@\EX@{\the\deftoks@}%
\ifx\@tmp@\empty
\WrSc@{*** No macros have been defined via \string\Def,
\string\Let, etc.}%
\else
\WrSc@{*** All macros defined via \string\Def,
\string\Let, etc. have been used.}%
\fi
\else
\WrSc@{*** The following macros defined via \string\Def,
\string\Let, etc. have not been used\string;}%
\WrSc@{%
*** --- you can probably delete their definitions\string:}%
\WrSc@{*** }%
\WrSc@{***** \the\unusedtoks@}%
\fi
\edef\@tmp@{\the\MATHchars@toks@}%
\ifx\@tmp@\empty\else
\WrSc@{ }%
\WrSc@{*** The following math chars defined by \noexpand\MATHchardef}%
\WrSc@{*** or \noexpand\NEWsymbol are really used\string:}%
\WrSc@{***** \the\MATHchars@toks@}%
\fi
\WrSc@{}%
\WrSc@{*** See the file \string"\AuditSheet@\string" for details.}%
\WrSc@{*** See the DefStrip utility for cleanup.}%
\WrOut@{}
\WrOut@{\the\AuditDepth\noexpand\ITERATIONCOUNTER}
\WrOut@{\Pct@ PLEASE iterate ***defstrip macro of QUEDM }
\WrOut@{\Pct@ until asterisks disappear from iteration counter line.}
\WrOut@{\Pct@ Name successive output files output1, output2, ...}
}
\ifx\undefined\@@end
\let\audprim@end@\end
\def\end{\The@Audit@\audprim@end@}
\else %%% LaTeX
\let\audprim@end@\@@end
\def\@@end{\The@Audit@\audprim@end@}
\fi
\Modify@Audit
\let\wlog\auditorwlog@ld
\catcode`\@=\auditAt
%\let\DDef\Def
\endinput %% comment out for tests
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% begin tests
\input amssym.def
\input amssym.occ
$\digamma\digamma\varkappa$
\Font\cmr cmr10 scaled 1500
%\cmr
\end
%\catcode`\@=11
%\documentstyle{article} %% LaTeX only
%\begin{document} %% LaTeX only
%\let\Def\def
%\let\Let\let
\Def\Rm#1{\mathop{\fam0#1}}
\Def \End {\Rm {End}}
\Def \Hom {\Rm {Hom}}
\Def \ind {\Rm {ind}}
\Def \Re {\Rm {Re}}
\Def \Tr {\Rm {Tr}}
\Def \rk {\Rm {rk}}
\Def \rg {\Rm {rg}}
\Def \Td {\Rm{Td}}
\Def \ch {\Rm{ch}}
\Def \T{\Rm{T}}
\Def \R{\Rm{R}}
\Def \e{\Rm{e}}
\Def \odd {\Rm{odd}}
\Def \even {\Rm{even}}
\Def \Ker {\Rm{Ker}}
\Def \id {\Rm{id}}
\Def \Pf {\Rm{Pf}}
\gDef\filler{filler}
\gLet\Filler\filler
%\Filler
\Font\myfont=cmr10 at 11.5pt
%\myfont
$\End
%\Hom
\ind
\Re
\Tr
\rk
\rg
\Td
\ch
\T
\R
\e
%\odd
%\even
\Ker
\id
\Pf $
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end tests
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% begin doc
DOCUMENTATION FOR auditor.tex.
Warnings : These macros are not bulletproof. I believe no such
macros could be bulletproof. But in practice that should be of
no importance; hopefully, any significant annoyances will be
routinely reported and remedied. Use of this alpha version
with an imbricated format like LaTeX is probably for hardened
texperts only. Plain and AmSTeX seem to respond well.
INSTRUCTIONS.
Suppose you have a macro file x.sty used for typesetting the
typescript x.tex. The aim is to find out, quickly and easily,
which of the macro definitions in x.sty are necessary to typeset
x.tex.
1) Modify a *copy* of x.sty to x-occ.sty by altering
definitions as follows:
(a) replace \def by \Def for definitions of macros you suspect
might be unused in x.tex. Similarly use \gDef in place
of \gdef or \global\def.
(b) similarly replace \mathchardef by \Mathchardef, and so forth
as indicated in the list of currently possible substitutions
indicated in occam.spc.
Provisional Warnings:
--- Do not modify \def's or \let's within other definitions.
This would be pointless and perhaps dangerous. Be ready to
revert to \def or \let if trouble ensues.
--- Avoid "\outer" and "\long" macros; also \alloc@
(c) Place the lines
%%% auditor.tex audits use of macros in a typescript.
\input auditor.tex %% Keep this file available to TeX!
at the head of x-occ.sty. (Watch the order!)
2) Modify x.tex temporarily replacing
\input x.sty by \input x-occ.sty
in the header. Typeset as usual. The audit should now proceed
with an explanatory dialog.
3) If there is trouble in step 2), repeat it choosing (by
dialog) to compose *without* an audit. There should be no
change from the original behavior of x.tex. Correct any
misbehavior --- probably arising from a malformation in
x-occ.sty. Sometimes, here and there in x-occ.sty, one has to
change \Def back to \def etc.
4) Delete the unused definitions in another copy of x.sty, say
x-min.sty. The list in the "audit.lst" output file is designed to
make this easy, in fact so easy that a utility called "defstrip" can
do the job automatically. Then replace x-occ.sty by x-min.sty in
the header of x.tex. Typeset x.tex and check a proof copy.
5) You can now send x.tex and x-min.sty to a colleague or
publisher, without burdening him/her with useless macros present in
x.sty.
IMPROVEMENTS CURRENT AND FUTURE
A) In all, the list of prepared macros is currently (July
1994):
\Def, \Let, \gDef, \gLet, \Font, \Mathchardef, \Newsymbol
Unless the contrary is indicated, each is to be used in analogy
with \Def replacing in x.sty a corresponding uncapitalized TeX
primitive.
[Exception: \newsymbol (from amssym.def) is *not*
primitive; it is used copiously for declaration of symbols from
the AmS math fonts msam and msbm, as in amssym.tex.]
When the file amssym.tex is \input, huge numbers of math
characters are defined via \newsymbol but only few are used. In
this case it is appropriate to use variants \MATHchardef,
\NEWsymbol. which signal math characters only if they are used
--- and *not* if they are unused. For this, try temporarily
replacing
\input amssym.tex
in x-occ.sty (after \input auditor.tex please) by
\input amssym.occ
where amssym.occ is obtained from amssym.tex by replacing
\newsymbol by \NEWsymbol; then you get a list of the symbols really
needed in x.tex.
In using \Let and \gLet, avoid macros with parameters and
note that the condition that the second argument be a macro is
often not satisfied. Do not use = in the syntax.
\Let, \gLet, and \Font tend to be troublesome; while
\Mathchardef, \MATHchardef, \Newsymbol, \NEWsymbolseem tend to
be troublefree.
The usefullness of the above list can be stretched by the
user. For example, before \Font was introduced
\font\myfont=cmr10 scaled 11.5pt
would have been replaced by
\font\myfont@=cmr10 at 11.5pt \Def\myfont{\myfont@}
to report use of \myfont.
In many formats, user definitions are made via macros not
available in Plain TeX; for example, \define and \redefine in
AmSTeX. In practice, they can usually be replaced by \Def for
the audit. But the programmer may want to invent new macros,
say \Define and \Redefine for AmSTeX.
(B) In case x.sty is of permanent interest, it is a good idea
to begin to use x-occ.sty instead of x.sty after commenting
out the line \input auditor.tex and replacing it by something
like
%% Audit.tex apparatus
\let\Def\def \let\gDef\gdef \let\Let\let
\let\Font\font \def\gLet{\global\let}
\let\Mathchardef\mathchardef %% extend as necessary
% \input auditor.tex %% comment out to suppress audit function
This will make steps (1) to (4) superfluous for your next
typescript y.tex.
(C) DefStrip automates the generation of x-min.sty.
(auditor.tex plus DefStrip make up the "Occam" utility.)
Its starting materials are "x-occ.sty" plus the "list audit.lst"
of unused macros provided by auditor.tex. This depends on a
special arrangement of x-occ.sty described in occam.spc.
Ultimately, an auxiliary ".tex" program "defstrip.tex"
will rewrite x-occ.sty omitting the inused definitions. This
auxiliary program resembles the "docstrip" utility of LaTeX
fame.
At the present time defstrip.tex is unavailable. But there
exists a QUEDM script called Auditor-QUEDM-Macros; QUEDM is a
editor with convenient "macro" (=composite command) capabilities
that is available on Macintosh computers at prices as low as $60
The instructions for Auditor-QUEDM-Macros are found in
defstrip.hlp.
*** How "auditor.tex" functions or fails to function.
"auditor.tex" prefixes a reporting device to the expansion
of macros defined by \Def; this device reports the use of the
macro by defining a tell-tale auxilliary macro that is then
polled after typesetting. But it may cause strange behavior or
even stop TeX.
As has been mentioned auditor.tex is not bullet-proof. Any
change whatever in the expansion of a macro can in principle
alter its behavior. For example TeX can use \ifx and many other
means to examine the expansion of a macro; it can detect any
tampering with definitions.
*** The "watchman" mechanism.
This mechanism is capable of deleting any collection of
lines of a macro file in response to the non-use of a single
macro called the "watchman". This "watchman" may be a macro that
is specially defined for the purpose. The mechanism is
definitely only for macro files carefully formatted for Occam.
This mechanism is more powerful but more cumbersome than that
for \Def etc. It is still to be implemented.
CAVEAT LaTeX : LaTeX environments tend to define their user
macros locally; indeed their definitions are not set up while
the macro file x.sty is being read but when the environment is
entered. Thus the modus operandi indicated above is suspect.
However, normally, the meanings assigned upon entering the
environment are stored in macros whose name involves @ ; these
are possibly the macros to spy on with \Def etc. Alternatively,
the "watchman" mechanism may prove effective. The cleanup based
on audit.lst is then still a delicate matter requiring texpert
attention. Further, LaTeX's fragility must be attended to...
|