Debian Codegraph @

texmf-dist/source/latex/makecmds/makecmds.dtx

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