summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/oberdiek/twoopt.dtx
blob: 8e139668c6ac33a13b7aaa45a00b0f22fcec3cf8 (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
% \iffalse meta-comment
%
% twoopt.dtx
%
% This file is part of the package `twoopt' for use with LaTeX2e.
%
% Function: Defining commands with two optional arguments.
%
% Copyright (C) 1998,1999 Heiko Oberdiek.
%
% This program can be redistributed and/or modified
% under the terms of the LaTeX Project Public License
% distributed from CTAN archives in directory
% macros/latex/base/lppl.txt; either version 1 of
% the License, or (at your option) any later version.
%
% Please send error reports and suggestions for improvements to
%   Heiko Oberdiek <oberdiek@ruf.uni-freiburg.de>.
%
%<*dtx>
          \ProvidesFile{twoopt.dtx}
%</dtx>
%<package>\NeedsTeXFormat{LaTeX2e}[1995/12/01]
%<package>\ProvidesPackage{twoopt}
%<driver>\ProvidesFile{twoopt.drv}
% \fi
%         \ProvidesFile{twoopt.dtx}
  [1999/04/12 v1.3 Definitions with two optional arguments (HO)]
%
% \GetFileInfo{twoopt.dtx}
%
% \CheckSum{103}
%
%% \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         \~}
%%
% \iffalse
%<*driver>
\documentclass{ltxdoc}
\usepackage{holtxdoc}
\begin{document}
   \DocInput{twoopt.dtx}
\end{document}
%</driver>
% \fi
%
% \DoNotIndex{\csname,\endcsname,\expandafter,\noexpand,\string}
% \DoNotIndex{\begingroup,\endgroup,\def,\xdef,\long,\let}
%
% \newenvironment{param}{^^A
%   \newcommand{\entry}[1]{\meta{\###1}:&}^^A
%   \begin{tabular}[t]{@{}l@{ }l@{}}^^A
% }{^^A
%   \end{tabular}^^A
% }
%
% \SetupTitle{definitions,optional,argument,LaTeX}
% \maketitle
%
% \begin{abstract}
%   This package provides commands to define macros with two
%   optional arguments.
% \end{abstract}
%
% \tableofcontents
%
% \section{Usage}
%    \DescribeMacro{\newcommandtwoopt}
%    \DescribeMacro{\renewcommandtwoopt}
%    \DescribeMacro{\providecommandtwoopt}
%    Similar to \cmd{\newcommand}, \cmd{\renewcommand}
%    and \cmd{\providecommand} this package provides commands
%    to define macros with two optional arguments.
%    The names of the commands are built by appending the
%    package name to the \LaTeX-pendants:
%    \begingroup
%      \def\x{\marg{cmd} \oarg{num} \oarg{default1}^^A
%             \oarg{default2} \marg{def.}}^^A
%      \begin{tabbing}
%        \cmd{\providecommandtwoopt} \=\kill
%        \cmd{\newcommandtwoopt}\>\x\\
%        \cmd{\renewcommandtwoopt}\>\x\\
%        \cmd{\providecommandtwoopt}\>\x\\
%      \end{tabbing}
%    \endgroup
%
%    Also the |*|-forms are supported. Indeed it is better to
%    use this ones, unless it is intended to hold
%    whole paragraphs in some of the arguments. If the macro
%    is defined with the |*|-form, missing braces
%    can be detected earlier.
%
%    Example:
%    \begin{quote}
%      |\newcommandtwoopt{\bsp}[3][AA][BB]{%|\\
%      |  \typeout{\string\bsp: #1,#2,#3}%|\\
%      |}|\\
%      \begin{tabular}{@{}l@{\quad$\rightarrow$\quad}l@{}}
%      |\bsp[aa][bb]{cc}|&|\bsp: aa,bb,cc|\\
%      |\bsp[aa]{cc}|&|\bsp: aa,BB,cc|\\
%      |\bsp{cc}|&|\bsp: AA,BB,cc|\\
%      \end{tabular}
%    \end{quote}
%
% \Installation
%
% \StopEventually{}
%
% \section{Implementation}
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
% \begin{macro}{\newcommandtwoopt}
%    \begin{macrocode}
\newcommand{\newcommandtwoopt}{%
  \@ifstar{\@newcommandtwoopt*}{\@newcommandtwoopt{}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@newcommandtwoopt}
%    \begin{param}
%      \entry1 star\\
%      \entry2 macro name to be defined
%    \end{param}
%    \begin{macrocode}
\newcommand{\@newcommandtwoopt}{}
\long\def\@newcommandtwoopt#1#2{%
  \expandafter\@@newcommandtwoopt
    \csname2\string#2\endcsname{#1}{#2}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@newcommandtwoopt}
%    \begin{param}
%      \entry1 help command to be defined
%        (\expandafter\cmd\csname 2\bslash<name>\endcsname)\\
%      \entry2 star\\
%      \entry3 macro name to be defined\\
%      \entry4 number of total arguments\\
%      \entry5 default for optional argument one\\
%      \entry6 default for optional argument two
%    \end{param}
%    \begin{macrocode}
\newcommand{\@@newcommandtwoopt}{}
\long\def\@@newcommandtwoopt#1#2#3[#4][#5][#6]{%
  \newcommand#2#3[1][{#5}]{%
    \to@ScanSecondOptArg#1{##1}{#6}%
  }%
  \newcommand#2#1[{#4}]%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\renewcommandtwoopt}
%    \begin{macrocode}
\newcommand{\renewcommandtwoopt}{%
  \@ifstar{\@renewcommandtwoopt*}{\@renewcommandtwoopt{}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@renewcommandtwoopt}
%    \begin{param}
%      \entry1 star\\
%      \entry2 command name to be defined
%    \end{param}
%    \begin{macrocode}
\newcommand{\@renewcommandtwoopt}{}
\long\def\@renewcommandtwoopt#1#2{%
  \begingroup
    \escapechar\m@ne
    \xdef\@gtempa{{\string#2}}%
  \endgroup
  \expandafter\@ifundefined\@gtempa{%
    \@latex@error{\noexpand#2undefined}\@ehc
  }{}%
  \let#2\@undefined
  \expandafter\let\csname2\string#2\endcsname\@undefined
  \expandafter\@@newcommandtwoopt
    \csname2\string#2\endcsname{#1}{#2}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\providecommandtwoopt}
%    \begin{macrocode}
\newcommand{\providecommandtwoopt}{%
  \@ifstar{\@providecommandtwoopt*}{\@providecommandtwoopt{}}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@providecommandtwoopt}
%    \begin{param}
%      \entry1 star\\
%      \entry2 command name to be defined
%    \end{param}
%    \begin{macrocode}
\newcommand{\@providecommandtwoopt}{}
\long\def\@providecommandtwoopt#1#2{%
  \begingroup
    \escapechar\m@ne
    \xdef\@gtempa{{\string#2}}%
  \endgroup
  \expandafter\@ifundefined\@gtempa{%
    \expandafter\@@newcommandtwoopt
      \csname2\string#2\endcsname{#1}{#2}%
  }{%
    \let\to@dummyA\@undefined
    \let\to@dummyB\@undefined
    \@@newcommandtwoopt\to@dummyA{#1}\to@dummyB
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\to@ScanSecondOptArg}
%    \begin{param}
%      \entry1 help command to be defined
%        (\expandafter\cmd\csname 2\bslash<name>\endcsname)\\
%      \entry2 first arg of command to be defined\\
%      \entry3 default for second opt. arg.
%    \end{param}
%    \begin{macrocode}
\newcommand{\to@ScanSecondOptArg}[3]{%
  \@ifnextchar[{%
    \expandafter#1\to@ArgOptToArgArg{#2}%
  }{%
    #1{#2}{#3}%
  }%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\to@ArgOptToArgArg}
%    \begin{macrocode}
\newcommand{\to@ArgOptToArgArg}{}
\long\def\to@ArgOptToArgArg#1[#2]{{#1}{#2}}
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \StartHistory
% \HistVersion{1998/10/30 v1.0}
%   \begin{itemize}
%   \item The first version was built as a response to a question
%     of \Email[Rebecca and Rowland]{rebecca@astrid.u-net.com},
%     published in the newsgroup
%     \href{news:comp.text.tex}{comp.text.tex}:\\
%     \URL{``Re: [Q] LaTeX command with two optional arguments?''}^^A
%     {http://www.dejanews.com/[ST_rn=ps]/getdoc.xp?AN=406573518}
%   \end{itemize}
% \HistVersion{1998/10/30 v1.1}
%   \begin{itemize}
%   \item Improvements added in response to
%     \Email[Stefan Ulrich]{ulrich@cis.uni-muenchen.de}
%     in the same thread:\\
%     \URL{``Re: [Q] LaTeX command with two optional arguments?''}^^A
%     {http://www.dejanews.com/[ST_rn=ps]/getdoc.xp?AN=406703373}
%   \end{itemize}
% \HistVersion{1998/11/04 v1.2}
%   \begin{itemize}
%   \item Fixes for LaTeX bugs 2896, 2901, 2902 added.
%   \end{itemize}
% \HistVersion{1999/04/12 v1.3}
%   \begin{itemize}
%   \item Fixes removed because of LaTeX [1998/12/01].
%   \item Documentation in dtx format.
%   \item Copyright: LPPL (\CTAN{macros/latex/base/lppl.txt})
%   \item First CTAN release.
%   \end{itemize}
%
% \hfuzz10pt
% \PrintIndex
%
% \Finale
\endinput