summaryrefslogtreecommitdiff
path: root/macros/latex209/contrib/misc/optarg.sty
blob: 9a5218296b5ad0c1db8b5a9250e81161c04d77ec (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
\def\newoptargcommand#1{%
  \@ifnextchar({\@xoptargcmd{#1}}%
               {\newcommand{#1}}%
}
 
\def\@xoptargcmd#1(#2){%
%  \@ifdefinable#1%
%     {
    \expandafter\def\expandafter#1\expandafter{%
          \expandafter
          \@ifnextchar
          \expandafter
          [%
          \csname\string#1\expandafter\endcsname
          \expandafter
          {\csname\string#1\endcsname[#2]}}%
       \expandafter\@zoptargcmd
          \csname\string#1\endcsname
}
 
\def\@zoptargcmd#1{%
  \@ifnextchar[{\@zzoptargcmd#1}%
               {\def#1[####1]}%
}
 
\catcode`\?=11\relax
\long\def\@zzoptargcmd#1[#2]#3{%
  \@tempcnta#2\relax
  \let#1\relax
  \let\@?@\relax
  \edef\@tempa{\long\def#1[\@?@1]}%
  \@tempcntb \tw@
  \@whilenum\@tempcnta>\z@
      \do{%
          \edef\@tempa{\@tempa\@?@\the\@tempcntb}%
          \advance\@tempcntb \@ne
          \advance\@tempcnta \m@ne}%
  \let\@?@##%
  \@tempa{#3}%
}
\catcode`\?=12\relax
\endinput