% showcmnd style, ver. 0.12, 2 Jan. 2000, by Oleg Motygin
%
%  information on definitions by \newcommand, \renewcommand placed between 
% \startTraceDefs{FOO} (where FOO is any identifier which can be treated as a name
% of a TeX command) and \endTraceDefs is collected  and can be used afterwards 
% to show list of commands by using \nomenclature{FOO}{WIDTH} which puts the list 
% to output with the items of width WIDTH and of the form: 
% command .... how it looks
%
% Some groups of commands can be traced using different names for groups.
%
% Sample of usage:
%
% \usepackage{showcmnd,multicol}
% ....
% \startTraceDefs{cmnds}
% \newcommand{\foo}[1]{\ensuremath{w_{#1}}}
% ....
% \endTraceDefs
%
% \begin{document}
%
%  \thispagestyle{empty}
%  \noindent Nomenclature:
%  \begin{multicols}{3}
%  \noindent
%  \nomenclature{cmnds}{11em}
%  \end{multicols}
%  \addtocounter{page}{-1}\clearpage
% ....
%
% This creates a page before the main text with definitions shown.
%
% Note that in creating presentation of the commands the style file 
% invokes them in the current mode, so if your commands are intended 
% to work in math mode, please use \ensuremath command as above.
%
% However, \nomenclature has additional parameter, e.g.
% \nomenclature[\ensuremath]{cmnds}{11em}
% so for creating the list of commands they are invoked within the scope 
% of \ensuremath (the command given as the additional parameter). The 
% latter is useful if all commands in the traced group are mathematical.

\def\filename{showcmnd}
\def\fileversion{v0.12}
\def\filedate{2000/01/02}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{showcmnd}[2000/01/02 v0.12]
\typeout{Package: `showcmnd' v0.12\space<2000/01/02>}

\let\after@rec=\newline
\let\@yargdef@init@@@=\@yargdef
\newif\iftr@cing

\def\startTraceDefs#1{%
\iftr@cing
  \@warning{<By Showcmnd>nested tracing of declarations not allowed}%
\else
  \global\tr@cingtrue%
  \expandafter\xdef\csname s@v@@lst#1\endcsname{}%
  \long\gdef\@yargdef##1##2##3{%
    \ifx##2\@ne
    \expandafter\xdef\csname s@v@@lst#1\endcsname%
       {\csname s@v@@lst#1\endcsname\expandafter\@gobble\string##1[##3][0]::}%
    \else
    \expandafter\xdef\csname s@v@@lst#1\endcsname%
       {\csname s@v@@lst#1\endcsname\expandafter\@gobbletwo\string##1[##3][1]::}%
    \fi
    \@yargdef@init@@@##1##2##3%
  }%
\fi}

\def\endTraceDefs{\global\tr@cingfalse\global\let\@yargdef=\@yargdef@init@@@}

\newcounter{p@r@m@numb}
\newcounter{p@r@m@numbi}

\newcommand{\nomenclature}[3][\@nil]{%
\@ifundefined{s@v@@lst#2}{\@warning{<By Showcmnd>set of commands #2 undefined}}{%
\def\@@@arg##1{\texttt{\#\kern-0.12em##1}}%
\def\@@@arg@##1{\{\kern-0.1em\#\kern-0.12em##1\kern-0.1em\}}%
\def\@com@ndsl@sh##1{\string\ \kern-0.5em##1}%
\def\op@br{\mbox{$[$}}\def\cl@br{\mbox{$]$}}%
\ifx#1\@nil
  \let\@dd@outer@cmnd=\relax
\else
  \let\@dd@outer@cmnd=#1%
\fi
\def\@ee@{\ifnum\thep@r@m@numbi<\thep@r@m@numb
  \addtocounter{p@r@m@numbi}{1}\@@@arg{\thep@r@m@numbi}\fi}%
\def\@ff@{\ifnum\thep@r@m@numbi<\thep@r@m@numb
  \addtocounter{p@r@m@numbi}{1}\@@@arg@{\thep@r@m@numbi}\fi}%
\def\init@@count##1{%
  \setcounter{p@r@m@numb}{##1}\setcounter{p@r@m@numbi}{0}}%
\def\init@@counti##1{%
  \setcounter{p@r@m@numb}{##1}\setcounter{p@r@m@numbi}{0}% 
  \addtocounter{p@r@m@numb}{-1}}%
\def\democom##1##2##3{%
  \ifnum##2=1%
    \def\name@cmnd{\init@@counti{##1}\@com@ndsl@sh{##3}\@ff@\@ff@\@ff@\@ff@%
        \@ff@\@ff@\@ff@\@ff@\@ff@\@ff@}%
    \def\res@cmnd{\init@@counti{##1}\@dd@outer@cmnd{\csname ##3\endcsname%
        \@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@}}%   
    \def\name@cmnd@i{\init@@counti{##1}\@com@ndsl@sh{##3}%
        \op@br\@@@arg{0}\cl@br\kern-0.1em%
        \@ff@\@ff@\@ff@\@ff@\@ff@\@ff@\@ff@\@ff@\@ff@\@ff@}% 
    \def\res@cmnd@i{\init@@counti{##1}\@dd@outer@cmnd{\csname ##3\endcsname[\@@@arg{0}]%
        \@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@}}%
  \else
    \def\name@cmnd{\init@@count{##1}\@com@ndsl@sh{##3}\@ff@\@ff@\@ff@\@ff@\@ff@\@ff@%
        \@ff@\@ff@\@ff@\@ff@}%
    \def\res@cmnd{\init@@count{##1}\@dd@outer@cmnd{\csname ##3\endcsname%
        \@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@\@ee@}}%
  \fi
\hbox to #3{\texttt{\name@cmnd}\ \dotfill\ \res@cmnd}\after@rec
\ifnum##2=1
  \hbox to #3{\texttt{\name@cmnd@i}\ \dotfill\ \res@cmnd@i}\after@rec
\fi
}%
\def\unlst@sv##1[##2][##3]::##4{\democom{##2}{##3}{##1}%
  \ifx##4.\def\next{\relax}\else\def\next{\unlst@sv##4}\fi\next}%
\expandafter\let\expandafter\a@a\csname s@v@@lst#2\endcsname
\expandafter\unlst@sv\a@a.}}

\endinput
%% End of file `showcmnd.sty'.
