]> AND Private Git Repository - UIC2013.git/blob - algorithmic.sty
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
new
[UIC2013.git] / algorithmic.sty
1 % ALGORITHMIC STYLE for LaTeX version 2e
2 %
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.
7 %
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.
12 %
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.
17 %
18 \NeedsTeXFormat{LaTeX2e}
19 \ProvidesPackage{algorithmic}[2006/06/02]
20 \typeout{Document Style `algorithmic' - environment}
21 %
22 \RequirePackage{ifthen}
23 \RequirePackage{calc}
24 \RequirePackage{keyval}
25 \newboolean{ALC@noend}
26 \setboolean{ALC@noend}{false}
27 \newcounter{ALC@line}
28 \newcounter{ALC@rem}
29 \newcounter{ALC@depth}
30 \newlength{\ALC@tlm}
31 %
32 \DeclareOption{noend}{\setboolean{ALC@noend}{true}}
33 %
34 \ProcessOptions
35 %
36 % For keyval-style options
37 \def\algsetup{\setkeys{ALG}}
38 %
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}}{}
45 %
46 % For line numbers' delimiters
47 \newcommand{\ALC@linenodelimiter}{:}
48 \define@key{ALG}{linenodelimiter}{\renewcommand{\ALC@linenodelimiter}{#1}}
49
50 %
51 % For line numbers' size
52 \newcommand{\ALC@linenosize}{\footnotesize}
53 \define@key{ALG}{linenosize}{\renewcommand{\ALC@linenosize}{#1}}
54
55 %
56 % ALGORITHMIC
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}}
78 \newcommand{\algorithmictrue}{\textbf{true}}
79 \newcommand{\algorithmicfalse}{\textbf{false}}
80 \def\ALC@setref{%
81   \def\@currentlabel{\theALC@line}%
82 }
83 \def\ALC@item[#1]{%
84 \if@noparitem \@donoparitem
85   \else \if@inlabel \indent \par \fi
86          \ifhmode \unskip\unskip \par \fi
87          \if@newlist \if@nobreak \@nbitem \else
88                         \addpenalty\@beginparpenalty
89                         \addvspace\@topsep \addvspace{-\parskip}\fi
90            \else \addpenalty\@itempenalty \addvspace\itemsep
91           \fi
92     \global\@inlabeltrue
93 \fi
94 \everypar{\global\@minipagefalse\global\@newlistfalse
95           \if@inlabel\global\@inlabelfalse \hskip -\parindent \box\@labels
96              \penalty\z@ \fi
97           \everypar{}}\global\@nobreakfalse
98 \if@noitemarg \@noitemargfalse \if@nmbrlist \refstepcounter{\@listctr}\fi \fi
99 \sbox\@tempboxa{\makelabel{#1}}%
100 \global\setbox\@labels
101  \hbox{\unhbox\@labels \hskip \itemindent
102        \hskip -\labelwidth \hskip -\ALC@tlm
103        \ifdim \wd\@tempboxa >\labelwidth
104                 \box\@tempboxa
105           \else \hbox to\labelwidth {\unhbox\@tempboxa}\fi
106        \hskip \ALC@tlm}\ignorespaces}
107 %
108 \newenvironment{algorithmic}[1][0]{
109 \setcounter{ALC@depth}{\@listdepth}%
110 \let\@listdepth\c@ALC@depth%
111 \let\@item\ALC@item%
112   \newcommand{\ALC@lno}{%
113 \ifthenelse{\equal{\arabic{ALC@rem}}{0}}
114 {{\ALC@linenosize \arabic{ALC@line}\ALC@linenodelimiter}}{}%
115 }
116 \let\@listii\@listi
117 \let\@listiii\@listi
118 \let\@listiv\@listi
119 \let\@listv\@listi
120 \let\@listvi\@listi
121 \let\@listvii\@listi
122   \newenvironment{ALC@g}{
123     \begin{list}{\ALC@lno}{ \itemsep\z@ \itemindent\z@
124     \listparindent\z@ \rightmargin\z@ 
125     \topsep\z@ \partopsep\z@ \parskip\z@\parsep\z@
126     \leftmargin \algorithmicindent%1em
127     \addtolength{\ALC@tlm}{\leftmargin}
128     }
129   }
130   {\end{list}}
131   \newcommand{\ALC@it}{\refstepcounter{ALC@rem}\refstepcounter{ALC@line}\ifthenelse{\equal{\arabic{ALC@rem}}{#1}}{\setcounter{ALC@rem}{0}}{}\item\ALC@setref}
132   \newcommand{\ALC@com}[1]{\ifthenelse{\equal{##1}{default}}%
133 {}{\ \algorithmiccomment{##1}}}
134   \newcommand{\REQUIRE}{\item[\algorithmicrequire]}
135   \newcommand{\ENSURE}{\item[\algorithmicensure]}
136   \newcommand{\PRINT}{\ALC@it\algorithmicprint{}\ \ }
137   \newcommand{\RETURN}{\ALC@it\algorithmicreturn{}\ \ }
138   \newcommand{\TRUE}{\algorithmictrue{}}
139   \newcommand{\FALSE}{\algorithmicfalse{}}
140   \newcommand{\STATE}{\ALC@it}
141   \newcommand{\STMT}{\ALC@it}
142   \newcommand{\COMMENT}[1]{\algorithmiccomment{##1}}
143   \newenvironment{ALC@if}{\begin{ALC@g}}{\end{ALC@g}}
144   \newenvironment{ALC@for}{\begin{ALC@g}}{\end{ALC@g}}
145   \newenvironment{ALC@whl}{\begin{ALC@g}}{\end{ALC@g}}
146   \newenvironment{ALC@loop}{\begin{ALC@g}}{\end{ALC@g}}
147   \newenvironment{ALC@rpt}{\begin{ALC@g}}{\end{ALC@g}}
148   \renewcommand{\\}{\@centercr}
149   \newcommand{\IF}[2][default]{\ALC@it\algorithmicif\ ##2\ \algorithmicthen%
150 \ALC@com{##1}\begin{ALC@if}}
151   \newcommand{\ELSE}[1][default]{\end{ALC@if}\ALC@it\algorithmicelse%
152 \ALC@com{##1}\begin{ALC@if}}
153   \newcommand{\ELSIF}[2][default]%
154 {\end{ALC@if}\ALC@it\algorithmicelsif\ ##2\ \algorithmicthen%
155 \ALC@com{##1}\begin{ALC@if}}
156   \newcommand{\FOR}[2][default]{\ALC@it\algorithmicfor\ ##2\ \algorithmicdo%
157 \ALC@com{##1}\begin{ALC@for}}
158   \newcommand{\FORALL}[2][default]{\ALC@it\algorithmicforall\ ##2\ %
159 \algorithmicdo%
160 \ALC@com{##1}\begin{ALC@for}}
161   \newcommand{\WHILE}[2][default]{\ALC@it\algorithmicwhile\ ##2\ %
162 \algorithmicdo%
163 \ALC@com{##1}\begin{ALC@whl}}
164   \newcommand{\LOOP}[1][default]{\ALC@it\algorithmicloop%
165 \ALC@com{##1}\begin{ALC@loop}}
166   \newcommand{\REPEAT}[1][default]{\ALC@it\algorithmicrepeat%
167 \ALC@com{##1}\begin{ALC@rpt}}
168   \newcommand{\UNTIL}[1]{\end{ALC@rpt}\ALC@it\algorithmicuntil\ ##1}
169   \ifthenelse{\boolean{ALC@noend}}{
170     \newcommand{\ENDIF}{\end{ALC@if}}
171     \newcommand{\ENDFOR}{\end{ALC@for}}
172     \newcommand{\ENDWHILE}{\end{ALC@whl}}
173     \newcommand{\ENDLOOP}{\end{ALC@loop}}
174   }{
175     \newcommand{\ENDIF}{\end{ALC@if}\ALC@it\algorithmicendif}
176     \newcommand{\ENDFOR}{\end{ALC@for}\ALC@it\algorithmicendfor}
177     \newcommand{\ENDWHILE}{\end{ALC@whl}\ALC@it\algorithmicendwhile}
178     \newcommand{\ENDLOOP}{\end{ALC@loop}\ALC@it\algorithmicendloop}
179   } 
180   \renewcommand{\@toodeep}{}
181   \begin{list}{\ALC@lno}{\setcounter{ALC@rem}{0}\setcounter{ALC@line}{0}%
182     \itemsep\z@ \itemindent\z@ \listparindent\z@%
183     \partopsep\z@ \parskip\z@ \parsep\z@%
184     \labelsep 0.5em \topsep 0.2em%
185 \ifthenelse{\equal{#1}{0}}
186   {\labelwidth 0.5em }
187   {\labelwidth  1.2em }
188 \leftmargin\labelwidth \addtolength{\leftmargin}{\labelsep}
189     \ALC@tlm\labelsep
190   }
191 }
192 {\end{list}}