1 % ALGORITHMIC STYLE for LaTeX version 2e
3 % This style file is free software; you can redistribute it and/or
4 % modify it under the terms of the GNU Lesser General Public
5 % License as published by the Free Software Foundation; either
6 % version 2 of the License, or (at your option) any later version.
8 % This style file is distributed in the hope that it will be useful,
9 % but WITHOUT ANY WARRANTY; without even the implied warranty of
10 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 % Lesser General Public License for more details.
13 % You should have received a copy of the GNU Lesser General Public
14 % License along with this style file; if not, write to the
15 % Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 % Boston, MA 02111-1307, USA.
18 \NeedsTeXFormat{LaTeX2e}
19 \ProvidesPackage{algorithmic}[2005/07/05]
20 \typeout{Document Style `algorithmic' - environment}
22 \RequirePackage{ifthen}
24 \RequirePackage{keyval}
25 \newboolean{ALC@noend}
26 \setboolean{ALC@noend}{false}
29 \newcounter{ALC@depth}
32 \DeclareOption{noend}{\setboolean{ALC@noend}{true}}
36 % For keyval-style options
37 \def\algsetup{\setkeys{ALG}}
39 % For indentation of algorithms
40 \newlength{\algorithmicindent}
41 \setlength{\algorithmicindent}{0pt}
42 \define@key{ALG}{indent}{\setlength{\algorithmicindent}{#1}}
43 \ifthenelse{\lengthtest{\algorithmicindent=0pt}}%
44 {\setlength{\algorithmicindent}{1em}}{}
46 % For line numbers' delimiters
47 \newcommand{\ALC@linenodelimiter}{:}
48 \define@key{ALG}{linenodelimiter}{\renewcommand{\ALC@linenodelimiter}{#1}}
51 % For line numbers' size
52 \newcommand{\ALC@linenosize}{\footnotesize}
53 \define@key{ALG}{linenosize}{\renewcommand{\ALC@linenosize}{#1}}
57 \newcommand{\algorithmicrequire}{\textbf{Require:}}
58 \newcommand{\algorithmicensure}{\textbf{Ensure:}}
59 \newcommand{\algorithmiccomment}[1]{\{#1\}}
60 \newcommand{\algorithmicend}{\textbf{end}}
61 \newcommand{\algorithmicif}{\textbf{if}}
62 \newcommand{\algorithmicthen}{\textbf{then}}
63 \newcommand{\algorithmicelse}{\textbf{else}}
64 \newcommand{\algorithmicelsif}{\algorithmicelse\ \algorithmicif}
65 \newcommand{\algorithmicendif}{\algorithmicend\ \algorithmicif}
66 \newcommand{\algorithmicfor}{\textbf{for}}
67 \newcommand{\algorithmicforall}{\textbf{for all}}
68 \newcommand{\algorithmicdo}{\textbf{do}}
69 \newcommand{\algorithmicendfor}{\algorithmicend\ \algorithmicfor}
70 \newcommand{\algorithmicwhile}{\textbf{while}}
71 \newcommand{\algorithmicendwhile}{\algorithmicend\ \algorithmicwhile}
72 \newcommand{\algorithmicloop}{\textbf{loop}}
73 \newcommand{\algorithmicendloop}{\algorithmicend\ \algorithmicloop}
74 \newcommand{\algorithmicrepeat}{\textbf{repeat}}
75 \newcommand{\algorithmicuntil}{\textbf{until}}
76 \newcommand{\algorithmicprint}{\textbf{print}}
77 \newcommand{\algorithmicreturn}{\textbf{return}}
79 \def\@currentlabel{\theALC@line}%
82 \if@noparitem \@donoparitem
83 \else \if@inlabel \indent \par \fi
84 \ifhmode \unskip\unskip \par \fi
85 \if@newlist \if@nobreak \@nbitem \else
86 \addpenalty\@beginparpenalty
87 \addvspace\@topsep \addvspace{-\parskip}\fi
88 \else \addpenalty\@itempenalty \addvspace\itemsep
92 \everypar{\global\@minipagefalse\global\@newlistfalse
93 \if@inlabel\global\@inlabelfalse \hskip -\parindent \box\@labels
95 \everypar{}}\global\@nobreakfalse
96 \if@noitemarg \@noitemargfalse \if@nmbrlist \refstepcounter{\@listctr}\fi \fi
97 \sbox\@tempboxa{\makelabel{#1}}%
98 \global\setbox\@labels
99 \hbox{\unhbox\@labels \hskip \itemindent
100 \hskip -\labelwidth \hskip -\ALC@tlm
101 \ifdim \wd\@tempboxa >\labelwidth
103 \else \hbox to\labelwidth {\unhbox\@tempboxa}\fi
104 \hskip \ALC@tlm}\ignorespaces}
106 \newenvironment{algorithmic}[1][0]{
107 \setcounter{ALC@depth}{\@listdepth}%
108 \let\@listdepth\c@ALC@depth%
110 \newcommand{\ALC@lno}{%
111 \ifthenelse{\equal{\arabic{ALC@rem}}{0}}
112 {{\ALC@linenosize \arabic{ALC@line}\ALC@linenodelimiter}}{}%
120 \newenvironment{ALC@g}{
121 \begin{list}{\ALC@lno}{ \itemsep\z@ \itemindent\z@
122 \listparindent\z@ \rightmargin\z@
123 \topsep\z@ \partopsep\z@ \parskip\z@\parsep\z@
124 \leftmargin \algorithmicindent%1em
125 \addtolength{\ALC@tlm}{\leftmargin}
129 \newcommand{\ALC@it}{\refstepcounter{ALC@line}\refstepcounter{ALC@rem}\ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}\item\ALC@setref}
130 \newcommand{\ALC@com}[1]{\ifthenelse{\equal{##1}{default}}%
131 {}{\ \algorithmiccomment{##1}}}
132 \newcommand{\REQUIRE}{\item[\algorithmicrequire]}
133 \newcommand{\ENSURE}{\item[\algorithmicensure]}
134 \newcommand{\PRINT}{\ALC@it\algorithmicprint{}\ \ }
135 \newcommand{\RETURN}{\ALC@it\algorithmicreturn{}\ \ }
136 \newcommand{\STATE}{\ALC@it}
137 \newcommand{\COMMENT}[1]{\algorithmiccomment{##1}}
138 \newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}}
139 \newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}}
140 \newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}}
141 \newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}}
142 \newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}}
143 \renewcommand{\\}{\@centercr}
144 \newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen%
145 \ALC@com{##1}\begin{ALC@if}}
146 \newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse%
147 \ALC@com{##1}\begin{ALC@if}}
148 \newcommand{\ELSIF}[2][default]%
149 {\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen%
150 \ALC@com{##1}\begin{ALC@if}}
151 \newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo%
152 \ALC@com{##1}\begin{ALC@for}}
153 \newcommand{\FORALL}[2][default]{\ALC@it\algorithmicforall\ ##2\ %
155 \ALC@com{##1}\begin{ALC@for}}
156 \newcommand{\WHILE}[2][default]{\ALC@it\algorithmicwhile\ ##2\ %
158 \ALC@com{##1}\begin{ALC@whl}}
159 \newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop%
160 \ALC@com{##1}\begin{ALC@loop}}
161 \newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat%
162 \ALC@com{##1}\begin{ALC@rpt}}
163 \newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1}
164 \ifthenelse{\boolean{ALC@noend}}{
165 \newcommand{\ENDIF}{\end{ALC@if}}
166 \newcommand{\ENDFOR}{\end{ALC@for}}
167 \newcommand{\ENDWHILE}{\end{ALC@whl}}
168 \newcommand{\ENDLOOP}{\end{ALC@loop}}
170 \newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif}
171 \newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor}
172 \newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile}
173 \newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop}
175 \renewcommand{\@toodeep}{}
176 \begin{list}{\ALC@lno}{\setcounter{ALC@line}{0}\setcounter{ALC@rem}{0}%
177 \itemsep\z@ \itemindent\z@ \listparindent\z@%
178 \partopsep\z@ \parskip\z@ \parsep\z@%
179 \labelsep 0.5em \topsep 0.2em%
180 \ifthenelse{\equal{#1}{0}}
183 \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}