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

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