1 % ALGORITHMIC STYLE -- Released 8 APRIL 1996
3 % Copyright -- 1994 Peter Williams
4 % E-mail PeterWilliams@dsto.defence.gov.au
5 \NeedsTeXFormat{LaTeX2e}
6 \ProvidesPackage{algorithmic}
7 \typeout{Document Style `algorithmic' - environment}
9 \RequirePackage{ifthen}
11 \newboolean{ALC@noend}
12 \setboolean{ALC@noend}{false}
17 \DeclareOption{noend}{\setboolean{ALC@noend}{true}}
22 \newcommand{\algorithmicrequire}{\textbf{Require:}}
23 \newcommand{\algorithmicensure}{\textbf{Ensure:}}
24 \newcommand{\algorithmiccomment}[1]{\{#1\}}
25 \newcommand{\algorithmicend}{\textbf{end}}
26 \newcommand{\algorithmicif}{\textbf{if}}
27 \newcommand{\algorithmicthen}{\textbf{then}}
28 \newcommand{\algorithmicelse}{\textbf{else}}
29 \newcommand{\algorithmicelsif}{\algorithmicelse\ \algorithmicif}
30 \newcommand{\algorithmicendif}{\algorithmicend\ \algorithmicif}
31 \newcommand{\algorithmicfor}{\textbf{for}}
32 \newcommand{\algorithmicforall}{\textbf{for all}}
33 \newcommand{\algorithmicdo}{\textbf{do}}
34 \newcommand{\algorithmicendfor}{\algorithmicend\ \algorithmicfor}
35 \newcommand{\algorithmicwhile}{\textbf{while}}
36 \newcommand{\algorithmicendwhile}{\algorithmicend\ \algorithmicwhile}
37 \newcommand{\algorithmicloop}{\textbf{loop}}
38 \newcommand{\algorithmicendloop}{\algorithmicend\ \algorithmicloop}
39 \newcommand{\algorithmicrepeat}{\textbf{repeat}}
40 \newcommand{\algorithmicuntil}{\textbf{until}}
42 \if@noparitem \@donoparitem
43 \else \if@inlabel \indent \par \fi
44 \ifhmode \unskip\unskip \par \fi
45 \if@newlist \if@nobreak \@nbitem \else
46 \addpenalty\@beginparpenalty
47 \addvspace\@topsep \addvspace{-\parskip}\fi
48 \else \addpenalty\@itempenalty \addvspace\itemsep
52 \everypar{\global\@minipagefalse\global\@newlistfalse
53 \if@inlabel\global\@inlabelfalse \hskip -\parindent \box\@labels
55 \everypar{}}\global\@nobreakfalse
56 \if@noitemarg \@noitemargfalse \if@nmbrlist \refstepcounter{\@listctr}\fi \fi
57 \sbox\@tempboxa{\makelabel{#1}}%
58 \global\setbox\@labels
59 \hbox{\unhbox\@labels \hskip \itemindent
60 \hskip -\labelwidth \hskip -\ALC@tlm
61 \ifdim \wd\@tempboxa >\labelwidth
63 \else \hbox to\labelwidth {\unhbox\@tempboxa}\fi
64 \hskip \ALC@tlm}\ignorespaces}
66 \newenvironment{algorithmic}[1][0]{
68 \newcommand{\ALC@lno}{%
69 \ifthenelse{\equal{\arabic{ALC@rem}}{0}}
70 {{\footnotesize \arabic{ALC@line}:}}{}%
78 \newenvironment{ALC@g}{
79 \begin{list}{\ALC@lno}{ \itemsep\z@ \itemindent\z@
80 \listparindent\z@ \rightmargin\z@
81 \topsep\z@ \partopsep\z@ \parskip\z@\parsep\z@
83 \addtolength{\ALC@tlm}{\leftmargin}
87 \newcommand{\ALC@it}{\addtocounter{ALC@line}{1}\addtocounter{ALC@rem}{1}\ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}\item}
88 \newcommand{\ALC@com}[1]{\ifthenelse{\equal{##1}{default}}%
89 {}{\ \algorithmiccomment{##1}}}
90 \newcommand{\REQUIRE}{\item[\algorithmicrequire]}
91 \newcommand{\ENSURE}{\item[\algorithmicensure]}
92 \newcommand{\STATE}{\ALC@it}
93 \newcommand{\COMMENT}[1]{\algorithmiccomment{##1}}
94 \newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}}
95 \newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}}
96 \newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}}
97 \newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}}
98 \newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}}
99 \renewcommand{\\}{\@centercr}
100 \newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen%
101 \ALC@com{##1}\begin{ALC@if}}
102 \newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse%
103 \ALC@com{##1}\begin{ALC@if}}
104 \newcommand{\ELSIF}[2][default]%
105 {\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen%
106 \ALC@com{##1}\begin{ALC@if}}
107 \newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo%
108 \ALC@com{##1}\begin{ALC@for}}
109 \newcommand{\FORALL}[2][default]{\ALC@it\algorithmicforall\ ##2\ %
111 \ALC@com{##1}\begin{ALC@for}}
112 \newcommand{\WHILE}[2][default]{\ALC@it\algorithmicwhile\ ##2\ %
114 \ALC@com{##1}\begin{ALC@whl}}
115 \newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop%
116 \ALC@com{##1}\begin{ALC@loop}}
117 \newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat%
118 \ALC@com{##1}\begin{ALC@rpt}}
119 \newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1}
120 \ifthenelse{\boolean{ALC@noend}}{
121 \newcommand{\ENDIF}{\end{ALC@if}}
122 \newcommand{\ENDFOR}{\end{ALC@for}}
123 \newcommand{\ENDWHILE}{\end{ALC@whl}}
124 \newcommand{\ENDLOOP}{\end{ALC@loop}}
126 \newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif}
127 \newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor}
128 \newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile}
129 \newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop}
131 \renewcommand{\@toodeep}{}
132 \begin{list}{\ALC@lno}{\setcounter{ALC@line}{0}\setcounter{ALC@rem}{0}%
133 \itemsep\z@ \itemindent\z@ \listparindent\z@%
134 \partopsep\z@ \parskip\z@ \parsep\z@%
135 \labelsep 0.5em \topsep 0.2em%
136 \ifthenelse{\equal{#1}{0}}
139 \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}