% \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
