% PSEUDOCODE ALGORITHMIC STYLE -- Released 17 DEC 2003
%    for LaTeX version 2e
%
% Copyright Szasz Janos
% E-mail kaporrr@yahoo.com
% Based on Peter Williams's algorithmic.sty
%
\NeedsTeXFormat{LaTeX2e}%
\ProvidesPackage{algpseudocode}%
\typeout{Document Style - pseudocode environments for use with the `algorithmicx' style}%
%
\RequirePackage{ifthen}%
\RequirePackage{algorithmicx}%
%
\newboolean{ALG@setpseudocode}%
\setboolean{ALG@setpseudocode}{true}%
\newboolean{ALG@noend}%
\setboolean{ALG@noend}{false}%
\newboolean{ALG@compatible}%
\setboolean{ALG@compatible}{false}%
%
%
%
\DeclareOption{noset}{\setboolean{ALG@setpseudocode}{false}}%
\DeclareOption{noend}{\setboolean{ALG@noend}{true}}%
\DeclareOption{end}{\setboolean{ALG@noend}{false}}%
\DeclareOption{compatible}{\setboolean{ALG@compatible}{true}}%
\DeclareOption{noncompatible}{\setboolean{ALG@noncompatible}{false}}%
%
\ProcessOptions%
%
%
%
%      ***      SET      ***
%
%
%
\newcommand{\ALG@setlanguage@pseudocode}%
{%
%
%
%
%      ***      KEYWORDS      ***
%
%
%
\newcommand{\algorithmicend}{\textbf{end}}
\newcommand{\algorithmicdo}{\textbf{do}}
\newcommand{\algorithmicwhile}{\textbf{while}}
\newcommand{\algorithmicfor}{\textbf{for}}
\newcommand{\algorithmicforall}{\textbf{for all}}
\newcommand{\algorithmicloop}{\textbf{loop}}
\newcommand{\algorithmicrepeat}{\textbf{repeat}}
\newcommand{\algorithmicuntil}{\textbf{until}}
\newcommand{\algorithmicprocedure}{\textbf{procedure}}
\newcommand{\algorithmicfunction}{\textbf{function}}
\newcommand{\algorithmicif}{\textbf{if}}
\newcommand{\algorithmicthen}{\textbf{then}}
\newcommand{\algorithmicelse}{\textbf{else}}
\newcommand{\algorithmicrequire}{\textbf{Require:}}
\newcommand{\algorithmicensure}{\textbf{Ensure:}}
\newcommand{\textproc}{\textsc}
%
%
%
%      ***      DECLARED LOOPS      ***
%
%
%
%
%  WHILE
%
\algblock[WHILE]{While}{EndWhile}
%
%  FOR
%
\algblock[FOR]{For}{EndFor}
\algblock[FOR]{ForAll}{EndFor}
%
%  LOOP
%
\algblock[LOOP]{Loop}{EndLoop}% ... do you realy need something like this???
%
%  REPEAT
%
\algblock[REPEAT]{Repeat}{Until}
%
%  PROCEDURE
%
\algblock[PROCEDURE]{Procedure}{EndProcedure}
%
%  FUNCTION
%
\algblock[FUNCTION]{Function}{EndFunction}
%
%  IF
%
\algblock[IF]{If}{EndIf}
\algcblock[ELSE]{IF}{Else}{EndIf}
\algcblock[IF]{IF}{ElsIf}{EndIf}
%
\ifthenelse{\boolean{ALG@compatible}}%
   {%
   \algblock[WHILE]{WHILE}{ENDWHILE}%
   \algblock[FOR]{FOR}{ENDFOR}%
   \algblock[FOR]{FORALL}{ENDFOR}%
   \algblock[LOOP]{LOOP}{ENDLOOP}% ... do you realy need something like this???
   \algblock[REPEAT]{REPEAT}{UNTIL}%
   \algblock[PROCEDURE]{PROCEDURE}{ENDPROCEDURE}%
   \algblock[FUNCTION]{FUNCTION}{ENDFUNCTION}%
   \algblock[IF]{IF}{ENDIF}%
   \algcblock[ELSE]{IF}{ELSE}{ENDIF}%
   \algcblock[IF]{IF}{ELSIF}{ENDIF}%
   }%
   {}%
%
%
%
%      ***      Setting the text of the environments      ***
%
%
%
\renewcommand{\algorithmicWhile}[1]{\algorithmicwhile\ ##1 \algorithmicdo}%
\renewcommand{\algorithmicFor}[1]{\algorithmicfor\ ##1 \algorithmicdo}%
\renewcommand{\algorithmicForAll}[1]{\algorithmicforall\ ##1 \algorithmicdo}%
\renewcommand{\algorithmicLoop}{\algorithmicloop}%
\renewcommand{\algorithmicRepeat}{\algorithmicrepeat}%
\renewcommand{\algorithmicUntil}[1]{\algorithmicuntil\ ##1}%
\renewcommand{\algorithmicProcedure}[2]%
   {%
   \algorithmicprocedure\ \textproc{##1}%
   \ifthenelse{\equal{##2}{}}{}{(##2)}% ($##2$) ???
   }%
\renewcommand{\algorithmicFunction}[2]%
   {%
   \algorithmicfunction\ \textproc{##1}%
   \ifthenelse{\equal{##2}{}}{}{(##2)}% ($##2$) ???
   }%
\renewcommand{\algorithmicIf}[1]{\algorithmicif\ ##1 \algorithmicthen}%
\renewcommand{\algorithmicElse}{\algorithmicelse}%
\renewcommand{\algorithmicElsIf}[1]{\algorithmicelse\ \algorithmicif\ ##1 \algorithmicthen}%
%
\ifthenelse{\boolean{ALG@compatible}}%
   {%
   \renewcommand{\algorithmicWHILE}{\algorithmicWhile}%
   \renewcommand{\algorithmicFOR}{\algorithmicFor}%
   \renewcommand{\algorithmicFORALL}{\algorithmicForAll}%
   \renewcommand{\algorithmicLOOP}{\algorithmicLoop}%
   \renewcommand{\algorithmicREPEAT}{\algorithmicRepeat}%
   \renewcommand{\algorithmicUNTIL}{\algorithmicUntil}%
   \renewcommand{\algorithmicPROCEDURE}{\algorithmicProcedure}%
   \renewcommand{\algorithmicFUNCTION}{\algorithmicFunction}%
   \renewcommand{\algorithmicIF}{\algorithmicIf}%
   \renewcommand{\algorithmicELSE}{\algorithmicElse}%
   \renewcommand{\algorithmicELSIF}{\algorithmicElsIf}%
   }%
   {}%
%
\ifthenelse{\boolean{ALG@noend}}%
   {%
   \algnotext{EndWhile}%
   \algnotext{EndFor}%
   \algnotext{EndLoop}%
   \algnotext{EndProcedure}%
   \algnotext{EndFunction}%
   \algnotext{EndIf}%
   \ifthenelse{\boolean{ALG@compatible}}%
      {%
      \algnotext{ENDWHILE}%
      \algnotext{ENDFOR}%
      \algnotext{ENDLOOP}%
      \algnotext{ENDPROCEDURE}%
      \algnotext{ENDFUNCTION}%
      \algnotext{ENDIF}%
      }%
      {}%
   }%
   {%
   \renewcommand{\algorithmicEndWhile}{\algorithmicend\ \algorithmicwhile}%
   \renewcommand{\algorithmicEndFor}{\algorithmicend\ \algorithmicfor}%
   \renewcommand{\algorithmicEndLoop}{\algorithmicend\ \algorithmicloop}%
   \renewcommand{\algorithmicEndProcedure}{\algorithmicend\ \algorithmicprocedure}%
   \renewcommand{\algorithmicEndFunction}{\algorithmicend\ \algorithmicfunction}%
   \renewcommand{\algorithmicEndIf}{\algorithmicend\ \algorithmicif}%
   \ifthenelse{\boolean{ALG@compatible}}%
      {%
      \renewcommand{\algorithmicENDWHILE}{\algorithmicEndWhile}%
      \renewcommand{\algorithmicENDFOR}{\algorithmicEndFor}%
      \renewcommand{\algorithmicENDLOOP}{\algorithmicEndLoop}%
      \renewcommand{\algorithmicENDPROCEDURE}{\algorithmicEndProcedure}%
      \renewcommand{\algorithmicENDFUNCTION}{\algorithmicEndFunction}%
      \renewcommand{\algorithmicENDIF}{\algorithmicEndIf}%
      }%
      {}%
   }%
%
%
%
%      ***      OTHER DECLARATIONS      ***
%
%
%
\newcommand{\Require}{\item[\algorithmicrequire]}
\newcommand{\Ensure}{\item[\algorithmicensure]}
\newcommand{\REQUIRE}{\Require}
\newcommand{\ENSURE}{\Ensure}
%
%
%
}%
%
%
%
%
%      ***      DEFINE THE COMMANDS, IF NEEDED      ***
%
%
%
\ifthenelse{\boolean{ALG@setpseudocode}}%
   {\algsetlanguage{pseudocode}}%
   {}%
%
