summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/makecmds/makecmds.dtx
blob: 8cb49e510c2e39a03e1abe66ae35091a1b2549c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
% \iffalse meta-comment
%
% makecmds.dtx
% Copyright 2000 Peter R. Wilson
%
% This program is provided under the terms of the
% LaTeX Project Public License distributed from CTAN
% archives in directory macros/latex/base/lppl.txt.
%
% Author: Peter Wilson, Herries Press
% Maintainer: Will Robertson (will dot robertson at latex-project dot org)
%
%<*driver>
\documentclass{ltxdoc}
\EnableCrossrefs
\CodelineIndex
\setcounter{StandardModuleDepth}{1}
\begin{document}
  \DocInput{makecmds.dtx}
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{113}
%
% \DoNotIndex{\',\.,\@M,\@@input,\@addtoreset,\@arabic,\@badmath}
% \DoNotIndex{\@centercr,\@cite}
% \DoNotIndex{\@dotsep,\@empty,\@float,\@gobble,\@gobbletwo,\@ignoretrue}
% \DoNotIndex{\@input,\@ixpt,\@m}
% \DoNotIndex{\@minus,\@mkboth,\@ne,\@nil,\@nomath,\@plus,\@set@topoint}
% \DoNotIndex{\@tempboxa,\@tempcnta,\@tempdima,\@tempdimb}
% \DoNotIndex{\@tempswafalse,\@tempswatrue,\@viipt,\@viiipt,\@vipt}
% \DoNotIndex{\@vpt,\@warning,\@xiipt,\@xipt,\@xivpt,\@xpt,\@xviipt}
% \DoNotIndex{\@xxpt,\@xxvpt,\\,\ ,\addpenalty,\addtolength,\addvspace}
% \DoNotIndex{\advance,\Alph,\alph}
% \DoNotIndex{\arabic,\ast,\begin,\begingroup,\bfseries,\bgroup,\box}
% \DoNotIndex{\bullet}
% \DoNotIndex{\cdot,\cite,\CodelineIndex,\cr,\day,\DeclareOption}
% \DoNotIndex{\def,\DisableCrossrefs,\divide,\DocInput,\documentclass}
% \DoNotIndex{\DoNotIndex,\egroup,\ifdim,\else,\fi,\em,\endtrivlist}
% \DoNotIndex{\EnableCrossrefs,\end,\end@dblfloat,\end@float,\endgroup}
% \DoNotIndex{\endlist,\everycr,\everypar,\ExecuteOptions,\expandafter}
% \DoNotIndex{\fbox}
% \DoNotIndex{\filedate,\filename,\fileversion,\fontsize,\framebox,\gdef}
% \DoNotIndex{\global,\halign,\hangindent,\hbox,\hfil,\hfill,\hrule}
% \DoNotIndex{\hsize,\hskip,\hspace,\hss,\if@tempswa,\ifcase,\or,\fi,\fi}
% \DoNotIndex{\ifhmode,\ifvmode,\ifnum,\iftrue,\ifx,\fi,\fi,\fi,\fi,\fi}
% \DoNotIndex{\input}
% \DoNotIndex{\jobname,\kern,\leavevmode,\let,\leftmark}
% \DoNotIndex{\list,\llap,\long,\m@ne,\m@th,\mark,\markboth,\markright}
% \DoNotIndex{\month,\newcommand,\newcounter,\newenvironment}
% \DoNotIndex{\NeedsTeXFormat,\newdimen}
% \DoNotIndex{\newlength,\newpage,\nobreak,\noindent,\null,\number}
% \DoNotIndex{\numberline,\OldMakeindex,\OnlyDescription,\p@}
% \DoNotIndex{\pagestyle,\par,\paragraph,\paragraphmark,\parfillskip}
% \DoNotIndex{\penalty,\PrintChanges,\PrintIndex,\ProcessOptions}
% \DoNotIndex{\protect,\ProvidesClass,\raggedbottom,\raggedright}
% \DoNotIndex{\refstepcounter,\relax,\renewcommand,\reset@font}
% \DoNotIndex{\rightmargin,\rightmark,\rightskip,\rlap,\rmfamily,\roman}
% \DoNotIndex{\roman,\secdef,\selectfont,\setbox,\setcounter,\setlength}
% \DoNotIndex{\settowidth,\sfcode,\skip,\sloppy,\slshape,\space}
% \DoNotIndex{\symbol,\the,\trivlist,\typeout,\tw@,\undefined,\uppercase}
% \DoNotIndex{\usecounter,\usefont,\usepackage,\vfil,\vfill,\viiipt}
% \DoNotIndex{\viipt,\vipt,\vskip,\vspace}
% \DoNotIndex{\wd,\xiipt,\year,\z@}
%
% \changes{v1.0}{2000/05/27}{First public release}
% \changes{v1.0a}{2009/09/03}{New maintainer (Will Robertson)}
%
% \def\fileversion{v1.0a}
% \def\filedate{2009/09/03}
% \newcommand*{\Lpack}[1]{\textsf {#1}}           ^^A typeset a package
% \newcommand*{\Lopt}[1]{\textsf {#1}}            ^^A typeset an option
% \newcommand*{\file}[1]{\texttt {#1}}            ^^A typeset a file
% \newcommand*{\Lcount}[1]{\textsl {\small#1}}    ^^A typeset a counter
% \newcommand*{\pstyle}[1]{\textsl {#1}}          ^^A typeset a pagestyle
% \newcommand*{\Lenv}[1]{\texttt {#1}}            ^^A typeset an environment
%
% \title{The \Lpack{makecmds} package\thanks{This
%        file has version number \fileversion, last revised
%        \filedate.}}
%
% \author{
%   Author: Peter Wilson, Herries Press \\
%   Maintainer: Will Robertson \\
%   \texttt{will dot robertson at latex-project dot org}
% }
% \date{\filedate}
% \maketitle
% \begin{abstract}
%    The \Lpack{makecmds} package provides several additional commands 
% along the lines of the traditional |\(re)newcommand| and friends.
% \end{abstract}
% \tableofcontents
%
% \StopEventually{}
%
% \section{Introduction}
%
% \LaTeX{} provides commands like |\newcommand|, |\renewcommand| and
% |\providecommand|. Similarly there are the |\newenvironment| and
% |\renewenvironment| commands but no matching |\provideenvironment|
% command. This package provides additional command making commands
% like |\makecommand|, which is equivalent to the pair |\providecommand|
% and |\renewcommand|, or |\provideenvironment| to match with
% |\providecommand|.
%
% This manual is typeset according to the conventions of the
% \LaTeX{} \textsc{docstrip} utility which enables the automatic
% extraction of the \LaTeX{} macro source files~\cite{GOOSSENS94}.
%
%    Section~\ref{sec:usc} describes the usage of the \Lpack{makecmds} 
% package and 
% commented source code is in Section~\ref{sec:code}.
%
% \section{The \Lpack{makecmds} package} \label{sec:usc}
%
% Table~\ref{tab:newc} shows the general kinds of macro making commands
% that are available in \LaTeX{} and the additional forms
% provided by the \Lpack{makecmds} package.
%
%    This package extends the basic commands with |\make...| versions
% of |command|, |environment|, |length| and |counter| macros, and 
% |\provide...| versions for |environment|, |length| and |counter| macros.
%
% \begin{table}
% \centering
% \caption{Macro making commands} \label{tab:newc}
% \begin{tabular}{lp{0.3\textwidth}p{0.3\textwidth}} \hline
% Command & Action & Condition \\ \hline
% |\new...{|\meta{name}|}|\meta{...} & 
% Creates new macro definition for \meta{name} &
% \meta{name} must not have been previously defined \\
% |\renew...{|\meta{name}|}|\meta{...} & 
% Redefines the macro definition for \meta{name} &
% \meta{name} must have been previously defined \\
% |\provide...{|\meta{name}|}|\meta{...} & 
% If \meta{name} has not been previously defined, creates new macro 
% definition for \meta{name} otherwise does nothing &  \\
% |\make...{|\meta{name}|}|\meta{...} & 
% Creates or changes the macro definition for \meta{name} & \\ \hline
% \end{tabular}
% \end{table}
%
% \subsection{Options}
%
%    Several commands of the form |\make...| are provided by the package.
% For example, |\makecommand{\foo}{...}| will define a new command
% |\foo| if it does not already exist, otherwise it will silently
% redefine |\foo|. The package takes a single option, namely \Lopt{warn}. 
% This option will generate a warning message whenever one of the
% |\make...| commands redefines an existing definition.
%
% \subsection{Commands}
%
% \DescribeMacro{\makecommand}
%  The |\makecommand| command takes the same arguments as the 
% |\(re)newcommand| family does, and likewise there is also a starred
% version of the command. |\makecommand{\foo}...}| is equivalent to
% first calling |\providecommand{\foo}{}| and then |\renewcommand{\foo}...}|.
% That is, it defines |\foo| irrespective of whether or not |\foo| has been
% previously defined.
%
% \DescribeMacro{\provideenvironment}
% \DescribeMacro{\makeenvironment}
%    The |\provideenvironment| macro is like |\providecommand| except 
% that it applies
% to an environment instead of a command. Similarly |\makeenvironment|
% is analagous to |\makecommand|. Both macros take the same arguments
% as the |\newenvironment| command.
%
% \DescribeMacro{\providelength}
% \DescribeMacro{\makelength}
%    These are |\provide...| and |\make...| versions of the |\newlength| 
% command. They take the same argument as |\newlength|.
%
% \DescribeMacro{\providecounter}
% \DescribeMacro{\makecounter}
%     These are |\provide...| and |\make...| versions of the |\newcounter|
% command. They take the same arguments as |\newcounter|.
%
%
% 
% \section{The class code} \label{sec:code}
%
%    To try and avoid name clashes, all the internal commands include
% the string |m@k|. I have used |\def| instead of |\newcommand| in the
% following code as I have previously coded variants of the new commands in
% some \LaTeX{} classes and packages, and therefore want to overwrite
% those if this package happens to be used in conjunction with the
% pre-existing macro definitions.
%
% \subsection{Preliminaries}
%
%    Announce the name and version of the package, which requires
% \LaTeXe.
%    \begin{macrocode}
%<*usc>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{makecmds}[2009/09/03 v1.0a extra command making commands]

%    \end{macrocode}
%
% \begin{macro}{\ifm@kwarn}
% This is used for implementing the \Lopt{warn} option.
%    \begin{macrocode}
\newif\ifm@kwarn
  \m@kwarnfalse
%    \end{macrocode}
% \end{macro}
%
% Now declare and process the options.
%    \begin{macrocode}
\DeclareOption{warn}{\m@kwarntrue}
\ProcessOptions\relax

%    \end{macrocode}
% 
% \subsection{The commands}
%
%    Much of the code consists of copying and then making minor alterations
% to the code in the \LaTeX{} kernel.
%
% \begin{macro}{\makecommand}
% \begin{macro}{\m@ke@command}
% The |\make...| version of |\newcommand|, originally defined in 
% \file{ltdefns.dtx}. |\m@ke@command| is the internal code that does the work.
%    \begin{macrocode}
\def\makecommand{\@star@or@long\m@ke@command}
\def\m@ke@command#1{%
  \ifx #1\undefined\else
    \ifm@kwarn
      \PackageWarning{makecmds}{Redefining command `\protect#1'}
    \fi
  \fi
  \let\@ifdefinable\@rc@ifdefinable
  \new@command#1}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\provideenvironment}
% \begin{macro}{\m@kprovide@environment}
%     The environment version of |\providecommand|, and is based
% on the code in \file{ltdefns.dtx}. The internal version is 
% |\m@kprovide@environment|. The kernel command |\new@environment| actually
% creates a new environment.
%    \begin{macrocode}
\def\provideenvironment{%
  \@star@or@long\m@kprovide@environment}
\def\m@kprovide@environment#1{%
  \@ifundefined{#1}{%
    \expandafter\let\csname#1\endcsname\relax
    \expandafter\let\csname end#1\endcsname\relax
    \new@environment{#1}}{\m@kdiscardenvargs{#1}}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\m@kdiscardenvargs}
% \begin{macro}{\m@kenva}
% \begin{macro}{\m@kenvb}
% |\m@kdiscardenvargs| gathers up the arguments to |\provideenvironment|, and
% then proceeds to discard them.
%    \begin{macrocode}
\def\m@kdiscardenvargs#1{%
  \@testopt{\m@kenva#1}0}
\def\m@kenva#1[#2]{%
  \@ifnextchar [{\m@kenvb#1[#2]}{\m@kthrowenv{#1}{[#2]}}}
\def\m@kenvb#1[#2][#3]{\m@kthrowenv{#1}{[#2][#3]}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\m@kthrowenv}
%  |\m@kthrowenv| takes all the possible (4) arguments to a |\(re)newenvironment|
% command and throws them away.
%    \begin{macrocode}
\def\m@kthrowenv#1#2#3#4{}

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\makeenvironment}
% \begin{macro}{\m@ke@environment}
% The |\make...| version of |\newenvironment|, originally defined in 
% \file{ltdefns.dtx}. |\m@ke@environment| is the internal code that does the work.
%    \begin{macrocode}
\def\makeenvironment{\@star@or@long\m@ke@environment}
\def\m@ke@environment#1{%
  \@ifundefined{#1}{\new@environment{#1}}{%
    \ifm@kwarn
      \PackageWarning{makecmds}{Redefining environment `#1'}
    \fi
    \renew@environment{#1}}
}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\providelength}
% \begin{macro}{\makelength}
%  These are |\provide...| and |\make...| versions of |\newlength| 
% (from \file{ltlength.dtx}).
%    \begin{macrocode}
\def\providelength#1{%
  \ifx #1\undefined
    \newlength{#1}
  \fi
}
\def\makelength#1{%
  \ifx #1\undefined
    \newlength{#1}
  \else
    \ifm@kwarn
      \PackageWarning{makecmds}{Redefining length `\protect#1'}
    \fi
    \newskip#1
  \fi
}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\providecounter}
% \begin{macro}{\makecounter}
%  These are |\provide...| and |\make...| versions of |\newcounter| 
% (from \file{ltcounts.dtx}).
%    \begin{macrocode}
\def\providecounter#1{%
  \@ifundefined{c@#1}{\newcounter{#1}}{%
    \@ifnextchar[{\m@k@gobbleendoptarg}{}}%
}
\def\makecounter#1{%
  \expandafter\ifx \csname c@#1\endcsname \undefined
  \else
    \ifm@kwarn
      \PackageWarning{makecmds}{Redefining counter `#1'}
    \fi
  \fi
  \@definecounter{#1}%
  \@ifnextchar[{\@newctr{#1}}{}
}

%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\m@k@gobbleendoptarg}
%    A macro that discards an optional argument coming at the end of
% a list of (optional) arguments (i.e., the tokens |...[optarg]|).
%    \begin{macrocode}
\def\m@k@gobbleendoptarg[#1]{}

%    \end{macrocode}
% \end{macro}
%
%    The end of this package.
%    \begin{macrocode}
%</usc>
%    \end{macrocode}
%
%
%
%
% \bibliographystyle{alpha}
%
% \begin{thebibliography}{GMS94}
%
% \bibitem[GMS94]{GOOSSENS94}
% Michel Goossens, Frank Mittelbach, and Alexander Samarin.
% \newblock {\em The LaTeX Companion}.
% \newblock Addison-Wesley Publishing Company, 1994.
%
% ^^A \bibitem[Wil96]{PRW96i}
% ^^A Peter~R. Wilson.
% ^^A \newblock {\em {LaTeX for standards: The LaTeX package files user manual}}.
% ^^A \newblock NIST Report NISTIR, June 1996.
%
% \end{thebibliography}
%
%
% \Finale
% \PrintIndex
%
\endinput

%% \CharacterTable
%%  {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
%%   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
%%   Digits        \0\1\2\3\4\5\6\7\8\9
%%   Exclamation   \!     Double quote  \"     Hash (number) \#
%%   Dollar        \$     Percent       \%     Ampersand     \&
%%   Acute accent  \'     Left paren    \(     Right paren   \)
%%   Asterisk      \*     Plus          \+     Comma         \,
%%   Minus         \-     Point         \.     Solidus       \/
%%   Colon         \:     Semicolon     \;     Less than     \<
%%   Equals        \=     Greater than  \>     Question mark \?
%%   Commercial at \@     Left bracket  \[     Backslash     \\
%%   Right bracket \]     Circumflex    \^     Underscore    \_
%%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%%   Right brace   \}     Tilde         \~}