%% LaTeX2e file `ttct0001.sty'
%% generated by the `filecontents' environment
%% from source `ttp04-22' on 2004/12/03.
%%
%%
%% (C) Copyright 1998, Frank Mittelbach.
%% All rights reserved
%%
%% Extracted from code for Tools and Techniques for Computer
%% Typesetting Series class file
%%
%% Commands to support LaTeX syntax display
%%
\newcommand\DefC[1]{\displayCmd{#1}\doArgScan}
\newcommand\DefE[1]{\displayEnv{#1}\doArgScan}

\newcommand\BDefC{\begin{BDef}\def\doDefFinish{\end{BDef}}\DefC}
\newcommand\BDefE{\begin{BDef}\def\doDefFinish{\end{BDef}}\DefE}

%% Scanning ...
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\@xexpast#1*#2#3#4\@@{%
  \edef\reserved@a{#1}%
  \@tempcnta#2\relax
  \ifnum\@tempcnta>\z@
    \@whilenum\@tempcnta>\z@\do
       {\edef\reserved@a{\reserved@a#3}\advance\@tempcnta \m@ne}%
    \let\reserved@b\@xexpast
  \else
    \let\reserved@b\@xexnoop
  \fi
  \expandafter\reserved@b\reserved@a #4\@@}

\def\@xexnoop #1\@@{}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand\doArgScan[1][]{%
  \@xexpast#1*0x\@@
  \expandafter\doArg\reserved@a!?}

\newcommand\doArg{}
\def\doArg#1#2?{%
  \if>#2>%                          % #2 empty then #1=! -> stop
    \doDefFinish                    % execute anything special before leaving
    \expandafter\@gobble
  \else
    \expandafter\@firstofone
  \fi
  {\xdoArg#1{#2}}%                   % scan further
}

\newcommand\xdoArg[3]{%
  \@ifundefined{displayArg#1}%
     {\ClassError{ttct}{Argument  specifier  `#1'  unknown}
                {The commands \noexpand\DefC and \noexpand\DefE etc.
                 support only a limited set of letters in\MessageBreak
                 their
                 optional argument, e.g., m (mandatory), o (optional).
                 Additional letters\MessageBreak
                 can be defined by supplying
                 a definition for \string\displayArg<letter>.}}%
  %
     {\csname displayArg#1\endcsname{#3}}%    % do what is necessary for this letter
  %
  \doArg#2?%      % pickup next potential letter
}

\newcommand\doDefFinish{}
\let\doDefFinish\relax

\newsavebox{\boxdef}

\newenvironment{BDef}
  {\begin{lrbox}\boxdef
      \def\arraystretch{1.0}%
      \begin{tabular}{@{}l@{}l@{}l@{}}%
  }
  {\end{tabular}\end{lrbox}%
   {\BCmd\fbox{\usebox\boxdef}\endBCmd}%
   \aftergroup\@afterindentfalse\aftergroup\@afterheading
  }

\newenvironment{BCmd}{
  \@beginparpenalty-\@lowpenalty
  \fboxsep2pt
  \flushleft}
 {\@endparpenalty\@M
  \@topsepadd 6pt\relax
  \endflushleft}

%%%%%%%%%%%%%
%%
%% LaTeX Syntax Displays
%%
%%%%%%%%%%%%%

\newcommand\Larg [1]{{\normalfont\itshape#1\/}}
\newcommand\Largb[1]{\lcb\Larg{#1}\rcb}          % curly brace
\newcommand\Largs[1]{\lsb\Larg{#1}\rsb}          % square brackets
\newcommand\Largr[1]{\lrb\Larg{#1}\rrb}          % round brackets

\DeclareRobustCommand\bs{{\normalfont\ttfamily\textbackslash}}

\DeclareRobustCommand\lcb{{\normalfont\ttfamily\textbraceleft}}
\DeclareRobustCommand\rcb{{\normalfont\ttfamily\textbraceright}}
\DeclareRobustCommand\lsb{{\normalfont\ttfamily[}}
\DeclareRobustCommand\rsb{{\normalfont\ttfamily]}}
\DeclareRobustCommand\lrb{{\normalfont\ttfamily(}}
\DeclareRobustCommand\rrb{{\normalfont\ttfamily)}}

\newcommand\displayEnv [1]{\nxLBEG{#1}\typeout{Environment name: #1}}
\newcommand\displayCmd [1]{\nxLcs {#1}\typeout{Command name: #1}}

%% define what to do for letters in optional argument of \DefC and friends
%%
\newcommand\displayArgm[1]{\Largb{#1}\typeout{\@spaces mandatory argument: #1}}
\newcommand\displayArgo[1]{\Largs{#1}\typeout{\@spaces optional argument: #1}}
\newcommand\displayArgp[1]{\Largr{#1}\typeout{\@spaces parenthesis argument: #1}}

\DeclareRobustCommand\nxLcs[1]{\mbox{\normalfont\ttfamily\bs#1}}
\DeclareRobustCommand\nxLBEG[1]{{\normalfont\ttfamily\bs{}begin\lcb#1\rcb}}
