3
% $Id: mdwtools.tex,v 1.1 2000/07/13 09:10:21 michael Exp $
5
% Common declarations for mdwtools.dtx files
7
% (c) 1996 Mark Wooding
9
%----- Revision history -----------------------------------------------------
11
% $Log: mdwtools.tex,v $
12
% Revision 1.1 2000/07/13 09:10:21 michael
15
% Revision 1.1 1998/09/21 10:19:01 michael
16
% Initial implementation
18
% Revision 1.4 1996/11/19 20:55:55 mdw
24
% \begin{meta-comment} <general public licence>
26
%% mdwtools common declarations
27
%% Copyright (c) 1996 Mark Wooding
29
%% This program is free software; you can redistribute it and/or modify
30
%% it under the terms of the GNU General Public License as published by
31
%% the Free Software Foundation; either version 2 of the License, or
32
%% (at your option) any later version.
34
%% This program is distributed in the hope that it will be useful,
35
%% but WITHOUT ANY WARRANTY; without even the implied warranty of
36
%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37
%% GNU General Public License for more details.
39
%% You should have received a copy of the GNU General Public License
40
%% along with this program; if not, write to the Free Software
41
%% Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45
% \begin{meta-comment} <file preamble>
47
\ProvidesFile{mdwtools.tex}
48
[1996/05/10 1.4 Shared definitions for mdwtools .dtx files]
54
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
55
%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
56
%% Digits \0\1\2\3\4\5\6\7\8\9
57
%% Exclamation \! Double quote \" Hash (number) \#
58
%% Dollar \$ Percent \% Ampersand \&
59
%% Acute accent \' Left paren \( Right paren \)
60
%% Asterisk \* Plus \+ Comma \,
61
%% Minus \- Point \. Solidus \/
62
%% Colon \: Semicolon \; Less than \<
63
%% Equals \= Greater than \> Question mark \?
64
%% Commercial at \@ Left bracket \[ Backslash \\
65
%% Right bracket \] Circumflex \^ Underscore \_
66
%% Grave accent \` Left brace \{ Vertical bar \|
67
%% Right brace \} Tilde \~}
70
% \section{Introduction and user guide}
72
% This file is really rather strange; it gets |\input| by other package
73
% documentation files to set up most of the environmental gubbins for them.
74
% It handles almost everything, like loading a document class, finding any
75
% packages, and building and formatting the title.
77
% It also offers an opportunity for users to customise my nice documentation,
78
% by using a |mdwtools.cfg| file (not included).
81
% \subsection{Declarations}
83
% A typical documentation file contains something like
84
% \begin{listinglist} \listingsize \obeylines
89
% The initial |\input| reads in this file and sets up the various commands
90
% which may be needed. The final |\mdwdoc| actually starts the document,
91
% inserting a title (which is automatically generated), a table of
92
% contents etc., and reads the documentation file in (using the |\DocInput|
93
% command from the \package{doc} package.
95
% \subsubsection{Describing packages}
97
% \DescribeMacro{\describespackage}
98
% \DescribeMacro{\describesclass}
99
% \DescribeMacro{\describesfile}
100
% \DescribeMacro{\describesfile*}
101
% The most important declarations are those which declare what the
102
% documentation describes. Saying \syntax{"\\describespackage{<package>}"}
103
% loads the \<package> (if necessary) and adds it to the auto-generated
104
% title, along with a footnote containing version information. Similarly,
105
% |\describesclass| adds a document class name to the title (without loading
106
% it -- the document itself must do this, with the |\documentclass| command).
107
% For files which aren't packages or classes, use the |\describesfile| or
108
% |\describesfile*| command (the $*$-version won't |\input| the file, which
109
% is handy for files like |mdwtools.tex|, which are already input).
111
% \DescribeMacro{\author}
112
% \DescribeMacro{\date}
113
% \DescribeMacro{\title}
114
% The |\author|, |\date| and |\title| declarations work slightly differently
115
% to normal -- they ensure that only the \emph{first} declaration has an
116
% effect. (Don't you play with |\author|, please, unless you're using this
117
% program to document your own packages.) Using |\title| suppresses the
118
% automatic title generation.
120
% \DescribeMacro{\docdate}
121
% The default date is worked out from the version string of the package or
122
% document class whose name is the same as that of the documentation file.
123
% You can choose a different `main' file by saying
124
% \syntax{"\\docdate{"<file>"}"}.
126
% \subsubsection{Contents handling}
128
% \DescribeMacro{\addcontents}
129
% A documentation file always has a table of contents. Other
130
% contents-like lists can be added by saying
131
% \syntax{"\\addcontents{"<extension>"}{"<command>"}"}. The \<extension>
132
% is the file extension of the contents file (e.g., \lit{lot} for the
133
% list of tables); the \<command> is the command to actually typeset the
134
% contents file (e.g., |\listoftables|).
136
% \subsubsection{Other declarations}
138
% \DescribeMacro{\implementation}
139
% The \package{doc} package wants you to say
140
% \syntax{"\\StopEventually{"<stuff>"}"}' before describing the package
141
% implementation. Using |mdwtools.tex|, you just say |\implementation|, and
142
% everything works. It will automatically read in the licence text (from
143
% |gpl.tex|, and wraps some other things up.
146
% \subsection{Other commands}
148
% The |mdwtools.tex| file includes the \package{syntax} and \package{sverb}
149
% packages so that they can be used in documentation files. It also defines
150
% some trivial commands of its own.
153
% Saying \syntax{"\\<"<text>">" is the same as "\\synt{"<text>"}"}; this
154
% is a simple abbreviation.
156
% \DescribeMacro{\smallf}
157
% Saying \syntax{"\\smallf" <number>"/"<number>} typesets a little fraction,
158
% like this: \smallf 3/4. It's useful when you want to say that the default
159
% value of a length is 2 \smallf 1/2\,pt, or something like that.
162
% \subsection{Customisation}
164
% You can customise the way that the package documentation looks by writing
165
% a file called |mdwtools.cfg|. You can redefine various commands (before
166
% they're defined here, even; |mdwtools.tex| checks most of the commands that
167
% it defines to make sure they haven't been defined already.
169
% \DescribeMacro{\indexing}
170
% If you don't want the prompt about whether to generate index files, you
171
% can define the |\indexing| command to either \lit{y} or \lit{n}. I'd
172
% recommend that you use |\providecommand| for this, to allow further
173
% customisation from the command line.
175
% \DescribeMacro{\mdwdateformat}
176
% If you don't like my date format (maybe you're American or something),
177
% you can redefine the |\mdwdateformat| command. It takes three arguments:
178
% the year, month and date, as numbers; it should expand to something which
179
% typesets the date nicely. The default format gives something like
180
% `10 May 1996'. You can produce something rather more exotic, like
181
% `10\textsuperscript{th} May \textsc{\romannumeral 1996}' by saying
183
%\newcommand{\mdwdateformat}[3]{%
184
% \number#3\textsuperscript{\numsuffix{#3}}\ %
186
% \textsc{\romannumeral #1}%
189
% \DescribeMacro{\monthname}
190
% \DescribeMacro{\numsuffix}
191
% Saying \syntax{"\\monthname{"<number>"}"} expands to the name of the
192
% numbered month (which can be useful when doing date formats). Saying
193
% \syntax{"\\numsuffix{"<number>"}"} will expand to the appropriate suffix
194
% (`th' or `rd' or whatever) for the \<number>. You'll have to superscript
195
% it yourself, if this is what you want to do. Putting the year number
196
% in roman numerals is just pretentious |;-)|.
198
% \DescribeMacro{\mdwhook}
199
% After all the declarations in |mdwtools.tex|, the command |\mdwhook| is
200
% executed, if it exists. This can be set up by the configuration file
201
% to do whatever you want.
203
% There are lots of other things you can play with; you should look at the
204
% implementation section to see what's possible.
208
% \section{Implementation}
214
% The first thing is that I'm not a \LaTeX\ package or anything official
215
% like that, so I must enable `|@|' as a letter by hand.
221
% Now input the user's configuration file, if it exists. This is fairly
225
\@input{mdwtools.cfg}
228
% Well, that's the easy bit done.
231
% \subsection{Initialisation}
233
% Obviously the first thing to do is to obtain a document class. Obviously,
234
% it would be silly to do this if a document class has already been loaded,
235
% either by the package documentation or by the configuration file.
237
% The only way I can think of for finding out if a document class is already
238
% loaded is by seeing if the |\documentclass| command has been redefined
239
% to raise an error. This isn't too hard, really.
242
\ifx\documentclass\@twoclasseserror\else
243
\documentclass[a4paper]{ltxdoc}
244
\ifx\doneclasses\mdw@undefined\else\doneclasses\fi
248
% As part of my standard environment, I'll load some of my more useful
249
% packages. If they're already loaded (possibly with different options),
250
% I'll not try to load them again.
253
\@ifpackageloaded{doc}{}{\usepackage{doc}}
254
\@ifpackageloaded{syntax}{}{\usepackage[rounded]{syntax}}
255
\@ifpackageloaded{sverb}{}{\usepackage{sverb}}
259
% \subsection{Some macros for interaction}
261
% I like the \LaTeX\ star-boxes, although it's a pain having to cope with
262
% \TeX's space-handling rules. I'll define a new typing-out macro which
263
% makes spaces more significant, and has a $*$-version which doesn't put
264
% a newline on the end, and interacts prettily with |\read|.
266
% First of all, I need to make spaces active, so I can define things about
270
\begingroup\obeyspaces
273
% Now to define the main macro. This is easy stuff. Spaces must be
274
% carefully rationed here, though.
276
% I'll start a group, make spaces active, and make spaces expand to ordinary
277
% space-like spaces. Then I'll look for a star, and pass either |\message|
278
% (which doesn't start a newline, and interacts with |\read| well) or
279
% |\immediate\write 16| which does a normal write well.
283
\begingroup\catcode`\ \active\let \space%
284
\@ifstar{\mdwtype@i{\message}}{\mdwtype@i{\immediate\write\sixt@@n}}%
289
% Now for the easy bit. I have the thing to do, and the thing to do it to,
290
% so do that and end the group.
293
\def\mdwtype@i#1#2{#1{#2}\endgroup}
297
% \subsection{Decide on indexing}
299
% A configuration file can decide on indexing by defining the |\indexing|
300
% macro to either \lit{y} or \lit{n}. If it's not set, then I'll prompt
303
% First of all, I want a switch to say whether I'm indexing.
309
% Right: now I need to decide how to make progress. If the macro's not set,
310
% then I want to set it, and start a row of stars.
313
\ifx\indexing\@@undefined
314
\mdwtype{*****************************}
319
% Now enter a loop, asking the user whether to do indexing, until I get
325
\if y\indexing\@tempswatrue\createindextrue\fi
326
\if Y\indexing\@tempswatrue\createindextrue\fi
327
\if n\indexing\@tempswatrue\createindexfalse\fi
328
\if N\indexing\@tempswatrue\createindexfalse\fi
330
\mdwtype*{* Create index files? (y/n) *}
331
\read\sixt@@n to\indexing%
335
% Now, based on the results of that, display a message about the indexing.
338
\mdwtype{*****************************}
340
\mdwtype{* Creating index files *}
341
\mdwtype{* This may take some time *}
343
\mdwtype{* Not creating index files *}
345
\mdwtype{*****************************}
348
% Now I can play with the indexing commands of the \package{doc} package
349
% to do whatever it is that the user wants.
361
% And register lots of plain \TeX\ things which shouldn't be indexed.
362
% This contains lots of |\if|\dots\ things which don't fit nicely in
363
% conditionals, which is a shame. Still, it doesn't matter that much,
367
\DoNotIndex{\def,\long,\edef,\xdef,\gdef,\let,\global}
368
\DoNotIndex{\if,\ifnum,\ifdim,\ifcat,\ifmmode,\ifvmode,\ifhmode,%
369
\iftrue,\iffalse,\ifvoid,\ifx,\ifeof,\ifcase,\else,\or,\fi}
370
\DoNotIndex{\box,\copy,\setbox,\unvbox,\unhbox,\hbox,%
371
\vbox,\vtop,\vcenter}
372
\DoNotIndex{\@empty,\immediate,\write}
373
\DoNotIndex{\egroup,\bgroup,\expandafter,\begingroup,\endgroup}
374
\DoNotIndex{\divide,\advance,\multiply,\count,\dimen}
375
\DoNotIndex{\relax,\space,\string}
376
\DoNotIndex{\csname,\endcsname,\@spaces,\openin,\openout,%
378
\DoNotIndex{\catcode,\endinput}
379
\DoNotIndex{\jobname,\message,\read,\the,\m@ne,\noexpand}
380
\DoNotIndex{\hsize,\vsize,\hskip,\vskip,\kern,\hfil,\hfill,\hss}
381
\DoNotIndex{\m@ne,\z@,\z@skip,\@ne,\tw@,\p@}
382
\DoNotIndex{\dp,\wd,\ht,\vss,\unskip}
385
% Last bit of indexing stuff, for now: I'll typeset the index in two columns
386
% (the default is three, which makes them too narrow for my tastes).
389
\setcounter{IndexColumns}{2}
393
% \subsection{Selectively defining things}
395
% I don't want to tread on anyone's toes if they redefine any of these
396
% commands and things in a configuration file. The following definitions
397
% are fairly evil, but should do the job OK.
399
% \begin{macro}{\@gobbledef}
401
% This macro eats the following |\def|inition, leaving not a trace behind.
404
\def\@gobbledef#1#{\@gobble}
409
% \begin{macro}{\tdef}
410
% \begin{macro}{\tlet}
412
% The |\tdef| command is a sort of `tentative' definition -- it's like
413
% |\def| if the control sequence named doesn't already have a definition.
414
% |\tlet| does the same thing with |\let|.
419
\expandafter\def\expandafter#1%
421
\expandafter\@gobbledef%
424
\def\tlet#1#2{\ifx#1\@@undefined\let#1=#2\fi}
431
% \subsection{General markup things}
433
% Now for some really simple things. I'll define how to typeset package
434
% names and environment names (both in the sans serif font, for now).
441
% I'll define the |\<|\dots|>| shortcut for syntax items suggested in the
442
% \package{syntax} package.
445
\tdef\<#1>{\synt{#1}}
448
% And because it's used in a few places (mainly for typesetting lengths),
449
% here's a command for typesetting fractions in text.
452
\tdef\smallf#1/#2{\ensuremath{^{#1}\!/\!_{#2}}}
456
% \subsection{A table environment}
458
% \begin{environment}{tab}
460
% Most of the packages don't use the (obviously perfect) \package{mdwtab}
461
% package, because it's big, and takes a while to load. Here's an
462
% environment for typesetting centred tables. The first (optional) argument
463
% is some declarations to perform. The mandatory argument is the table
464
% preamble (obviously).
468
\newenvironment{tab}[2][\relax]{%
483
% \subsection{Commenting out of stuff}
485
% \begin{environment}{meta-comment}
487
% Using |\iffalse|\dots|\fi| isn't much fun. I'll define a gobbling
488
% environment using the \package{sverb} stuff.
491
\ignoreenv{meta-comment}
497
% \subsection{Float handling}
499
% This gubbins will try to avoid float pages as much as possible, and (with
500
% any luck) encourage floats to be put on the same pages as text.
503
\def\textfraction{0.1}
504
\def\topfraction{0.9}
505
\def\bottomfraction{0.9}
506
\def\floatpagefraction{0.7}
509
% Now redefine the default float-placement parameters to allow `here' floats.
512
\def\fps@figure{htbp}
517
% \subsection{Other bits of parameter tweaking}
519
% Make \env{grammar} environments look pretty, by indenting the left hand
520
% sides by a large amount.
526
% I don't like being told by \TeX\ that my paragraphs are hard to linebreak:
527
% I know this already. This lot should shut \TeX\ up about most problems.
535
% Also make \TeX\ shut up in the index. The \package{multicol} package
536
% irritatingly plays with |\hbadness|. This is the best hook I could find
537
% for playing with this setting.
540
\expandafter\def\expandafter\IndexParms\expandafter{%
546
% The other thing I really don't like is `Marginpar moved' warnings. This
547
% will get rid of them, and lots of other \LaTeX\ warnings at the same time.
550
\let\@latex@warning@no@line\@gobble
553
% Put some extra space between table rows, please.
556
\def\arraystretch{1.2}
559
% Most of the code is at guard level one, so typeset that in upright text.
562
\setcounter{StandardModuleDepth}{1}
566
% \subsection{Contents handling}
568
% I use at least one contents file (the main table of contents) although
569
% I may want more. I'll keep a list of contents files which I need to
572
% There are two things I need to do to contents files here:
574
% \item I must typeset the table of contents at the beginning of the
576
% \item I want to typeset tables of contents in two columns (using the
577
% \package{multicol} package).
580
% The list consists of items of the form
581
% \syntax{"\\do{"<extension>"}{"<command>"}"}, where \<extension> is the
582
% file extension of the contents file, and \<command> is the command to
585
% \begin{macro}{\docontents}
587
% This is where I keep the list of contents files. I'll initialise it to
588
% just do the standard contents table.
591
\def\docontents{\do{toc}{\tableofcontents}}
596
% \begin{macro}{\addcontents}
598
% By saying \syntax{"\\addcontents{"<extension>"}{"<command>"}"}, a document
599
% can register a new table of contents which gets given the two-column
600
% treatment properly. This is really easy to implement.
603
\def\addcontents#1#2{%
604
\toks@\expandafter{\docontents\do{#1}{#2}}%
605
\edef\docontents{\the\toks@}%
612
% \subsection{Finishing it all off}
614
% \begin{macro}{\finalstuff}
616
% The |\finalstuff| macro is a hook for doing things at the end of the
617
% document. Currently, it inputs the licence agreement as an appendix.
620
\tdef\finalstuff{\appendix\part*{Appendix}\input{gpl}}
625
% \begin{macro}{\implementation}
627
% The |\implementation| macro starts typesetting the implementation of
628
% the package(s). If we're not doing the implementation, it just does
629
% this lot and ends the input file.
631
% I define a macro with arguments inside the |\StopEventually|, which causes
632
% problems, since the code gets put through an extra level of |\def|fing
633
% depending on whether the implementation stuff gets typeset or not. I'll
634
% store the code I want to do in a separate macro.
637
\def\implementation{\StopEventually{\attheend}}
640
% Now for the actual activity. First, I'll do the |\finalstuff|. Then, if
641
% \package{doc}'s managed to find the \package{multicol} package, I'll add
642
% the end of the environment to the end of each contents file in the list.
643
% Finally, I'll read the index in from its formatted |.ind| file.
649
\def\do##1##2{\addtocontents{##1}{\protect\end{multicols}}}%
659
% \subsection{File version information}
661
% \begin{macro}{\mdwpkginfo}
663
% For setting up the automatic titles, I'll need to be able to work out
664
% file versions and things. This macro will, given a file name, extract
665
% from \LaTeX\ the version information and format it into a sensible string.
667
% First of all, I'll put the original string (direct from the
668
% |\Provides|\dots\ command). Then I'll pass it to another macro which can
669
% parse up the string into its various bits, along with the original
674
\edef\@tempa{\csname ver@#1\endcsname}%
675
\expandafter\mdwpkginfo@i\@tempa\@@#1\@@%
679
% Now for the real business. I'll store the string I build in macros called
680
% \syntax{"\\"<filename>"date", "\\"<filename>"version" and
681
% "\\"<filename>"info"}, which store the file's date, version and
682
% `information string' respectively. (Note that the file extension isn't
683
% included in the name.)
685
% This is mainly just tedious playing with |\expandafter|. The date format
686
% is defined by a separate macro, which can be modified from the
687
% configuration file.
690
\def\mdwpkginfo@i#1/#2/#3 #4 #5\@@#6.#7\@@{%
691
\expandafter\def\csname #6date\endcsname%
692
{\protect\mdwdateformat{#1}{#2}{#3}}%
693
\expandafter\def\csname #6version\endcsname{#4}%
694
\expandafter\def\csname #6info\endcsname{#5}%
700
% \begin{macro}{\mdwdateformat}
702
% Given three arguments, a year, a month and a date (all numeric), build a
703
% pretty date string. This is fairly simple really.
706
\tdef\mdwdateformat#1#2#3{\number#3\ \monthname{#2}\ \number#1}
709
January\or February\or March\or April\or May\or June\or%
710
July\or August\or September\or October\or November\or December%
722
\fi\fi\fi\fi\fi\fi\fi%
728
% \begin{macro}{\mdwfileinfo}
730
% Saying \syntax{"\\mdwfileinfo{"<file-name>"}{"<info>"}"} extracts the
731
% wanted item of \<info> from the version information for file \<file-name>.
734
\def\mdwfileinfo#1#2{\mdwfileinfo@i{#2}#1.\@@}
735
\def\mdwfileinfo@i#1#2.#3\@@{\csname#2#1\endcsname}
741
% \subsection{List handling}
743
% There are several other lists I need to build. These macros will do
744
% the necessary stuff.
746
% \begin{macro}{\mdw@ifitem}
748
% The macro \syntax{"\\mdw@ifitem"<item>"\\in"<list>"{"<true-text>"}"^^A
749
% "{"<false-text>"}"} does \<true-text> if the \<item> matches any item in
750
% the \<list>; otherwise it does \<false-text>.
753
\def\mdw@ifitem#1\in#2{%
756
\def\do##1{\def\@tempb{##1}\ifx\@tempa\@tempb\@tempswatrue\fi}%
758
\if@tempswa\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi%
764
% \begin{macro}{\mdw@append}
766
% Saying \syntax{"\\mdw@append"<item>"\\to"<list>} adds the given \<item>
767
% to the end of the given \<list>.
770
\def\mdw@append#1\to#2{%
772
\toks\tw@\expandafter{#2}%
773
\edef#2{\the\toks\tw@\the\toks@}%
779
% \begin{macro}{\mdw@prepend}
781
% Saying \syntax{"\\mdw@prepend"<item>"\\to"<list>} adds the \<item> to the
782
% beginning of the \<list>.
785
\def\mdw@prepend#1\to#2{%
787
\toks\tw@\expandafter{#2}%
788
\edef#2{\the\toks@\the\toks\tw@}%
794
% \begin{macro}{\mdw@add}
796
% Finally, saying \syntax{"\\mdw@add"<item>"\\to"<list>} adds the \<item>
797
% to the list only if it isn't there already.
800
\def\mdw@add#1\to#2{\mdw@ifitem#1\in#2{}{\mdw@append#1\to#2}}
806
% \subsection{Described file handling}
808
% I'l maintain lists of packages, document classes, and other files
809
% described by the current documentation file.
811
% First of all, I'll declare the various list macros.
819
% \begin{macro}{\describespackage}
821
% A document file can declare that it describes a package by saying
822
% \syntax{"\\describespackage{"<package-name>"}"}. I add the package to
823
% my list, read the package into memory (so that the documentation can
824
% offer demonstrations of it) and read the version information.
827
\def\describespackage#1{%
828
\mdw@ifitem#1\in\dopackages{}{%
829
\mdw@append#1\to\dopackages%
838
% \begin{macro}{\describesclass}
840
% By saying \syntax{"\\describesclass{"<class-name>"}"}, a document file
841
% can declare that it describes a document class. I'll assume that the
842
% document class is already loaded, because it's much too late to load
846
\def\describesclass#1{\mdw@add#1\to\doclasses\mdwpkginfo{#1.cls}}
851
% \begin{macro}{\describesfile}
853
% Finally, other `random' files, which don't have the status of real \LaTeX\
854
% packages or document classes, can be described by saying \syntax{^^A
855
% "\\describesfile{"<file-name>"}" or "\\describesfile*{"<file-name>"}"}.
856
% The difference is that the starred version will not |\input| the file.
860
\@ifstar{\describesfile@i\@gobble}{\describesfile@i\input}%
862
\def\describesfile@i#1#2{%
863
\mdw@ifitem#2\in\dootherfiles{}{%
864
\mdw@add#2\to\dootherfiles%
874
% \subsection{Author and title handling}
876
% I'll redefine the |\author| and |\title| commands so that I get told
877
% whether I need to do it myself.
879
% \begin{macro}{\author}
881
% This is easy: I'll save the old meaning, and then redefine |\author| to
882
% do the old thing and redefine itself to then do nothing.
885
\let\mdw@author\author
886
\def\author{\let\author\@gobble\mdw@author}
891
% \begin{macro}{\title}
893
% And oddly enough, I'll do exactly the same thing for the title, except
894
% that I'll also disable the |\mdw@buildtitle| command, which constructs
895
% the title automatically.
899
\def\title{\let\title\@gobble\let\mdw@buildtitle\relax\mdw@title}
904
% \begin{macro}{\date}
906
% This works in a very similar sort of way.
909
\def\date#1{\let\date\@gobble\def\today{#1}}
914
% \begin{macro}{\datefrom}
916
% Saying \syntax{"\\datefrom{"<file-name>"}"} sets the document date from
917
% the given filename.
921
\protected@edef\@tempa{\noexpand\date{\csname #1date\endcsname}}%
928
% \begin{macro}{\docfile}
930
% Saying \syntax{"\\docfile{"<file-name>"}"} sets up the file name from which
931
% documentation will be read.
935
\def\@tempa##1.##2\@@{\def\@basefile{##1.##2}\def\@basename{##1}}%
936
\edef\@tempb{\noexpand\@tempa#1\noexpand\@@}%
941
% I'll set up a default value as well.
944
\docfile{\jobname.dtx}
950
% \subsection{Building title strings}
952
% This is rather tricky. For each list, I need to build a legible looking
955
% \begin{macro}{\mdw@addtotitle}
958
%\syntax{"\\mdw@addtotitle{"<list>"}{"<command>"}{"<singular>"}{"<plural>"}"}
959
% I can add the contents of a list to the current title string in the
960
% |\mdw@title| macro.
963
\tdef\mdw@addtotitle#1#2#3#4{%
966
% Now to get to work. I need to keep one `lookahead' list item, and a count
967
% of the number of items read so far. I'll keep the lookahead item in
968
% |\@nextitem| and the counter in |\count@|.
974
% Now I'll define what to do for each list item. The |\protect| command is
975
% already set up appropriately for playing with |\edef| commands.
981
% The first job is to add the previous item to the title string. If this
982
% is the first item, though, I'll just add the appropriate \lit{The } or
983
% \lit{ and the } string to the title (this is stored in the |\@prefix|
989
\ifcase\count@\@prefix%
996
% That was rather easy. Now I'll set up the |\@nextitem| macro for the
997
% next time around the loop.
1003
The \protect#2{##1} #3 is currently at version %
1004
\mdwfileinfo{##1}{version}, dated \mdwfileinfo{##1}{date}.%
1009
% Finally, I need to increment the counter.
1012
\advance\count@\@ne%
1016
% Now execute the list.
1022
% I still have one item left over, unless the list was empty. I'll add
1029
\or\@nextitem\space#3%
1030
\or\ and \@nextitem\space#4%
1035
% Finally, if $|\count@| \ne 0$, I must set |\@prefix| to \lit{ and the }.
1038
\ifnum\count@>\z@\def\@prefix{ and the }\fi%
1044
% \begin{macro}{\mdw@buildtitle}
1046
% This macro will actually do the job of building the title string.
1049
\tdef\mdw@buildtitle{%
1052
% First of all, I'll open a group to avoid polluting the namespace with
1053
% my gubbins (although the code is now much tidier than it has been in
1054
% earlier releases).
1060
% The title building stuff makes extensive use of |\edef|. I'll set
1061
% |\protect| appropriately. (For those not in the know,
1062
% |\@unexpandable@protect| expands to `|\noexpand\protect\noexpand|',
1063
% which prevents expansion of the following macro, and inserts a |\protect|
1064
% in front of it ready for the next |\edef|.)
1067
\let\@@protect\protect\let\protect\@unexpandable@protect%
1070
% Set up some simple macros ready for the main code.
1077
% Now build the title. This is fun.
1080
\mdw@addtotitle\dopackages\package{package}{packages}%
1081
\mdw@addtotitle\doclasses\package{document class}{document classes}%
1082
\mdw@addtotitle\dootherfiles\texttt{file}{files}%
1085
% Now I want to end the group and set the title from my string. The
1086
% following hacking will do this.
1089
\edef\next{\endgroup\noexpand\title{\mdw@title}}%
1097
% \subsection{Starting the main document}
1099
% \begin{macro}{\mdwdoc}
1101
% Once the document preamble has done all of its stuff, it calls the
1102
% |\mdwdoc| command, which takes over and really starts the documentation
1109
% First, I'll construct the title string.
1113
\author{Mark Wooding}%
1116
% Set up the date string based on the date of the package which shares
1117
% the same name as the current file.
1120
\datefrom\@basename%
1123
% Set up verbatim characters after all the packages have started.
1130
% Start the document, and put the title in.
1137
% This is nasty. It makes maths displays work properly in demo environments.
1138
% \emph{The \LaTeX\ Companion} exhibits the bug which this hack fixes. So
1142
\abovedisplayskip\z@%
1145
% Now start the contents tables. After starting each one, I'll make it
1151
\ifhave@multicol\addtocontents{##1}{%
1152
\protect\begin{multicols}{2}%
1159
% Input the main file now.
1162
\DocInput{\@basefile}%
1165
% That's it. I'm done.
1175
% \subsection{And finally\dots}
1177
% Right at the end I'll put a hook for the configuration file.
1180
\ifx\mdwhook\@@undefined\else\expandafter\mdwhook\fi
1183
% That's all the code done now. I'll change back to `user' mode, where
1184
% all the magic control sequences aren't allowed any more.
1191
% Oh, wait! What if I want to typeset this documentation? Aha. I'll cope
1192
% with that by comparing |\jobname| with my filename |mdwtools|. However,
1193
% there's some fun here, because |\jobname| contains category-12 letters,
1194
% while my letters are category-11. Time to play with |\string| in a messy
1200
\edef\@tempa{\expandafter\@gobble\string\mdwtools}
1201
\edef\@tempb{\jobname}
1203
\describesfile*{mdwtools.tex}
1204
\docfile{mdwtools.tex}
1214
% \hfill Mark Wooding, \today