]> AND Private Git Repository - book_gpu.git/blob - BookGPU/algorithm2e.sty
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
8c5f4b75870827833e153199dc5bde02a88da48e
[book_gpu.git] / BookGPU / algorithm2e.sty
1 %  algorithm2e.sty --- style file for algorithms
2 %                      almost everything can be customized by users. See the document for more explanations
3 %% Copyright 1996-2008 Christophe Fiorio
4 %
5 % This program may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.2
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 %   http://www.latex-project.org/lppl.txt
10 % and version 1.2 or later is part of all distributions of LaTeX 
11 % version 1999/12/01 or later.
12 %
13 % This program consists of the files algorithm2e.sty and algorithm2e.tex and algorithm2e-compatibility.sty
14 %  
15 %  Report bugs and comments to:
16 %  - algorithm2e-announce@lirmm.fr  mailing list for announcement about releases^^J%
17 %  - algorithm2e-discussion@lirmm.fr mailing list for discussion about package^^J%
18 %  subscribe by emailing sympa@lirmm.fr with 'subscribe <list> <firstname name>'^^J%
19 %
20 %  $Id: algorithm2e.sty,v 4.1 2009/12/15 08:54:08 cfiorio Exp $
21 %
22 %  PACKAGES REQUIRED:
23 %
24 %  - float   (in contrib/supported/float)
25 %  - ifthen  (in base)
26 %  - xspace  (in packages/tools)
27 %  - relsize (in contrib/misc/relsize.sty)
28 %
29 %%%%%%%%%%%%%%%  Release 4.01
30 %
31 %   Package options: 
32 %   ---------------
33 %   - oldcommands                      : to use old command names
34 %   - french, english, german, 
35 %     portuguese, czech, italiano,
36 %     slovak                           : for the name of the algorithm and some keyword code
37 %   - onelanguage                      : to simply switch keyword from one language to another without changing
38 %                                        keyword commands
39 %   - boxed, boxruled, ruled, tworuled, 
40 %     algoruled, plain                 : layout of the algorithm
41 %   - algo2e                           : environment is algorithm2e instead of algorithms and \listofalgorithmes
42 %                                        instead of \listofalgorithms
43 %   - slide                            : to use when making slides
44 %   - noline,lined,vlined              : how block are designed.
45 %   - shortend, longend, noend         : short or long end keyword as endif for e.g.
46 %   - linesnumbered                    : auto numbering of the algorithm's lines
47 %   - linesnumberedhidden              : to hide autonumbered lines (show number on a line with \ShowLn
48 %   - commentsnumbered, inoutnumbered  : to autonumber comments and inout keywords (by defaut not numbered)
49 %   - rightnl                          : to have line number on the right instead of on the left as default
50 %   - algonl                           : line numbers preceded by algo number
51 %   - scright, scleft                  : right or left justified side comments
52 %   - fillcomment, nofillcomment       : end mark of comment is flushed to the right so comments fill the line
53 %   - dotocloa                         : add an entry in the toc for list of algorithms (require tocbibind package)
54 %   - endfloat                         : add algoendfloat environment pushing algorithm so written to the end of document
55 %   - resetcount, noresetcount         : start value of line numbers.
56 %   - algopart,algochapter,algosection : algo numbering within part, chapter or section
57 %   - titlenumbered,titlenotnumbered   : numbering of title set by \Titleofalgo
58 %   - figure                           : algorithms are figures, numbered as figures, and put in the list of figures.
59 %   - procnumbered                     : procedure or function are numbered as algorithm
60 %   - nokwfunc                         : procedure or function name doens't become a command
61 %   - norelsize                        : don't use relsize package (useful if it breaks the compatibily)
62 %  
63 %   defaults are; english,plain,resetcount,titlenotnumbered
64 %
65 %%%%%%%%%%%%%%
66 %
67 %   Short summary  
68 %   -------------
69 %  
70 %   algorithm is an environment for writing algorithm in LaTeX2e.
71 %   Almost all is customizable. You can add keywords, change style, change the layout, ...
72 %   It provide macros that allow you to create differents sorts of key words, therefore a set of predefined key
73 %   word is gived.
74 %
75 %   IT should be used as follows
76 %
77 %   \begin{algorithm}
78 %       ...
79 %       ...
80 %   \end{algorithm}
81 %
82 %
83 %   IMPORTANT : each line MUST end with \;
84 %
85 %   Note that if you define macros outside algorithm environment they
86 %   are avaible in all the document and particulary you can use then
87 %   inside all algorithms without re-define them.
88 %  
89 %   an example:
90 %
91 %   \begin{algorithm}
92 %     \SetAlgoLined
93 %     \KwIn{this text}
94 %     \KwOut{how to write algorithm with \LaTeX2e }
95 %     
96 %     initialization\;
97 %     \While{not at end of this document}{
98 %       read current section\;
99 %       \eIf{understand}{
100 %         go to next section\;
101 %         current section becomes this one\;
102 %         }{
103 %         go back to the beginning of current section\;
104 %         }
105 %       }
106 %     \caption{How to write algorithm}
107 %   \end{algorithm}
108 %
109 %
110 %%%%%%%%%%%%%%         predefined keywords
111 %
112 %     \KwIn{input}
113 %     \KwOut{output}
114 %     \KwData{input}
115 %     \KwResult{output}
116 %     \KwTo                                       % a simple keyword
117 %     \KwFrom                                     % a simple keyword
118 %     \KwRet{[value]}
119 %     \Return{[value]}
120 %     \Begin{block inside}
121 %     \eIf{condition}{Then Block}{Else block}     % in blocks
122 %     \If{condition}{Then block}                  % in a block
123 %     \uIf{condition}{Then block}                 % in a block unended
124 %     \lIf{condition}{Else text}                  % on the same line
125 %     \Else{inside Else}                          % in a block
126 %     \lElse{Else text}                           % on the same line        
127 %     \uElse{Else text}                           % in a block unended
128 %     \ElseIf{inside Elseif}                      % in a block
129 %     \lElseIf{Elseif text}                       % on the same line        
130 %     \uElseIf{Elseif text}                       % in a block unended
131 %     \Switch{Condition}{Switch block}
132 %     \Case{a case}{case block}                   % in a block
133 %     \lCase{a case}{case text}                   % on the same line
134 %     \Other{otherwise block}                     % in a block
135 %     \lOther{otherwise block}                    % on the same line
136 %     \For{condition}{text loop}                  % in a block
137 %     \lFor{condition}{text}                      % on the same line
138 %     \ForEach{condition}{text loop}              % in a block
139 %     \lForEach{condition}{text}                  % on the same line
140 %     \ForPar{condition}{text loop}               % in a block
141 %     \lForPar{condition}{text}                   % on the same line
142 %     \While{condition}{text loop}                % in a block
143 %     \lWhile{condition}{text loop}               % on the same line
144 %     \Repeat{End condition}{text loop}           % in a block
145 %     \lRepeat{condition}{text}                   % on the same line
146 %
147 %%%%%%%%%%%%%%
148 %
149 %   History: 
150 %
151 %   - december 14 2009 - revision 4.01
152 %                     * ADD : new command \SetKwHangingKw{Name}{text} (hanging indent with keyword): This creates a
153 %                             hanging indent much like \texttt{SetKwInput}, except that it removes the trailing `:'
154 %                             and does not reset numbering.
155 %
156 %   - november 17 2009  - revision 4.00 -
157 %
158 %                      * CHANGE : IMPORTANT : some commands have been renamed to have consistent naming (CamlCase
159 %                                 syntax) and old commands are no more available. If you doesn't want to change
160 %                                 your mind or use old latex files, you can use oldcommands option to enable old
161 %                                 commands back.
162 %                                 text. Here are these commands:
163 %                                 - \SetNoLine becomes \SetAlgoNoLine
164 %                                 - \SetVline  becomes \SetAlgoVlined
165 %                                 - \Setvlineskip  becomes \SetVlineSkip
166 %                                 - \SetLine   becomes \SetAlgoLined
167 %                                 - \dontprintsemicolon becomes \DontPrintSemicolon
168 %                                 - \printsemicolon becomes \PrintSemicolon
169 %                                 - \incmargin becomes \IncMargin
170 %                                 - \decmargin becomes \DecMargin
171 %                                 - \setnlskip becomes \SetNlSkip
172 %                                 - \Setnlskip becomes \SetNlSkip
173 %                                 - \setalcapskip becomes \SetAlCapSkip
174 %                                 - \setalcaphskip becomes \SetAlCapHSkip
175 %                                 - \nlSty becomes \NlSty
176 %                                 - \Setnlsty becomes \SetNlSty
177 %                                 - \linesnumbered becomes \LinesNumbered
178 %                                 - \linesnotnumbered becomes \LinesNotNumbered
179 %                                 - \linesnumberedhidden becomes \LinesNumberedHidden
180 %                                 - \showln becomes \ShowLn
181 %                                 - \showlnlabel becomes \ShowLnLabel
182 %                                 - \nocaptionofalgo becomes \NoCaptionOfAlgo
183 %                                 - \restorecaptionofalgo becomes \RestoreCaptionOfAlgo
184 %                                 - \restylealgo becomes \RestyleAlgo
185 %                                 - gIf macros and so on do no more exist
186 %                      * NEW: - Compatibily with other packages improven by changing name of internal
187 %                               macros. Algorithm2e can now be used with arabtex for example, if this last is
188 %                               loaded after algorithm2e package.
189 %                      * ADD: - OPTION endfloat: endfloat packages doesn't allow float environment inside other
190 %                               environment. So using it with figure option of algorithm2e makes error. This
191 %                               option enables a new environment algoendfloat to be used instead of algorithm
192 %                               environment that put algorithm at the end. algoendfloat environment make
193 %                               algorithm acting as endfloat figures. This option requires endfloat packages.
194 %                      * ADD: - OPTION norelsize: starting from this release (v4.00), algorithm2e package uses
195 %                               relsize package in order to get relative size for lines numbers; but it seems
196 %                               that some rare classes (such as inform1.cls) are not compatible with relsize; to
197 %                               have algorithm2e working, this option makes algorithm2e not to load relsize
198 %                               package and go back to previous definition by using \scriptsize font for lines
199 %                               numbers.
200 %                      * ADD: - OPTION onelanguage: allow, if using standard keywords listed below, to switch
201 %                               from one language to another without changing keywords by using appropriate
202 %                               language option :
203 %                               . KwIn, KwOut, KwData, KwResult
204 %                               . KwTo KwFrom
205 %                               . KwRet, Return
206 %                               . Begin
207 %                               . Repeat
208 %                               . If, ElseIf, Else
209 %                               . Switch, Case, Other
210 %                               . For, ForPar, ForEach, ForAll, While
211 %                               .
212 %                      * ADD: - OPTION rightnl: put lines numbers to the right of the algorithm instead of left.
213 %                      * ADD:   new commands \setRightLinesNumbers and \setLeftLinesNumbers which sets the lines
214 %                               numbers to the right or to the left of the algorithm.
215 %                      * ADD: - new kind of keywords : KwArray used to define arrays:
216 %                               \SetKwArray{Kw}{array} defines an array keywords Kw called array and printed in
217 %                               DataSty style when call with \Kw. It can be used with one argument which
218 %                               denotes the element index: \Kw{n} prints array[n] with array in DataSty and n in
219 %                               ArgSty.
220 %                      * ADD/FIX: rules of ruled, algoruled, tworuled styles used rules of different sizes! This
221 %                                 is now fixed. Moreover size of the rules is now controlled by a length and so
222 %                                 can be customized by the user.
223 %                                 \algoheightrule is the height of the rules and can be changed via \setlength
224 %                                 \algoheightruledefault is the default height of he rules (0.8pt)
225 %                                 \algotitleheightrule is the height of the rule that comes just after the
226 %                                 caption in ruled and algoruled style; it can be changed via \setlength
227 %                                 \algotitleheightruledefault is the default height of this rules (0.8pt)
228 %                                 Thanks to Philippe Dumas who reports the bug and make the suggestion.
229 %                      * ADD: - \SetAlgoCaptionSeparator which sets the separator between Algorithm 1 and the
230 %                               title. By default it's ':' and caption looks like "Algorithm 2: title" but now
231 %                               you can change it by using for example \SetAlgoCaptionSeparator{.} which will
232 %                               give "Algorithm 3. title"
233 %                      * ADD: - \SetAlgoLongEnd and \SetAlgoShortEnd and \SetAlgoNoEnd commands which act as
234 %                               corresponding package options
235 %                      * ADD: - OPTIONS italiano and slovak as new language (thanks to Roberto Posenato and
236 %                               Miroslav Binas) 
237 %                      * CHANGE: - Fnt and Sty macro to have consistent use and naming (see below)
238 %                      * ADD: - \AlCapSty, \AlCapNameSty, \AlCapFnt, \AlCapNameFnt, \ProcSty, \ProcFnt,
239 %                               \ProcNameSty, \ProcNameFnt, \ProcArgSty, ProcArgFnt and corresponding "set macro" 
240 %                               \SetAlCapSty, \SetAlCapNameSty, \SetAlCapFnt, \SetAlCapNameFnt, \SetProcSty,
241 %                               \SetProcFnt, \SetProcNameSty, \SetProcNameFnt, \SetProcArgSty, \SetProcArgFnt which
242 %                               control the way caption is printed. Sty macro use command taking one parameter as
243 %                               argument, Fnt macros use directly command. In Fact caption is printed as follow :
244 %                               \AlCapSty{\AlCapFnt Algorithm 1:}\AlCapNameSty{\AlCapNameFnt my algorithm}
245 %                               By default, \AlCapSty is textbf and \AlCapFnt is nothing. \AlCapNameSty keep text 
246 %                               as it is, and \AlCapNameFnt do nothing also.
247 %                               You can redefine \AlCapFnt and \AlCapNameFnt by giving macro to \Set commands. For
248 %                               example, you can do \SetAlCapFnt{\large} to see Algorithm printed in \large font.
249 %                               You can redefine \AlCapSty, \AlCapFnt, \AlCapNameSty and \AlCapNameFnt with the
250 %                               corresponding \Set command. For the Sty commands, you have to give in parameter
251 %                               name of a macro (whithout \)  which takes one argument. For example,
252 %                               \SetAlCapFnt{textbf} defines the default behaviour. If you want to do more
253 %                               complicated thing, you should define your own macro and give it to \SetAlCapFnt or
254 %                               \SetAlCapNameFnt. Here are two examples:
255 %                               - \newcommand{\mycapsty}[1]{\tiny #1}\SetAlCapNameSty{mycapsty}
256 %                               - \newcommand{\mycapsty}[1]{\textsl{\small #1}}\SetAlCapNameSty{mycapsty}
257 %                               Or you can combine the two, for the last example you can also do:
258 %                               \SetAlCapNameSty{textsl}\SetAlCapNameFnt{\small}
259 %                               Thanks to Jan Stilhammer who gives me the idea of \AlCapNameFnt.
260 %                      * CHANGE \AlTitleFnt to match definition of all other Fnt macros and add a \AlTitleSty 
261 %                               macro (see below) . Now you set \AlTitleFnt by calling \SetAlTitleFnt with 
262 %                               directly a macro without parameter in argument:
263 %                               Example: \SetAlTitleFnt{\small} to set title in small font.
264 %                      * ADD: - \AlTitleSty and \SetAlTitleSty commands to set a style for title. These commands
265 %                               are defined from a macro taking the text in argument, as \textbf for example. 
266 %                               To set the TitleSty you have to give name of the macro (without the '\') 
267 %                               to \SetAlTitleSty. For example \SetAlTitleSty{textbf} to set \textbf style.
268 %                      * ADD: - new command \SetAlgorithmName{algorithmname}{list of algorithms name} which
269 %                               redefines name of the algorithms and the sentence list of algorithms. Second
270 %                               argument is the name that \autoref, from hyperref package, will use. Example:
271 %                               \SetAlgorithmName{Protocol}{List of protocols} if you prefer protocol than
272 %                               algorithm.
273 %                      * ADD: - new \SetAlgoRefName{QXY} which change the default ref (number of the algorithm) by
274 %                               the name given in parameter (QXY in the example). 
275 %                      * ADD: - new command \SetAlgoRefRelativeSize{-2} which sets the output size of refs, defined
276 %                               by \SetAlgoRefName, used in list of algorithms.
277 %                      * ADD: - two dimensions to control the layout of caption in ruled, algoruled and boxruled
278 %                               algorithms:
279 %                               - interspacetitleruled (2pt by defaut) which controls the vertical space between
280 %                                 rules and title in ruled and algoruled algorithms.
281 %                               - interspaceboxruled (2\lineskip by default) which controls the vertical space
282 %                                 between rules and title in boxruled algorithms.
283 %                               These two dimensions can be changed by using \setlength command.
284 %                      * ADD: - With the fix (see below) of procedure and function environments, a new feature has
285 %                               been added: the name of the procedure or function set in caption is automatically
286 %                               defined as a KwFunction and so can be used as a macro. For example, if inside a
287 %                               procedure environment you set \caption{myproc()}, you can use \myproc macro in you
288 %                               main text. Beware that the macro is only defined after the \caption!
289 %                      * ADD: - OPTION nokwfunc to unable the new feature described above in function and
290 %                               procedure environment. Useful if you use name of procedure or function that cannot
291 %                               be a command name as a math display for example.
292 %                      * ADD: - \SetAlgoNlRelativeSize{number} command which sets the relative size of line
293 %                               numbers. By default, line numbers are two size smaller than algorithm text. Use
294 %                               this macro to change this behavior. For example, \SetAlgoNlRelativeSize{0} sets it
295 %                               to the same size, \SetAlgoNlRelativeSize{-1} to one size smaller and
296 %                               \SetAlgoNlRelativeSize{1} to one size bigger
297 %                      * ADD: - \SetAlgoProcName{aname} command which sets the name of Procedure printed by
298 %                               procedure environment (the environment prints Procedure by default). Second
299 %                               argument is the name that \autoref, from hyperref package, will use.
300 %                      * ADD: - \SetAlgoFuncName{aname} command which sets the name of Function printed by
301 %                               procedure environment (the environment prints Function by default). Second
302 %                               argument is the name that \autoref, from hyperref package, will use. 
303 %                      * ADD: - \SetAlgoCaptionLayout{style} command which sets style of the caption; style must
304 %                               be the name of a macro taking one argument (the text of the caption). Examples
305 %                               below show how to use it:
306 %                               . \SetAlgoCaptionLayout{centerline} to have centered caption
307 %                               . \SetAlgoCaptionLayout{textbf} to have bold caption
308 %                               If you want to apply two styles in the same time, such as centered bold, you have
309 %                               to define you own macro and then use \SetAlgoCaptionLayout with its name.
310 %                      * ADD: - OPTION procnumbered: which makes the procedure and function to be numbered as
311 %                               algorithm
312 %                      * ADD: - OPTIONS tworuled and boxruled
313 %                               these are two new layouts: tworuled acts like ruled but doesn't put a line after
314 %                               caption ; boxruled surround algorithm by a box, puts caption above and add a line
315 %                               after caption.
316 %                      * REMOVE: - SetKwInParam has been deleted since not useful itself because of different
317 %                                macros which can do the same in a better and a more consistent way as
318 %                                SetKwFunction or SetKw.
319 %                      * FIX: - line number is now correctly vertically aligned with math display.
320 %                      * FIX: - references with hyperref. No more same identifier or missing name error. BUT now
321 %                               you must NOT use naturalnames option of hyperref packages if you do PdfLaTeX
322 %                      * FIX: - autoref with hyperref package (thanks to Jörg Sommer who notices the problem).
323 %                      * FIX: - titlenumbered was not working! fixed.
324 %                      * FIX: - Else(){} acted like uElse. Corrected.
325 %                      * FIX: - noend management: when a block was inside another and end of block was following
326 %                               each other, a blank line was added: it's now corrected.
327 %                      * FIX: - Function and Procedure environment was no more working as defined originally: the
328 %                               label was no more name of the procedure, it acts always as if procumbered option
329 %                               has been used.
330 %                      * FIX: - line numbers had a fixed size which can be bigger than algorithm text accordingly
331 %                               to \AlFnt set (see also new command \SetAlgoNlRelativeSize above)
332 %                      * FIX: - semicolon in comments when dontprintsemicolon is used.
333 %                      * FIX: - listofalgorithms adds a vertical space before first algo of a chapter as for
334 %                               listoffigures or listoftables
335 %                      * FIX: - listofalgorithms with twocolumns mode and some classes which don't allow onecolumn
336 %                               and so don't define \if@restonecol as prescribed in LaTeX (sig-alternate for
337 %                               example)
338 %                      * FIX: - algorithm2e now works with elsart cls and some more classes.
339 %                      * FIX: - blocks defined by SetKwBlock act now as other blocks (if for instance) and don't
340 %                               write end in vlined mode, instead they print a small horizontal line as required
341 %                               by the option.
342 %                      * FIX: - underfull hbox warning at each end of algorithm environment removed.
343 %
344 %                      * INTERNAL CHANGE: - short end keyword are deduce from long end keyword by keeping the
345 %                                           first one. Allows to avoid double definition.
346 %                      * INTERNAL CHANGE: - procedure, function and algorithm are now resolved by the same
347 %                               environment to avoid code duplication. 
348 %
349 %   - October  04 2005  - revision 3.9 -
350 %                      * ADD: - \setalcaphskip command which sets the horizontal skip before Algorithm: in caption
351 %                               when used in ruled algorithm.
352 %                      * ADD: - \SetAlgoInsideSkip command which allows to add an extra vertical space before and
353 %                               after the core of the algorithm (ie: \SetAlgoInsideSkip{bigskip}) 
354 %                      * CHANGE: - caption, when used with figure option, is no more controlled by algorithm2e
355 %                                  package and so follows the exact behaviour of figures. The drawback is that you
356 %                                  cannot change the typo with AlTitleFnt or CapFnt. The avantage is that if you
357 %                                  use caption package, it works.
358 %                      * FIX: - problem with numbering line and pdflatex
359 %                      * FIX: - error when algorithm2e package was used with beamer and listings together
360 %   - February 12 2005  - revision 3.8 -
361 %                      * FIX: - extra line with noend option.
362 %   - February 10 2005  - revision 3.7 -
363 %                      * ADD: - sidecomment: different macros allowing to put text right after code on the same
364 %                               line. They are defined in the same time comment macros are defined with a star
365 %                               after the macro name. By default comments are right justified but this can be
366 %                               change with appropriate option in the macro. Ex:
367 %                               . default: \tcc*{side comment}
368 %                               . same as previous: \tcc*[r]{side comment}
369 %                               . left justify: \tcc*[l]{side comment}
370 %                               . here: \tcc*[h]{side comment} don't put the end of line mark before
371 %                                       comment (; by default) and don't end the line.
372 %                               . flushed: \tcc*[f]{side comment} same as the precedent but right
373 %                                 justified
374 %                      * ADD: - OPTION scright (default): right justified side comments (side comments
375 %                               are flushed to the righr)
376 %                      * ADD: - OPTION scleft: left justified side comments (side comments are put right after the
377 %                               code line)
378 %                      * ADD: - \SetSideCommentLeft acts as scleft option
379 %                      * ADD: - \SetSideCommentRight acts as scright option
380 %                      * ADD: - block like macro side text: all macro defining a block allows now to put text right
381 %                               after key words by putting text into (). Done to be used with sidecomment macros,
382 %                               but all text can be used. 
383 %                               Ex: \eIf(\tcc*[f]{then comment}){test}{then text}(else side text){else text}
384 %                      * ADD: - OPTION fillcomment (default): end mark of comment is flushed to the right so
385 %                               comments fill all the width of text.
386 %                      * ADD: - OPTION nofillcomment: end mark of comment is put right after the comment.
387 %                      * ADD: - \SetNoFillComment acts as nofillcomment option.
388 %                      * ADD: - \SetFillComment acts as fillcomment option.
389 %                      * ADD: - OPTION dotocloa: which adds an entry in the toc for the list of algorithms. This
390 %                               option load package tocbibind if not already done and so list of figures and list
391 %                               of tables are also added in the toc. If you want to control which ones of the lists
392 %                               will be added in the toc, please load package tocbibind before package algorithm
393 %                               and give it the options you want.
394 %                      * FIX: - vertical spacing for uif macro with noend option
395 %                      * FIX: - all the compatibility problems between caption and other packages
396 %                      * FIX: - typographical differences between list of algorithms and other lists  when in
397 %                               report or book 
398 %
399 %   - January 24 2005  - revision 3.6 -
400 %                      * FIX: - vertical spacing and space characters at the beginning or end of comments.
401 %                               line numbers of comments not in the NlSty.
402 %                               Thanks to Arnaud Giersch for his comments and suggestions.
403 %                      * FIX: - Set*Sty macro: the styles defined was not protected and was modified by surrounding
404 %                               context. For example KwTo in a \For{}{} was in bold AND italic instead of just in
405 %                               bold.
406 %                      * FIX: - line number misplacement after \Indp
407 %
408 %   - January 21 2005  - revision 3.5 -
409 %                      * ADD: - hidden numbering of the lines. Lines are auto-numbered but numbers are shown only
410 %                               on lines you specify:
411 %                               * linesnumberedhidden option or \LinesNumberedHidden macro activate this
412 %                                 functionnality.
413 %                               * \ShowLn and \ShowLnLabel{lab} macros make the number visible on the
414 %                               line. \ShowLnLabel{lab} allows to set a label for this line. 
415 %                               Thanks to Samson de Jager who makes this suggestion and provides the macros.
416 %                      * ADD: - \AlCapFnt and \SetAlCapFnt which allow to have a different font for
417 %                               caption. Works like \AlFnt and \SetAlFnt and by default is the same.
418 %                      * ADD: - \AlCapSkip skip length. This vertical space is added before caption in plain ou
419 %                               boxed mode. It allows to change distance between text and caption.
420 %                      * FIX: - caption compatible with IEEEtran class. 
421 %                      * FIX: - some vertical spacing error with \uIf macros (Thanks to Arnaud Giersch)
422 %                      * FIX: - Procedure and Function: lines are also numbered like algorithms
423 %                      * FIX: - CommentSty was not used for Comments
424 %
425 %   - January 10 2005  - revision 3.4 -
426 %                      * FIX: - caption compatible with new release of Beamer class. 
427 %
428 %   - June 16 2004     - revision 3.3 - 
429 %                      * FIX: - Hyperlink references of Hyperref package works now if compiled with pdflatex 
430 %                               and [naturalnames] option of hyperref package is used.
431 %                      * FIX: - algorithm[H] had problem in an list environment - corrected
432 %                      * FIX: - interline was not so regular in nested blocks - corrected
433 %                      * ADD  - \SetVlineSkip macro which sets the vertical skip after the little horizontal 
434 %                               rule which closes a block in Vlined mode. By default 0.8ex
435 %
436 %   - June 11 2004     - revision 3.2 - AUTO NUMBERING LINES !!!
437 %                      * ADD: auto numbering of the lines (the so asked and so long awaiting feature)
438 %                             this feature is managed by 3 options and 3 commands:
439 %                             - linesnumbered option: lines of the algo are numbered except for comments and
440 %                               input/output (KwInput and KwInOut)
441 %                             - commentsnumbered option: makes comments be numbered
442 %                             - inoutnumbered option: makes data input/output be numbered
443 %                             - \nllabel{lab} labels the line so you can cite with \ref{lab}
444 %                             - \LinesNumbered make the following algorithms having auto-numbered lines
445 %                             - \linesnotnumbered make the following algorithms having no auto-numbered lines
446 %                      * Change: algo2e option renames listofalgorithms in listofalgorithmes
447 %                      * FIX: new solution for compatibility with color package, more robust and not tricky.
448 %                             Many thanks to David Carlisle for his advices
449 %
450 %   - June 09 2004     - revision 3.1 -
451 %                      * Change: \SetKwSwitch command defines an additionnal macro \uCase and \Case prints end
452 %                      * Change: now macros SetKw* do a renewcommand if the keyword is already defined. So you can
453 %                                redefine default definition at your own convenience or change your definition
454 %                                without introducing a new macro and changing your text.
455 %                      * ADD: new macro \SetKwIF which do \SetKwIf and
456 %                             \SetKwIfElseIf.The following default definition has been added:
457 %                             \SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}
458 %                             and so you get the macros;
459 %                             \If \eIf \lIf \uIf \ElseIf \uElseIf \lElseIf \Else \uElse \lElse
460 %                      * ADD: new macro \SetAlgoSkip which allow to fix the vertical skip before and after the
461 %                             algorithms. Default is smallskip, do \SetAlgoSkip{} if you don't want an extra space
462 %                             or \SetAlgoSkip{medskip} or \SetAlgoSkip{bigskip} if you want bigger space.
463 %                      * ADD: macro \SetKwIf defines in addition a new macro \uElse  (depending on wat name you
464 %                             have given in #2 arg).
465 %                      * ADD: macro \SetKwIfElseIf defines in addition a new macro \uElse and \ugElseIf (depending
466 %                             on what name you have given in #2 and #3 arg).
467 %                      * Change: baseline of algorithm is now top, so two algorithms can be put side by side.
468 %                      * FIX: Compatibility with color package solved. The problem was due to a redefinition of
469 %                             standard macros by color package. This solves compatibility problem with other
470 %                             packages as pstcol or colortbl. (notified by Dirk Fressmann, Antti Tarvainen and Koby
471 %                             Crammer)
472 %                      * Fix: extra little shift to the right with boxed style algorithm removed (notified by
473 %                             P. Tanovski)
474 %                      * Fix: algoln option was buggy (notified bye Jiaying Shen)
475 %                      * Fix: german and portuges option didn't work due to bad typo (notified by Martin Sievers,
476 %                             Thorsten Vitt and Jeronimo Pellegrini)
477 %                      
478 %   - February 13 2004 - revision 3.0 -
479 %                      * Major revision which makes the package independent from float.sty, so now
480 %                        - algorithm* works better, in particular can be used in multicols environments
481 %                        - (known bug corrected)
482 %                          [H] works now for all sort of environment but is handled differently for classic
483 %                          environment and star environment (algorithm, figure, procedure and function). For star
484 %                          environment, H acts like for classical figure environment, so it doesn't stay here
485 %                          absolutely.
486 %                        - (known bug corrected)
487 %                          you can use now floatflt package with algorithm package and even with figure
488 %                          option. Beware that if you want to put an algorithm inside a floatingfigure, it cannot
489 %                          be floating, so [H] is required and then figure option should not be used, since
490 %                          standard figure[H] are still floating with LaTeX.
491 %                      * boxruled: a new style added. Possible now since no style no more defined by the float
492 %                        package.
493 %                      * nocaptionofalgo: dosen't print Algorithm #: in the caption for algorithm in ruled or
494 %                        algoruled style.
495 %                        note: this is just documentation of a macro which was already in the package.
496 %   - December 14 2003 - revision 2.52 -
497 %                      * output message shorter
498 %                      * french keyword macro \PourTous was missing for longend option, it has been added.
499 %                      * TitleofAlgo prints Function or Procedure in corresponding environments.
500 %
501 %   - October 27 2003  - revision 2.51 - Revision submitted to CTAN archive
502 %                      * correction of a minor which make caption in procedure
503 %                        and function to be blanck with pdfscreen package
504 %                        (thanks to Joel Gossens for the notification)
505 %                      * add two internal definition to avoid some errors when
506 %                        used with Hyperref package (Hyperref package need to
507 %                        define new counter macro from existing ones, and
508 %                        don't do it for algorithm2e package, so we do it)
509 %
510 %   - October 17 2003  - revision 2.50 - first revision for CTAN archive
511 %                      * add \AlFnt and \SetAlFnt{font} macros: \AlFnt is used at the beginning of the caption and
512 %                        the body of algorithm in order to define the fonts used for typesetting algorithms. You
513 %                        can use it elsewhere you want to typeset text as algorithm. For example you can do
514 %                        \SetAlFnt{\small\sf} to have algorithms typeset in small sf font. Default is nothing so
515 %                        algorithm is typeset as the text of the document.
516 %                      * add \AlTitleFnt{text} and \SetAlTitleFnt{font} macros: The {Algorithm: } in the caption is
517 %                        typeset with \AlTitleFnt{Algorithm:}. You can use it to have text typeset as {Algorithm:}
518 %                        of captions. Default is textbf.  Default can be redefined by \SetAlTitleFnt{font}, for
519 %                        example you can do \SetAlTitleFnt{emph}
520 %                      * add CommentSty typo for text comment.  
521 %                      * add some compatibility with hyperref package (still an error on multiply defined refs but
522 %                        pdf correctly generated)
523 %                      * flush text to left in order to have correct indentation even with class as amsart which
524 %                        center all figures
525 %                      * add german, portugues and czech options for title of algorithms and typo.
526 %                      * add portuguese translation of predefined keywords * add czech translation of some
527 %                        predefined keywords
528 %
529 %   - December 23 2002 - revision 2.40
530 %                      * add some french keyword missing
531 %                      * add function* and procedure* environment like algorithme* environment: print in one column
532 %                        even if twocolumn option is specified for the document.
533 %                      * add a new macro \SetKwComment to define macro which writes comments in the text. First
534 %                        argument is the name of the macro, second is the text put before the comment, third is the
535 %                        text put at the end of the comment.Default are \tcc and \tcp
536 %                      * add new options to change the way algo are numbered:
537 %                        [algopart] algo are numbered within part (counter must exist)
538 %                        [algochapter] algo are numbered within chapter
539 %                        [algosection] algo are numbered within section
540 %
541 %   - March 27 2002   - revision 2.39
542 %                      * Gilles Geeraerts: added the \SetKwIfElseIf to manage
543 %                        if (c)
544 %                             i;
545 %                        else if (c)
546 %                             i;
547 %                        ...
548 %                        else
549 %                             i;
550 %                        end
551 %                      * Also added \gIf \gElseIf \gElse.
552 %
553 %   - January 02 2001 - revision 2.38
554 %                      * bugs related to the caption in procedure and function
555 %                        environment are corrected.
556 %                      * bug related to option noend (extra vertical space added
557 %                        after block command as If or For) is corrected.
558 %                      * czech option language added (thanks to Libor Bus: l.bus@sh.cvut.cz).
559 %  
560 %   - October 16 2000 - revision 2.37
561 %                      * option algo2e added: change the name of environment
562 %                        algorithm into algorithm2e. So allow to use the package
563 %                        with some journal style which already define an algorithm
564 %                        environment.
565 %  
566 %   - September 13 2000 - revision 2.36
567 %                      * option slide added: require package color
568 %                      * Hack for slide class in order to have correct
569 %                        margins
570 %  
571 %   - November 25 1999 - revision 2.35
572 %                      * revision number match RCS number
573 %                      * Thanks to David A. Bader, a new option is added:
574 %                        noend: no end keywords are printed.
575 %  
576 %   - November 19 1999 - revision 2.32
577 %                      * minor bug on longend option corrected.
578 %  
579 %   - August 26 1999 - revision 2.31
580 %                      * add an option : figure
581 %                        this option makes algorithms be figure and so are numbered
582 %                        as figures, have Figure as caption and are put in 
583 %                        the \listoffigures
584 %  
585 %   - January 21 1999 - revision 2.3 beta
586 %                    add 2 new environments: procedure and function.
587 %                    These environments works like algorithm environment but:
588 %                    - the ruled (or algoruled) style is imperative.
589 %                    - the caption now writes Procedure name....
590 %                    - the syntax of the \caption command is restricted as
591 %                      follow: you MUST put a name followed by 2 braces like
592 %                      this ``()''. You can put arguments inside the braces and
593 %                      text after. If no argument is given, the braces will be
594 %                      removed in the title. 
595 %                    - label now puts the name (the text before the braces in the
596 %                      caption) of the procedure or function as reference (not
597 %                      the number like a classic algorithm environment).
598 %                    There are also two new styles : ProcNameSty and
599 %                    ProcArgSty. These style are by default the same as FuncSty
600 %                    and ArgSty but are used in the caption of a procedure or a
601 %                    function.
602 %                    
603 %   - November 28 1996 - revision 2.22
604 %                    add a new macro \SetKwInParam{arg1}{arg2}{arg3}:
605 %                    it defines a macro \arg1{name}{arg} which prints name in keyword
606 %                    style followed byt arg surrounded by arg2 and arg3. The main
607 %                    application is to a function working as \SetKwInput to be used
608 %                    in the head of the algorithm. For example
609 %                    \SetKwInParam{Func}{(}{)} allows
610 %                    \Func{functionname}{list of arguments} which prints:
611 %                    \KwSty{functioname(}list of arguments\KwSty{)}
612 %       
613 %
614 %   - November 27 1996 - revision 2.21 :
615 %                    minor bug in length of InOut boxes fixed.
616 %                    add algorithm* environment.
617 %
618 %   - July 12 1996 - revision 2.2 : \SetArg and \SetKwArg macros removed.
619 %                        
620 %                    \SetArg has been removed since it never has been
621 %                    documented.
622 %                    \SetKwArg has been removed since \SetKw can now
623 %                    take an argument in order to be consistent with
624 %                    \SetKwData and \SetKwFunction macros.
625 %
626 %   - July 04 1996 - revision 2.1 : still more LaTeX2e! Minor compatibility break
627 %
628 %                    Macros use now \newcommand instead of \def, use of \setlength, 
629 %                    \newsavebox, ... and other LaTeX2e specific stuff.
630 %                    The compatibility break:
631 %                    - \SetData becomes \SetKwData to be more consistent. So the old 
632 %                      \SetKwData becomes \SetKwInput
633 %                    - old macros \titleofalgo, \Freetitleofalgo and \freetitleofalgo
634 %                      from LaTeX209 version which did print a warning message and call 
635 %                      \Titleofalgo in version 2.0 are now removed!
636 %
637 %   - March 13 1996 - revision 2.0: first official major revision.
638 %   
639 %
640 %%%%%%%%%%%%%%
641 %
642 %   Known bugs: 
643 %   -----------
644 %   - no more known bugs... all are corrected!
645 %
646 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
647 %
648 % for more complete informations you can see algorithm2e.tex
649 %
650 %
651 %%%%%%%%%%%%%%%%%%%%%%%% Identification Part %%%%%%%%%%%%%%%%%%%%%%%%%%%%
652 %
653 \NeedsTeXFormat{LaTeX2e}[1994/12/01]
654 %
655 \ProvidesPackage{algorithm2e}[2008/00/00 v3.10 algorithms environments]
656 %
657 %
658 %%%%%%%%%%%%%%%%%%%%%%%%%%% Initial Code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
659 %
660 \@makeother\*% some package redefined it as a letter (as color.sty)
661 \def\@firstword#1 #2\@nil{#1}% an useful fonction
662 %
663 % definition of commands which can be redefined in options of the package.
664 %
665 \newcounter{AlgoLine}%
666 \setcounter{AlgoLine}{0}%
667 %
668 \newcommand{\algocf@algocfref}{\relax}%
669 \newcommand{\listalgorithmcfname}{}%
670 \newcommand{\algorithmcfname}{}%
671 \@ifundefined{algorithmautorefname}{\newcommand{\algorithmautorefname}{algorithm}}{\renewcommand{\algorithmautorefname}{algorithm}}%
672 \newcommand{\algorithmcflinename}{}%
673 \newcommand{\algocf@typo}{}%
674 \newcommand{\@algocf@procname}{}\newcommand{\procedureautorefname}{}%
675 \newcommand{\SetAlgoProcName}[2]{\renewcommand{\@algocf@procname}{#1}\renewcommand{\procedureautorefname}{#2}}%
676 \newcommand{\@algocf@funcname}{}\newcommand{\functionautorefname}{}%
677 \newcommand{\SetAlgoFuncName}[2]{\renewcommand{\@algocf@funcname}{#1}\renewcommand{\functionautorefname}{#2}}%
678 \newcommand{\@algocf@titleofalgoname}{\algorithmcfname}%
679 \newcommand{\@algocf@algotitleofalgo}{%
680   \renewcommand{\@algocf@titleofalgoname}{\algorithmcfname}}%
681 \newcommand{\@algocf@proctitleofalgo}{%
682   \renewcommand{\@algocf@titleofalgoname}{\algocf@procname}}%
683 %
684 \newcommand{\algocf@style}{plain}%
685 \newcommand{\@ResetCounterIfNeeded}{}%
686 \newcommand{\@titleprefix}{}%
687 %
688 \newcommand{\algocf@numbering}[1]{\newcommand{\algocf@within}{#1}}%
689 %
690 \newcommand{\defaultsmacros@algo}{\algocf@defaults@shortend}%
691 %
692 \newcommand{\algocf@list}{loa}%
693 \newcommand{\algocf@float}{algocf}%
694 %
695 \newcommand{\algocf@envname}{algorithm}%
696 \newcommand{\algocf@listofalgorithms}{listofalgorithms}%
697 %
698 %
699 %% redefine chapter so that it adds a vspace in the loa as the original does for lof and lot
700 \let\algocf@original@chapter=\chapter%
701 \def\chapter{\expandafter\addtocontents{loa}{\protect\addvspace{10\p@}}\algocf@original@chapter}%
702 %
703 %% if@restonecol is defined in article and book but some other classes don't define it and we need it, so we do
704 \ifx\if@restonecol\relax\else\newif\if@restonecol\fi%
705 %
706 %
707 %%%%%%%%%%%%%%%%%%%%%% Declaration of Options %%%%%%%%%%%%%%%%%%%%%%%%%%%
708 %
709 \RequirePackage{ifthen}%
710 %
711 \newboolean{algocf@nokwfunc}\setboolean{algocf@nokwfunc}{false}%
712 \DeclareOption{nokwfunc}{%
713   \setboolean{algocf@nokwfunc}{true}%
714 }%
715 %
716 \newboolean{algocf@oldcommands}\setboolean{algocf@oldcommands}{false}%
717 \DeclareOption{oldcommands}{%
718   \setboolean{algocf@oldcommands}{true}%
719 }%
720 %
721 \newboolean{algocf@leftlinenumber}\setboolean{algocf@leftlinenumber}{true}%
722 \newcommand{\setLeftLinesNumbers}{\setboolean{algocf@leftlinenumber}{true}}%
723 \newcommand{\setRightLinesNumbers}{\setboolean{algocf@leftlinenumber}{false}}%
724 \DeclareOption{rightnl}{%
725   \setRightLinesNumbers%
726 }%
727 %
728 \newboolean{algocf@endfloat}\setboolean{algocf@endfloat}{false}%
729 \DeclareOption{endfloat}{%
730   \setboolean{algocf@endfloat}{true}%
731   \newcounter{postalgo}\setcounter{postalgo}{0}%
732 }%
733 %
734 \newboolean{algocf@procnumbered}\setboolean{algocf@procnumbered}{false}%
735 \DeclareOption{procnumbered}{%
736   \setboolean{algocf@procnumbered}{true}%
737 }%
738 %
739 \DeclareOption{algo2e}{%
740   \renewcommand{\algocf@envname}{algorithm2e}%
741   \renewcommand{\algocf@listofalgorithms}{listofalgorithmes}%
742 }%
743 %
744 \newboolean{algocf@slide}\setboolean{algocf@slide}{false}%
745 \DeclareOption{slide}{%
746   \setboolean{algocf@slide}{true}%
747 }%
748 %
749 \DeclareOption{figure}{%
750 \renewcommand{\algocf@list}{lof}%
751 \renewcommand{\algocf@float}{figure}%
752 }%
753 %
754 \newboolean{algocf@optonelanguage}\setboolean{algocf@optonelanguage}{false}%
755 \DeclareOption{onelanguage}{\setboolean{algocf@optonelanguage}{true}}%
756 %
757 \newcommand{\algocf@languagechoosen}{english}%
758 %
759 \DeclareOption{english}{%
760 \renewcommand{\listalgorithmcfname}{List of Algorithms}%
761 \renewcommand{\algorithmcfname}{Algorithm}%
762 \renewcommand{\algorithmautorefname}{algorithm}%
763 \renewcommand{\algorithmcflinename}{line}%
764 \renewcommand{\algocf@typo}{}%
765 \renewcommand{\@algocf@procname}{Procedure}%
766 \renewcommand{\@algocf@funcname}{Function}%
767 \renewcommand{\procedureautorefname}{procedure}%
768 \renewcommand{\functionautorefname}{function}%
769 \renewcommand{\algocf@languagechoosen}{english}%
770 }%
771 %
772 \DeclareOption{french}{%
773 \renewcommand{\listalgorithmcfname}{Liste des Algorithmes}%
774 \renewcommand{\algorithmcfname}{Algorithme}%
775 \renewcommand{\algorithmautorefname}{algorithme}%
776 \renewcommand{\algorithmcflinename}{ligne}%
777 \renewcommand{\algocf@typo}{\ }%
778 \renewcommand{\@algocf@procname}{Procédure}%
779 \renewcommand{\@algocf@funcname}{Fonction}%
780 \renewcommand{\procedureautorefname}{procédure}%
781 \renewcommand{\functionautorefname}{fonction}%
782 \renewcommand{\algocf@languagechoosen}{french}%
783 }%
784 %
785 \DeclareOption{czech}{%
786 \renewcommand{\listalgorithmcfname}{Seznam algoritm\v{u}}%
787 \renewcommand{\algorithmcfname}{Algoritmus}%
788 \renewcommand{\algorithmautorefname}{\algorithmcfname}%
789 \renewcommand{\algorithmcflinename}{Radek}%
790 \renewcommand{\algocf@typo}{}%
791 \renewcommand{\@algocf@procname}{Procedura}%
792 \renewcommand{\@algocf@funcname}{Funkce}%
793 \renewcommand{\procedureautorefname}{\@algocf@procname}%
794 \renewcommand{\functionautorefname}{\@algocf@funcname}%
795 \renewcommand{\algocf@languagechoosen}{czech}%
796 }%
797 %
798 \DeclareOption{german}{%
799 \renewcommand{\listalgorithmcfname}{Liste der Algorithmen}%
800 \renewcommand{\algorithmcfname}{Algorithmus}%
801 \renewcommand{\algorithmautorefname}{\algorithmcfname}%
802 \renewcommand{\algorithmcflinename}{Zeile}%
803 \renewcommand{\algocf@typo}{\ }%
804 \renewcommand{\@algocf@procname}{Prozedur}%
805 \renewcommand{\@algocf@funcname}{Funktion}%
806 \renewcommand{\procedureautorefname}{\@algocf@procname}%
807 \renewcommand{\functionautorefname}{\@algocf@funcname}%
808 \renewcommand{\algocf@languagechoosen}{german}%
809 }%
810 %
811 \DeclareOption{portuguese}{%
812 \renewcommand{\listalgorithmcfname}{Lista de Algoritmos}%
813 \renewcommand{\algorithmcfname}{Algoritmo}%
814 \renewcommand{\algorithmautorefname}{algoritmo}%
815 \renewcommand{\algorithmcflinename}{linha}%
816 \renewcommand{\algocf@typo}{}%
817 \renewcommand{\@algocf@procname}{Procedimento}%
818 \renewcommand{\@algocf@funcname}{Fun\c{c}\~{a}o}%
819 \renewcommand{\procedureautorefname}{procedimento}%
820 \renewcommand{\functionautorefname}{fun\c{c}\~{a}o}%
821 \renewcommand{\algocf@languagechoosen}{portuguese}%
822 }%
823 %
824 \DeclareOption{italiano}{%
825 \renewcommand{\listalgorithmcfname}{Elenco degli algoritmi}%
826 \renewcommand{\algorithmcfname}{Algoritmo}%
827 \renewcommand{\algorithmautorefname}{algoritmo}%
828 \renewcommand{\algorithmcflinename}{riga}%
829 \renewcommand{\algocf@typo}{}%
830 \renewcommand{\@algocf@procname}{Procedura}%
831 \renewcommand{\@algocf@funcname}{Funzione}%
832 \renewcommand{\procedureautorefname}{procedura}%
833 \renewcommand{\functionautorefname}{funzione}%
834 \renewcommand{\algocf@languagechoosen}{italiano}%
835 }%
836 \DeclareOption{slovak}{%
837 \renewcommand{\listalgorithmcfname}{Zoznam algoritmov}%
838 \renewcommand{\algorithmcfname}{Algoritmus}%
839 \renewcommand{\algorithmautorefname}{\algorithmcfname}%
840 \renewcommand{\algorithmcflinename}{Radek}%
841 \renewcommand{\algocf@typo}{}%
842 \renewcommand{\@algocf@procname}{Proced\'{u}ra}%
843 \renewcommand{\@algocf@funcname}{Funkcia}%
844 \renewcommand{\procedureautorefname}{\@algocf@procname}%
845 \renewcommand{\functionautorefname}{\@algocf@funcname}%
846 \renewcommand{\algocf@languagechoosen}{slovak}%
847 }%
848 %
849 % OPTIONs plain, boxed, ruled, algoruled & boxruled
850 %
851 \newcommand{\algocf@style@plain}{\renewcommand{\algocf@style}{plain}}%
852 \newcommand{\algocf@style@boxed}{\renewcommand{\algocf@style}{boxed}}%
853 \newcommand{\algocf@style@ruled}{\renewcommand{\algocf@style}{ruled}}%
854 \newcommand{\algocf@style@algoruled}{\renewcommand{\algocf@style}{algoruled}}%
855 \newcommand{\algocf@style@boxruled}{\renewcommand{\algocf@style}{boxruled}}%
856 \newcommand{\algocf@style@tworuled}{\renewcommand{\algocf@style}{tworuled}}%
857 \newcommand{\RestyleAlgo}[1]{\csname algocf@style@#1\endcsname}%
858 \DeclareOption{plain}{\algocf@style@plain}%
859 \DeclareOption{boxed}{\algocf@style@boxed}%
860 \DeclareOption{ruled}{\algocf@style@ruled}%
861 \DeclareOption{algoruled}{\algocf@style@algoruled}%
862 \DeclareOption{boxruled}{\algocf@style@boxruled}%
863 \DeclareOption{tworuled}{\algocf@style@tworuled}%
864 %
865 % OPTIONs algopart,algochapter & algosection
866 %
867 \DeclareOption{algopart}{\algocf@numbering{part}}%       %algo part numbered
868 \DeclareOption{algochapter}{\algocf@numbering{chapter}}% %algo chapter numbered
869 \DeclareOption{algosection}{\algocf@numbering{section}}% %algo section numbered
870 %
871 % OPTIONs resetcount & noresetcount
872 %
873 \DeclareOption{resetcount}{\renewcommand{\@ResetCounterIfNeeded}{\setcounter{AlgoLine}{0}}}%
874 \DeclareOption{noresetcount}{\renewcommand{\@ResetCounterIfNeeded}{}}%
875 %
876 % OPTION linesnumbered
877 %
878 \newboolean{algocf@linesnumbered}\setboolean{algocf@linesnumbered}{false}%
879 \newcommand{\algocf@linesnumbered}{\relax}%
880 \DeclareOption{linesnumbered}{%
881   \setboolean{algocf@linesnumbered}{true}%
882   \renewcommand{\algocf@linesnumbered}{\everypar={\nl}}%
883 }%
884 %
885 % OPTION linesnumberedhidden
886 %
887 \DeclareOption{linesnumberedhidden}{%
888   \setboolean{algocf@linesnumbered}{true}%
889   \renewcommand{\algocf@linesnumbered}{\everypar{\stepcounter{AlgoLine}}}%
890 }%
891 %
892 % OPTION commentsnumbered inoutnumbered
893 %
894 \newboolean{algocf@commentsnumbered}\setboolean{algocf@commentsnumbered}{false}%
895 \DeclareOption{commentsnumbered}{\setboolean{algocf@commentsnumbered}{true}}%
896 \newboolean{algocf@inoutnumbered}\setboolean{algocf@inoutnumbered}{false}%
897 \DeclareOption{inoutnumbered}{\setboolean{algocf@inoutnumbered}{true}}%
898 %
899 % OPTIONs titlenumbered & titlenotnumbered
900 %
901 \DeclareOption{titlenumbered}{%
902   \renewcommand{\@titleprefix}{%
903     \refstepcounter{\algocf@float}%
904     \AlTitleSty{\AlTitleFnt\@algocf@titleofalgoname\ \expandafter\csname the\algocf@float\endcsname\algocf@typo: }%
905   }%
906 }%
907 %
908 \DeclareOption{titlenotnumbered}{\renewcommand{\@titleprefix}{%
909     \AlTitleSty{\AlTitleFnt\@algocf@titleofalgoname\algocf@typo: }}%
910 }%
911 %
912 % OPTIONs algonl
913 % line numbered with the counter of the algorithm
914 %
915 \DeclareOption{algonl}{\renewcommand{\theAlgoLine}{\expandafter\csname the\algocf@float\endcsname.\arabic{AlgoLine}}}%
916 %
917 % OPTIONs lined, vlined & noline
918 %
919 \DeclareOption{lined}{\AtBeginDocument{\SetAlgoLined}}%   \SetAlgoLined
920 \DeclareOption{vlined}{\AtBeginDocument{\SetAlgoVlined}}% \SetAlgoVlined
921 \DeclareOption{noline}{\AtBeginDocument{\SetAlgoNoLine}}%\SetAlgoNoLine (default)
922 %
923 % OPTIONs longend, shotend & noend
924 %
925 \DeclareOption{longend}{\AtBeginDocument{\SetAlgoLongEnd}}%  \SetAlgoLongEnd
926 \DeclareOption{shortend}{\AtBeginDocument{\SetAlgoShortEnd}}%\SetAlgoShortEnd
927 \DeclareOption{noend}{\AtBeginDocument{\SetAlgoNoEnd}}%      \SetAlgoNoEnd
928 %
929 % OPTION dotoc
930 %
931 \newboolean{algocf@dotocloa}\setboolean{algocf@dotocloa}{false}%
932 \DeclareOption{dotocloa}{%
933   \setboolean{algocf@dotocloa}{true}%
934 }
935 %
936 % OPTION comments
937 %
938 \newboolean{algocf@optfillcomment}\setboolean{algocf@optfillcomment}{true}%
939 \DeclareOption{nofillcomment}{%
940   \setboolean{algocf@optfillcomment}{false}%
941 }%
942 \DeclareOption{fillcomment}{%
943   \setboolean{algocf@optfillcomment}{true}%
944 }%
945 %
946 % OPTION sidecommments
947 %
948 \newboolean{algocf@scleft}\setboolean{algocf@scleft}{false}%
949 \DeclareOption{scleft}{%
950   \setboolean{algocf@scleft}{true}%
951 }%
952 \DeclareOption{sright}{% default
953   \setboolean{algocf@scleft}{false}%
954 }%
955 %
956 % OPTION norelsize
957 %
958 \newboolean{algocf@norelsize}\setboolean{algocf@norelsize}{false}%
959 \DeclareOption{norelsize}{%
960   \setboolean{algocf@norelsize}{true}%
961 }%
962 %
963 %
964 %%%%%%%%%%%%%%%%%%%%%%% Execution of Options %%%%%%%%%%%%%%%%%%%%%%%%%%%%
965 %
966 \ExecuteOptions{english,plain,resetcount,titlenotnumbered,lined,shortend}%
967 %
968 \ProcessOptions%
969 %
970 \@algocf@algotitleofalgo% fix name for \TitleOfAlgo to \algorithmcfname by default
971 %
972 %%%%%%%%%%%%%%%%%%%%%%%%%% Package Loading %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
973 %
974 %
975 \RequirePackage{xspace}%
976 %
977 \ifthenelse{\boolean{algocf@endfloat}}{%
978   \RequirePackage{endfloat}%
979 }{\relax}%
980 %
981 \ifthenelse{\boolean{algocf@norelsize}}{%
982   \newcommand{\relsize}[1]{\scriptsize}%
983 }{%
984   \RequirePackage{relsize}%
985 }%
986 %
987 \ifthenelse{\boolean{algocf@slide}}{\RequirePackage{color}}{}%
988 %
989
990 \AtEndOfPackage{%
991   \ifthenelse{\boolean{algocf@dotocloa}}{%
992     \renewcommand{\listofalgorithmes}{\tocfile{\listalgorithmcfname}{loa}}%
993   }{\relax}%
994 }%
995 %
996 % if loa in toc required, load tocbibind package if not already done.
997 \ifthenelse{\boolean{algocf@dotocloa}}{%
998   \ifx\@tocextra\undefined%
999   \RequirePackage{tocbibind}%
1000   \fi%
1001 }%
1002 %
1003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Main Part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1004 %
1005 \newcommand{\algocf@name}{algorithm2e}%
1006 \newcommand{\algocf@date}{december 14 2009}%
1007 \newcommand{\algocf@version}{Release 4.01}%
1008 \newcommand{\algocf@id}{\algocf@version\space -- \algocf@date\space --}%
1009 \typeout{********************************************************^^JPackage `\algocf@name'\space\algocf@id^^J%
1010          - algorithm2e-announce@lirmm.fr  mailing list for announcement about releases^^J%
1011          - algorithm2e-discussion@lirmm.fr mailing list for discussion about package^^J%
1012          subscribe by emailing sympa@lirmm.fr with 'subscribe <list> <firstname name>'^^J%
1013          - Author: Christophe Fiorio (fiorio@lirmm.fr)^^J********************************************************}%
1014 %%
1015 %%
1016 %%
1017 %%
1018 %%
1019 %%
1020 %%%% hyperref compatibility tricks: Hyperref package defines H counters from
1021    % standard counters (i.e \theHpage from \thepage) and check some particular
1022    % counters of some packages, unfortunately it doesn't do the same for
1023    % algorithm2e package but act as Hcounter was defined. To avoid errors we
1024    % defined \theHalgocf ourself
1025 %%%%
1026 %
1027 \@ifundefined{theHalgocf}{\def\theHalgocf{\thealgocf}}{}%
1028 \@ifundefined{theHAlgoLine}{\def\theHAlgoLine{\theAlgoLine}}{}%
1029 \@ifundefined{theHalgocfproc}{\def\theHalgocfproc{0}}{}%
1030 \@ifundefined{theHalgocffunc}{\def\theHalgocffunc{0}}{}%
1031 \@ifundefined{toclevel@algocf}{\def\toclevel@algocf{0}}{}%
1032 %
1033 % autoref from hyperref needs an autorefname, so we give it.
1034 \def\AlgoLineautorefname{\algorithmcflinename}%
1035 \def\algocfautorefname{\algorithmautorefname}%
1036 \def\algocfprocautorefname{\procedureautorefname}%
1037 \def\algocffuncautorefname{\functionautorefname}%
1038 %%
1039 %%
1040 %%
1041 \newcommand{\@defaultskiptotal}{0.5em}%
1042 \newskip\skiptotal\skiptotal=0.5em%
1043 \newskip\skiplinenumber\skiplinenumber=\hsize\advance\skiplinenumber by-\skiptotal%
1044 \newskip\skiprule%
1045 \newskip\skiphlne%
1046 \newskip\skiptext%
1047 \newskip\skiplength%
1048 \newskip\algomargin%
1049 \newskip\skipalgocfslide\skipalgocfslide=1em%
1050 \newdimen\algowidth%
1051 \newdimen\inoutsize%
1052 \newdimen\inoutline%
1053 \newdimen\interspacetitleruled\setlength{\interspacetitleruled}{2pt}%
1054 \newdimen\interspacealgoruled\setlength{\interspacealgoruled}{2pt}%
1055 \newdimen\interspacetitleboxruled\setlength{\interspacetitleboxruled}{2\lineskip}%
1056 %
1057 \newcommand{\@algoskip}{\smallskip}%
1058 \newcommand{\SetAlgoSkip}[1]{\renewcommand{\@algoskip}{\csname#1\endcsname}}%
1059 \newcommand{\@algoinsideskip}{\relax}%
1060 \newcommand{\SetAlgoInsideSkip}[1]{\renewcommand{\@algoinsideskip}{\csname#1\endcsname}}%
1061 %
1062 \newsavebox{\algocf@inoutbox}%
1063 \newsavebox{\algocf@inputbox}%
1064 %%
1065 %%
1066 \newcommand{\arg@e}{}%
1067 \newcommand{\arg@space}{\ }%
1068 \newcommand{\BlankLine}{\vskip 1ex}%
1069 %%
1070 \newcommand{\vespace}{1ex}%
1071 \newcommand{\SetInd}[2]{%
1072 \skiprule=#1%
1073 \skiptext=#2%
1074 \skiplength=\skiptext\advance\skiplength by \skiprule\advance\skiplength by 0.4pt}%
1075 \SetInd{0.5em}{1em}
1076 \algomargin=\leftskip\advance\algomargin by \parindent%
1077 \newcommand{\IncMargin}[1]{\advance\algomargin by #1}%
1078 \newcommand{\DecMargin}[1]{\advance\algomargin by -#1}%
1079 \newcommand{\SetNlSkip}[1]{%
1080   \renewcommand{\@defaultskiptotal}{#1}%
1081   \setlength{\skiptotal}{#1}}%
1082 %%
1083 \newskip\AlCapSkip\AlCapSkip=0ex%
1084 \newskip\AlCapHSkip\AlCapSkip=0ex%
1085 \newcommand{\SetAlCapSkip}[1]{\setlength{\AlCapSkip}{#1}}%
1086 \newcommand{\SetAlCapHSkip}[1]{\setlength{\AlCapHSkip}{#1}}%
1087 \SetAlCapHSkip{.5\algomargin}%
1088 %%
1089 %%
1090 \newcommand{\Indentp}[1]{\advance\leftskip by #1}%
1091 \newcommand{\Indp}{\advance\leftskip by 1em}%
1092 \newcommand{\Indpp}{\advance\leftskip by 0.5em}%
1093 \newcommand{\Indm}{\advance\leftskip by -1em}%
1094 \newcommand{\Indmm}{\advance\leftskip by -0.5em}%
1095 %%
1096 %%
1097 %% Line Numbering
1098 %%
1099 %%
1100 % number line style
1101 \newcommand{\algocf@nlrelsize}{-2}\newcommand{\SetAlgoNlRelativeSize}[1]{\renewcommand{\algocf@nlrelsize}{#1}}%
1102 \newcommand{\NlSty}[1]{\textnormal{\textbf{\relsize{\algocf@nlrelsize}#1}}}% default definition
1103 \newcommand{\SetNlSty}[3]{\renewcommand{\NlSty}[1]{\textnormal{\csname#1\endcsname{\relsize{\algocf@nlrelsize}#2##1#3}}}}%
1104 %
1105 % nl definitions
1106 %
1107 \newsavebox{\algocf@nlbox}%
1108 \newcommand{\algocf@printnl}[1]{%
1109   \ifthenelse{\boolean{algocf@leftlinenumber}}{%
1110     \skiplinenumber=\skiptotal\advance\skiplinenumber by\leftskip%
1111     \strut\raisebox{0pt}{\llap{\NlSty{#1}\kern\skiplinenumber}}\ignorespaces%
1112   }{%
1113     \sbox\algocf@nlbox{\NlSty{#1}}%
1114     \skiplinenumber=\hsize\advance\skiplinenumber by-\leftskip\advance\skiplinenumber by-\skiptext%
1115     \advance\skiplinenumber by\algomargin\advance\skiplinenumber by.3em\advance\skiplinenumber by-\wd\algocf@nlbox%
1116     \strut\raisebox{0pt}{\rlap{\kern\skiplinenumber\NlSty{#1\ignorespaces}}}\ignorespaces%
1117   }%
1118 }%
1119 \newcommand{\algocf@nl@sethref}[1]{%
1120   \renewcommand{\theHAlgoLine}{\thealgocfproc.#1}%
1121   \hyper@refstepcounter{AlgoLine}\gdef\@currentlabel{#1}%
1122 }%
1123 \newcommand{\nl}{%
1124   \@ifundefined{hyper@refstepcounter}{% if not hyperref then do a simple refstepcounter
1125     \refstepcounter{AlgoLine}%
1126   }{% else if hyperref, do the anchor so 2 lines in two differents algorithms cannot have the same href
1127     \stepcounter{AlgoLine}\algocf@nl@sethref{\theAlgoLine}%
1128   }% now we can do the line numbering
1129   \algocf@printnl{\theAlgoLine}%
1130 }%
1131 %
1132 \newcommand{\nllabel}[1]{\label{#1}}%
1133 %
1134 \newcommand{\enl}{%
1135   \@ifundefined{hyper@refstepcounte}{% if not hyperref then do a simple refstepcounter
1136     \refstepcounter{AlgoLine}%
1137   }{% else if hyperref, do the anchor so 2 lines in two differents algorithms cannot have the same href
1138     \stepcounter{AlgoLine}\algocf@nl@sethref{\theAlgoLine}%
1139   }% now we can do the line numbering
1140   \skiplinenumber=\hsize\advance\skiplinenumber by-\leftskip%
1141   \strut\raisebox{0pt}{\rlap{\kern\skiplinenumber\strut\NlSty{\theAlgoLine}}}\ignorespaces%
1142 }
1143 %% nlset
1144 \newcommand{\nlset}[1]{%
1145   \@ifundefined{hyper@refstepcounter}{\protected@edef\@currentlabel{#1}}{\algocf@nl@sethref{#1}}\algocf@printnl{#1}%
1146 }%
1147 %
1148 %% lnl definitions
1149 \newcommand{\lnl}[1]{\nl\label{#1}}%
1150 %
1151 %% lnlset
1152 \newcommand{\lnlset}[2]{\nlset{#2}\label{#1}}%
1153 %
1154 % set char put at end of each line
1155 %
1156 \newcommand{\algocf@endline}{\string;}
1157 \newcommand{\SetEndCharOfAlgoLine}[1]{\renewcommand{\algocf@endline}{#1}}
1158 %
1159 % end of line definition
1160 %
1161 \newcommand{\@endalgocfline}{\algocf@endline}% default definition: printsemicolon
1162 \newcommand{\DontPrintSemicolon}{\renewcommand{\@endalgocfline}{\relax}}%
1163 \newcommand{\PrintSemicolon}{\renewcommand{\@endalgocfline}{\algocf@endline}}%
1164 \newcommand{\@endalgoln}{\@endalgocfline\hfill\strut\par}%
1165 %
1166 % line numbering
1167 %
1168 \newcommand{\LinesNumbered}{\setboolean{algocf@linesnumbered}{true}\renewcommand{\algocf@linesnumbered}{\everypar={\nl}}}%
1169 \newcommand{\LinesNotNumbered}{%
1170   \setboolean{algocf@linesnumbered}{false}%
1171   \renewcommand{\algocf@linesnumbered}{\relax}%
1172 }%
1173 %
1174 \newcommand{\LinesNumberedHidden}{%
1175   \setboolean{algocf@linesnumbered}{true}\renewcommand{\algocf@linesnumbered}{\everypar{\stepcounter{AlgoLine}}}}%
1176 \newcommand{\ShowLn}{\nlset{\theAlgoLine}\ignorespaces}% display the line number on this line (without labelling)
1177 \newcommand{\ShowLnLabel}[1]{\lnlset{#1}{\theAlgoLine}\ignorespaces}% display the line number and label this line
1178 %
1179 %%
1180 %
1181 %%
1182 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1183 %
1184 % Styling text commands
1185 %
1186 \newcommand{\AlFnt}{\relax}% default definition
1187 \newcommand{\SetAlFnt}[1]{\renewcommand{\AlFnt}{#1}}%
1188 \newcommand{\AlTitleFnt}{\relax}% default definition
1189 \newcommand{\SetAlTitleFnt}[1]{\renewcommand{\AlTitleFnt}{#1}}%
1190 %
1191 \newcommand{\AlCapFnt}{\relax}% default definition
1192 \newcommand{\SetAlCapFnt}[1]{\renewcommand{\AlCapFnt}{#1}}%
1193 \newcommand{\AlCapNameFnt}{\relax}% default definition
1194 \newcommand{\SetAlCapNameFnt}[1]{\renewcommand{\AlCapNameFnt}{#1}}%
1195 %
1196 \newcommand{\ProcFnt}{\relax}% default definition
1197 \newcommand{\SetProcFnt}[1]{\renewcommand{\ProcFnt}{#1}}%
1198 \newcommand{\ProcNameFnt}{\relax}% default definition
1199 \newcommand{\SetProcNameFnt}[1]{\renewcommand{\ProcNameFnt}{#1}}%
1200 \newcommand{\ProcArgFnt}{\relax}% default definition
1201 \newcommand{\SetProcArgFnt}[1]{\renewcommand{\ProcArgFnt}{#1}}%
1202 %
1203 \newcommand{\AlTitleSty}[1]{\textbf{#1}\unskip}% default definition
1204 \newcommand{\SetAlTitleSty}[1]{\renewcommand{\AlTitleSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1205 \newcommand{\AlCapSty}[1]{\textnormal{\textbf{#1}}\unskip}% default definition
1206 \newcommand{\SetAlCapSty}[1]{\renewcommand{\AlCapSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1207 \newcommand{\AlCapNameSty}[1]{\textnormal{#1}\unskip}% default definition
1208 \newcommand{\SetAlCapNameSty}[1]{\renewcommand{\AlCapNameSty}[1]{\textnormal{\csname #1\endcsname{##1}}\unskip}}%
1209 %
1210 \newcommand{\ProcSty}[1]{\AlCapSty{#1}}%
1211 \newcommand{\SetProcSty}[1]{\renewcommand{\ProcSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1212 \newcommand{\ProcNameSty}[1]{\AlCapNameSty{#1}}%
1213 \newcommand{\SetProcNameSty}[1]{\renewcommand{\ProcNameSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1214 \newcommand{\ProcArgSty}[1]{\AlCapNameSty{#1}}%
1215 \newcommand{\SetProcArgSty}[1]{\renewcommand{\ProcArgSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1216 %
1217 \newcommand{\KwSty}[1]{\textnormal{\textbf{#1}}\unskip}% default definition
1218 \newcommand{\SetKwSty}[1]{\renewcommand{\KwSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1219 \newcommand{\ArgSty}[1]{\textnormal{\emph{#1}}\unskip}%\SetArgSty{emph}
1220 \newcommand{\SetArgSty}[1]{\renewcommand{\ArgSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1221 \newcommand{\FuncSty}[1]{\textnormal{\texttt{#1}}\unskip}%\SetFuncSty{texttt}
1222 \newcommand{\SetFuncSty}[1]{\renewcommand{\FuncSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1223 \newcommand{\DataSty}[1]{\textnormal{\textsf{#1}}\unskip}%%\SetDataSty{textsf}
1224 \newcommand{\SetDataSty}[1]{\renewcommand{\DataSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1225 \newcommand{\CommentSty}[1]{\textnormal{\texttt{#1}}\unskip}%%\SetDataSty{texttt}
1226 \newcommand{\SetCommentSty}[1]{\renewcommand{\CommentSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1227 \newcommand{\TitleSty}[1]{#1\unskip}%\SetTitleSty{}{}
1228 \newcommand{\SetTitleSty}[2]{\renewcommand{\TitleSty}[1]{%
1229 \csname#1\endcsname{\csname#2\endcsname##1}}\unskip}%
1230 %
1231 %%
1232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1233 %
1234 % Block basic commands
1235 %
1236 \newcommand{\algocf@push}[1]{\advance\skiptotal by #1\moveright #1}%
1237 \newcommand{\algocf@pop}[1]{\advance\skiptotal by -#1}%
1238 \newcommand{\algocf@addskiptotal}{\advance\skiptotal by 0.4pt\advance\hsize by -0.4pt}% 0.4 pt=width of \vrule
1239 \newcommand{\algocf@subskiptotal}{\advance\skiptotal by -0.4pt\advance\hsize by 0.4pt}% 0.4 pt=width of \vrule
1240 %
1241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1242 %%
1243 %% group of instructions definition
1244 %
1245 \skiphlne=.8ex%
1246 \newcommand{\SetVlineSkip}[1]{\skiphlne=#1}%
1247 %
1248 %% block with a vertical line end by a little horizontal line
1249 \newcommand{\algocf@Vline}[1]{%     no vskip in between boxes but a strut to separate them, 
1250   \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
1251   \algocf@push{\skiprule}%        move to the right before the vertical rule
1252   \hbox{\vrule%
1253     \vtop{\algocf@push{\skiptext}%move the right after the rule
1254       \vtop{\algocf@addskiptotal\advance\hsize by -\skiplength #1}\Hlne}}\vskip\skiphlne% inside the block
1255   \algocf@pop{\skiprule}%\algocf@subskiptotal% restore indentation
1256   \nointerlineskip}% no vskip after
1257 %
1258 %% block with a vertical line
1259 \newcommand{\algocf@Vsline}[1]{%    no vskip in between boxes but a strut to separate them, 
1260   \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
1261   \algocf@push{\skiprule}%        move to the right before the vertical rule
1262   \hbox{\vrule%               the vertical rule
1263     \vtop{\algocf@push{\skiptext}%move the right after the rule
1264       \vtop{\algocf@addskiptotal\advance\hsize by -\skiplength #1}}}% inside the block
1265   \algocf@pop{\skiprule}}% restore indentation
1266 %
1267 \newcommand{\algocf@Hlne}{\hrule height 0.4pt depth 0pt width .5em}%
1268 %
1269 %% block without line
1270 \newcommand{\algocf@Noline}[1]{%    no vskip in between boxes but a strut to separate them, 
1271   \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
1272   \algocf@push{\skiprule}%
1273   \hbox{%
1274     \vtop{\algocf@push{\skiptext}%
1275       \vtop{\advance\hsize by -\skiplength #1}}}% inside the block
1276   \algocf@pop{\skiprule}%
1277   % \nointerlineskip% no vskip after
1278 }%
1279 %
1280 %% default=NoLine
1281 %
1282 \newcommand{\algocf@group}[1]{\algocf@Noline{##1}}% group: set of instruction depending from another (ex: then part of the If)
1283 \newcommand{\algocf@@block}[2]{\algocf@Noline{##1}\KwSty{##2}\par}% block: group with a end keyword.
1284 \newcommand{\algocf@block}[2]{\algocf@@block{#1}{#2}}% command that will be used and redefined accordingly to noend option
1285 \newcommand{\algocf@setBlock}{%
1286   \ifthenelse{\boolean{algocf@optnoend}}{%     if no end option
1287     \renewcommand{\algocf@block}[2]{\algocf@group{##1}}%     block will be a group
1288   }{%                                          else
1289     \renewcommand{\algocf@block}[2]{\algocf@@block{##1}{##2}}% block stays a block
1290   }%
1291 }%
1292 %
1293 \newcommand{\Hlne}{}% little hrizontal line ending a block in vline mode
1294 %
1295 \newcommand{\@algocf@endoption}[1]{#1}%
1296 \newboolean{algocf@optnoend}\setboolean{algocf@optnoend}{false}%
1297 %
1298 \newcommand{\SetAlgoLongEnd}{%%%%%%%%%%%%%%%%%%%%%%%%% Long End
1299   \setboolean{algocf@optnoend}{false}%
1300   \renewcommand{\@algocf@endoption}[1]{##1}%
1301   \algocf@setBlock}%
1302 %
1303 \newcommand{\SetAlgoShortEnd}{%%%%%%%%%%%%%%%%%%%%%%%% ShortEnd
1304   \setboolean{algocf@optnoend}{false}%
1305   \renewcommand{\@algocf@endoption}[1]{\@firstword##1 \@nil}%
1306   \algocf@setBlock}%
1307 %
1308 \newcommand{\SetAlgoNoEnd}{%%%%%%%%%%%%%%%%%%%%%%%%%%% NoEnd
1309   \setboolean{algocf@optnoend}{true}%
1310   \renewcommand{\@algocf@endoption}[1]{}%
1311   \algocf@setBlock}%
1312 %
1313 \newcommand{\SetAlgoNoLine}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Noline
1314 \renewcommand{\algocf@@block}[2]{\algocf@Noline{##1}\KwSty{##2}\strut\par}%
1315 \renewcommand{\algocf@group}[1]{\algocf@Noline{##1}}%
1316 \renewcommand{\Hlne}{}}%
1317 %
1318 \newcommand{\SetAlgoVlined}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Vline
1319 \renewcommand{\algocf@@block}[2]{\algocf@Vline{##1}}%
1320 \renewcommand{\algocf@group}[1]{\algocf@Vsline{##1}\ifthenelse{\boolean{algocf@optnoend}}{\relax}{\strut\ignorespaces}}%
1321 \renewcommand{\Hlne}{\algocf@Hlne}}%
1322 %
1323 \newcommand{\SetAlgoLined}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Line
1324 \renewcommand{\algocf@@block}[2]{\strut\algocf@Vsline{##1}\KwSty{##2}\strut\par}% no skip after a block so garantie at least a line
1325 \renewcommand{\algocf@group}[1]{\algocf@Vsline{##1}\ifthenelse{\boolean{algocf@optnoend}}{\relax}{\strut\ignorespaces}}%
1326 \renewcommand{\Hlne}{}}%
1327 %
1328 \newcommand{\SetNothing}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Noline
1329 \renewcommand{\algocf@@block}[2]{\algocf@Noline{##1}\par}%
1330 %\long
1331 \renewcommand{\algocf@group}[1]{\algocf@Noline{##1}}%
1332 \renewcommand{\Hlne}{}}%
1333 %
1334 %%
1335 %%
1336 %
1337 %
1338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1339 %
1340 % ``Input :'''s like command 
1341 %
1342 %%%
1343 % text staying at the right of the longer keyword of KwInOut commands 
1344 % (text of KwInOut commands are all vertically aligned)
1345 %
1346 \newcommand{\algocf@newinout}{\par\parindent=\wd\algocf@inoutbox}% to put right indentation after a \\ in the KwInOut
1347 \newcommand{\SetKwInOut}[2]{%
1348   \sbox\algocf@inoutbox{\KwSty{#2}\algocf@typo:}%
1349   \expandafter\ifx\csname InOutSizeDefined\endcsname\relax% if first time used
1350     \newcommand\InOutSizeDefined{}\setlength{\inoutsize}{\wd\algocf@inoutbox}%
1351   \else% else keep the larger dimension
1352     \ifdim\wd\algocf@inoutbox>\inoutsize\setlength{\inoutsize}{\wd\algocf@inoutbox}\fi%
1353   \fi% the dimension of the box is now defined.
1354   \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1355   \expandafter\algocf@mkcmd\csname#1\endcsname[1]{%
1356     \ifthenelse{\boolean{algocf@inoutnumbered}}{\relax}{\everypar={\relax}}%
1357     {\let\\\algocf@newinout\hangindent=\wd\algocf@inoutbox\hangafter=1\parbox[t]{\inoutsize}{\KwSty{#2}\algocf@typo\hfill:}~##1\par}%
1358     \algocf@linesnumbered% reset the numbering of the lines
1359   }}%
1360 %
1361 %% allow to ajust the skip size of InOut
1362 %%
1363 \newcommand{\ResetInOut}[1]{%
1364   \sbox\algocf@inoutbox{\hbox{\KwSty{#1}\algocf@typo:\ }}%
1365   \setlength{\inoutsize}{\wd\algocf@inoutbox}%
1366   }%
1367 %
1368
1369 %%%
1370 % text staying at the right of the keyword.
1371 %
1372 \newcommand{\algocf@newinput}{\par\parindent=\wd\algocf@inputbox}% to put right indentation after a \\ in the KwInput
1373 \newcommand{\SetKwInput}[2]{%
1374   \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1375   \expandafter\algocf@mkcmd\csname#1\endcsname[1]{%
1376     \sbox\algocf@inputbox{\hbox{\KwSty{#2}\algocf@typo: }}%
1377     \ifthenelse{\boolean{algocf@inoutnumbered}}{\relax}{\everypar={\relax}}%
1378     {\let\\\algocf@newinput\hangindent=\wd\algocf@inputbox\hangafter=1\unhbox\algocf@inputbox##1\par}%
1379     \algocf@linesnumbered% reset the numbering of the lines
1380   }}%
1381 \newcommand{\SetKwData}[2]{%
1382   \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1383   \expandafter\algocf@mkcmd\csname @#1\endcsname[1]{\DataSty{#2(}\ArgSty{##1}\DataSty{)}}%
1384   \expandafter\algocf@mkcmd\csname#1\endcsname{%
1385     \@ifnextchar\bgroup{\csname @#1\endcsname}{\DataSty{#2}\xspace}}%
1386   }%
1387 %
1388 %
1389 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1390 % tallent:
1391 %
1392 % Add following macros:
1393 %   \SetKwHangingKw:  [kw] ------------   <= hanging determined by [kw]
1394 %                          ------------
1395 % Should act like a combination of \SetKwInput and \SetKw.
1396 % Based on \SetKwInput:
1397 %   - remove ':' at end of keyword
1398 %   - do not reset numbering
1399 %   - use separate savebox
1400 \newsavebox{\algocf@hangingbox}
1401 \newcommand{\algocf@newhanging}{\par\parindent=\wd\algocf@hangingbox}% to put right indentation after a \\ in the KwInput
1402 \newcommand{\SetKwHangingKw}[2]{%
1403   \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1404   \expandafter\algocf@mkcmd\csname#1\endcsname[1]{%
1405     \sbox\algocf@hangingbox{\hbox{\KwSty{#2}\algocf@typo\ }}%
1406     {\let\\\algocf@newhanging\hangindent=\wd\algocf@hangingbox\hangafter=1\unhbox\algocf@hangingbox##1\;}%
1407   }%
1408 }%
1409 %
1410 %
1411 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1412 %
1413 % Comments macros
1414 %
1415 %%%%
1416 % comment in the text, first argument is the name of the macro, second is
1417 % the text put before the comment, third is the text put at the end of the
1418 % comment.
1419 %
1420 % first side comment justification
1421 \newcommand{\SetSideCommentLeft}{\setboolean{algocf@scleft}{true}}%
1422 \newcommand{\SetSideCommentRight}{\setboolean{algocf@scleft}{false}}%
1423 \newcommand{\SetNoFillComment}{\setboolean{algocf@optfillcomment}{false}}%
1424 \newcommand{\SetFillComment}{\setboolean{algocf@optfillcomment}{true}}%
1425 %
1426 % next comment and side comment
1427 %
1428 \newcommand{\algocf@endmarkcomment}{\relax}%
1429 \newcommand{\algocf@fillcomment}{%
1430   \ifthenelse{\boolean{algocf@optfillcomment}}{\hfill}{\relax}}%
1431 %
1432 \newcommand{\algocf@startcomment}{%
1433   \hangindent=\wd\algocf@inputbox\hangafter=1\usebox\algocf@inputbox}%
1434 \newcommand{\algocf@endcomment}{\algocf@fillcomment\algocf@endmarkcomment\ignorespaces\par}%
1435 \newcommand{\algocf@endstartcomment}{\algocf@endcomment\algocf@startcomment\ignorespaces}%
1436 %
1437 \newboolean{algocf@sidecomment}%
1438 \newboolean{algocf@altsidecomment}\setboolean{algocf@altsidecomment}{false}%
1439 \newcommand{\algocf@scpar}{\ifthenelse{\boolean{algocf@altsidecomment}}{\relax}{\par}}%
1440 \newcommand{\algocf@sclfill}{\ifthenelse{\boolean{algocf@scleft}}{\algocf@fillcomment}{\relax}}%
1441 \newcommand{\algocf@scrfill}{\ifthenelse{\boolean{algocf@scleft}}{\relax}{\hfill}}%
1442 \newcommand{\algocf@startsidecomment}{\usebox\algocf@inputbox}%
1443 \newcommand{\algocf@endsidecomment}{\algocf@endmarkcomment\algocf@scpar}%
1444 \newcommand{\algocf@endstartsidecomment}{%
1445   \algocf@sclfill\algocf@endsidecomment%
1446   \algocf@scrfill\algocf@startsidecomment\ignorespaces}%
1447 %
1448 \newcommand{\SetKwComment}[3]{%
1449   % newcommand or renewcommand ?
1450   \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1451   %%% comment definition
1452   \expandafter\algocf@mkcmd\csname algocf@#1\endcsname[1]{%
1453     \sbox\algocf@inputbox{\CommentSty{\hbox{#2}}}%
1454     \ifthenelse{\boolean{algocf@commentsnumbered}}{\relax}{\everypar={\relax}}%
1455     {\renewcommand{\algocf@endmarkcomment}{#3}%
1456       \let\\\algocf@endstartcomment%
1457       \algocf@startcomment\CommentSty{%
1458         \strut\ignorespaces##1\strut\algocf@fillcomment#3}\par}%
1459     \algocf@linesnumbered% reset the numbering of the lines
1460   }%
1461   %%% side comment definitions
1462   % option or not?
1463   \expandafter\algocf@mkcmd\csname algocf@#1@star\endcsname{%
1464     \@ifnextchar [{\csname algocf@#1@staropt\endcsname}{\csname algocf@#1@sidecomment\endcsname}%
1465   }%
1466   % manage option
1467   \expandafter\def\csname algocf@#1@staropt\endcsname[##1]##2{%
1468     \ifthenelse{\boolean{algocf@scleft}}{\setboolean{algocf@sidecomment}{true}}{\setboolean{algocf@sidecomment}{false}}%
1469     \ifx##1h\setboolean{algocf@altsidecomment}{true}\SetSideCommentLeft\fi%
1470     \ifx##1f\setboolean{algocf@altsidecomment}{true}\SetSideCommentRight\fi%
1471     \ifx##1l\setboolean{algocf@altsidecomment}{false}\SetSideCommentLeft\fi%
1472     \ifx##1r\setboolean{algocf@altsidecomment}{false}\SetSideCommentRight\fi%
1473     \csname algocf@#1@sidecomment\endcsname{##2}% call sidecomment
1474     \ifthenelse{\boolean{algocf@sidecomment}}{\setboolean{algocf@scleft}{true}}{\setboolean{algocf@scleft}{false}}%
1475     \setboolean{algocf@altsidecomment}{false}%
1476   }%
1477   % side comment
1478   \expandafter\algocf@mkcmd\csname algocf@#1@sidecomment\endcsname[1]{%
1479     \sbox\algocf@inputbox{\CommentSty{\hbox{#2}}}%
1480     \ifthenelse{\boolean{algocf@commentsnumbered}}{\relax}{\everypar={\relax}}%
1481     {%
1482       \renewcommand{\algocf@endmarkcomment}{#3}%
1483       \let\\\algocf@endstartsidecomment%
1484       % here is the comment
1485       %\ifthenelse{\boolean{algocf@altsidecomment}}{\relax}{\algocf@endline\ }%
1486       \ifthenelse{\boolean{algocf@altsidecomment}}{\relax}{\@endalgocfline\ }%
1487       \algocf@scrfill\algocf@startsidecomment\CommentSty{%
1488         \strut\ignorespaces##1\strut\algocf@sclfill#3}\algocf@scpar%
1489     }%
1490     \algocf@linesnumbered% reset the numbering of the lines
1491   }
1492   \expandafter\algocf@mkcmd\csname#1\endcsname{\@ifstar{\csname algocf@#1@star\endcsname}{\csname algocf@#1\endcsname}}%
1493 }%
1494 %
1495 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1496 %
1497 % Kw
1498 %
1499 \newcommand{\SetKw}[2]{%
1500   \@ifundefined{#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1501   \expandafter\algocf@mkcmd\csname @#1\endcsname[1]{\KwSty{#2} \ArgSty{##1}}%
1502   \expandafter\algocf@mkcmd\csname#1\endcsname{%
1503     \@ifnextchar\bgroup{\csname @#1\endcsname}{\KwSty{#2}\xspace}}%
1504   }%
1505 %
1506 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1507 %
1508 % KwFunction
1509 %
1510 \newcommand{\SetKwFunction}[2]{%
1511 %%% use of gdef since newcommand doesn't manage to define the macro when SetKwFunction is used in \algocf@caption@proc
1512   \expandafter\gdef\csname @#1\endcsname##1{\FuncSty{#2(}\ArgSty{##1}\FuncSty{)}}%
1513   \expandafter\gdef\csname#1\endcsname{%
1514     \@ifnextchar\bgroup{\csname @#1\endcsname}{\FuncSty{#2}\xspace}}%
1515 }%
1516 %
1517 %
1518 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1519 %
1520 % KwTab
1521 %
1522 \newcommand{\SetKwArray}[2]{%
1523 %%% use of gdef since newcommand doesn't manage to define the macro when SetKwFunction is used in \algocf@caption@proc
1524   \expandafter\gdef\csname @#1\endcsname##1{\DataSty{#2[}\ArgSty{##1}\DataSty{]}}%
1525   \expandafter\gdef\csname#1\endcsname{%
1526     \@ifnextchar\bgroup{\csname @#1\endcsname}{\DataSty{#2}\xspace}}%
1527 }%
1528 %
1529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1530 %
1531 % KwBlock
1532 %
1533 \newcommand{\SetKwBlock}[3]{%
1534 \@ifundefined{algocf@#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1535 % side text or not? 
1536 \expandafter\def\csname#1\endcsname{%Begin
1537   \@ifnextchar({\csname algocf@#1opt\endcsname}{\csname algocf@#1\endcsname}}%
1538 % with side text
1539 \expandafter\def\csname algocf@#1opt\endcsname(##1)##2{% \Begin(){}
1540   \KwSty{#2} ##1\algocf@block{##2}{\@algocf@endoption{#3}}%
1541   \@ifnextchar({\csname algocf@#1end\endcsname}{\par}}%
1542 % without side text at the beginning
1543 \expandafter\algocf@mkcmd\csname algocf@#1\endcsname[1]{% \Begin{}
1544   \KwSty{#2}\algocf@block{##1}{\@algocf@endoption{#3}}\@ifnextchar({\csname algocf@#1end\endcsname}{\par}}%
1545 % side text at the end
1546 \expandafter\def\csname algocf@#1end\endcsname(##1){% \Begin{}
1547   \ ##1\par}%
1548 }%
1549 %
1550 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1551 %
1552 % For Switch
1553 %
1554 \newcommand{\SetKwSwitch}[8]{% #1=\Switch #2=\Case #3=\Other #4=swicth #5=case #6=do #7=otherwise #8=endsw
1555 %%%% Switch
1556 \@ifundefined{algocf@#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1557 % side text or not? 
1558 \expandafter\def\csname#1\endcsname{%Switch
1559   \@ifnextchar({\csname algocf@#1opt\endcsname}{\csname algocf@#1\endcsname}}%
1560 % with side text
1561 \expandafter\def\csname algocf@#1opt\endcsname(##1)##2##3{% \Switch(){}{}
1562   \KwSty{#4} \ArgSty{##2} \KwSty{#5} ##1\algocf@block{##3}{\@algocf@endoption{#8}}}%
1563 % without side text
1564 \expandafter\algocf@mkcmd\csname algocf@#1\endcsname[2]{% \Switch{}{}
1565   \KwSty{#4} \ArgSty{##1} \KwSty{#5}\algocf@block{##2}{\@algocf@endoption{#8}}}%
1566 % side text at the end
1567 \expandafter\def\csname algocf@#1end\endcsname(##1){% \Switch{}{}()
1568 }%
1569 %
1570 %%%% Case
1571 \@ifundefined{algocf@#2}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1572 % side text or not?
1573 \expandafter\def\csname#2\endcsname{%Case
1574   \@ifnextchar({\csname algocf@#2opt\endcsname}{\csname algocf@#2\endcsname}}%
1575 \expandafter\def\csname u#2\endcsname{%uCase
1576   \@ifnextchar({\csname algocf@u#2opt\endcsname}{\csname algocf@u#2\endcsname}}%
1577 \expandafter\def\csname l#2\endcsname{%lCase
1578   \@ifnextchar({\csname algocf@l#2opt\endcsname}{\csname algocf@l#2\endcsname}}%
1579 % with side text
1580 \expandafter\def\csname algocf@#2opt\endcsname(##1)##2##3{% \Case(){}{}
1581   \KwSty{#6} \ArgSty{##2} ##1\algocf@block{##3}{\@algocf@endoption{#8}}}%
1582 \expandafter\def\csname algocf@u#2opt\endcsname(##1)##2##3{% \uCase(){}{}
1583   \KwSty{#6} \ArgSty{##2} ##1\algocf@group{##3}}%
1584 \expandafter\def\csname algocf@l#2opt\endcsname(##1)##2##3{% \lCase(){}{}
1585   \KwSty{#6} \ArgSty{##2} ##3\algocf@endline\ ##1\par}%
1586 % without side text
1587 \expandafter\algocf@mkcmd\csname algocf@#2\endcsname[2]{% \Case{}{}
1588   \KwSty{#6} \ArgSty{##1}\algocf@block{##2}{\@algocf@endoption{#8}}}%
1589 \expandafter\algocf@mkcmd\csname algocf@u#2\endcsname[2]{% \uCase{}{}
1590   \KwSty{#6} \ArgSty{##1}\algocf@group{##2}}%
1591 \expandafter\algocf@mkcmd\csname algocf@l#2\endcsname[2]{% \lCase{}{}
1592   \KwSty{#6} \ArgSty{##1} ##2}%
1593 %%%% Other
1594 \@ifundefined{algocf@#3}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1595 % side text or not?
1596 \expandafter\def\csname#3\endcsname{%Other
1597   \@ifnextchar({\csname algocf@#3opt\endcsname}{\csname algocf@#3\endcsname}}%
1598 \expandafter\def\csname l#3\endcsname{%Other
1599   \@ifnextchar({\csname algocf@l#3opt\endcsname}{\csname algocf@l#3\endcsname}}%
1600 % with side text
1601 \expandafter\def\csname algocf@#3opt\endcsname(##1)##2{% \Other(){}{}
1602   \KwSty{#7} ##1\algocf@block{##2}{\@algocf@endoption{#8}}}%
1603 \expandafter\def\csname algocf@l#3opt\endcsname(##1)##2{% \Other(){}{}
1604   \KwSty{#7} ##2\algocf@endline\ ##1\par}%
1605 % without side text
1606 \expandafter\algocf@mkcmd\csname algocf@#3\endcsname[1]{% default
1607   \KwSty{#7}\algocf@block{##1}{\@algocf@endoption{#8}}}%
1608 \expandafter\algocf@mkcmd\csname algocf@l#3\endcsname[1]{% ldefault
1609   \KwSty{#7} ##1}%
1610 }%
1611 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1612 %
1613 % If macros
1614 %
1615 \newcommand{\SetKwIF}[8]{% #1=\If #2=\ElseIf #3=\Else #4=if #5=then #6=elseif si #7=else #8=endif
1616
1617 % common text
1618 \@ifundefined{#1@ifthen}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1619 \expandafter\algocf@mkcmd\csname #1@ifthen\endcsname[1]{%
1620   \KwSty{#4} \ArgSty{##1} \KwSty{#5}}%
1621 \expandafter\algocf@mkcmd\csname #1@endif\endcsname[1]{\algocf@block{##1}{\@algocf@endoption{#8}}}%
1622 \expandafter\algocf@mkcmd\csname #1@noend\endcsname[1]{\algocf@group{##1}}%
1623 \expandafter\algocf@mkcmd\csname #1@else\endcsname[1]{\algocf@group{##1}\KwSty{#7}}%
1624 \@ifundefined{#2@elseif}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1625 \expandafter\algocf@mkcmd\csname #2@elseif\endcsname[1]{%
1626   \KwSty{#6} \ArgSty{##1} \KwSty{#5}}%
1627 \@ifundefined{#3@else}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1628 \expandafter\algocf@mkcmd\csname #3@else\endcsname{\KwSty{#7}}%
1629 %%%% If then { } endif
1630 %
1631 \@ifundefined{algocf@#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1632 % side text or not?
1633 \expandafter\def\csname#1\endcsname{%
1634   \@ifnextchar({\csname algocf@#1opt\endcsname}{\csname algocf@#1\endcsname}}%
1635 % with side text
1636 \expandafter\def\csname algocf@#1opt\endcsname(##1)##2##3{% \If(){}{}
1637   \csname #1@ifthen\endcsname{##2} ##1\csname #1@endif\endcsname{##3}}%
1638 % without side text
1639 \expandafter\algocf@mkcmd\csname algocf@#1\endcsname[2]{% \If{}{}
1640   \csname #1@ifthen\endcsname{##1}\csname #1@endif\endcsname{##2}}%
1641 %
1642 %%%% If then {} else {} endif
1643 %
1644 % side text or not?
1645 \expandafter\def\csname e#1\endcsname{%
1646   \@ifnextchar({\csname algocf@e#1thenopt\endcsname}{\csname algocf@e#1then\endcsname}}%
1647 % with side text after if
1648 \expandafter\def\csname algocf@e#1thenopt\endcsname(##1)##2##3{% \eIf()
1649   \csname #1@ifthen\endcsname{##2} ##1\csname #1@else\endcsname{##3}%
1650   \csname algocf@e#1thenelse\endcsname}%
1651 % without side text after if
1652 \expandafter\def\csname algocf@e#1then\endcsname##1##2{% \eIf()
1653   \csname #1@ifthen\endcsname{##1}\csname #1@else\endcsname{##2}%
1654   \csname algocf@e#1thenelse\endcsname}%
1655 % side text after else or not ?
1656 \expandafter\def\csname algocf@e#1thenelse\endcsname{%
1657   \@ifnextchar({\csname algocf@e#1elseopt\endcsname}{\csname algocf@e#1else\endcsname}}%
1658 % else with a side text
1659 \expandafter\def\csname algocf@e#1elseopt\endcsname(##1)##2{% 
1660   ##1\csname #1@endif\endcsname{##2}}%
1661 % else without side text
1662 \expandafter\algocf@mkcmd\csname algocf@e#1else\endcsname[1]{%
1663   \csname #1@endif\endcsname{##1}}%
1664 %
1665 %%%% If then 
1666 %
1667 % side text or not?
1668 \expandafter\def\csname l#1\endcsname{% lif
1669   \@ifnextchar({\csname algocf@l#1opt\endcsname}{\csname algocf@l#1\endcsname}}%
1670 \expandafter\def\csname u#1\endcsname{% uif
1671   \@ifnextchar({\csname algocf@u#1opt\endcsname}{\csname algocf@u#1\endcsname}}%
1672 % with side text
1673 \expandafter\def\csname algocf@l#1opt\endcsname(##1)##2##3{% \lIf(){}{}
1674   \csname #1@ifthen\endcsname{##2} ##3\algocf@endline\ ##1\par}%
1675 \expandafter\def\csname algocf@u#1opt\endcsname(##1)##2##3{% \uIf(){}{}
1676   \csname #1@ifthen\endcsname{##2} ##1\csname#1@noend\endcsname{##3}}%
1677 % without side text
1678 \expandafter\algocf@mkcmd\csname algocf@l#1\endcsname[2]{% \lIf{}{}
1679   \csname #1@ifthen\endcsname{##1} ##2}%
1680 \expandafter\algocf@mkcmd\csname algocf@u#1\endcsname[2]{% \uIf{}{}
1681   \csname #1@ifthen\endcsname{##1}\csname#1@noend\endcsname{##2}}%
1682 %
1683 %%%% ElseIf {} endif
1684 %
1685 \@ifundefined{algocf@#2}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1686 % side text or not?
1687 \expandafter\def\csname#2\endcsname{% ElseIf
1688   \@ifnextchar({\csname algocf@#2opt\endcsname}{\csname algocf@#2\endcsname}}%
1689 % with side text
1690 \expandafter\def\csname algocf@#2opt\endcsname(##1)##2##3{% \ElseIf(){}{}
1691   \csname #2@elseif\endcsname{##2} ##1\csname #1@endif\endcsname{##3}}%
1692 % without side text
1693 \expandafter\algocf@mkcmd\csname algocf@#2\endcsname[2]{% \ElseIf{}{}
1694   \csname #2@elseif\endcsname{##1}\csname #1@endif\endcsname{##2}}%
1695 %
1696 %%%% ElseIf
1697 %
1698 % side text or not?
1699 \expandafter\def\csname l#2\endcsname{% lElseIf
1700   \@ifnextchar({\csname algocf@l#2opt\endcsname}{\csname algocf@l#2\endcsname}}%
1701 \expandafter\def\csname u#2\endcsname{% uElseIf
1702   \@ifnextchar({\csname algocf@u#2opt\endcsname}{\csname algocf@u#2\endcsname}}%
1703 % with side text
1704 \expandafter\def\csname algocf@l#2opt\endcsname(##1)##2##3{% \lElseIf(){}{}
1705   \csname #2@elseif\endcsname{##2} ##3\algocf@endline\ ##1\par}%
1706 \expandafter\def\csname algocf@u#2opt\endcsname(##1)##2##3{% \uElseIf(){}{}
1707   \csname #2@elseif\endcsname{##2} ##1\csname #1@noend\endcsname{##3}}%
1708 % without side text
1709 \expandafter\algocf@mkcmd\csname algocf@l#2\endcsname[2]{% \lElseIf{}{}
1710   \csname #2@elseif\endcsname{##1} ##2}%
1711 \expandafter\algocf@mkcmd\csname algocf@u#2\endcsname[2]{% \uElseIf{}{}
1712   \csname #2@elseif\endcsname{##1}\csname #1@noend\endcsname{##2}}%
1713 %
1714 %%%% Else {} endif
1715 %
1716 \@ifundefined{algocf@#3}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1717 % side text or not?
1718 \expandafter\def\csname#3\endcsname{% Else
1719   \@ifnextchar({\csname algocf@#3opt\endcsname}{\csname algocf@#3\endcsname}}%
1720 % with side text
1721 \expandafter\def\csname algocf@#3opt\endcsname(##1)##2{% \Else(){}
1722   \csname #3@else\endcsname\ ##1\csname #1@endif\endcsname{##2}}%
1723 % without side text
1724 \expandafter\algocf@mkcmd\csname algocf@#3\endcsname[1]{% \Else{}
1725   \csname #3@else\endcsname\csname #1@endif\endcsname{##1}}%
1726 %
1727 %%%% Else 
1728 %
1729 % side text or not?
1730 \expandafter\def\csname l#3\endcsname{% lElse
1731   \@ifnextchar({\csname algocf@l#3opt\endcsname}{\csname algocf@l#3\endcsname}}%
1732 \expandafter\def\csname u#3\endcsname{% uElse
1733   \@ifnextchar({\csname algocf@u#3opt\endcsname}{\csname algocf@u#3\endcsname}}%
1734 % with side text
1735 \expandafter\def\csname algocf@l#3opt\endcsname(##1)##2{% \lElse(){}
1736   \csname #3@else\endcsname\ ##2\algocf@endline\ ##1\par}%
1737 \expandafter\def\csname algocf@u#3opt\endcsname(##1)##2{% \uElse(){}
1738   \csname #3@else\endcsname\ ##1\csname #1@noend\endcsname{##2}}%
1739 % without side text
1740 \expandafter\algocf@mkcmd\csname algocf@l#3\endcsname[1]{% \lElse{}
1741   \csname #3@else\endcsname\ ##1}%
1742 \expandafter\algocf@mkcmd\csname algocf@u#3\endcsname[1]{% \uElse{}
1743   \csname #3@else\endcsname\csname #1@noend\endcsname{##1}}%
1744 }%
1745 %
1746 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1747 %
1748 % For macros
1749 %
1750 \newcommand{\SetKwFor}[4]{%
1751 \@ifundefined{algocf@#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1752 % side text or not? 
1753 \expandafter\def\csname#1\endcsname{%For
1754   \@ifnextchar({\csname algocf@#1opt\endcsname}{\csname algocf@#1\endcsname}}%
1755 \expandafter\def\csname l#1\endcsname{%For
1756   \@ifnextchar({\csname algocf@l#1opt\endcsname}{\csname algocf@l#1\endcsname}}%
1757 % with side text
1758 \expandafter\def\csname algocf@#1opt\endcsname(##1)##2##3{% \For(){}{}
1759   \KwSty{#2} \ArgSty{##2} \KwSty{#3} ##1\algocf@block{##3}{\@algocf@endoption{#4}}}%
1760 \expandafter\def\csname algocf@l#1opt\endcsname(##1)##2##3{% \lFor(){}{}
1761   \KwSty{#2} \ArgSty{##2} \KwSty{#3} ##3\algocf@endline\ ##1\par}%
1762 % without side text
1763 \expandafter\algocf@mkcmd\csname algocf@#1\endcsname[2]{% \For{}{}
1764   \KwSty{#2} \ArgSty{##1} \KwSty{#3}\algocf@block{##2}{\@algocf@endoption{#4}}}%
1765 \expandafter\algocf@mkcmd\csname algocf@l#1\endcsname[2]{% \lFor{}{}
1766   \KwSty{#2} \ArgSty{##1} \KwSty{#3} ##2}%
1767 }%
1768 %
1769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1770 %
1771 % Repeat macros
1772 %
1773 \newcommand{\SetKwRepeat}[3]{%
1774 \@ifundefined{algocf@#1}{\let\algocf@mkcmd=\newcommand}{\let\algocf@mkcmd=\renewcommand}%
1775 % side text or not?
1776 \expandafter\def\csname#1\endcsname{% Repeat
1777   \@ifnextchar({\csname algocf@#1opt\endcsname}{\csname algocf@#1\endcsname}}%
1778 \expandafter\def\csname l#1\endcsname{% lRepeat
1779   \@ifnextchar({\csname algocf@l#1opt\endcsname}{\csname algocf@l#1\endcsname}}%
1780 % with side text
1781 \expandafter\def\csname algocf@#1opt\endcsname(##1)##2##3{% \Repeat(){}{}
1782   \KwSty{#2} ##1\algocf@group{##3}\KwSty{#3} \ArgSty{##2}%
1783   \@ifnextchar({\csname algocf@#1optopt\endcsname}{\@endalgoln}%
1784 }%
1785 \expandafter\def\csname algocf@#1optopt\endcsname(##1){% \Repeat(){}{}()
1786   ##1\@endalgoln}%
1787 \expandafter\def\csname algocf@l#1opt\endcsname(##1)##2##3{% \lRepeat(){}{}
1788   \KwSty{#2} ##3 \KwSty{#3} \ArgSty{##2}\algocf@endline\ ##1\par}%
1789 % without side text
1790 \expandafter\algocf@mkcmd\csname algocf@#1\endcsname[2]{% \Repeat{}{}
1791   \KwSty{#2}\algocf@group{##2}\KwSty{#3} \ArgSty{##1}%
1792   \@ifnextchar({\csname algocf@#1optopt\endcsname}{\@endalgoln}%
1793 }%
1794 \expandafter\algocf@mkcmd\csname algocf@l#1\endcsname[2]{% \lRepeat{}{}
1795   \KwSty{#2} ##2 \KwSty{#3} \ArgSty{##1}}%
1796 }%
1797 %
1798
1799 %
1800 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1801 %%%%%%%%%%%%%%%%%%%%        Environments definitions     %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1802 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1803 %
1804 %%
1805 %% Caption management
1806 %%
1807 % for the following macros:
1808 % #1 is given by caption and is equal to fnum@algocf
1809 % #2 is the text given in argument by the user in the \caption macro
1810 %
1811 %%%%% text of caption
1812 \newcommand{\algocf@captionlayout}[1]{#1}%
1813 \newcommand{\SetAlgoCaptionLayout}[1]{%
1814   \renewcommand{\algocf@captionlayout}[1]{\csname #1\endcsname{##1}}}%
1815 \newcommand{\algocf@capseparator}{:}%
1816 \newcommand{\SetAlgoCaptionSeparator}[1]{\renewcommand{\algocf@capseparator}{#1}}%
1817 \newcommand{\algocf@captiontext}[2]{%
1818   \algocf@captionlayout{\AlCapSty{\AlCapFnt #1\algocf@typo\algocf@capseparator}\nobreakspace%
1819     \AlCapNameSty{\AlCapNameFnt{}#2}}}% text of caption
1820 %
1821 %%%%% default caption of algorithm: used if no specific style caption is defined
1822 \newcommand{\algocf@makecaption}[2]{%
1823   \addtolength{\hsize}{\algomargin}%
1824   \sbox\@tempboxa{\algocf@captiontext{#1}{#2}}%
1825   \ifdim\wd\@tempboxa >\hsize%     % if caption is longer than a line
1826     \hskip .5\algomargin%
1827     \parbox[t]{\hsize}{\algocf@captiontext{#1}{#2}}% then caption is not centered
1828   \else%
1829     \global\@minipagefalse%
1830     \hbox to\hsize{\hfil\box\@tempboxa\hfil}% else caption is centered
1831   \fi%
1832   \addtolength{\hsize}{-\algomargin}%
1833 }%
1834 %
1835 \newsavebox\algocf@capbox%
1836 \newcommand{\algocf@makecaption@plain}[2]{%
1837   \global\sbox\algocf@capbox{\algocf@makecaption{#1}{#2}}}%
1838 \newcommand{\algocf@makecaption@boxed}[2]{%
1839   \addtolength{\hsize}{-\algomargin}%
1840   \global\sbox\algocf@capbox{\algocf@makecaption{#1}{#2}}%
1841   \addtolength{\hsize}{\algomargin}%
1842  }%
1843 %
1844 \newcommand{\algocf@makecaption@tworuled}[2]{\algocf@makecaption@ruled{#1}{#2}}%
1845 \newcommand{\algocf@makecaption@algoruled}[2]{\algocf@makecaption@ruled{#1}{#2}}%
1846 \newcommand{\algocf@makecaption@boxruled}[2]{\algocf@makecaption@ruled{#1}{#2}}%
1847 \newcommand{\algocf@makecaption@ruled}[2]{%
1848   \global\sbox\algocf@capbox{\hskip\AlCapHSkip% .5\algomargin%
1849     \parbox[t]{\hsize}{\algocf@captiontext{#1}{#2}}}% then caption is not centered
1850 }%
1851 %
1852 \newlength{\algoheightruledefault}\setlength{\algoheightruledefault}{0.8pt}%
1853 \newlength{\algoheightrule}\setlength{\algoheightrule}{\algoheightruledefault}%
1854 \newlength{\algotitleheightruledefault}\setlength{\algotitleheightruledefault}{0.8pt}%
1855 \newlength{\algotitleheightrule}\setlength{\algotitleheightrule}{\algotitleheightruledefault}%
1856 \newcommand{\algocf@caption@plain}{\vskip\AlCapSkip\box\algocf@capbox}%
1857 \newcommand{\algocf@caption@boxed}{\vskip\AlCapSkip\box\algocf@capbox}%
1858 \newcommand{\algocf@caption@ruled}{\box\algocf@capbox\kern\interspacetitleruled\hrule  height\algotitleheightrule depth0pt\kern\interspacealgoruled}%
1859 \newcommand{\algocf@caption@tworuled}{\box\algocf@capbox\kern\interspacetitleruled}%
1860 \newcommand{\algocf@caption@algoruled}{\algocf@caption@ruled}%
1861 \newcommand{\algocf@caption@boxruled}{%
1862   \addtolength{\hsize}{-0.8pt}%
1863   \hbox to\hsize{%
1864     \vrule%\hskip-0.35pt%
1865     \vbox{%
1866       \hrule\vskip\interspacetitleboxruled%
1867       \hbox to\hsize{\unhbox\algocf@capbox\hfill}\vskip\interspacetitleboxruled%
1868     }% 
1869     %\hskip-0.35pt%
1870     \vrule%
1871   }\nointerlineskip%
1872   \addtolength{\hsize}{0.8pt}%
1873 }%
1874 %
1875 %
1876 %%%% set caption for the environment
1877 \newcommand{\algocf@captionref}{%
1878   \renewcommand{\fnum@algocf}[1]{\AlCapSty{\AlCapFnt\algorithmcfname\nobreakspace\algocf@algocfref}}%
1879   \addtocounter{algocf}{-1}% \caption do a refstepcounter, so we restore the precedent value
1880   \let\old@thealgocf=\thealgocf\renewcommand{\thealgocf}{{\relsize{\algocf@refrelsize}\algocf@algocfref}}%
1881   \gdef\@currentlabel{\algocf@algocfref}% let the label use the new ref
1882 }%
1883 %
1884 % Unfortunatly, we also need our own caption to set some specific stuff for special references. But after these
1885 % settings, we call the original caption.
1886 %
1887 \long\def\algocf@caption@algo#1[#2]#3{%
1888   \ifthenelse{\equal{\algocf@algocfref}{\relax}}{}{\algocf@captionref}%
1889   \@ifundefined{hyper@refstepcounter}{\relax}{% if hyper@refstepcounter undefind, no hyperref, else...
1890     \ifthenelse{\equal{\algocf@algocfref}{\relax}}{\renewcommand{\theHalgocf}{\thealgocf}}{% take algocf as Href
1891       \renewcommand{\theHalgocf}{\algocf@algocfref}}%else if SetAlgoRefName done, take this name as ref.
1892     \hyper@refstepcounter{algocf}%set algocf as category of ref
1893   }%
1894   \algocf@latexcaption{#1}[#2]{#3}% call original caption
1895 }%
1896 %
1897 % beamer define is own caption overrinding latex caption!
1898 % as we need it, we have put here the original definition
1899 % to handle manual ref, unfortunately we have to add one line to handle algocf@algocfref
1900 \long\def\algocf@latexcaption#1[#2]#3{% original definition of caption
1901   \par%
1902   \addcontentsline{\csname ext@#1\endcsname}{#1}%
1903   {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
1904   \begingroup%
1905   \@parboxrestore%
1906   \if@minipage%
1907     \@setminipage%
1908   \fi%
1909   \normalsize%
1910   \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par%
1911   \endgroup%
1912 }%
1913 %
1914 % \ifx\beamer@makecaption\undefined%
1915 % \else% beamer detected
1916 \ifx\@makecaption\undefined%
1917 \newcommand{\@makecaption}[2]{\relax}%
1918 \fi%
1919 %%
1920
1921 %
1922 % more and more packages redefine \@caption instead of just \@makecaption which makes algorithm2e
1923 % caption not works since based on standard \@caption. So we force the definition of \@caption to be
1924 % the standard one (the one from LaTeX) inside algorithm environment.
1925 %
1926 % unfortunately, makecaption is called with \ignorespace #3 so 
1927 % we can't do the @currentlabel definition inside \algocf@captionproctext
1928 \long\def\algocf@caption@proc#1[#2]#3{%
1929   \ifthenelse{\boolean{algocf@nokwfunc}}{\relax}{%
1930     \SetKwFunction{\algocf@captname#3@}{\algocf@captname#3@}%
1931   }%
1932   % we tell hyperref to use algocfproc as category and to take the appropriate ref.
1933   \ifthenelse{\boolean{algocf@func}}{\def\@proc@func{algocffunc}}{\def\@proc@func{algocfproc}}%
1934   \@ifundefined{hyper@refstepcounter}{\relax}{% if hyper@refstepcounter undefind, no hyperref, else...
1935     \ifthenelse{\boolean{algocf@procnumbered}}{% 
1936       \expandafter\def\csname theH\@proc@func\endcsname{\algocf@captname#3@}%if procnumbered, take \thealgocf as ref
1937     }{%
1938       \expandafter\def\csname theH\@proc@func\endcsname{\algocf@captname#3@}%else take procedure or function name
1939     }%
1940     \hyper@refstepcounter{\@proc@func}%
1941   }%
1942   \ifthenelse{\boolean{algocf@procnumbered}}{\relax}{%
1943     \addtocounter{algocf}{-1}% \caption do a refstepcounter, so we restore the precedent value
1944     \gdef\@currentlabel{\algocf@captname#3@}% let the label be the name of the function, not the counter
1945   }%
1946   \ifthenelse{\equal{\algocf@captparam#2@}{\arg@e}}{% if no paramater, we remove the ()
1947     \algocf@latexcaption{#1}[\algocf@procname\nobreakspace\algocf@captname#2@]{#3}%
1948   }{%                                                 else we give the complete name
1949     \algocf@latexcaption{#1}[\algocf@procname\nobreakspace#2]{#3}%
1950   }%
1951 }%
1952 %%
1953 %%% setcaption
1954 \newcommand{\algocf@setcaption}{%
1955   \ifthenelse{\boolean{algocf@procenvironment}}{% if proc environment, caption text must be changed
1956     \let\algocf@oldcaptiontext=\algocf@captiontext%
1957     \renewcommand{\algocf@captiontext}[2]{%
1958       \algocf@captionproctext{##1}{##2}%
1959     }%
1960   }{}%
1961   \let\algocf@savecaption=\@caption%
1962   \ifthenelse{\boolean{algocf@procenvironment}}{\let\@caption=\algocf@caption@proc}{\let\@caption=\algocf@caption@algo}%
1963   \let\algocf@oldmakecaption=\@makecaption%
1964   \renewcommand{\@makecaption}[2]{%
1965     \expandafter\csname algocf@makecaption@\algocf@style\endcsname{##1}{##2}%
1966   }%
1967 }%
1968 %
1969 %%%%% reset caption
1970 %
1971 % since we have force the LaTeX caption for algorithm environment, we must go back to the caption
1972 % used in the text.
1973 \newcommand{\algocf@resetcaption}{%
1974   \ifthenelse{\boolean{algocf@procenvironment}}{% if proc environment
1975     \let\thealgocf=\old@thealgocf% restore normal counter printing
1976     \let\algocf@captiontext=\algocf@oldcaptiontext% restore normal caption text
1977   }{}%
1978   \let\@caption=\algocf@savecaption% now restore caption outside algo/proc/func environment
1979   \let\@makecaption=\algocf@oldmakecaption% and restore makecaption outside outside algo/proc/func environment
1980   \algocf@resetfnum%
1981 }%
1982 %
1983 %%%%% nocaptionofalgo and restorecaptionofalgo --
1984 \newcommand{\NoCaptionOfAlgo}{%
1985   \let\@old@algocf@captiontext=\algocf@captiontext%
1986   \renewcommand{\algocf@captiontext}[2]{\AlCapNameSty{\AlCapNameFnt{}##2}}%
1987 }%
1988 \newcommand{\RestoreCaptionOfAlgo}{%
1989   \let\algocf@captiontext=\@old@algocf@captiontext%
1990 }%
1991 %
1992 % ----------------------  algocf environment
1993 %
1994 \newcounter{algocfline}%                    % new counter to make lines numbers be internally 
1995 \setcounter{algocfline}{0}%                 % different in different algorithms
1996 \newcounter{algocfproc}% counter to count all algo environment (proc, func), just used by hyperref to avoir "same
1997 \setcounter{algocfproc}{0}% identifier" error caused by algocf being set to '-' for procedure or function or not
1998   % changed if no caption is given.
1999 %
2000 \expandafter\ifx\csname algocf@within\endcsname\relax% if \algocf@within doesn't exist
2001 \newcounter{algocf}%                        % just define a new counter
2002 \renewcommand{\thealgocf}{\@arabic\c@algocf}% and the way it is printed
2003 \else%                                     else
2004 \newcounter{algocf}[\algocf@within]%        % counter is numbered within \algocf@within
2005 \renewcommand\thealgocf{\csname the\algocf@within\endcsname.\@arabic\c@algocf}%
2006 \fi%
2007 %
2008 \def\fps@algocf{htbp}%        % default
2009 \def\ftype@algocf{10}%        % float type
2010 \def\ext@algocf{\algocf@list} % loa by default, lof if figure option used
2011 \newcommand{\fnum@algocf}[1]{\AlCapSty{\AlCapFnt\algorithmcfname\nobreakspace\thealgocf}}%
2012 \newcommand{\algocf@resetfnum}{\renewcommand{\fnum@algocf}[1]{\AlCapSty{\AlCapFnt\algorithmcfname\nobreakspace\thealgocf}}}%
2013 \newenvironment{algocf}%      % float environment for algorithms
2014                {\@float{algocf}}%
2015                {\end@float}%
2016 \newenvironment{algocf*}%     % float* environment for algorithms
2017                {\@dblfloat{algocf}}%
2018                {\end@dblfloat}%
2019 %
2020 \def\algocf@seclistalgo{}%
2021 \ifx\l@chapter\undefined\let\algocf@seclistalgo=\section\else\let\algocf@seclistalgo=\chapter\fi%
2022 \@ifundefined{if@restonecol}{\newif\if@restonecol}\relax%
2023 \newcommand\listofalgocfs{%
2024      \ifx\algocf@seclistalgo\chapter%
2025       \if@twocolumn\@restonecoltrue\onecolumn\else\@restonecolfalse\fi%
2026     \fi%
2027      \algocf@seclistalgo*{\listalgorithmcfname}%
2028        \@mkboth{\MakeUppercase\listalgorithmcfname}%
2029                {\MakeUppercase\listalgorithmcfname}%
2030      \@starttoc{loa}%
2031     \ifx\algocf@seclistalgo\chapter%
2032       \if@restonecol\twocolumn\fi%
2033     \fi%
2034 }
2035 %
2036 \newcommand*\l@algocf{\@dottedtocline{1}{1em}{2.3em}}% line of the list
2037 %
2038 % ----------------------  algorithm environment
2039 %
2040 %%%%%%%
2041 %%
2042 %% Algorithm environment definition
2043 %%
2044 %%%%%%%
2045 %%
2046 %
2047 \newsavebox\algocf@algoframe%
2048 \def\@algocf@pre@plain{\relax}%  action to be done before printing the algo.
2049 \def\@algocf@post@plain{\relax}% action to be done after printing the algo.
2050 \def\@algocf@capt@plain{bottom}% where the caption should be localized.
2051 \def\@algocf@pre@boxed{\noindent\begin{lrbox}{\algocf@algoframe}}
2052 \def\@algocf@post@boxed{\end{lrbox}\framebox[\hsize]{\box\algocf@algoframe}\par}%
2053 \def\@algocf@capt@boxed{under}%
2054 \def\@algocf@pre@ruled{\hrule height\algoheightrule depth0pt\kern\interspacetitleruled}%
2055 \def\@algocf@post@ruled{\kern\interspacealgoruled\hrule height\algoheightrule\relax}%
2056 \def\@algocf@capt@ruled{top}%
2057 \def\@algocf@pre@algoruled{\hrule height\algoheightrule depth0pt\kern\interspacetitleruled}%
2058 \def\@algocf@post@algoruled{\kern\interspacealgoruled\hrule height\algoheightrule \relax}%
2059 \def\@algocf@capt@algoruled{top}%
2060 \def\@algocf@pre@tworuled{\hrule height\algoheightrule depth0pt\kern\interspacetitleruled}%
2061 \def\@algocf@post@tworuled{\kern\interspacealgoruled\hrule height\algoheightrule\relax}%
2062 \def\@algocf@capt@tworuled{top}%
2063 \def\@algocf@pre@boxruled{\noindent\begin{lrbox}{\algocf@algoframe}}%
2064 \def\@algocf@post@boxruled{\end{lrbox}\framebox[\hsize]{\box\algocf@algoframe}\par}%
2065 \def\@algocf@capt@boxruled{above}%
2066 %
2067 \newcommand{\noalgocaption}{\def\@algocf@capt@ruled{none}}
2068 %
2069 %% before algocf or figure environment
2070 \newcommand{\@algocf@init@caption}{%
2071   \ifthenelse{\boolean{algocf@procenvironment}}{% if we are inside a procedure/function environment
2072     \@algocf@proctitleofalgo% set Titleofalgo to Procedure: or Function:
2073                             % accordingly to the environment
2074     \let\old@thealgocf=\thealgocf\ifthenelse{\boolean{algocf@procnumbered}}{\relax}{%
2075       \renewcommand{\thealgocf}{-}}%
2076   }{% else inside environment algorithm
2077     \@algocf@algotitleofalgo% fix name for \Titleofalgo to \algorithmcfname
2078   }%
2079   \algocf@setcaption%       set caption to our caption style
2080 }%
2081 %
2082 \newcommand{\@algofloatboxreset}{\@setminipage}
2083 \newcommand{\@algocf@init}{%
2084   \refstepcounter{algocfline}%
2085   \stepcounter{algocfproc}%to have a different counter for each environment and being abble to make the difference
2086     %between href of algoline in different algorithms.
2087   \ifthenelse{\boolean{algocf@optnoend}}{%
2088       \renewcommand{\algocf@block}[2]{\algocf@group{##1}}%
2089     }{%
2090       \renewcommand{\algocf@block}[2]{\algocf@@block{##1}{##2}}%
2091     }%
2092 }%
2093 %% after the end of algocf or figure environment
2094 \newcommand{\@algocf@term@caption}{%
2095   \algocf@resetcaption% restore original caption
2096 }%
2097 %
2098 \newcommand{\@algocf@term}{%
2099   \setboolean{algocf@algoH}{false}% no H by default
2100   \ifthenelse{\boolean{algocf@optnoend}}{%
2101     \renewcommand{\algocf@block}[2]{\algocf@@block{##1}{##2}}%
2102   }{%
2103     \renewcommand{\algocf@block}[2]{\algocf@group{##1}}%
2104   }%
2105   \SetAlgoRefName{\relax}%
2106 }%
2107 %
2108 %%%%%%%%%%%%%%%%%
2109 %% makethealgo: macro which print effectively the algo in its box
2110 %% 
2111 \newsavebox\algocf@algobox%
2112 \newcommand{\algocf@makethealgo}{%
2113   \vtop{%
2114     % place caption above if needed  bye the style
2115     \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{above}}%
2116     {\csname algocf@caption@\algocf@style\endcsname}{}%
2117     %
2118     % precommand according to the style
2119     \csname @algocf@pre@\algocf@style\endcsname%
2120     % place caption at top if needed  bye the style
2121      \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{top}}%
2122      {\csname algocf@caption@\algocf@style\endcsname}{}%
2123     %
2124     \box\algocf@algobox% the algo
2125     % place caption at bottom if needed  bye the style
2126      \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{bottom}}%
2127      {\csname algocf@caption@\algocf@style\endcsname}{}%
2128     % postcommand according to the style
2129     \csname @algocf@post@\algocf@style\endcsname%
2130     % place caption under if needed  bye the style
2131      \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{under}}%
2132      {\csname algocf@caption@\algocf@style\endcsname}{}%
2133   }%
2134 }%
2135 %%%%%%%%%%%%%%%%%%%
2136 %
2137 %% at the beginning of algocf or figure environment
2138 \newcommand{\@algocf@start}{%
2139   \@algoskip%
2140   \begin{lrbox}{\algocf@algobox}%
2141   \setlength{\algowidth}{\hsize}%
2142   \vbox\bgroup% save all the algo in a box
2143   \hbox to\algowidth\bgroup\hbox to \algomargin{\hfill}\vtop\bgroup%
2144   \ifthenelse{\boolean{algocf@slide}}{\parskip 0.5ex\color{black}}{}%
2145   % initialization
2146   \addtolength{\hsize}{-1.5\algomargin}%
2147   \let\@mathsemicolon=\;\def\;{\ifmmode\@mathsemicolon\else\@endalgoln\fi}%
2148   \raggedright\AlFnt{}%
2149   \ifthenelse{\boolean{algocf@slide}}{\IncMargin{\skipalgocfslide}}{}%
2150   \@algoinsideskip%
2151 }%
2152 %
2153 %% at the end of algocf or figure environment
2154 \newcommand{\@algocf@finish}{%
2155   \@algoinsideskip%
2156   \egroup%end of vtop which contain all the text
2157   \hfill\egroup%end of hbox wich contains [margin][vtop]
2158   \ifthenelse{\boolean{algocf@slide}}{\DecMargin{\skipalgocfslide}}{}%
2159   %
2160   \egroup%end of main vbox
2161   \end{lrbox}%
2162   \algocf@makethealgo% print the algo
2163   \@algoskip%
2164   % restore dimension and macros
2165   \setlength{\hsize}{\algowidth}%
2166   \lineskip\normallineskip\setlength{\skiptotal}{\@defaultskiptotal}%
2167   \let\;=\@mathsemicolon%  
2168 }%
2169 %
2170 %%%%%%%%%%%%%%%%%%%%
2171 %% basic definition of the environment algorithm
2172 %%
2173 %
2174 \newboolean{algocf@procenvironment}\setboolean{algocf@procenvironment}{false}%
2175 \newboolean{algocf@func}\setboolean{algocf@func}{false}%
2176 \newboolean{algocf@algoH}\setboolean{algocf@algoH}{false}%
2177 \newboolean{algocf@algostar}\setboolean{algocf@algostar}{false}%
2178 %
2179 %%% environment for {algorithm}[H]
2180 \newenvironment{algocf@Here}{\noindent%
2181   \def\@captype{algocf}% if not defined, caption exit with an error
2182   \begin{minipage}{\hsize}%
2183 }{%
2184   \end{minipage}%\par%
2185 }%
2186 %%% real algorithm environment which manages H and * option
2187 %    \let\algocf@originalfloatboxreset=\@floatboxreset%
2188 %    \let\@floatboxreset=\@algofloatboxreset%
2189 \newenvironment{algocf@algorithm}[1][htbp]{
2190    \@algocf@init%
2191    \ifthenelse{\equal{\algocf@float}{figure}}{% if option figure set
2192      \ifthenelse{\boolean{algocf@algostar}}{% if algorithm* with figure option
2193        \begin{figure*}[#1]% call figure*
2194      }{% else algorithm environment with figure option
2195        \begin{figure}[#1]%  call figure
2196      }%
2197    }{% else normal algorithm environment
2198      \@algocf@init@caption%
2199      \ifthenelse{\equal{#1}{H}}{% if [H] algorithm
2200        \if@twocolumn\@latex@error{[H] in two columns mode is not allowed for algorithms}\fi% TODO: SCREAM if H in two colums!
2201        \setboolean{algocf@algoH}{true}\begin{algocf@Here}% call corresponding environment
2202      }{% else floating algorithm environment
2203        \ifthenelse{\boolean{algocf@algostar}}{% if algorithm*
2204          \begin{algocf*}[#1]% call algocf*
2205        }{% else algorithm environment
2206          \begin{algocf}[#1]%  call algcf
2207        }%
2208      }%
2209    }% fin test option figure ou pas
2210    \@algocf@start% 
2211    \@ResetCounterIfNeeded%
2212    \algocf@linesnumbered\ignorespaces%
2213 }{%
2214   \@algocf@finish%
2215   \ifthenelse{\equal{\algocf@float}{figure}}{%
2216      \ifthenelse{\boolean{algocf@algostar}}{% if algorithm* with figure option
2217        \end{figure*}% call figure*
2218      }{% else algorithm environment with figure option
2219        \end{figure}%  call figure
2220      }%
2221   }{%
2222     \@algocf@term@caption%
2223     \ifthenelse{\boolean{algocf@algoH}}{% if [H] algorithm
2224        \end{algocf@Here}\par% call corresponding environment
2225      }{% else floating algorithm environment
2226        \ifthenelse{\boolean{algocf@algostar}}{% if algorithm*
2227          \end{algocf*}% call algocf*
2228        }{% else algorithm environment
2229          \end{algocf}%  call algocf
2230        }%
2231      }%
2232   }%
2233   \@algocf@term\ignorespacesafterend%
2234 }%
2235 %
2236 %%% user algorithm environment
2237 % \newenvironment{\algocf@envname}[1][htbp]{%
2238 %   \setboolean{algocf@algostar}{false}%
2239 %   \setboolean{algocf@procenvironment}{false}\gdef\algocfautorefname{\algorithmautorefname}%
2240 %   \begin{algocf@algorithm}[#1]\ignorespaces%
2241 % }{%
2242 %   \end{algocf@algorithm}\ignorespacesafterend%
2243 % }%
2244
2245 % %%% user algorithm* environment
2246 % \newenvironment{\algocf@envname*}[1][htbp]{%
2247 %   \setboolean{algocf@algostar}{true}%
2248 %   \setboolean{algocf@procenvironment}{false}\gdef\algocfautorefname{\algorithmautorefname}%
2249 %   \begin{algocf@algorithm}[#1]\ignorespaces%
2250 % }{%
2251 %   \end{algocf@algorithm}\ignorespacesafterend%
2252 % }%
2253 %
2254 %%%%%%%%%%%%%%%%%%%%%%%
2255 %%%
2256 %
2257 % \expandafter\newcommand\csname\algocf@listofalgorithms\endcsname{%
2258 %   \ifthenelse{\equal{\algocf@float}{figure}}{\listoffigures}{\listofalgocfs}%
2259 % }%
2260 %%%
2261 %%%
2262 %
2263 % ----------------------  procedure and function environments
2264 %
2265 %
2266 % -- new style (used in particular in the caption of function and procedure environments)
2267 %
2268 % three macros to extract parts of the caption
2269 \gdef\algocf@captname#1(#2)#3@{#1}  % keep characters before the first brace
2270 \gdef\algocf@captparam#1(#2)#3@{#2} % keep character in between the braces
2271 \gdef\algocf@captother#1(#2)#3@{#3} % keep character after the braces
2272 %
2273 %%% Text of caption for Procedure or Function
2274 \newcommand{\algocf@captionproctext}[2]{%
2275   {%
2276     \ProcSty{\ProcFnt\algocf@procname\ifthenelse{\boolean{algocf@procnumbered}}{\nobreakspace\thealgocf\algocf@typo\algocf@capseparator}{\relax}}%
2277     \nobreakspace\ProcNameSty{\ProcNameFnt\algocf@captname #2@}% Name of the procedure in ProcName Style. 
2278     \ifthenelse{\equal{\algocf@captparam #2@}{\arg@e}}{}{% if no argument, write nothing
2279       \ProcNameSty{\ProcNameFnt(}\ProcArgSty{\ProcArgFnt\algocf@captparam #2@}\ProcNameSty{\ProcNameFnt)}%else put arguments in ProcArgSty:
2280     }% endif
2281     \algocf@captother #2@%
2282   }%
2283 }%
2284 %
2285 %
2286 % -- procedure and function environments are defined from algocf@algorithm environment
2287 %
2288 \newenvironment{procedure}[1][htbp]{%
2289   \setboolean{algocf@algostar}{false}%
2290   \setboolean{algocf@procenvironment}{true}\setboolean{algocf@func}{false}%
2291   \newcommand{\algocf@procname}{\@algocf@procname}\gdef\algocfprocautorefname{\procedureautorefname}%
2292   \begin{algocf@algorithm}[#1]\ignorespaces%
2293 }{%
2294   \end{algocf@algorithm}\ignorespacesafterend%
2295 }%
2296 \newenvironment{function}[1][htbp]{%
2297   \setboolean{algocf@algostar}{false}%
2298   \setboolean{algocf@procenvironment}{true}\setboolean{algocf@func}{true}%
2299   \newcommand{\algocf@procname}{\@algocf@funcname}\gdef\algocffuncautorefname{\functionautorefname}%
2300   \begin{algocf@algorithm}[#1]\ignorespaces%
2301 }{%
2302   \end{algocf@algorithm}\ignorespacesafterend%
2303 }%
2304 %
2305 \newenvironment{procedure*}[1][htbp]{%
2306   \setboolean{algocf@algostar}{true}%
2307   \setboolean{algocf@procenvironment}{true}\setboolean{algocf@func}{false}%
2308   \newcommand{\algocf@procname}{\@algocf@procname}\gdef\algocfprocautorefname{\procedureautorefname}%
2309   \begin{algocf@algorithm}[#1]\ignorespaces%
2310 }{%
2311   \end{algocf@algorithm}\ignorespacesafterend%
2312 }%
2313 \newenvironment{function*}[1][htbp]{%
2314   \setboolean{algocf@algostar}{true}%
2315   \setboolean{algocf@procenvironment}{true}\setboolean{algocf@func}{true}%
2316   \newcommand{\algocf@procname}{\@algocf@funcname}\gdef\algocffuncautorefname{\functionautorefname}%
2317   \begin{algocf@algorithm}[#1]\ignorespaces%
2318 }{%
2319   \end{algocf@algorithm}\ignorespacesafterend%
2320 }%
2321 %
2322 %
2323 %%%%%%%%%%%%%%%%%%%%
2324 %% definition of algondfloat environment
2325 %%
2326 \ifthenelse{\boolean{algocf@endfloat}}{% if endfloat option then
2327 \newcommand{\algoplace}{% macro which is used to writhe algorithm about there
2328    \begin{center}%
2329      [\algorithmcfname~\thepostfig\ about here.]%
2330    \end{center}%
2331 }%
2332 \newcommand{\algoendfloat}{% use as a \begin{algoendfloat} environment to start scanning of line
2333 %  \immediate\openout\@mainfff\jobname.fff%
2334   \efloat@condopen{fff}
2335   \efloat@iwrite{fff}{\string\begin{\algocf@envname}}%
2336     \if@domarkers%
2337        \ifthenelse{\equal{\algocf@list}{lof}}{%
2338          \addtocounter{postfig}{1}%
2339        }{%
2340          \addtocounter{postalgo}{1}%
2341        }%
2342        \algoplace%
2343     \fi%
2344     \bgroup%
2345     \let\do\ef@makeinnocent\dospecials%
2346     \ef@makeinnocent\^^L% and whatever other special cases
2347     \endlinechar`\^^M \catcode`\^^M=12 \ef@xalgocfendfloat}%
2348 }{\relax}%%%% end of endfloat option ifthenelse
2349 %% some macros useful for endfloat option that cannot be defined inside the ifthenelse
2350 %scan algoendfloat algorithm and write the text into .fff file
2351 {\catcode`\^^M=12 \endlinechar=-1 %
2352  \gdef\ef@xalgocfendfloat#1^^M{% scan the lines inside algoendfloat environment being read by latex
2353    \def\test{#1}% test is the line being currently scan by latex
2354    \ifx\test\ef@endalgocftest% if it is \end{algoendfloat}
2355      \def\next{% define next as to not continue the scan and write \end{algorithm} into .fff file
2356        \egroup\end{algoendfloat}%
2357        \efloat@iwrite{fff}{\string\end{\algocf@envname}}%
2358        \efloat@iwrite{fff}{\string\efloatseparator}%
2359        \efloat@iwrite{fff}{ }%
2360      }%
2361      \else% else write the current line being scanned by latex and set next to continue the scan
2362        \efloat@iwrite{fff}{#1}%
2363        \let\next\ef@xalgocfendfloat%
2364      \fi% endif
2365      \next}% next is continue if it was else condition, else it does not continue the scan and write end to file
2366 }%
2367 % test if the scan is finish by looking at the string \end{algoendfloat}
2368 {\escapechar=-1%
2369  \xdef\ef@endalgocftest{\string\\end\string\{algoendfloat\string\}}%
2370 }%
2371 %
2372 %
2373 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2374 %
2375
2376 \newcommand{\TitleOfAlgo}[1]{\@titleprefix\ 
2377   \TitleSty{#1}\par\smallskip}%
2378 %
2379 \newcommand{\SetAlgorithmName}[3]{%
2380   \renewcommand{\listalgorithmcfname}{#3}%
2381   \renewcommand{\algorithmcfname}{#1}%
2382   \renewcommand{\algorithmautorefname}{#2}%
2383 }%
2384 %
2385 \newcommand{\algocf@refrelsize}{-2}\newcommand{\SetAlgoRefRelativeSize}[1]{\renewcommand{\algocf@refrelsize}{#1}}%
2386 \newcommand{\SetAlgoRefName}[1]{%
2387   \renewcommand{\algocf@algocfref}{#1}%
2388 }%
2389 %
2390 %
2391 %
2392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2393 %
2394
2395 % -------------------------   Default Definitions
2396 %
2397 %%
2398 %%
2399 %
2400 \SetKwComment{tcc}{/* }{ */}%
2401 \SetKwComment{tcp}{// }{}%
2402 %
2403 %\newcommand{\algocf@defaults@common}{
2404 %
2405 %
2406 % french keywords
2407 %
2408 %\SetKwInOut{AlgDonnees}{Donn\'ees}\SetKwInOut{AlgRes}{R\'esultat}
2409 \SetKwInput{Donnees}{Donn\'ees}%
2410 \SetKwInput{Res}{R\'esultat}%
2411 \SetKwInput{Entree}{Entr\'ees}%
2412 \SetKwInput{Sortie}{Sorties}%
2413 \SetKw{KwA}{\`a}%
2414 \SetKw{Retour}{retourner}%
2415 \SetKwBlock{Deb}{d\'ebut}{fin}%
2416 \SetKwRepeat{Repeter}{r\'ep\'eter}{jusqu'\`a}%
2417 %
2418 \SetKwIF{Si}{SinonSi}{Sinon}{si}{alors}{sinon si}{sinon}{fin si}%
2419 \SetKwSwitch{Suivant}{Cas}{Autre}{suivant}{faire}{cas o\`u}{autres cas}{fin d'alternative}%
2420 \SetKwFor{Pour}{pour}{faire}{fin pour}%
2421 \SetKwFor{PourPar}{pour}{faire en parallèle}{fin pour}%
2422 \SetKwFor{PourCh}{pour chaque}{faire}{fin pour chaque}%
2423 \SetKwFor{PourTous}{pour tous les}{faire}{fin pour tous}%
2424 \SetKwFor{Tq}{tant que}{faire}{fin tq}%
2425 %
2426 % english keywords
2427 %
2428 \SetKwInput{KwIn}{Input}%
2429 \SetKwInput{KwOut}{Output}%
2430 \SetKwInput{KwData}{Data}%
2431 \SetKwInput{KwResult}{Result}%
2432 \SetKw{KwTo}{to}
2433 \SetKw{KwRet}{return}%
2434 \SetKw{Return}{return}%
2435 \SetKwBlock{Begin}{begin}{end}%
2436 \SetKwRepeat{Repeat}{repeat}{until}%
2437 %
2438 \SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{end if}%
2439 \SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{end switch}%
2440 \SetKwFor{For}{for}{do}{end for}%
2441 \SetKwFor{ForPar}{for}{do in parallel}{end forpar}
2442 \SetKwFor{ForEach}{foreach}{do}{end foreach}%
2443 \SetKwFor{ForAll}{forall the}{do}{end forall}%
2444 \SetKwFor{While}{while}{do}{end while}%
2445 %
2446 % --- German keywords
2447 %
2448 \SetKwInput{Ein}{Eingabe}%KwIn
2449 \SetKwInput{Aus}{Ausgabe}%KwOut
2450 \SetKwInput{Daten}{Daten}%KwData
2451 \SetKwInput{Ergebnis}{Ergebnis}%KwResult
2452 \SetKw{Bis}{bis}%KwTo
2453 \SetKw{KwZurueck}{zur\"uck}%KwRet
2454 \SetKw{Zurueck}{zur\"uck}%Return
2455 \SetKwBlock{Beginn}{Beginn}{Ende}%Begin
2456 \SetKwRepeat{Wiederh}{wiederhole}{bis}%Repeat
2457 %
2458 \SetKwIF{Wenn}{SonstWenn}{Sonst}{wenn}{dann}{sonst wenn}{sonst}{Ende wenn}%gIf
2459 \SetKwSwitch{Unterscheide}{Fall}{Anderes}{unterscheide}{tue}{Fall}{sonst}{Ende Unt.}%Switch
2460 \SetKwFor{Fuer}{f\"ur}{tue}{Ende f\"ur}%For
2461 \SetKwFor{FuerPar}{f\"ur}{tue gleichzeitig}{Ende gleichzeitig}%ForPar
2462 \SetKwFor{FuerJedes}{f\"ur jedes}{tue}{Ende f\"ur}%ForEach
2463 \SetKwFor{FuerAlle}{f\"ur alle}{tue}{Ende f\"ur}%ForAll
2464 \SetKwFor{Solange}{solange}{tue}{Ende solange}%While
2465 %
2466 % --- Czech keywords
2467 %
2468 \SetKwInput{Vst}{Vstup}%
2469 \SetKwInput{Vyst}{V\'{y}stup}%
2470 \SetKwInput{Vysl}{V\'{y}sledek}%
2471 %
2472 % --- Portuguese keywords
2473 %
2474 \SetKwInput{Entrada}{Entrada}%
2475 \SetKwInput{Saida}{Sa\'{i}da}%
2476 \SetKwInput{Dados}{Dados}%
2477 \SetKwInput{Resultado}{Resultado}%
2478 \SetKw{Ate}{at\'{e}}
2479 \SetKw{KwRetorna}{retorna}%
2480 \SetKw{Retorna}{retorna}%
2481 \SetKwBlock{Inicio}{in\'{i}cio}{fim}%
2482 \SetKwRepeat{Repita}{repita}{at\'{e}}%
2483 %
2484 \SetKwIF{Se}{SenaoSe}{Senao}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{fim se}%
2485 \SetKwSwitch{Selec}{Caso}{Outro}{selecione}{fa\c{c}a}{caso}{sen\~{a}o}{fim selec}%
2486 \SetKwFor{Para}{para}{fa\c{c}a}{fim para}%
2487 \SetKwFor{ParaPar}{para}{fa\c{c}a em paralelo}{fim para}
2488 \SetKwFor{ParaCada}{para cada}{fa\c{c}a}{fim para cada}%
2489 \SetKwFor{ParaTodo}{para todo}{fa\c{c}a}{fim para todo}%
2490 \SetKwFor{Enqto}{enquanto}{fa\c{c}a}{fim enqto}%
2491 %
2492 % --- Italian keywords
2493 %
2494 \SetKwInput{KwIng}{Ingresso}%
2495 \SetKwInput{KwUsc}{Uscita}%
2496 \SetKwInput{KwDati}{Dati}%
2497 \SetKwInput{KwRisult}{Risultato}%
2498 \SetKw{KwA}{a}%
2499 \SetKw{KwRitorna}{ritorna}%
2500 \SetKw{Ritorna}{ritorna}%
2501 \SetKwBlock{Inizio}{inizio}{fine}%
2502 \SetKwRepeat{Ripeti}{ripeti}{finché}%
2503 %
2504 \SetKwIF{Sea}{AltSe}{Altrimenti}{se}{allora}{altrimenti se}{allora}{fine se}%
2505 \SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{endsw}%
2506 \SetKwFor{Per}{per}{fai}{fine per}%
2507 \SetKwFor{PerPar}{per}{fai in parallelo}{fine per}%
2508 \SetKwFor{PerCiascun}{per ciascun}{fai}{fine per ciascun}%
2509 \SetKwFor{PerTutti}{per tutti i}{fai}{fine per tutti}%
2510 \SetKwFor{Finche}{finché}{fai}{fine finché}%
2511 %
2512 % --- End 
2513 %}
2514 %
2515 %\algocf@defaults@common
2516 %
2517 % option onelanguage redefinition
2518 %
2519 \ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{french}}{%
2520 \SetKwInput{KwIn}{Entr\'ees}%
2521 \SetKwInput{KwOutSortie}{Sorties}%
2522 \SetKwInput{KwData}{Donn\'ees}%
2523 \SetKwInput{KwResult}{R\'esultat}%
2524 \SetKw{KwTo}{\`a}%
2525 \SetKw{KwRet}{retourner}%
2526 \SetKw{Return}{retourner}%
2527 \SetKwBlock{Begin}{d\'ebut}{fin}%
2528 \SetKwRepeat{Repeat}{r\'ep\'eter}{jusqu'\`a}%
2529 %
2530 \SetKwIF{If}{ElseIf}{Else}{si}{alors}{sinon si}{sinon}{fin si}%
2531 \SetKwSwitch{Switch}{Case}{Other}{suivant}{faire}{cas o\`u}{autres cas}{fin d'alternative}%
2532 \SetKwFor{For}{pour}{faire}{fin pour}%
2533 \SetKwFor{ForPar}{pour}{faire en parallèle}{fin pour}%
2534 \SetKwFor{ForEach}{pour chaque}{faire}{fin pour chaque}%
2535 \SetKwFor{ForAll}{pour tous les}{faire}{fin pour tous}%
2536 \SetKwFor{While}{tant que}{faire}{fin tq}%
2537 }{}%
2538 \ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{german}}{%
2539 \SetKwInput{KwIn}{Eingabe}%KwIn
2540 \SetKwInput{KwOut}{Ausgabe}%KwOut
2541 \SetKwInput{KwData}{Daten}%KwData
2542 \SetKwInput{KwResult}{Ergebnis}%KwResult
2543 \SetKw{KwTo}{bis}%KwTo
2544 \SetKw{KwRet}{zur\"uck}%KwRet
2545 \SetKw{Return}{zur\"uck}%Return
2546 \SetKwBlock{Begin}{Beginn}{Ende}%Begin
2547 \SetKwRepeat{Repeat}{wiederhole}{bis}%Repeat
2548 %
2549 \SetKwIF{If}{ElseIf}{Else}{wenn}{dann}{sonst wenn}{sonst}{Ende wenn}%gIf
2550 \SetKwSwitch{Switch}{Case}{Other}{unterscheide}{tue}{Fall}{sonst}{Ende Unt.}%Switch
2551 \SetKwFor{For}{f\"ur}{tue}{Ende f\"ur}%For
2552 \SetKwFor{ForPar}{f\"ur}{tue gleichzeitig}{Ende gleichzeitig}%ForPar
2553 \SetKwFor{ForEach}{f\"ur jedes}{tue}{Ende f\"ur}%ForEach
2554 \SetKwFor{ForAll}{f\"ur alle}{tue}{Ende f\"ur}%ForAll
2555 \SetKwFor{While}{solange}{tue}{Ende solange}%While
2556 }{}%
2557 \ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{portugues}}{%
2558 \SetKwInput{KwIn}{Entrada}%
2559 \SetKwInput{KwOut}{Sa\'{i}da}%
2560 \SetKwInput{KwData}{Dados}%
2561 \SetKwInput{KwResult}{Resultado}%
2562 \SetKw{KwTo}{at\'{e}}
2563 \SetKw{KwRet}{retorna}%
2564 \SetKw{Return}{retorna}%
2565 \SetKwBlock{Begin}{in\'{i}cio}{fim}%
2566 \SetKwRepeat{Repeat}{repita}{at\'{e}}%
2567 %
2568 \SetKwIF{If}{ElseIf}{Else}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{fim se}%
2569 \SetKwSwitch{Switch}{Case}{Other}{selecione}{fa\c{c}a}{caso}{sen\~{a}o}{fim selec}%
2570 \SetKwFor{For}{para}{fa\c{c}a}{fim para}%
2571 \SetKwFor{ForPar}{para}{fa\c{c}a em paralelo}{fim para}
2572 \SetKwFor{ForEach}{para cada}{fa\c{c}a}{fim para cada}%
2573 \SetKwFor{ForAll}{para todo}{fa\c{c}a}{fim para todo}%
2574 \SetKwFor{While}{enquanto}{fa\c{c}a}{fim enqto}%
2575 }{}%
2576 \ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{italiano}}{%
2577 \SetKwInput{KwIn}{Ingresso}%
2578 \SetKwInput{KwOut}{Uscita}%
2579 \SetKwInput{KwData}{Dati}%
2580 \SetKwInput{KwResult}{Risultato}%
2581 \SetKw{KwTo}{a}%
2582 \SetKw{KwRet}{ritorna}%
2583 \SetKw{Return}{ritorna}%
2584 \SetKwBlock{Begin}{inizio}{fine}%
2585 \SetKwRepeat{Repeat}{ripeti}{finché}%
2586 %
2587 \SetKwIF{If}{ElseIf}{Else}{se}{allora}{altrimenti se}{allora}{fine se}%
2588 \SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{endsw}%
2589 \SetKwFor{For}{per}{fai}{fine per}%
2590 \SetKwFor{ForPar}{per}{fai in parallelo}{fine per}%
2591 \SetKwFor{ForEach}{per ciascun}{fai}{fine per ciascun}%
2592 \SetKwFor{ForAll}{per tutti i}{fai}{fine per tutti}%
2593 \SetKwFor{While}{finché}{fai}{fine finché}%
2594 }{}%
2595 %
2596 %%%% old commands compatibility
2597 %
2598 \ifthenelse{\boolean{algocf@oldcommands}}{%
2599 \newcommand{\SetNoLine}{\SetAlgoNoLine}%
2600 \newcommand{\SetVline}{\SetAlgoVlined}%
2601 \newcommand{\SetLine}{\SetAlgoLined}%
2602 %
2603 \newcommand{\dontprintsemicolon}{\DontPrintSemicolon}%
2604 \newcommand{\printsemicolon}{\PrintSemicolon}%
2605 \newcommand{\incmargin}[1]{\IncMargin{#1}}%
2606 \newcommand{\decmargin}[1]{\DecMargin{-#1}}%
2607 \newcommand{\setnlskip}[1]{\SetNlSkip{#1}}%
2608 \newcommand{\Setnlskip}[1]{\SetNlSkip{#1}}%
2609 \newcommand{\setalcapskip}[1]{\SetAlCapSkip{#1}}%
2610 \newcommand{\setalcaphskip}[1]{\SetAlCapHSkip{#1}}%
2611 \newcommand{\nlSty}[1]{\NlSty{#1}}%
2612 \newcommand{\Setnlsty}[3]{\SetNlSty{#1}{#2}{#3}}%
2613 \newcommand{\linesnumbered}{\LinesNumbered}%
2614 \newcommand{\linesnotnumbered}{\LinesNotNumbered}%
2615 \newcommand{\linesnumberedhidden}{\LinesNumberedHidden}%
2616 \newcommand{\showln}{\ShowLn}%
2617 \newcommand{\showlnlabel}[1]{\ShowLnLabel{#1}}%
2618 \newcommand{\nocaptionofalgo}{\NoCaptionOfAlgo}%
2619 \newcommand{\restorecaptionofalgo}{\RestoreCaptionOfAlgo}%
2620 \newcommand{\restylealgo}[1]{\RestyleAlgo{#1}}%
2621 %
2622 \newcommand{\Titleofalgo}[1]{\TitleOfAlgo{#1}}%
2623 \SetKwIF{gSi}{gSinonSi}{gSinon}{si}{alors}{sinon si}{sinon}{fin si}%
2624 \SetKwIF{gIf}{gElsIf}{gElse}{if}{then}{else if}{else}{end if}%
2625 \SetKwIF{gIf}{gElseIf}{gElse}{if}{then}{else if}{else}{end if}%
2626 \SetKwIF{gWenn}{gSonstWenn}{gSonst}{wenn}{dann}{sonst wenn}{sonst}{Ende wenn}%gIf
2627 \SetKwIF{gSe}{gSenaoSe}{gSenao}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{fim se}%
2628 \SetKwIF{gSea}{gAltSe}{gAltrimenti}{se}{allora}{altrimenti se}{allora}{fine se}%
2629 }{%
2630   \relax%
2631 }%
2632 %
2633 %
2634 %
2635 %%
2636 %%%
2637 %%%% END