1 % algorithm2e.sty --- style file for algorithms
2 % almost everything can be customized by users. See the document for more explanations
3 %% Copyright 1996-2013 Christophe Fiorio
5 % This program may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.2
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.2 or later is part of all distributions of LaTeX
11 % version 1999/12/01 or later.
13 % This program consists of the files algorithm2e.sty and algorithm2e.tex and algorithm2e-compatibility.sty
15 % Report bugs and comments to:
16 % - algorithm2e-announce@lirmm.fr mailing list for announcement about releases^^J%
17 % - algorithm2e-discussion@lirmm.fr mailing list for discussion about package^^J%
18 % subscribe by emailing sympa@lirmm.fr with 'subscribe <list> <firstname name>'^^J%
20 % $Id: algorithm2e.sty,v 5.0 2013/01/06 14:40:35 cfiorio Exp $
24 % - float (in contrib/supported/float)
26 % - xspace (in packages/tools)
27 % - relsize (in contrib/misc/relsize.sty)
29 %%%%%%%%%%%%%%% Release 5.0
33 % - oldcommands : to use old command names
34 % - french, english, german, ngerman
35 % portuguese, czech, italiano,
36 % slovak, croatian, spanish : for the name of the algorithm and some keyword code
37 % - onelanguage : to simply switch keyword from one language to another without changing
39 % - boxed, boxruled, ruled, tworuled,
40 % algoruled, plain : layout of the algorithm
41 % - algo2e : environment is algorithm2e instead of algorithms and \listofalgorithmes
42 % instead of \listofalgorithms
43 % - slide : to use when making slides
44 % - noline,lined,vlined : how block are designed.
45 % - shortend, longend, noend : short or long end keyword as endif for e.g.
46 % - linesnumbered : auto numbering of the algorithm's lines
47 % - linesnumberedhidden : to hide autonumbered lines (show number on a line with \ShowLn
48 % - commentsnumbered, inoutnumbered : to autonumber comments and inout keywords (by defaut not numbered)
49 % - rightnl : to have line number on the right instead of on the left as default
50 % - algonl : line numbers preceded by algo number
51 % - scright, scleft : right or left justified side comments
52 % - fillcomment, nofillcomment : end mark of comment is flushed to the right so comments fill the line
53 % - dotocloa : add an entry in the toc for list of algorithms (require tocbibind package)
54 % - endfloat : add algoendfloat environment pushing algorithm so written to the end of document
55 % - resetcount, noresetcount : start value of line numbers.
56 % - algopart,algochapter,algosection : algo numbering within part, chapter or section
57 % - titlenumbered,titlenotnumbered : numbering of title set by \Titleofalgo
58 % - figure : algorithms are figures, numbered as figures, and put in the list of figures.
59 % - procnumbered : procedure or function are numbered as algorithm
60 % - nokwfunc : procedure or function name doens't become a command
61 % - norelsize : don't use relsize package (useful if it breaks the compatibily)
62 % - displayblockmarkers : display begin, end keywords at start of each block
64 % defaults are; english,plain,resetcount,titlenotnumbered
71 % algorithm is an environment for writing algorithm in LaTeX2e.
72 % Almost all is customizable. You can add keywords, change style, change the layout, ...
73 % It provide macros that allow you to create differents sorts of key words, therefore a set of predefined key
76 % IT should be used as follows
84 % IMPORTANT : each line MUST end with \;
86 % Note that if you define macros outside algorithm environment they
87 % are avaible in all the document and particulary you can use then
88 % inside all algorithms without re-define them.
95 % \KwOut{how to write algorithm with \LaTeX2e }
98 % \While{not at end of this document}{
99 % read current section\;
101 % go to next section\;
102 % current section becomes this one\;
104 % go back to the beginning of current section\;
107 % \caption{How to write algorithm}
111 %%%%%%%%%%%%%% predefined keywords
117 % \KwTo % a simple keyword
118 % \KwFrom % a simple keyword
121 % \Begin{block inside}
122 % \eIf{condition}{Then Block}{Else block} % in blocks
123 % \If{condition}{Then block} % in a block
124 % \uIf{condition}{Then block} % in a block unended
125 % \lIf{condition}{Else text} % on the same line
126 % \Else{inside Else} % in a block
127 % \lElse{Else text} % on the same line
128 % \uElse{Else text} % in a block unended
129 % \ElseIf{inside Elseif} % in a block
130 % \lElseIf{Elseif text} % on the same line
131 % \uElseIf{Elseif text} % in a block unended
132 % \Switch{Condition}{Switch block}
133 % \Case{a case}{case block} % in a block
134 % \lCase{a case}{case text} % on the same line
135 % \Other{otherwise block} % in a block
136 % \lOther{otherwise block} % on the same line
137 % \For{condition}{text loop} % in a block
138 % \lFor{condition}{text} % on the same line
139 % \ForEach{condition}{text loop} % in a block
140 % \lForEach{condition}{text} % on the same line
141 % \ForPar{condition}{text loop} % in a block
142 % \lForPar{condition}{text} % on the same line
143 % \While{condition}{text loop} % in a block
144 % \lWhile{condition}{text loop} % on the same line
145 % \Repeat{End condition}{text loop} % in a block
146 % \lRepeat{condition}{text} % on the same line
152 % - January 06 2013 - revision 5.0
153 % * CHANGE: SetKwSwith takes now 9 args: 9th arg is the same as
154 % previous 8th arg ('end of switch' keyword). New 8th arg is
155 % 'end of case' keyword. This is due to change of release
156 % 3.2 which introduce end after case block... as I never
157 % test with longend option, I never see that the 'end
158 % switch' used for case was not good.
159 % * CHANGE: when no end keyword is defined in a block macro, then
160 % algorithm2e does no more try to print it. So even with lined or noline
161 % option, no empty line is printed (before: a blank end was
162 % printed, so a blank line appeared)
163 % * Internal Change: add some internal function to improve readibility
164 % (thanks to Philip K. F. H\ölzenspies)
165 % * ADD: Block markers.
166 % You can now ask package to put begin and end keywords automatically at begin
167 % and end of blocks, it means each group of commands shifted and enclosed in
169 % This is tricky to use but, combined with \SetStartEndCondition and
170 % redefinition of keywords, you should be abble to simulate any syntax. See
171 % examples in documentation where a generic example is derived in pseudo-code,
172 % python and C by keeping code and changing only style using block markers
173 % macros, \SetStartEndCondition and some redefinition of keywords.
174 % These new block markers macros are:
175 % - \AlgoDisplayBlockMarkers and \AlgoDontDisplayBlockMarkers
176 % - \SetAlgoBlockMarkers{begin marker}{end marker}
177 % - \BlockMarkersSty{text} and \SetBlockMarkersSty
178 % Note that a new option has also been added: displayblockmarkers
179 % * ADD: \leIf macro automatically defined by \SetKwIF: allow to define
180 % an if-then-else on a single line.
181 % * ADD: new macro \SetStartEndCondition{typo1}{typo2}{typo3} which
182 % sets typo around condition in For, If, Switch, Case and
183 % Repeat macros. First two are used around For, If, Swith
184 % conditions, First and third are used for Case and Repeat
185 % condition where condition ends the line. Default definition
186 % is \SetStartEndCondition{ }{ }{}.
187 % A common alternative is \SetStartEndCondition{ (}{) }{)}
188 % Can also be used to remove space around condition, for
189 % example if you want python style commands:
190 % \SetStartEndCondition{ }{}{} and \SetKwFor{For}{for}{:}{}
191 % * ADD: new environment algomathdisplay which allow display math (like inside \[ \] or $$ $$)
192 % handling end line and line number
193 % * ADD: new command \SetKwProg{Env}{Title}{is}{end} which defines a macro
194 % \Env{args}{text}. Env is a block with 'Title' (in \CapSty) at the beginning
195 % followed by args followed by 'is' then 'text' is put below inside a block ended
196 % by 'end'. If no 'end' is specified, nothing is written (no
197 % blank line is inserted). Useful to typeset function or prog for example:
198 % \SetKwProg{Fn}{Function}{is}{end} makes \Fn{afunc(i: int) : int}{return 0\;}
200 % Function afunc(i: int) : int is
203 % or \SetKwProg{Def}{def}{:}{} makes \Def{afunc(i: int)}{return 0\;} writes:
206 % Tip: combine it with \SetKwFunction to write recursive function algorithm. With
207 % example above, you could define \SetKwFunction{\Afunc}{afunc} and then write:
208 % \Def{\Afunc{i:int}{\eIf{i>0}{\KwRet \Afunc{i-1}}{\KwRet 0\;}} that writes:
211 % | return afunc(i-1)
214 % with appropriate typo.
215 % * ADD: option croatian: croation keywords (thanks to Ivan Gavran)
216 % * ADD: option ngerman: same as german option but so can be used with global option ngerman
218 % * ADD: option spanish: Spanish support (thanks to Mario Abarca)
219 % * ADD: unterminated block: useful to add part separator that doesn't necessary need an end
221 % Designed on the pattern of unterminated if (see \uIf macro) allowing to
222 % add a block that is not terminated by a keyword. Such block are defined in the same
223 % time as a block is defined by adding a macro beginning with u. So, for example,
224 % predefined \SetKwBlock{Begin}{begin}{end} defines now two commands:
225 % - \Begin{} as previously which print a begin - end block
226 % - \uBegin{} that defines a begin only block
227 % * FIX: problem when numbering line inside until condition of
228 % \SetKwRepeat macro: line number was not correctly aligned.
229 % * FIX: dotocloa option which was broken
230 % * FIX: uIf and uCase didn't have same behavior when used with
231 % noline, vlined or lined option. This is fixed. Side effect: no empty
232 % line after an uIf or uCase when used with options lined or vlined
233 % * FIX: a bug with Repeat Until command when use with side comment on Until
234 % * FIX: a bug with side text -- text put into () -- of command macro (SetKwIf and so on)
235 % which was always setting a ';' even after a \DontPrintSemicolon
236 % * FIX: a bug with hyperref and chapter definition (thanks to Hubert Meier)
237 % * FIX: bugs with l macro and side comment
238 % * FIX: revision number
239 % * FIX: fix non ascii character (utf8 not yet recognized by all latex engine)
240 % * FIX: fnum@algocf had an useless parameter which sometimes broke expansion and output an error
241 % * FIX: works now with multicol package
243 % - december 14 2009 - revision 4.1
244 % * ADD: new command \SetKwHangingKw{Name}{text} (hanging indent with keyword): This creates a
245 % hanging indent much like \texttt{SetKwInput}, except that it removes the trailing `:'
246 % and does not reset numbering (thanks to Nathan Tallent)
248 % - november 17 2009 - revision 4.00 -
250 % * CHANGE: IMPORTANT: some commands have been renamed to have consistent naming (CamlCase
251 % syntax) and old commands are no more available. If you doesn't want to change
252 % your mind or use old latex files, you can use oldcommands option to enable old
254 % text. Here are these commands:
255 % - \SetNoLine becomes \SetAlgoNoLine
256 % - \SetVline becomes \SetAlgoVlined
257 % - \Setvlineskip becomes \SetVlineSkip
258 % - \SetLine becomes \SetAlgoLined
259 % - \dontprintsemicolon becomes \DontPrintSemicolon
260 % - \printsemicolon becomes \PrintSemicolon
261 % - \incmargin becomes \IncMargin
262 % - \decmargin becomes \DecMargin
263 % - \setnlskip becomes \SetNlSkip
264 % - \Setnlskip becomes \SetNlSkip
265 % - \setalcapskip becomes \SetAlCapSkip
266 % - \setalcaphskip becomes \SetAlCapHSkip
267 % - \nlSty becomes \NlSty
268 % - \Setnlsty becomes \SetNlSty
269 % - \linesnumbered becomes \LinesNumbered
270 % - \linesnotnumbered becomes \LinesNotNumbered
271 % - \linesnumberedhidden becomes \LinesNumberedHidden
272 % - \showln becomes \ShowLn
273 % - \showlnlabel becomes \ShowLnLabel
274 % - \nocaptionofalgo becomes \NoCaptionOfAlgo
275 % - \restorecaptionofalgo becomes \RestoreCaptionOfAlgo
276 % - \restylealgo becomes \RestyleAlgo
277 % - gIf macros and so on do no more exist
278 % * NEW: - Compatibily with other packages improven by changing name of internal
279 % macros. Algorithm2e can now be used with arabtex for example, if this last is
280 % loaded after algorithm2e package.
281 % * ADD: - OPTION endfloat: endfloat packages doesn't allow float environment inside other
282 % environment. So using it with figure option of algorithm2e makes error. This
283 % option enables a new environment algoendfloat to be used instead of algorithm
284 % environment that put algorithm at the end. algoendfloat environment make
285 % algorithm acting as endfloat figures. This option requires endfloat packages.
286 % * ADD: - OPTION norelsize: starting from this release (v4.00), algorithm2e package uses
287 % relsize package in order to get relative size for lines numbers; but it seems
288 % that some rare classes (such as inform1.cls) are not compatible with relsize; to
289 % have algorithm2e working, this option makes algorithm2e not to load relsize
290 % package and go back to previous definition by using \scriptsize font for lines
292 % * ADD: - OPTION onelanguage: allow, if using standard keywords listed below, to switch
293 % from one language to another without changing keywords by using appropriate
295 % . KwIn, KwOut, KwData, KwResult
301 % . Switch, Case, Other
302 % . For, ForPar, ForEach, ForAll, While
304 % * ADD: - OPTION rightnl: put lines numbers to the right of the algorithm instead of left.
305 % * ADD: new commands \setRightLinesNumbers and \setLeftLinesNumbers which sets the lines
306 % numbers to the right or to the left of the algorithm.
307 % * ADD: - new kind of keywords: KwArray used to define arrays:
308 % \SetKwArray{Kw}{array} defines an array keywords Kw called array and printed in
309 % DataSty style when call with \Kw. It can be used with one argument which
310 % denotes the element index: \Kw{n} prints array[n] with array in DataSty and n in
312 % * ADD/FIX: rules of ruled, algoruled, tworuled styles used rules of different sizes! This
313 % is now fixed. Moreover size of the rules is now controlled by a length and so
314 % can be customized by the user.
315 % \algoheightrule is the height of the rules and can be changed via \setlength
316 % \algoheightruledefault is the default height of he rules (0.8pt)
317 % \algotitleheightrule is the height of the rule that comes just after the
318 % caption in ruled and algoruled style; it can be changed via \setlength
319 % \algotitleheightruledefault is the default height of this rules (0.8pt)
320 % Thanks to Philippe Dumas who reports the bug and make the suggestion.
321 % * ADD: - \SetAlgoCaptionSeparator which sets the separator between Algorithm 1 and the
322 % title. By default it's ':' and caption looks like "Algorithm 2: title" but now
323 % you can change it by using for example \SetAlgoCaptionSeparator{.} which will
324 % give "Algorithm 3. title"
325 % * ADD: - \SetAlgoLongEnd and \SetAlgoShortEnd and \SetAlgoNoEnd commands which act as
326 % corresponding package options
327 % * ADD: - OPTIONS italiano and slovak as new language (thanks to Roberto Posenato and
329 % * CHANGE: - Fnt and Sty macro to have consistent use and naming (see below)
330 % * ADD: - \AlCapSty, \AlCapNameSty, \AlCapFnt, \AlCapNameFnt, \ProcSty, \ProcFnt,
331 % \ProcNameSty, \ProcNameFnt, \ProcArgSty, ProcArgFnt and corresponding "set macro"
332 % \SetAlCapSty, \SetAlCapNameSty, \SetAlCapFnt, \SetAlCapNameFnt, \SetProcSty,
333 % \SetProcFnt, \SetProcNameSty, \SetProcNameFnt, \SetProcArgSty, \SetProcArgFnt which
334 % control the way caption is printed. Sty macro use command taking one parameter as
335 % argument, Fnt macros use directly command. In Fact caption is printed as follow:
336 % \AlCapSty{\AlCapFnt Algorithm 1:}\AlCapNameSty{\AlCapNameFnt my algorithm}
337 % By default, \AlCapSty is textbf and \AlCapFnt is nothing. \AlCapNameSty keep text
338 % as it is, and \AlCapNameFnt do nothing also.
339 % You can redefine \AlCapFnt and \AlCapNameFnt by giving macro to \Set commands. For
340 % example, you can do \SetAlCapFnt{\large} to see Algorithm printed in \large font.
341 % You can redefine \AlCapSty, \AlCapFnt, \AlCapNameSty and \AlCapNameFnt with the
342 % corresponding \Set command. For the Sty commands, you have to give in parameter
343 % name of a macro (whithout \) which takes one argument. For example,
344 % \SetAlCapFnt{textbf} defines the default behaviour. If you want to do more
345 % complicated thing, you should define your own macro and give it to \SetAlCapFnt or
346 % \SetAlCapNameFnt. Here are two examples:
347 % - \newcommand{\mycapsty}[1]{\tiny #1}\SetAlCapNameSty{mycapsty}
348 % - \newcommand{\mycapsty}[1]{\textsl{\small #1}}\SetAlCapNameSty{mycapsty}
349 % Or you can combine the two, for the last example you can also do:
350 % \SetAlCapNameSty{textsl}\SetAlCapNameFnt{\small}
351 % Thanks to Jan Stilhammer who gives me the idea of \AlCapNameFnt.
352 % * CHANGE \AlTitleFnt to match definition of all other Fnt macros and add a \AlTitleSty
353 % macro (see below) . Now you set \AlTitleFnt by calling \SetAlTitleFnt with
354 % directly a macro without parameter in argument:
355 % Example: \SetAlTitleFnt{\small} to set title in small font.
356 % * ADD: - \AlTitleSty and \SetAlTitleSty commands to set a style for title. These commands
357 % are defined from a macro taking the text in argument, as \textbf for example.
358 % To set the TitleSty you have to give name of the macro (without the '\')
359 % to \SetAlTitleSty. For example \SetAlTitleSty{textbf} to set \textbf style.
360 % * ADD: - new command \SetAlgorithmName{algorithmname}{list of algorithms name} which
361 % redefines name of the algorithms and the sentence list of algorithms. Second
362 % argument is the name that \autoref, from hyperref package, will use. Example:
363 % \SetAlgorithmName{Protocol}{List of protocols} if you prefer protocol than
365 % * ADD: - new \SetAlgoRefName{QXY} which change the default ref (number of the algorithm) by
366 % the name given in parameter (QXY in the example).
367 % * ADD: - new command \SetAlgoRefRelativeSize{-2} which sets the output size of refs, defined
368 % by \SetAlgoRefName, used in list of algorithms.
369 % * ADD: - two dimensions to control the layout of caption in ruled, algoruled and boxruled
371 % - interspacetitleruled (2pt by defaut) which controls the vertical space between
372 % rules and title in ruled and algoruled algorithms.
373 % - interspaceboxruled (2\lineskip by default) which controls the vertical space
374 % between rules and title in boxruled algorithms.
375 % These two dimensions can be changed by using \setlength command.
376 % * ADD: - With the fix (see below) of procedure and function environments, a new feature has
377 % been added: the name of the procedure or function set in caption is automatically
378 % defined as a KwFunction and so can be used as a macro. For example, if inside a
379 % procedure environment you set \caption{myproc()}, you can use \myproc macro in you
380 % main text. Beware that the macro is only defined after the \caption!
381 % * ADD: - OPTION nokwfunc to unable the new feature described above in function and
382 % procedure environment. Useful if you use name of procedure or function that cannot
383 % be a command name as a math display for example.
384 % * ADD: - \SetAlgoNlRelativeSize{number} command which sets the relative size of line
385 % numbers. By default, line numbers are two size smaller than algorithm text. Use
386 % this macro to change this behavior. For example, \SetAlgoNlRelativeSize{0} sets it
387 % to the same size, \SetAlgoNlRelativeSize{-1} to one size smaller and
388 % \SetAlgoNlRelativeSize{1} to one size bigger
389 % * ADD: - \SetAlgoProcName{aname} command which sets the name of Procedure printed by
390 % procedure environment (the environment prints Procedure by default). Second
391 % argument is the name that \autoref, from hyperref package, will use.
392 % * ADD: - \SetAlgoFuncName{aname} command which sets the name of Function printed by
393 % procedure environment (the environment prints Function by default). Second
394 % argument is the name that \autoref, from hyperref package, will use.
395 % * ADD: - \SetAlgoCaptionLayout{style} command which sets style of the caption; style must
396 % be the name of a macro taking one argument (the text of the caption). Examples
397 % below show how to use it:
398 % . \SetAlgoCaptionLayout{centerline} to have centered caption
399 % . \SetAlgoCaptionLayout{textbf} to have bold caption
400 % If you want to apply two styles in the same time, such as centered bold, you have
401 % to define you own macro and then use \SetAlgoCaptionLayout with its name.
402 % * ADD: - OPTION procnumbered: which makes the procedure and function to be numbered as
404 % * ADD: - OPTIONS tworuled and boxruled
405 % these are two new layouts: tworuled acts like ruled but doesn't put a line after
406 % caption ; boxruled surround algorithm by a box, puts caption above and add a line
408 % * REMOVE: - SetKwInParam has been deleted since not useful itself because of different
409 % macros which can do the same in a better and a more consistent way as
410 % SetKwFunction or SetKw.
411 % * FIX: - line number is now correctly vertically aligned with math display.
412 % * FIX: - references with hyperref. No more same identifier or missing name error. BUT now
413 % you must NOT use naturalnames option of hyperref packages if you do PdfLaTeX
414 % * FIX: - autoref with hyperref package (thanks to Jörg Sommer who notices the problem).
415 % * FIX: - titlenumbered was not working! fixed.
416 % * FIX: - Else(){} acted like uElse. Corrected.
417 % * FIX: - noend management: when a block was inside another and end of block was following
418 % each other, a blank line was added: it's now corrected.
419 % * FIX: - Function and Procedure environment was no more working as defined originally: the
420 % label was no more name of the procedure, it acts always as if procumbered option
422 % * FIX: - line numbers had a fixed size which can be bigger than algorithm text accordingly
423 % to \AlFnt set (see also new command \SetAlgoNlRelativeSize above)
424 % * FIX: - semicolon in comments when dontprintsemicolon is used.
425 % * FIX: - listofalgorithms adds a vertical space before first algo of a chapter as for
426 % listoffigures or listoftables
427 % * FIX: - listofalgorithms with twocolumns mode and some classes which don't allow onecolumn
428 % and so don't define \if@restonecol as prescribed in LaTeX (sig-alternate for
430 % * FIX: - algorithm2e now works with elsart cls and some more classes.
431 % * FIX: - blocks defined by SetKwBlock act now as other blocks (if for instance) and don't
432 % write end in vlined mode, instead they print a small horizontal line as required
434 % * FIX: - underfull hbox warning at each end of algorithm environment removed.
436 % * INTERNAL CHANGE: - short end keyword are deduce from long end keyword by keeping the
437 % first one. Allows to avoid double definition.
438 % * INTERNAL CHANGE: - procedure, function and algorithm are now resolved by the same
439 % environment to avoid code duplication.
441 % - October 04 2005 - revision 3.9 -
442 % * ADD: - \setalcaphskip command which sets the horizontal skip before Algorithm: in caption
443 % when used in ruled algorithm.
444 % * ADD: - \SetAlgoInsideSkip command which allows to add an extra vertical space before and
445 % after the core of the algorithm (ie: \SetAlgoInsideSkip{bigskip})
446 % * CHANGE: - caption, when used with figure option, is no more controlled by algorithm2e
447 % package and so follows the exact behaviour of figures. The drawback is that you
448 % cannot change the typo with AlTitleFnt or CapFnt. The avantage is that if you
449 % use caption package, it works.
450 % * FIX: - problem with numbering line and pdflatex
451 % * FIX: - error when algorithm2e package was used with beamer and listings together
452 % - February 12 2005 - revision 3.8 -
453 % * FIX: - extra line with noend option.
454 % - February 10 2005 - revision 3.7 -
455 % * ADD: - sidecomment: different macros allowing to put text right after code on the same
456 % line. They are defined in the same time comment macros are defined with a star
457 % after the macro name. By default comments are right justified but this can be
458 % change with appropriate option in the macro. Ex:
459 % . default: \tcc*{side comment}
460 % . same as previous: \tcc*[r]{side comment}
461 % . left justify: \tcc*[l]{side comment}
462 % . here: \tcc*[h]{side comment} don't put the end of line mark before
463 % comment (; by default) and don't end the line.
464 % . flushed: \tcc*[f]{side comment} same as the precedent but right
466 % * ADD: - OPTION scright (default): right justified side comments (side comments
467 % are flushed to the righr)
468 % * ADD: - OPTION scleft: left justified side comments (side comments are put right after the
470 % * ADD: - \SetSideCommentLeft acts as scleft option
471 % * ADD: - \SetSideCommentRight acts as scright option
472 % * ADD: - block like macro side text: all macro defining a block allows now to put text right
473 % after key words by putting text into (). Done to be used with sidecomment macros,
474 % but all text can be used.
475 % Ex: \eIf(\tcc*[f]{then comment}){test}{then text}(else side text){else text}
476 % * ADD: - OPTION fillcomment (default): end mark of comment is flushed to the right so
477 % comments fill all the width of text.
478 % * ADD: - OPTION nofillcomment: end mark of comment is put right after the comment.
479 % * ADD: - \SetNoFillComment acts as nofillcomment option.
480 % * ADD: - \SetFillComment acts as fillcomment option.
481 % * ADD: - OPTION dotocloa: which adds an entry in the toc for the list of algorithms. This
482 % option load package tocbibind if not already done and so list of figures and list
483 % of tables are also added in the toc. If you want to control which ones of the lists
484 % will be added in the toc, please load package tocbibind before package algorithm
485 % and give it the options you want.
486 % * FIX: - vertical spacing for uif macro with noend option
487 % * FIX: - all the compatibility problems between caption and other packages
488 % * FIX: - typographical differences between list of algorithms and other lists when in
491 % - January 24 2005 - revision 3.6 -
492 % * FIX: - vertical spacing and space characters at the beginning or end of comments.
493 % line numbers of comments not in the NlSty.
494 % Thanks to Arnaud Giersch for his comments and suggestions.
495 % * FIX: - Set*Sty macro: the styles defined was not protected and was modified by surrounding
496 % context. For example KwTo in a \For{}{} was in bold AND italic instead of just in
498 % * FIX: - line number misplacement after \Indp
500 % - January 21 2005 - revision 3.5 -
501 % * ADD: - hidden numbering of the lines. Lines are auto-numbered but numbers are shown only
502 % on lines you specify:
503 % * linesnumberedhidden option or \LinesNumberedHidden macro activate this
505 % * \ShowLn and \ShowLnLabel{lab} macros make the number visible on the
506 % line. \ShowLnLabel{lab} allows to set a label for this line.
507 % Thanks to Samson de Jager who makes this suggestion and provides the macros.
508 % * ADD: - \AlCapFnt and \SetAlCapFnt which allow to have a different font for
509 % caption. Works like \AlFnt and \SetAlFnt and by default is the same.
510 % * ADD: - \AlCapSkip skip length. This vertical space is added before caption in plain ou
511 % boxed mode. It allows to change distance between text and caption.
512 % * FIX: - caption compatible with IEEEtran class.
513 % * FIX: - some vertical spacing error with \uIf macros (Thanks to Arnaud Giersch)
514 % * FIX: - Procedure and Function: lines are also numbered like algorithms
515 % * FIX: - CommentSty was not used for Comments
517 % - January 10 2005 - revision 3.4 -
518 % * FIX: - caption compatible with new release of Beamer class.
520 % - June 16 2004 - revision 3.3 -
521 % * FIX: - Hyperlink references of Hyperref package works now if compiled with pdflatex
522 % and [naturalnames] option of hyperref package is used.
523 % * FIX: - algorithm[H] had problem in an list environment - corrected
524 % * FIX: - interline was not so regular in nested blocks - corrected
525 % * ADD - \SetVlineSkip macro which sets the vertical skip after the little horizontal
526 % rule which closes a block in Vlined mode. By default 0.8ex
528 % - June 11 2004 - revision 3.2 - AUTO NUMBERING LINES !!!
529 % * ADD: auto numbering of the lines (the so asked and so long awaiting feature)
530 % this feature is managed by 3 options and 3 commands:
531 % - linesnumbered option: lines of the algo are numbered except for comments and
532 % input/output (KwInput and KwInOut)
533 % - commentsnumbered option: makes comments be numbered
534 % - inoutnumbered option: makes data input/output be numbered
535 % - \nllabel{lab} labels the line so you can cite with \ref{lab}
536 % - \LinesNumbered make the following algorithms having auto-numbered lines
537 % - \linesnotnumbered make the following algorithms having no auto-numbered lines
538 % * Change: algo2e option renames listofalgorithms in listofalgorithmes
539 % * FIX: new solution for compatibility with color package, more robust and not tricky.
540 % Many thanks to David Carlisle for his advices
542 % - June 09 2004 - revision 3.1 -
543 % * Change: \SetKwSwitch command defines an additionnal macro \uCase and \Case prints end
544 % * Change: now macros SetKw* do a renewcommand if the keyword is already defined. So you can
545 % redefine default definition at your own convenience or change your definition
546 % without introducing a new macro and changing your text.
547 % * ADD: new macro \SetKwIF which do \SetKwIf and
548 % \SetKwIfElseIf.The following default definition has been added:
549 % \SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}
550 % and so you get the macros;
551 % \If \eIf \lIf \uIf \ElseIf \uElseIf \lElseIf \Else \uElse \lElse
552 % * ADD: new macro \SetAlgoSkip which allow to fix the vertical skip before and after the
553 % algorithms. Default is smallskip, do \SetAlgoSkip{} if you don't want an extra space
554 % or \SetAlgoSkip{medskip} or \SetAlgoSkip{bigskip} if you want bigger space.
555 % * ADD: macro \SetKwIf defines in addition a new macro \uElse (depending on wat name you
556 % have given in #2 arg).
557 % * ADD: macro \SetKwIfElseIf defines in addition a new macro \uElse and \ugElseIf (depending
558 % on what name you have given in #2 and #3 arg).
559 % * Change: baseline of algorithm is now top, so two algorithms can be put side by side.
560 % * FIX: Compatibility with color package solved. The problem was due to a redefinition of
561 % standard macros by color package. This solves compatibility problem with other
562 % packages as pstcol or colortbl. (notified by Dirk Fressmann, Antti Tarvainen and Koby
564 % * Fix: extra little shift to the right with boxed style algorithm removed (notified by
566 % * Fix: algoln option was buggy (notified bye Jiaying Shen)
567 % * Fix: german and portuges option didn't work due to bad typo (notified by Martin Sievers,
568 % Thorsten Vitt and Jeronimo Pellegrini)
570 % - February 13 2004 - revision 3.0 -
571 % * Major revision which makes the package independent from float.sty, so now
572 % - algorithm* works better, in particular can be used in multicols environments
573 % - (known bug corrected)
574 % [H] works now for all sort of environment but is handled differently for classic
575 % environment and star environment (algorithm, figure, procedure and function). For star
576 % environment, H acts like for classical figure environment, so it doesn't stay here
578 % - (known bug corrected)
579 % you can use now floatflt package with algorithm package and even with figure
580 % option. Beware that if you want to put an algorithm inside a floatingfigure, it cannot
581 % be floating, so [H] is required and then figure option should not be used, since
582 % standard figure[H] are still floating with LaTeX.
583 % * boxruled: a new style added. Possible now since no style no more defined by the float
585 % * nocaptionofalgo: dosen't print Algorithm #: in the caption for algorithm in ruled or
587 % note: this is just documentation of a macro which was already in the package.
588 % - December 14 2003 - revision 2.52 -
589 % * output message shorter
590 % * french keyword macro \PourTous was missing for longend option, it has been added.
591 % * TitleofAlgo prints Function or Procedure in corresponding environments.
593 % - October 27 2003 - revision 2.51 - Revision submitted to CTAN archive
594 % * correction of a minor which make caption in procedure
595 % and function to be blanck with pdfscreen package
596 % (thanks to Joel Gossens for the notification)
597 % * add two internal definition to avoid some errors when
598 % used with Hyperref package (Hyperref package need to
599 % define new counter macro from existing ones, and
600 % don't do it for algorithm2e package, so we do it)
602 % - October 17 2003 - revision 2.50 - first revision for CTAN archive
603 % * add \AlFnt and \SetAlFnt{font} macros: \AlFnt is used at the beginning of the caption and
604 % the body of algorithm in order to define the fonts used for typesetting algorithms. You
605 % can use it elsewhere you want to typeset text as algorithm. For example you can do
606 % \SetAlFnt{\small\sf} to have algorithms typeset in small sf font. Default is nothing so
607 % algorithm is typeset as the text of the document.
608 % * add \AlTitleFnt{text} and \SetAlTitleFnt{font} macros: The {Algorithm: } in the caption is
609 % typeset with \AlTitleFnt{Algorithm:}. You can use it to have text typeset as {Algorithm:}
610 % of captions. Default is textbf. Default can be redefined by \SetAlTitleFnt{font}, for
611 % example you can do \SetAlTitleFnt{emph}
612 % * add CommentSty typo for text comment.
613 % * add some compatibility with hyperref package (still an error on multiply defined refs but
614 % pdf correctly generated)
615 % * flush text to left in order to have correct indentation even with class as amsart which
617 % * add german, portuguese and czech options for title of algorithms and typo.
618 % * add portuguese translation of predefined keywords * add czech translation of some
619 % predefined keywords
621 % - December 23 2002 - revision 2.40
622 % * add some french keyword missing
623 % * add function* and procedure* environment like algorithme* environment: print in one column
624 % even if twocolumn option is specified for the document.
625 % * add a new macro \SetKwComment to define macro which writes comments in the text. First
626 % argument is the name of the macro, second is the text put before the comment, third is the
627 % text put at the end of the comment.Default are \tcc and \tcp
628 % * add new options to change the way algo are numbered:
629 % [algopart] algo are numbered within part (counter must exist)
630 % [algochapter] algo are numbered within chapter
631 % [algosection] algo are numbered within section
633 % - March 27 2002 - revision 2.39
634 % * Gilles Geeraerts: added the \SetKwIfElseIf to manage
643 % * Also added \gIf \gElseIf \gElse.
645 % - January 02 2001 - revision 2.38
646 % * bugs related to the caption in procedure and function
647 % environment are corrected.
648 % * bug related to option noend (extra vertical space added
649 % after block command as If or For) is corrected.
650 % * czech option language added (thanks to Libor Bus: l.bus@sh.cvut.cz).
652 % - October 16 2000 - revision 2.37
653 % * option algo2e added: change the name of environment
654 % algorithm into algorithm2e. So allow to use the package
655 % with some journal style which already define an algorithm
658 % - September 13 2000 - revision 2.36
659 % * option slide added: require package color
660 % * Hack for slide class in order to have correct
663 % - November 25 1999 - revision 2.35
664 % * revision number match RCS number
665 % * Thanks to David A. Bader, a new option is added:
666 % noend: no end keywords are printed.
668 % - November 19 1999 - revision 2.32
669 % * minor bug on longend option corrected.
671 % - August 26 1999 - revision 2.31
672 % * add an option: figure
673 % this option makes algorithms be figure and so are numbered
674 % as figures, have Figure as caption and are put in
677 % - January 21 1999 - revision 2.3 beta
678 % add 2 new environments: procedure and function.
679 % These environments works like algorithm environment but:
680 % - the ruled (or algoruled) style is imperative.
681 % - the caption now writes Procedure name....
682 % - the syntax of the \caption command is restricted as
683 % follow: you MUST put a name followed by 2 braces like
684 % this ``()''. You can put arguments inside the braces and
685 % text after. If no argument is given, the braces will be
686 % removed in the title.
687 % - label now puts the name (the text before the braces in the
688 % caption) of the procedure or function as reference (not
689 % the number like a classic algorithm environment).
690 % There are also two new styles: ProcNameSty and
691 % ProcArgSty. These style are by default the same as FuncSty
692 % and ArgSty but are used in the caption of a procedure or a
695 % - November 28 1996 - revision 2.22
696 % add a new macro \SetKwInParam{arg1}{arg2}{arg3}:
697 % it defines a macro \arg1{name}{arg} which prints name in keyword
698 % style followed byt arg surrounded by arg2 and arg3. The main
699 % application is to a function working as \SetKwInput to be used
700 % in the head of the algorithm. For example
701 % \SetKwInParam{Func}{(}{)} allows
702 % \Func{functionname}{list of arguments} which prints:
703 % \KwSty{functioname(}list of arguments\KwSty{)}
706 % - November 27 1996 - revision 2.21:
707 % minor bug in length of InOut boxes fixed.
708 % add algorithm* environment.
710 % - July 12 1996 - revision 2.2: \SetArg and \SetKwArg macros removed.
712 % \SetArg has been removed since it never has been
714 % \SetKwArg has been removed since \SetKw can now
715 % take an argument in order to be consistent with
716 % \SetKwData and \SetKwFunction macros.
718 % - July 04 1996 - revision 2.1: still more LaTeX2e! Minor compatibility break
720 % Macros use now \newcommand instead of \def, use of \setlength,
721 % \newsavebox, ... and other LaTeX2e specific stuff.
722 % The compatibility break:
723 % - \SetData becomes \SetKwData to be more consistent. So the old
724 % \SetKwData becomes \SetKwInput
725 % - old macros \titleofalgo, \Freetitleofalgo and \freetitleofalgo
726 % from LaTeX209 version which did print a warning message and call
727 % \Titleofalgo in version 2.0 are now removed!
729 % - March 13 1996 - revision 2.0: first official major revision.
736 % - horizontal spacing (indent) doesn't work with revtex4 class.
738 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
740 % for more complete informations you can see algorithm2e.tex
743 %%%%%%%%%%%%%%%%%%%%%%%% Identification Part %%%%%%%%%%%%%%%%%%%%%%%%%%%%
745 \NeedsTeXFormat{LaTeX2e}[1994/12/01]
747 \ProvidesPackage{algorithm2e}[2013/01/06 v5.00 algorithms environments]
750 %%%%%%%%%%%%%%%%%%%%%%%%%%% Initial Code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
752 \@makeother\*% some package redefined it as a letter (as color.sty)
753 \def\@firstword#1 #2\@nil{#1}% an useful fonction
755 % \ifArgumentEmpty<c><t><e> ; if c is empty, i.e. {}, then t, else e.
756 % Function used internally, but may as well expose it to the user; it's useful
757 \long\def\ifArgumentEmpty#1{\bgroup
760 \long\def\@tempa##1##2Q##3##4##5T{##4}%
761 \xdef\@tempa{\@tempa#1QQ{\noexpand\@secondoftwo}{\noexpand\@firstoftwo}T}%
764 % \algocf@longdef -> shorthand to reduce
765 % \expandafter\long\expandafter\def
767 % \expandafter\algocf@longdef
768 % may look insignificant, but reads that much better ;)
769 \def\algocf@longdef{\long\def}
771 % \algocf@newcommand (and helper \algocf@new@command) behaves like LaTeX's newcommand,
772 % with two differences:
773 % - the argument is not "\<name>", but rather "<name>"; i.e. one level of indirection
774 % - if the command exists already, then \renewcommand, rather than \newcommand
775 \def\algocf@newcommand#1{\expandafter\algocf@new@command\csname#1\endcsname}
776 \def\algocf@new@command#1{%
777 \begingroup \escapechar\m@ne\xdef\@gtempa{{\string#1}}\endgroup
778 \expandafter\@ifundefined\@gtempa\newcommand\renewcommand#1}%
780 % \algocf@newcmdside<name><arity><body>
781 % The largest time-saver; many commands we define have the pattern:
782 % \<name>(<side_text>)<argX><argY>...
783 % where "(<side_text>)" is optional. By defining them with this function,
784 % the arguments are parsed and renumbered, i.e. the body works as if the
786 % \<name><side_text><argX><argY>...
787 % and can use \ifArgumentEmpty to see whether its #1 exists (default case
788 % for the side text is (), so there's no difference between calling
792 % Technically this is new behaviour, but it shouldn't really occur...
793 \algocf@longdef\algocf@newcmdside#1#2#3{%
794 \expandafter\def\csname#1\endcsname{%
795 \@ifnextchar({\csname algocf@#1strip\endcsname}{\csname algocf@#1strip\endcsname()}%
797 \expandafter\algocf@longdef\csname algocf@#1strip\endcsname(##1){\csname algocf@#1main\endcsname{##1}}%
798 \algocf@newcommand{algocf@#1main}[#2]{#3}%
801 % \algocf@newcmdsides<name><arity><body><tail><closing>
802 % Like the command above, but with an optional side text at the end
803 % of the command as well, i.e.:
804 % \<name>(<side_text>)<argX><argY>(<end_text>)
805 % It may be a bit confusing that <arity> doesn't count <end_text>,
806 % but since it is for internal use, the naming can be a little more
807 % fuzzy. This function behaves as if:
808 % <body'> = <body><if end_text: tail{end_text}><closing>
809 \algocf@longdef\algocf@newcmdsides#1#2#3#4#5{%
810 \expandafter\def\csname#1\endcsname{%
811 \@ifnextchar({\csname algocf@#1strip\endcsname}{\csname algocf@#1strip\endcsname()}%
813 \expandafter\algocf@longdef\csname algocf@#1strip\endcsname(##1){\csname algocf@#1main\endcsname{##1}}%
814 \algocf@newcommand{algocf@#1main}[#2]{#3\@ifnextchar({\csname algocf@#1end\endcsname}{#4#5}}%
815 \expandafter\algocf@longdef\csname algocf@#1end\endcsname(##1){#4{##1}\strut\par}%
818 % definition of commands which can be redefined in options of the package.
820 \newcounter{AlgoLine}%
821 \setcounter{AlgoLine}{0}%
823 \newcommand{\algocf@algocfref}{\relax}%
824 \newcommand{\listalgorithmcfname}{}%
825 \newcommand{\algorithmcfname}{}%
826 \@ifundefined{algorithmautorefname}{\newcommand{\algorithmautorefname}{algorithm}}{\renewcommand{\algorithmautorefname}{algorithm}}%
827 \newcommand{\algorithmcflinename}{}%
828 \newcommand{\algocf@typo}{}%
829 \newcommand{\@algocf@procname}{}\newcommand{\procedureautorefname}{}%
830 \newcommand{\SetAlgoProcName}[2]{\renewcommand{\@algocf@procname}{#1}\renewcommand{\procedureautorefname}{#2}}%
831 \newcommand{\@algocf@funcname}{}\newcommand{\functionautorefname}{}%
832 \newcommand{\SetAlgoFuncName}[2]{\renewcommand{\@algocf@funcname}{#1}\renewcommand{\functionautorefname}{#2}}%
833 \newcommand{\@algocf@titleofalgoname}{\algorithmcfname}%
834 \newcommand{\@algocf@algotitleofalgo}{%
835 \renewcommand{\@algocf@titleofalgoname}{\algorithmcfname}}%
836 \newcommand{\@algocf@proctitleofalgo}{%
837 \renewcommand{\@algocf@titleofalgoname}{\algocf@procname}}%
839 \newcommand{\algocf@style}{plain}%
840 \newcommand{\@ResetCounterIfNeeded}{}%
841 \newcommand{\@titleprefix}{}%
843 \newcommand{\algocf@numbering}[1]{\newcommand{\algocf@within}{#1}}%
845 \newcommand{\defaultsmacros@algo}{\algocf@defaults@shortend}%
847 \newcommand{\algocf@list}{loa}%
848 \newcommand{\algocf@float}{algocf}%
850 \newcommand{\algocf@envname}{algorithm}%
851 \newcommand{\algocf@listofalgorithms}{listofalgorithms}%
854 %% redefine chapter so that it adds a vspace in the loa as the original does for lof and lot
855 % \let\algocf@original@chapter=\chapter%
856 % \def\chapter{\expandafter\addtocontents{loa}{\protect\addvspace{10\p@}}\algocf@original@chapter}%
858 % bug correction with hyperref submitted by Hubert Meier
859 \begingroup\expandafter\expandafter\expandafter\endgroup
860 \expandafter\ifx\csname @chapter\endcsname\relax\else
861 % \let\algocf@original@chapter=\chapter%
862 % \def\chapter{\addtocontents{loa}{\protect\addvspace{10\p@}}\algocf@original@chapter}%
863 \let\algocf@original@chapter=\@chapter%
864 \def\@chapter[#1]#2{\algocf@original@chapter[#1]{#2}\addtocontents{loa}{\protect\addvspace{10\p@}}}%
867 %% if@restonecol is defined in article and book but some other classes don't define it and we need it, so we do
868 \ifx\if@restonecol\relax\else\newif\if@restonecol\fi%
871 %%%%%%%%%%%%%%%%%%%%%% Declaration of Options %%%%%%%%%%%%%%%%%%%%%%%%%%%
873 \RequirePackage{ifthen}%
875 \newboolean{algocf@displayblockmarkers}\setboolean{algocf@displayblockmarkers}{false}%
876 \DeclareOption{displayblockmarkers}{%
877 \setboolean{algocf@displayblockmarkers}{true}%
880 \newboolean{algocf@nokwfunc}\setboolean{algocf@nokwfunc}{false}%
881 \DeclareOption{nokwfunc}{%
882 \setboolean{algocf@nokwfunc}{true}%
885 \newboolean{algocf@oldcommands}\setboolean{algocf@oldcommands}{false}%
886 \DeclareOption{oldcommands}{%
887 \setboolean{algocf@oldcommands}{true}%
890 \newboolean{algocf@leftlinenumber}\setboolean{algocf@leftlinenumber}{true}%
891 \newcommand{\setLeftLinesNumbers}{\setboolean{algocf@leftlinenumber}{true}}%
892 \newcommand{\setRightLinesNumbers}{\setboolean{algocf@leftlinenumber}{false}}%
893 \DeclareOption{rightnl}{%
894 \setRightLinesNumbers%
897 \newboolean{algocf@endfloat}\setboolean{algocf@endfloat}{false}%
898 \DeclareOption{endfloat}{%
899 \setboolean{algocf@endfloat}{true}%
900 \newcounter{postalgo}\setcounter{postalgo}{0}%
903 \newboolean{algocf@procnumbered}\setboolean{algocf@procnumbered}{false}%
904 \DeclareOption{procnumbered}{%
905 \setboolean{algocf@procnumbered}{true}%
908 \DeclareOption{algo2e}{%
909 \renewcommand{\algocf@envname}{algorithm2e}%
910 \renewcommand{\algocf@listofalgorithms}{listofalgorithmes}%
913 \newboolean{algocf@slide}\setboolean{algocf@slide}{false}%
914 \DeclareOption{slide}{%
915 \setboolean{algocf@slide}{true}%
918 \DeclareOption{figure}{%
919 \renewcommand{\algocf@list}{lof}%
920 \renewcommand{\algocf@float}{figure}%
923 \newboolean{algocf@optonelanguage}\setboolean{algocf@optonelanguage}{false}%
924 \DeclareOption{onelanguage}{\setboolean{algocf@optonelanguage}{true}}%
926 \newcommand{\algocf@languagechoosen}{english}%
928 \DeclareOption{english}{%
929 \renewcommand{\listalgorithmcfname}{List of Algorithms}%
930 \renewcommand{\algorithmcfname}{Algorithm}%
931 \renewcommand{\algorithmautorefname}{algorithm}%
932 \renewcommand{\algorithmcflinename}{line}%
933 \renewcommand{\algocf@typo}{}%
934 \renewcommand{\@algocf@procname}{Procedure}%
935 \renewcommand{\@algocf@funcname}{Function}%
936 \renewcommand{\procedureautorefname}{procedure}%
937 \renewcommand{\functionautorefname}{function}%
938 \renewcommand{\algocf@languagechoosen}{english}%
941 \DeclareOption{french}{%
942 \renewcommand{\listalgorithmcfname}{Liste des Algorithmes}%
943 \renewcommand{\algorithmcfname}{Algorithme}%
944 \renewcommand{\algorithmautorefname}{algorithme}%
945 \renewcommand{\algorithmcflinename}{ligne}%
946 \renewcommand{\algocf@typo}{\ }%
947 \renewcommand{\@algocf@procname}{Proc\'edure}%
948 \renewcommand{\@algocf@funcname}{Fonction}%
949 \renewcommand{\procedureautorefname}{proc\'edure}%
950 \renewcommand{\functionautorefname}{fonction}%
951 \renewcommand{\algocf@languagechoosen}{french}%
954 \DeclareOption{czech}{%
955 \renewcommand{\listalgorithmcfname}{Seznam algoritm\v{u}}%
956 \renewcommand{\algorithmcfname}{Algoritmus}%
957 \renewcommand{\algorithmautorefname}{\algorithmcfname}%
958 \renewcommand{\algorithmcflinename}{Radek}%
959 \renewcommand{\algocf@typo}{}%
960 \renewcommand{\@algocf@procname}{Procedura}%
961 \renewcommand{\@algocf@funcname}{Funkce}%
962 \renewcommand{\procedureautorefname}{\@algocf@procname}%
963 \renewcommand{\functionautorefname}{\@algocf@funcname}%
964 \renewcommand{\algocf@languagechoosen}{czech}%
967 \DeclareOption{german}{%
968 \renewcommand{\listalgorithmcfname}{Liste der Algorithmen}%
969 \renewcommand{\algorithmcfname}{Algorithmus}%
970 \renewcommand{\algorithmautorefname}{\algorithmcfname}%
971 \renewcommand{\algorithmcflinename}{Zeile}%
972 \renewcommand{\algocf@typo}{\ }%
973 \renewcommand{\@algocf@procname}{Prozedur}%
974 \renewcommand{\@algocf@funcname}{Funktion}%
975 \renewcommand{\procedureautorefname}{\@algocf@procname}%
976 \renewcommand{\functionautorefname}{\@algocf@funcname}%
977 \renewcommand{\algocf@languagechoosen}{german}%
980 \DeclareOption{ngerman}{%
981 \renewcommand{\listalgorithmcfname}{Liste der Algorithmen}%
982 \renewcommand{\algorithmcfname}{Algorithmus}%
983 \renewcommand{\algorithmautorefname}{\algorithmcfname}%
984 \renewcommand{\algorithmcflinename}{Zeile}%
985 \renewcommand{\algocf@typo}{\ }%
986 \renewcommand{\@algocf@procname}{Prozedur}%
987 \renewcommand{\@algocf@funcname}{Funktion}%
988 \renewcommand{\procedureautorefname}{\@algocf@procname}%
989 \renewcommand{\functionautorefname}{\@algocf@funcname}%
990 \renewcommand{\algocf@languagechoosen}{german}%
993 \DeclareOption{portuguese}{%
994 \renewcommand{\listalgorithmcfname}{Lista de Algoritmos}%
995 \renewcommand{\algorithmcfname}{Algoritmo}%
996 \renewcommand{\algorithmautorefname}{algoritmo}%
997 \renewcommand{\algorithmcflinename}{linha}%
998 \renewcommand{\algocf@typo}{}%
999 \renewcommand{\@algocf@procname}{Procedimento}%
1000 \renewcommand{\@algocf@funcname}{Fun\c{c}\~{a}o}%
1001 \renewcommand{\procedureautorefname}{procedimento}%
1002 \renewcommand{\functionautorefname}{fun\c{c}\~{a}o}%
1003 \renewcommand{\algocf@languagechoosen}{portuguese}%
1006 \DeclareOption{italiano}{%
1007 \renewcommand{\listalgorithmcfname}{Elenco degli algoritmi}%
1008 \renewcommand{\algorithmcfname}{Algoritmo}%
1009 \renewcommand{\algorithmautorefname}{algoritmo}%
1010 \renewcommand{\algorithmcflinename}{riga}%
1011 \renewcommand{\algocf@typo}{}%
1012 \renewcommand{\@algocf@procname}{Procedura}%
1013 \renewcommand{\@algocf@funcname}{Funzione}%
1014 \renewcommand{\procedureautorefname}{procedura}%
1015 \renewcommand{\functionautorefname}{funzione}%
1016 \renewcommand{\algocf@languagechoosen}{italiano}%
1018 \DeclareOption{spanish}{%
1019 \renewcommand{\listalgorithmcfname}{\'Indice de algoritmos}%
1020 \renewcommand{\algorithmcfname}{Algoritmo}%
1021 \renewcommand{\algorithmautorefname}{algoritmo}%
1022 \renewcommand{\algorithmcflinename}{l\'inea}%
1023 \renewcommand{\algocf@typo}{}%
1024 \renewcommand{\@algocf@procname}{Procedimiento}%
1025 \renewcommand{\@algocf@funcname}{Funci\'on}%
1026 \renewcommand{\procedureautorefname}{procedimiento}%
1027 \renewcommand{\functionautorefname}{funci\'on}%
1028 \renewcommand{\algocf@languagechoosen}{spanish}%
1030 \DeclareOption{slovak}{%
1031 \renewcommand{\listalgorithmcfname}{Zoznam algoritmov}%
1032 \renewcommand{\algorithmcfname}{Algoritmus}%
1033 \renewcommand{\algorithmautorefname}{\algorithmcfname}%
1034 \renewcommand{\algorithmcflinename}{Radek}%
1035 \renewcommand{\algocf@typo}{}%
1036 \renewcommand{\@algocf@procname}{Proced\'{u}ra}%
1037 \renewcommand{\@algocf@funcname}{Funkcia}%
1038 \renewcommand{\procedureautorefname}{\@algocf@procname}%
1039 \renewcommand{\functionautorefname}{\@algocf@funcname}%
1040 \renewcommand{\algocf@languagechoosen}{slovak}%
1043 \DeclareOption{croatian}{%
1044 \renewcommand{\listalgorithmcfname}{Popis algoritama}%
1045 \renewcommand{\algorithmcfname}{Algoritam}%
1046 \renewcommand{\algorithmautorefname}{\algorithmcfname}%
1047 \renewcommand{\algorithmcflinename}{linija}%
1048 \renewcommand{\algocf@typo}{}%
1049 \renewcommand{\@algocf@procname}{Procedura}%
1050 \renewcommand{\@algocf@funcname}{Funkcija}%
1051 \renewcommand{\procedureautorefname}{\@algocf@procname}%
1052 \renewcommand{\functionautorefname}{\@algocf@funcname}%
1053 \renewcommand{\algocf@languagechoosen}{croatian}%
1056 % OPTIONs plain, boxed, ruled, algoruled & boxruled
1058 \newcommand{\algocf@style@plain}{\renewcommand{\algocf@style}{plain}}%
1059 \newcommand{\algocf@style@boxed}{\renewcommand{\algocf@style}{boxed}}%
1060 \newcommand{\algocf@style@ruled}{\renewcommand{\algocf@style}{ruled}}%
1061 \newcommand{\algocf@style@algoruled}{\renewcommand{\algocf@style}{algoruled}}%
1062 \newcommand{\algocf@style@boxruled}{\renewcommand{\algocf@style}{boxruled}}%
1063 \newcommand{\algocf@style@tworuled}{\renewcommand{\algocf@style}{tworuled}}%
1064 \newcommand{\algocf@style@plainruled}{\renewcommand{\algocf@style}{plainruled}}%
1065 \newcommand{\RestyleAlgo}[1]{\csname algocf@style@#1\endcsname}%
1066 \DeclareOption{plain}{\algocf@style@plain}%
1067 \DeclareOption{plainruled}{\algocf@style@plainruled}%
1068 \DeclareOption{boxed}{\algocf@style@boxed}%
1069 \DeclareOption{ruled}{\algocf@style@ruled}%
1070 \DeclareOption{algoruled}{\algocf@style@algoruled}%
1071 \DeclareOption{boxruled}{\algocf@style@boxruled}%
1072 \DeclareOption{tworuled}{\algocf@style@tworuled}%
1074 % OPTIONs algopart,algochapter & algosection
1076 \DeclareOption{algopart}{\algocf@numbering{part}}% %algo part numbered
1077 \DeclareOption{algochapter}{\algocf@numbering{chapter}}% %algo chapter numbered
1078 \DeclareOption{algosection}{\algocf@numbering{section}}% %algo section numbered
1080 % OPTIONs resetcount & noresetcount
1082 \DeclareOption{resetcount}{\renewcommand{\@ResetCounterIfNeeded}{\setcounter{AlgoLine}{0}}}%
1083 \DeclareOption{noresetcount}{\renewcommand{\@ResetCounterIfNeeded}{}}%
1085 % OPTION linesnumbered
1087 \newboolean{algocf@linesnumbered}\setboolean{algocf@linesnumbered}{false}%
1088 \newcommand{\algocf@linesnumbered}{\relax}%
1089 \DeclareOption{linesnumbered}{%
1090 \setboolean{algocf@linesnumbered}{true}%
1091 \renewcommand{\algocf@linesnumbered}{\everypar={\nl}}%
1094 % OPTION linesnumberedhidden
1096 \DeclareOption{linesnumberedhidden}{%
1097 \setboolean{algocf@linesnumbered}{true}%
1098 \renewcommand{\algocf@linesnumbered}{\everypar{\stepcounter{AlgoLine}}}%
1101 % OPTION commentsnumbered inoutnumbered
1103 \newboolean{algocf@commentsnumbered}\setboolean{algocf@commentsnumbered}{false}%
1104 \DeclareOption{commentsnumbered}{\setboolean{algocf@commentsnumbered}{true}}%
1105 \newboolean{algocf@inoutnumbered}\setboolean{algocf@inoutnumbered}{false}%
1106 \DeclareOption{inoutnumbered}{\setboolean{algocf@inoutnumbered}{true}}%
1108 % OPTIONs titlenumbered & titlenotnumbered
1110 \DeclareOption{titlenumbered}{%
1111 \renewcommand{\@titleprefix}{%
1112 \refstepcounter{\algocf@float}%
1113 \AlTitleSty{\AlTitleFnt\@algocf@titleofalgoname\ \expandafter\csname the\algocf@float\endcsname\algocf@typo: }%
1117 \DeclareOption{titlenotnumbered}{\renewcommand{\@titleprefix}{%
1118 \AlTitleSty{\AlTitleFnt\@algocf@titleofalgoname\algocf@typo: }}%
1122 % line numbered with the counter of the algorithm
1124 \DeclareOption{algonl}{\renewcommand{\theAlgoLine}{\expandafter\csname the\algocf@float\endcsname.\arabic{AlgoLine}}}%
1126 % OPTIONs lined, vlined & noline
1128 \DeclareOption{lined}{\AtBeginDocument{\SetAlgoLined}}% \SetAlgoLined
1129 \DeclareOption{vlined}{\AtBeginDocument{\SetAlgoVlined}}% \SetAlgoVlined
1130 \DeclareOption{noline}{\AtBeginDocument{\SetAlgoNoLine}}%\SetAlgoNoLine (default)
1132 % OPTIONs longend, shotend & noend
1134 \DeclareOption{longend}{\AtBeginDocument{\SetAlgoLongEnd}}% \SetAlgoLongEnd
1135 \DeclareOption{shortend}{\AtBeginDocument{\SetAlgoShortEnd}}%\SetAlgoShortEnd
1136 \DeclareOption{noend}{\AtBeginDocument{\SetAlgoNoEnd}}% \SetAlgoNoEnd
1138 \DeclareOption{nosemicolon}{\AtBeginDocument{\DontPrintSemicolon}}% \SetAlgoNoEnd
1142 \newboolean{algocf@dotocloa}\setboolean{algocf@dotocloa}{false}%
1143 \DeclareOption{dotocloa}{%
1144 \setboolean{algocf@dotocloa}{true}%
1149 \newboolean{algocf@optfillcomment}\setboolean{algocf@optfillcomment}{true}%
1150 \DeclareOption{nofillcomment}{%
1151 \setboolean{algocf@optfillcomment}{false}%
1153 \DeclareOption{fillcomment}{%
1154 \setboolean{algocf@optfillcomment}{true}%
1157 % OPTION sidecommments
1159 \newboolean{algocf@scleft}\setboolean{algocf@scleft}{false}%
1160 \DeclareOption{scleft}{%
1161 \setboolean{algocf@scleft}{true}%
1163 \DeclareOption{sright}{% default
1164 \setboolean{algocf@scleft}{false}%
1169 \newboolean{algocf@norelsize}\setboolean{algocf@norelsize}{false}%
1170 \DeclareOption{norelsize}{%
1171 \setboolean{algocf@norelsize}{true}%
1175 %%%%%%%%%%%%%%%%%%%%%%% Execution of Options %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1177 \ExecuteOptions{english,plain,resetcount,titlenotnumbered,lined,shortend}%
1181 \@algocf@algotitleofalgo% fix name for \TitleOfAlgo to \algorithmcfname by default
1183 %%%%%%%%%%%%%%%%%%%%%%%%%% Package Loading %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1186 \RequirePackage{xspace}%
1188 \ifthenelse{\boolean{algocf@endfloat}}{%
1189 \RequirePackage{endfloat}%
1192 \ifthenelse{\boolean{algocf@norelsize}}{%
1193 \newcommand{\relsize}[1]{\scriptsize}%
1195 \RequirePackage{relsize}%
1198 \ifthenelse{\boolean{algocf@slide}}{\RequirePackage{color}}{}%
1202 \ifthenelse{\boolean{algocf@dotocloa}}{%
1203 \renewcommand{\listofalgorithms}{\tocfile{\listalgorithmcfname}{loa}}%
1207 % if loa in toc required, load tocbibind package if not already done.
1208 \ifthenelse{\boolean{algocf@dotocloa}}{%
1209 \ifx\@tocextra\undefined%
1210 \RequirePackage{tocbibind}%
1214 %%%%%%%%%%%%%%%%%%%%%%%%%%%%% Main Part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1216 \newcommand{\algocf@name}{algorithm2e}%
1217 \newcommand{\algocf@date}{january 06 2013}%
1218 \newcommand{\algocf@version}{Release 5.0}%
1219 \newcommand{\algocf@id}{\algocf@version\space -- \algocf@date\space --}%
1220 \typeout{********************************************************^^JPackage `\algocf@name'\space\algocf@id^^J%
1221 - algorithm2e-announce@lirmm.fr mailing list for announcement about releases^^J%
1222 - algorithm2e-discussion@lirmm.fr mailing list for discussion about package^^J%
1223 subscribe by emailing sympa@lirmm.fr with 'subscribe <list> <firstname name>'^^J%
1224 - Author: Christophe Fiorio (cfiorio@um2.fr)^^J********************************************************}%
1231 %%%% hyperref compatibility tricks: Hyperref package defines H counters from
1232 % standard counters (i.e \theHpage from \thepage) and check some particular
1233 % counters of some packages, unfortunately it doesn't do the same for
1234 % algorithm2e package but act as Hcounter was defined. To avoid errors we
1235 % defined \theHalgocf ourself
1238 \@ifundefined{theHalgocf}{\def\theHalgocf{\thealgocf}}{}%
1239 \@ifundefined{theHAlgoLine}{\def\theHAlgoLine{\theAlgoLine}}{}%
1240 \@ifundefined{theHalgocfproc}{\def\theHalgocfproc{0}}{}%
1241 \@ifundefined{theHalgocffunc}{\def\theHalgocffunc{0}}{}%
1242 \@ifundefined{toclevel@algocf}{\def\toclevel@algocf{0}}{}%
1244 % autoref from hyperref needs an autorefname, so we give it.
1245 \def\AlgoLineautorefname{\algorithmcflinename}%
1246 \def\algocfautorefname{\algorithmautorefname}%
1247 \def\algocfprocautorefname{\procedureautorefname}%
1248 \def\algocffuncautorefname{\functionautorefname}%
1252 \newcommand{\@defaultskiptotal}{0.5em}%
1253 \newskip\skiptotal\skiptotal=0.5em%
1254 \newskip\skiplinenumber\skiplinenumber=\hsize\advance\skiplinenumber by-\skiptotal%
1258 \newskip\skiplength%
1259 \newskip\algomargin%
1260 \newskip\skipalgocfslide\skipalgocfslide=1em%
1261 \newdimen\algowidth%
1262 \newdimen\inoutsize%
1263 \newdimen\inoutindent%
1264 \newdimen\interspacetitleruled\setlength{\interspacetitleruled}{2pt}%
1265 \newdimen\interspacealgoruled\setlength{\interspacealgoruled}{2pt}%
1266 \newdimen\interspacetitleboxruled\setlength{\interspacetitleboxruled}{2\lineskip}%
1268 \newcommand{\@algoskip}{\smallskip}%
1269 \newcommand{\SetAlgoSkip}[1]{\renewcommand{\@algoskip}{\csname#1\endcsname}}%
1270 \newcommand{\@algoinsideskip}{\relax}%
1271 \newcommand{\SetAlgoInsideSkip}[1]{\renewcommand{\@algoinsideskip}{\csname#1\endcsname}}%
1273 \newsavebox{\algocf@inoutbox}%
1274 \newsavebox{\algocf@inputbox}%
1277 \newcommand{\arg@e}{}%
1278 \newcommand{\arg@space}{\ }%
1279 \newcommand{\BlankLine}{\vskip 1ex}%
1281 \newcommand{\vespace}{1ex}%
1282 \newcommand{\SetInd}[2]{%
1285 \skiplength=\skiptext\advance\skiplength by \skiprule\advance\skiplength by 0.4pt}%
1287 \algomargin=\leftskip\advance\algomargin by \parindent%
1288 \newcommand{\IncMargin}[1]{\advance\algomargin by #1}%
1289 \newcommand{\DecMargin}[1]{\advance\algomargin by -#1}%
1290 \newcommand{\SetNlSkip}[1]{%
1291 \renewcommand{\@defaultskiptotal}{#1}%
1292 \setlength{\skiptotal}{#1}}%
1294 \newskip\AlCapSkip\AlCapSkip=0ex%
1295 \newskip\AlCapHSkip\AlCapSkip=0ex%
1296 \newcommand{\SetAlCapSkip}[1]{\setlength{\AlCapSkip}{#1}}%
1297 \newcommand{\SetAlCapHSkip}[1]{\setlength{\AlCapHSkip}{#1}}%
1298 \SetAlCapHSkip{.5\algomargin}%
1301 \newskip\algoskipindent
1302 \newcommand{\algocf@adjustskipindent}{%
1303 \algoskipindent=\skiprule%
1304 \advance\algoskipindent by \skiptext\advance\algoskipindent by 0.4pt}
1305 \algocf@adjustskipindent%
1307 \newcommand{\Indentp}[1]{\advance\leftskip by #1}%
1308 \newcommand{\Indp}{\algocf@adjustskipindent\advance\leftskip by \algoskipindent}
1309 \newcommand{\Indpp}{\advance\leftskip by 0.5em}%
1310 \newcommand{\Indm}{\algocf@adjustskipindent\advance\leftskip by -\algoskipindent}
1311 \newcommand{\Indmm}{\advance\leftskip by -0.5em}%
1318 \newcommand{\algocf@nlrelsize}{-2}\newcommand{\SetAlgoNlRelativeSize}[1]{\renewcommand{\algocf@nlrelsize}{#1}}%
1319 \newcommand{\NlSty}[1]{\textnormal{\textbf{\relsize{\algocf@nlrelsize}#1}}}% default definition
1320 \newcommand{\SetNlSty}[3]{\renewcommand{\NlSty}[1]{\textnormal{\csname#1\endcsname{\relsize{\algocf@nlrelsize}#2##1#3}}}}%
1324 \newsavebox{\algocf@nlbox}%
1325 \newcommand{\algocf@printnl}[1]{%
1326 \ifthenelse{\boolean{algocf@leftlinenumber}}{%
1327 \skiplinenumber=\skiptotal\advance\skiplinenumber by\leftskip%
1328 \strut\raisebox{0pt}{\llap{\NlSty{#1}\kern\skiplinenumber}}\ignorespaces%
1330 \sbox\algocf@nlbox{\NlSty{#1}}%
1331 \skiplinenumber=\hsize\advance\skiplinenumber by-\leftskip\advance\skiplinenumber by-\skiptext%
1332 \advance\skiplinenumber by\algomargin\advance\skiplinenumber by.3em\advance\skiplinenumber by-\wd\algocf@nlbox%
1333 % to handle particular case of until: printnl is after 'until' keyword has been writen, so we need to substract length of this keyword
1334 \advance\skiplinenumber by-\algocf@skipuntil%
1335 \strut\raisebox{0pt}{\rlap{\kern\skiplinenumber\NlSty{#1\ignorespaces}}}\ignorespaces%
1338 \newcommand{\algocf@nl@sethref}[1]{%
1339 \renewcommand{\theHAlgoLine}{\thealgocfproc.#1}%
1340 \hyper@refstepcounter{AlgoLine}\gdef\@currentlabel{#1}%
1343 \@ifundefined{hyper@refstepcounter}{% if not hyperref then do a simple refstepcounter
1344 \refstepcounter{AlgoLine}%
1345 }{% else if hyperref, do the anchor so 2 lines in two differents algorithms cannot have the same href
1346 \stepcounter{AlgoLine}\algocf@nl@sethref{\theAlgoLine}%
1347 }% now we can do the line numbering
1348 \algocf@printnl{\theAlgoLine}%
1351 \newcommand{\nllabel}[1]{\label{#1}}%
1354 \@ifundefined{hyper@refstepcounte}{% if not hyperref then do a simple refstepcounter
1355 \refstepcounter{AlgoLine}%
1356 }{% else if hyperref, do the anchor so 2 lines in two differents algorithms cannot have the same href
1357 \stepcounter{AlgoLine}\algocf@nl@sethref{\theAlgoLine}%
1358 }% now we can do the line numbering
1359 \skiplinenumber=\hsize\advance\skiplinenumber by-\leftskip%
1360 \strut\raisebox{0pt}{\rlap{\kern\skiplinenumber\strut\NlSty{\theAlgoLine}}}\ignorespaces%
1363 \newcommand{\nlset}[1]{%
1364 \@ifundefined{hyper@refstepcounter}{\protected@edef\@currentlabel{#1}}{\algocf@nl@sethref{#1}}\algocf@printnl{#1}%
1368 \newcommand{\lnl}[1]{\nl\label{#1}\ignorespaces}%
1371 \newcommand{\lnlset}[2]{\nlset{#2}\label{#1}}%
1373 % set char put at end of each line
1375 \newcommand{\algocf@endline}{\string;}
1376 \newcommand{\SetEndCharOfAlgoLine}[1]{\renewcommand{\algocf@endline}{#1}}
1378 % end of line definition
1380 \newcommand{\@endalgocfline}{\algocf@endline}% default definition: printsemicolon
1381 \newcommand{\DontPrintSemicolon}{\renewcommand{\@endalgocfline}{\relax}}%
1382 \newcommand{\PrintSemicolon}{\renewcommand{\@endalgocfline}{\algocf@endline}}%
1383 \newcommand{\@endalgoln}{\@endalgocfline\hfill\strut\par}%
1387 \newcommand{\LinesNumbered}{\setboolean{algocf@linesnumbered}{true}\renewcommand{\algocf@linesnumbered}{\everypar={\nl}}}%
1388 \newcommand{\LinesNotNumbered}{%
1389 \setboolean{algocf@linesnumbered}{false}%
1390 \renewcommand{\algocf@linesnumbered}{\relax}%
1393 \newcommand{\LinesNumberedHidden}{%
1394 \setboolean{algocf@linesnumbered}{true}\renewcommand{\algocf@linesnumbered}{\everypar{\stepcounter{AlgoLine}}}}%
1395 \newcommand{\ShowLn}{\nlset{\theAlgoLine}\ignorespaces}% display the line number on this line (without labelling)
1396 \newcommand{\ShowLnLabel}[1]{\lnlset{#1}{\theAlgoLine}\ignorespaces}% display the line number and label this line
1401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1403 % Styling text commands
1405 \newcommand{\AlFnt}{\relax}% default definition
1406 \newcommand{\SetAlFnt}[1]{\renewcommand{\AlFnt}{#1}}%
1407 \newcommand{\AlTitleFnt}{\relax}% default definition
1408 \newcommand{\SetAlTitleFnt}[1]{\renewcommand{\AlTitleFnt}{#1}}%
1410 \newcommand{\AlCapFnt}{\relax}% default definition
1411 \newcommand{\SetAlCapFnt}[1]{\renewcommand{\AlCapFnt}{#1}}%
1412 \newcommand{\AlCapNameFnt}{\relax}% default definition
1413 \newcommand{\SetAlCapNameFnt}[1]{\renewcommand{\AlCapNameFnt}{#1}}%
1415 \newcommand{\ProcFnt}{\relax}% default definition
1416 \newcommand{\SetProcFnt}[1]{\renewcommand{\ProcFnt}{#1}}%
1417 \newcommand{\ProcNameFnt}{\relax}% default definition
1418 \newcommand{\SetProcNameFnt}[1]{\renewcommand{\ProcNameFnt}{#1}}%
1419 \newcommand{\ProcArgFnt}{\relax}% default definition
1420 \newcommand{\SetProcArgFnt}[1]{\renewcommand{\ProcArgFnt}{#1}}%
1422 \newcommand{\AlTitleSty}[1]{\textbf{#1}\unskip}% default definition
1423 \newcommand{\SetAlTitleSty}[1]{\renewcommand{\AlTitleSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1424 \newcommand{\AlCapSty}[1]{\textnormal{\textbf{#1}}\unskip}% default definition
1425 \newcommand{\SetAlCapSty}[1]{\renewcommand{\AlCapSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1426 \newcommand{\AlCapNameSty}[1]{\textnormal{#1}\unskip}% default definition
1427 \newcommand{\SetAlCapNameSty}[1]{\renewcommand{\AlCapNameSty}[1]{\textnormal{\csname #1\endcsname{##1}}\unskip}}%
1429 \newcommand{\ProcSty}[1]{\AlCapSty{#1}}%
1430 \newcommand{\SetProcSty}[1]{\renewcommand{\ProcSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1431 \newcommand{\ProcNameSty}[1]{\AlCapNameSty{#1}}%
1432 \newcommand{\SetProcNameSty}[1]{\renewcommand{\ProcNameSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1433 \newcommand{\ProcArgSty}[1]{\AlCapNameSty{#1}}%
1434 \newcommand{\SetProcArgSty}[1]{\renewcommand{\ProcArgSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1436 \newcommand{\KwSty}[1]{\textnormal{\textbf{#1}}\unskip}% default definition
1437 \newcommand{\SetKwSty}[1]{\renewcommand{\KwSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1438 \newcommand{\ArgSty}[1]{\textnormal{\emph{#1}}\unskip}%\SetArgSty{emph}
1439 \newcommand{\SetArgSty}[1]{\renewcommand{\ArgSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1440 \newcommand{\FuncSty}[1]{\textnormal{\texttt{#1}}\unskip}%\SetFuncSty{texttt}
1441 \newcommand{\SetFuncSty}[1]{\renewcommand{\FuncSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1442 \newcommand{\DataSty}[1]{\textnormal{\textsf{#1}}\unskip}%%\SetDataSty{textsf}
1443 \newcommand{\SetDataSty}[1]{\renewcommand{\DataSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1444 \newcommand{\CommentSty}[1]{\textnormal{\texttt{#1}}\unskip}%%\SetDataSty{texttt}
1445 \newcommand{\SetCommentSty}[1]{\renewcommand{\CommentSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1446 \newcommand{\TitleSty}[1]{#1\unskip}%\SetTitleSty{}{}
1447 \newcommand{\SetTitleSty}[2]{\renewcommand{\TitleSty}[1]{%
1448 \csname#1\endcsname{\csname#2\endcsname##1}}\unskip}%
1449 \newcommand{\BlockMarkersSty}[1]{\KwSty{#1}}%
1450 \newcommand{\SetBlockMarkersSty}[1]{\renewcommand{\BlockMarkersSty}[1]{\textnormal{\csname#1\endcsname{##1}}\unskip}}%
1453 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1455 % Block basic commands
1457 \newcommand{\algocf@push}[1]{\advance\skiptotal by #1\moveright #1}%
1458 \newcommand{\algocf@pop}[1]{\advance\skiptotal by -#1}%
1459 \newcommand{\algocf@addskiptotal}{\advance\skiptotal by 0.4pt\advance\hsize by -0.4pt\advance\hsize by -\skiplength}% 0.4 pt=width of \vrule
1460 \newcommand{\algocf@subskiptotal}{\advance\skiptotal by -0.4pt\advance\hsize by 0.4pt\advance\hsize by \skiplength}% 0.4 pt=width of \vrule
1462 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1464 %% group of instructions definition
1467 \newcommand{\SetVlineSkip}[1]{\skiphlne=#1}%
1468 \newcommand{\algocf@bblock}{\BlockMarkersSty{begin}}%
1469 \newcommand{\algocf@eblock}{\BlockMarkersSty{end}}%
1470 \newcommand{\AlgoDisplayBlockMarkers}{\setboolean{algocf@displayblockmarkers}{true}}%
1471 \newcommand{\AlgoDontDisplayBlockMarkers}{\setboolean{algocf@displayblockmarkers}{false}}%
1472 \newcommand{\algocf@bblockcode}{%
1473 \ifthenelse{\boolean{algocf@displayblockmarkers}}{\algocf@bblock\par}{\relax}%
1475 \newcommand{\algocf@eblockcode}{%
1476 \ifthenelse{\boolean{algocf@displayblockmarkers}}{\algocf@eblock\par}{\relax}%
1478 \newcommand{\SetAlgoBlockMarkers}[2]{%
1479 \ifArgumentEmpty{#1}{%
1480 \renewcommand{\algocf@bblock}{\relax}%
1482 \renewcommand{\algocf@bblock}{\BlockMarkersSty{#1}}%
1484 \ifArgumentEmpty{#2}{%
1485 \renewcommand{\algocf@eblock}{\relax}%
1487 \renewcommand{\algocf@eblock}{\BlockMarkersSty{#2}}%
1491 %%%%%%%%% block with a vertical line end by a little horizontal line
1492 \newcommand{\algocf@Vline}[1]{% no vskip in between boxes but a strut to separate them,
1493 \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
1494 \algocf@push{\skiprule}% move to the right before the vertical rule
1496 \vtop{\algocf@push{\skiptext}%move the right after the rule
1497 \vtop{\algocf@addskiptotal #1}\Hlne}}\vskip\skiphlne% inside the block
1498 \algocf@pop{\skiprule}%\algocf@subskiptotal% restore indentation
1499 \nointerlineskip}% no vskip after
1501 %%%%%%%%% block with a vertical line
1502 \newcommand{\algocf@Vsline}[1]{% no vskip in between boxes but a strut to separate them,
1503 \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
1505 \algocf@push{\skiprule}% move to the right before the vertical rule
1506 \hbox{\vrule% the vertical rule
1507 \vtop{\algocf@push{\skiptext}%move the right after the rule
1508 \vtop{\algocf@addskiptotal #1}}}% inside the block
1509 \algocf@pop{\skiprule}% restore indentation
1513 \newcommand{\algocf@Hlne}{\hrule height 0.4pt depth 0pt width .5em}%
1515 %%%%%%%%% block without line
1516 \newcommand{\algocf@Noline}[1]{% no vskip in between boxes but a strut to separate them,
1517 \strut\par\nointerlineskip% then interblock space stay the same whatever is inside it
1519 \algocf@push{\skiprule}%
1521 \vtop{\algocf@push{\skiptext}%
1522 \vtop{\algocf@addskiptotal #1}}}% inside the block
1523 \algocf@pop{\skiprule}%
1525 % \nointerlineskip% no vskip after
1531 \newcommand{\algocf@group}[1]{\algocf@Noline{#1}}% group: set of instruction depending from another (ex: then part of the If)
1532 \newcommand{\algocf@@@block}[2]{#1\ifArgumentEmpty{#2}{\relax}{\KwSty{\@algocf@endoption{#2}}\strut\par}}% block: group with a end keyword.
1533 \newcommand{\algocf@@block}[2]{\algocf@@@block{#1}{#2}}% block: group with a end keyword.
1534 \newcommand{\algocf@block}[2]{\algocf@@block{#1}{#2}}% command that will be used and redefined accordingly to noend option
1535 \newcommand{\algocf@setBlock}{%
1536 \ifthenelse{\boolean{algocf@optnoend}}{% if no end option
1537 \renewcommand{\algocf@block}[2]{\algocf@group{##1}}% block will be a group
1539 \renewcommand{\algocf@block}[2]{\algocf@@block{##1}{##2}}% block stays a block
1543 \newcommand{\Hlne}{}% little hrizontal line ending a block in vline mode
1545 \newcommand{\@algocf@endoption}[1]{#1}%
1546 \newboolean{algocf@optnoend}\setboolean{algocf@optnoend}{false}%
1548 \newcommand{\SetAlgoLongEnd}{%%%%%%%%%%%%%%%%%%%%%%%%% Long End
1549 \setboolean{algocf@optnoend}{false}%
1550 \renewcommand{\@algocf@endoption}[1]{##1}%
1553 \newcommand{\SetAlgoShortEnd}{%%%%%%%%%%%%%%%%%%%%%%%% ShortEnd
1554 \setboolean{algocf@optnoend}{false}%
1555 \renewcommand{\@algocf@endoption}[1]{\@firstword##1 \@nil}%
1558 \newcommand{\SetAlgoNoEnd}{%%%%%%%%%%%%%%%%%%%%%%%%%%% NoEnd
1559 \setboolean{algocf@optnoend}{true}%
1560 \renewcommand{\@algocf@endoption}[1]{}%
1563 \newcommand{\SetAlgoNoLine}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Noline
1564 \renewcommand{\algocf@@block}[2]{\algocf@@@block{\algocf@Noline{##1}}{##2}}%
1565 \renewcommand{\algocf@group}[1]{\algocf@Noline{##1}}%
1566 \renewcommand{\Hlne}{}}%
1568 \newcommand{\SetAlgoVlined}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Vline
1569 \renewcommand{\algocf@@block}[2]{\algocf@Vline{##1}}%
1570 \renewcommand{\algocf@group}[1]{\algocf@Vsline{##1}}%\ifthenelse{\boolean{algocf@optnoend}}{\relax}{\strut\ignorespaces}}%
1571 \renewcommand{\Hlne}{\algocf@Hlne}}%
1573 \newcommand{\SetAlgoLined}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Line
1574 \renewcommand{\algocf@@block}[2]{\algocf@@@block{\strut\algocf@Vsline{##1}}{##2}}% no skip after a block so garantie at least one line
1575 \renewcommand{\algocf@group}[1]{\algocf@Vsline{##1}}%\ifthenelse{\boolean{algocf@optnoend}}{\relax}{\strut\ignorespaces}}%
1576 \renewcommand{\Hlne}{}}%
1578 \newcommand{\SetNothing}{%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Noline
1579 \renewcommand{\algocf@@block}[2]{\algocf@Noline{##1}\par}%
1581 \renewcommand{\algocf@group}[1]{\algocf@Noline{##1}}%
1582 \renewcommand{\Hlne}{}}%
1588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1590 % ``Input:'''s like command
1593 % text staying at the right of the longer keyword of KwInOut commands
1594 % (text of KwInOut commands are all vertically aligned)
1596 \newcommand{\algocf@newinout}{\par\parindent=\inoutindent}% to put right indentation after a \\ in the KwInOut
1597 \newcommand{\SetKwInOut}[2]{%
1598 \sbox\algocf@inoutbox{\KwSty{#2}\algocf@typo:}%
1599 \expandafter\ifx\csname InOutSizeDefined\endcsname\relax% if first time used
1600 \newcommand\InOutSizeDefined{}\setlength{\inoutsize}{\wd\algocf@inoutbox}%
1601 \sbox\algocf@inoutbox{\parbox[t]{\inoutsize}{\KwSty{#2}\algocf@typo\hfill:}~}\setlength{\inoutindent}{\wd\algocf@inoutbox}%
1602 \else% else keep the larger dimension
1603 \ifdim\wd\algocf@inoutbox>\inoutsize%
1604 \setlength{\inoutsize}{\wd\algocf@inoutbox}%
1605 \sbox\algocf@inoutbox{\parbox[t]{\inoutsize}{\KwSty{#2}\algocf@typo\hfill:}~}\setlength{\inoutindent}{\wd\algocf@inoutbox}%
1607 \fi% the dimension of the box is now defined.
1608 \algocf@newcommand{#1}[1]{%
1609 \ifthenelse{\boolean{algocf@inoutnumbered}}{\relax}{\everypar={\relax}}%
1610 % {\let\\\algocf@newinout\hangindent=\wd\algocf@inoutbox\hangafter=1\parbox[t]{\inoutsize}{\KwSty{#2}\algocf@typo\hfill:}~##1\par}%
1611 {\let\\\algocf@newinout\hangindent=\inoutindent\hangafter=1\parbox[t]{\inoutsize}{\KwSty{#2}\algocf@typo\hfill:}~##1\par}%
1612 \algocf@linesnumbered% reset the numbering of the lines
1615 %% allow to ajust the skip size of InOut
1617 \newcommand{\ResetInOut}[1]{%
1618 \sbox\algocf@inoutbox{\hbox{\KwSty{#1}\algocf@typo:\ }}%
1619 \setlength{\inoutsize}{\wd\algocf@inoutbox}%
1624 % text staying at the right of the keyword.
1626 \newcommand{\algocf@newinput}{\par\parindent=\wd\algocf@inputbox}% to put right indentation after a \\ in the KwInput
1627 \newcommand{\SetKwInput}[2]{%
1628 \algocf@newcommand{#1}[1]{%
1629 \sbox\algocf@inputbox{\hbox{\KwSty{#2}\algocf@typo: }}%
1630 \ifthenelse{\boolean{algocf@inoutnumbered}}{\relax}{\everypar={\relax}}%
1631 {\let\\\algocf@newinput\hangindent=\wd\algocf@inputbox\hangafter=1\unhbox\algocf@inputbox##1\par}%
1632 \algocf@linesnumbered% reset the numbering of the lines
1634 \newcommand{\SetKwData}[2]{%
1635 \algocf@newcommand{@#1}[1]{\DataSty{#2(}\ArgSty{##1}\DataSty{)}}%
1636 \algocf@newcommand{#1}{%
1637 \@ifnextchar\bgroup{\csname @#1\endcsname}{\DataSty{#2}\xspace}}%
1641 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1644 % Add following macros:
1645 % \SetKwHangingKw: [kw] ------------ <= hanging determined by [kw]
1647 % Should act like a combination of \SetKwInput and \SetKw.
1648 % Based on \SetKwInput:
1649 % - remove ':' at end of keyword
1650 % - do not reset numbering
1651 % - use separate savebox
1652 \newsavebox{\algocf@hangingbox}
1653 \newcommand{\algocf@newhanging}{\par\parindent=\wd\algocf@hangingbox}% to put right indentation after a \\ in the KwInput
1654 \newcommand{\SetKwHangingKw}[2]{%
1655 \algocf@newcommand{#1}[1]{%
1656 \sbox\algocf@hangingbox{\hbox{\KwSty{#2}\algocf@typo\ }}%
1657 {\let\\\algocf@newhanging\hangindent=\wd\algocf@hangingbox\hangafter=1\unhbox\algocf@hangingbox##1\;}%
1662 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1667 % comment in the text, first argument is the name of the macro, second is
1668 % the text put before the comment, third is the text put at the end of the
1671 % first side comment justification
1672 \newcommand{\SetSideCommentLeft}{\setboolean{algocf@scleft}{true}}%
1673 \newcommand{\SetSideCommentRight}{\setboolean{algocf@scleft}{false}}%
1674 \newcommand{\SetNoFillComment}{\setboolean{algocf@optfillcomment}{false}}%
1675 \newcommand{\SetFillComment}{\setboolean{algocf@optfillcomment}{true}}%
1677 % next comment and side comment
1679 \newcommand{\algocf@endmarkcomment}{\relax}%
1680 \newcommand{\algocf@fillcomment}{%
1681 \ifthenelse{\boolean{algocf@optfillcomment}}{\hfill}{\relax}}%
1683 \newcommand{\algocf@startcomment}{%
1684 \hangindent=\wd\algocf@inputbox\hangafter=1\usebox\algocf@inputbox}%
1685 \newcommand{\algocf@endcomment}{\algocf@fillcomment\algocf@endmarkcomment\ignorespaces\par}%
1686 \newcommand{\algocf@endstartcomment}{\algocf@endcomment\algocf@startcomment\ignorespaces}%
1688 \newboolean{algocf@sidecomment}%
1689 \newboolean{algocf@altsidecomment}\setboolean{algocf@altsidecomment}{false}%
1690 \newcommand{\algocf@scpar}{\ifthenelse{\boolean{algocf@altsidecomment}}{\relax}{\par}}%
1691 \newcommand{\algocf@sclfill}{\ifthenelse{\boolean{algocf@scleft}}{\algocf@fillcomment}{\relax}}%
1692 \newcommand{\algocf@scrfill}{\ifthenelse{\boolean{algocf@scleft}}{\relax}{\hfill}}%
1693 \newcommand{\algocf@startsidecomment}{\usebox\algocf@inputbox}%
1694 \newcommand{\algocf@endsidecomment}{\algocf@endmarkcomment\algocf@scpar}%
1695 \newcommand{\algocf@endstartsidecomment}{%
1696 \algocf@sclfill\algocf@endsidecomment%
1697 \algocf@scrfill\algocf@startsidecomment\ignorespaces}%
1699 \newcommand{\SetKwComment}[3]{%
1700 \algocf@newcommand{#1}{\@ifstar{\csname algocf@#1@star\endcsname}{\csname algocf@#1\endcsname}}%
1701 \algocf@newcommand{algocf@#1}[1]{%
1702 \sbox\algocf@inputbox{\CommentSty{\hbox{#2}}}%
1703 \ifthenelse{\boolean{algocf@commentsnumbered}}{\relax}{\everypar={\relax}}%
1704 {\renewcommand{\algocf@endmarkcomment}{#3}%
1705 \let\\\algocf@endstartcomment%
1706 \algocf@startcomment\CommentSty{%
1707 \strut\ignorespaces##1\strut\algocf@fillcomment#3}\par}%
1708 \algocf@linesnumbered% reset the numbering of the lines
1710 %%% side comment definitions
1711 \algocf@newcommand{algocf@#1@star}[2][]{%
1712 \ifArgumentEmpty{##1}\relax{% TODO: Is this even necessary, with all those \ifx's?
1713 \ifthenelse{\boolean{algocf@scleft}}{\setboolean{algocf@sidecomment}{true}}{\setboolean{algocf@sidecomment}{false}}%
1714 \ifx##1h\setboolean{algocf@altsidecomment}{true}\SetSideCommentLeft\fi%
1715 \ifx##1f\setboolean{algocf@altsidecomment}{true}\SetSideCommentRight\fi%
1716 \ifx##1l\setboolean{algocf@altsidecomment}{false}\SetSideCommentLeft\fi%
1717 \ifx##1r\setboolean{algocf@altsidecomment}{false}\SetSideCommentRight\fi%
1719 \sbox\algocf@inputbox{\CommentSty{\hbox{#2}}}%
1720 \ifthenelse{\boolean{algocf@commentsnumbered}}{\relax}{\everypar={\relax}}%
1722 \renewcommand{\algocf@endmarkcomment}{#3}%
1723 \let\\\algocf@endstartsidecomment%
1724 % here is the comment
1725 \ifthenelse{\boolean{algocf@altsidecomment}}{\relax}{\@endalgocfline\ }%
1726 \algocf@scrfill\algocf@startsidecomment\CommentSty{%
1727 \strut\ignorespaces##2\strut\algocf@sclfill#3}\algocf@scpar%
1729 \algocf@linesnumbered% reset the numbering of the lines
1730 \ifArgumentEmpty{##1}\relax{%
1731 \ifthenelse{\boolean{algocf@sidecomment}}{\setboolean{algocf@scleft}{true}}{\setboolean{algocf@scleft}{false}}%
1732 \setboolean{algocf@altsidecomment}{false}%
1737 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1741 \newcommand{\SetKwProg}[4]{%
1742 \algocf@newcmdside{#1} 3{\KwSty{#2}\ifArgumentEmpty{#2}\relax{\ }\ArgSty{##2}\KwSty{#3}\ifArgumentEmpty{##1}\relax{ ##1}\algocf@block{##3}{#4}}%
1743 \algocf@newcmdside{l#1}3{\KwSty{#2} \ArgSty{##2}\KwSty{#3} ##3\@endalgocfline\ifArgumentEmpty{##1}\relax{##1}\strut\par}%
1748 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1752 \newcommand{\SetKw}[2]{%
1753 \algocf@newcommand{@#1}[1]{\KwSty{#2} \ArgSty{##1}}
1754 \algocf@newcommand{#1}{\@ifnextchar\bgroup{\csname @#1\endcsname}{\KwSty{#2}\xspace}}%
1757 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1761 \newcommand{\SetKwFunction}[2]{%
1762 %%% use of gdef since newcommand doesn't manage to define the macro when SetKwFunction is used in \algocf@caption@proc
1763 \expandafter\gdef\csname @#1\endcsname##1{\FuncSty{#2(}\ArgSty{##1}\FuncSty{)}}%
1764 \expandafter\gdef\csname#1\endcsname{%
1765 \@ifnextchar\bgroup{\csname @#1\endcsname}{\FuncSty{#2}\xspace}}%
1769 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1773 \newcommand{\SetKwArray}[2]{%
1774 %%% use of gdef since newcommand doesn't manage to define the macro when SetKwFunction is used in \algocf@caption@proc
1775 \expandafter\gdef\csname @#1\endcsname##1{\DataSty{#2[}\ArgSty{##1}\DataSty{]}}%
1776 \expandafter\gdef\csname#1\endcsname{%
1777 \@ifnextchar\bgroup{\csname @#1\endcsname}{\DataSty{#2}\xspace}}%
1780 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1784 \newcommand{\SetKwBlock}[3]{%
1785 \algocf@newcmdside{#1}{2}
1786 {\KwSty{#2}\ifArgumentEmpty{##1}\relax{ ##1}\algocf@block{##2}{#3}\par}
1789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1793 \newcommand{\algocf@scond}{ }
1794 \newcommand{\algocf@econd}{ }
1795 \newcommand{\algocf@ucond}{}
1796 \newcommand{\SetStartEndCondition}[3]{%
1797 \renewcommand{\algocf@scond}{#1}\renewcommand{\algocf@econd}{#2}\renewcommand{\algocf@ucond}{#3}}
1799 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1803 \newcommand{\SetKwSwitch}[9]{% #1=\Switch #2=\Case #3=\Other #4=switch #5=do #6=case #7=otherwise #8=endcase #9=endsw
1804 \algocf@newcmdside{#1}{3}
1805 {\KwSty{#4}\algocf@scond\ArgSty{##2}\algocf@econd\KwSty{#5}\ifArgumentEmpty{##1}\relax{ ##1}\algocf@block{##3}{#9}}
1807 \algocf@newcmdside{#2}{3}{\KwSty{#6}\algocf@scond\ArgSty{##2}\algocf@ucond\ifArgumentEmpty{##1}\relax{ ##1}\algocf@block{##3}{#8}}%
1808 \algocf@newcmdside{u#2}{3}{\KwSty{#6}\algocf@scond\ArgSty{##2}\algocf@ucond\ifArgumentEmpty{##1}\relax{ ##1}\algocf@group{##3}}%
1809 \algocf@newcmdside{l#2}{3}{\KwSty{#6}\algocf@scond\ArgSty{##2}\algocf@ucond\ ##3\@endalgocfline\ifArgumentEmpty{##1}\relax{ ##1}\strut\par}%
1811 \algocf@newcmdside{#3}{2}{\KwSty{#7}\ifArgumentEmpty{##1}\relax{ ##1}\algocf@block{##2}{#8}}%
1812 \algocf@newcmdside{l#3}{2}{\KwSty{#7}\ ##2\@endalgocfline\ifArgumentEmpty{##1}\relax{ ##1}\strut\par}%
1814 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1818 \newcommand{\SetKwIF}[8]{% #1=\If #2=\ElseIf #3=\Else #4=if #5=then #6=elseif #7=else #8=endif
1821 \algocf@newcommand{#1@ifthen}[1]{\KwSty{#4}\algocf@scond\ArgSty{##1}\algocf@econd\KwSty{#5}}%
1822 \algocf@newcommand{#1@endif} [1]{\algocf@block{##1}{#8}}%
1823 \algocf@newcommand{#1@noend} [1]{\algocf@group{##1}}%
1824 \algocf@newcommand{#1@else} [1]{\algocf@group{##1}\KwSty{#7}}%
1825 \algocf@newcommand{#2@elseif}[1]{\KwSty{#6}\algocf@scond\ArgSty{##1}\algocf@econd\KwSty{#5}}%
1826 \algocf@newcommand{#3@else} {\KwSty{#7}}%
1827 %%%% If then { } endif
1828 \algocf@newcmdside{#1}3{\csname #1@ifthen\endcsname{##2}\ifArgumentEmpty{##1}\relax{ ##1}\csname #1@endif\endcsname{##3}}%
1829 %%%% If then {} else {} endif
1830 % first command to handle optional side comment of else (so just after first braces)
1831 \algocf@newcmdside{algocf@e#1thenelse}2{\ifArgumentEmpty{##1}\relax{ ##1}\csname #1@endif\endcsname{##2}}
1832 % the definition of if-then-else command using command above
1833 \algocf@newcmdside{e#1}3{\csname #1@ifthen\endcsname{##2}\ifArgumentEmpty{##1}\relax{ ##1}\csname #1@else\endcsname{##3}\csname algocf@e#1thenelse\endcsname}%
1835 \algocf@newcmdside{le#1}4{\csname #1@ifthen\endcsname{##2} ##3 \csname #3@else\endcsname\ ##4\@endalgocfline\ifArgumentEmpty{##1}\relax{##1}\strut\par}
1837 \algocf@newcmdside{l#1}3{\csname #1@ifthen\endcsname{##2} ##3\@endalgocfline\ifArgumentEmpty{##1}\relax{##1}\strut\par}%
1838 \algocf@newcmdside{u#1}3{\csname #1@ifthen\endcsname{##2}\ifArgumentEmpty{##1}\relax{ ##1}\csname #1@noend\endcsname{##3}}%
1839 %%%% ElseIf {} endif
1840 \algocf@newcmdside{#2} 3{\csname #2@elseif\endcsname{##2}\relax\ifArgumentEmpty{##1}\relax{ ##1}\csname #1@endif\endcsname{##3}}%
1842 \algocf@newcmdside{l#2}3{\csname #2@elseif\endcsname{##2} ##3\@endalgocfline\ifArgumentEmpty{##1}\relax{##1}\strut\par}%
1843 \algocf@newcmdside{u#2}3{\csname #2@elseif\endcsname{##2}\relax\ifArgumentEmpty{##1}\relax{ ##1}\csname #1@noend\endcsname{##3}}%
1845 \algocf@newcmdside{#3} 2{\csname #3@else\endcsname\ifArgumentEmpty{##1}\relax\ ##1\csname #1@endif\endcsname{##2}}%
1847 \algocf@newcmdside{l#3}2{\csname #3@else\endcsname\ ##2\@endalgocfline\ifArgumentEmpty{##1}\relax{##1}\strut\par}%
1848 \algocf@newcmdside{u#3}2{\csname #3@else\endcsname \ifArgumentEmpty{##1}\relax{\ ##1\relax}\csname #1@noend\endcsname{##2}}%
1851 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1855 \newcommand{\SetKwFor}[4]{%
1856 \algocf@newcmdside{#1} 3{\KwSty{#2}\algocf@scond\ArgSty{##2}\algocf@econd\KwSty{#3}\ifArgumentEmpty{##1}\relax{ ##1}\algocf@block{##3}{#4}}%
1857 \algocf@newcmdside{l#1}3{\KwSty{#2}\algocf@scond\ArgSty{##2}\algocf@econd\KwSty{#3} ##3\@endalgocfline\ifArgumentEmpty{##1}\relax{##1}\strut\par}%
1860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1864 \newsavebox{\algocf@untilbox}% to handle width of until keyword needed to have good skip
1866 \newskip\algocf@skipuntil
1867 \newcommand{\SetKwRepeat}[3]{%
1868 \algocf@newcmdsides{#1}{3}{%
1869 \sbox\algocf@untilbox{\KwSty{#3}\algocf@scond}\algocf@skipuntil=\wd\algocf@untilbox%
1870 \KwSty{#2}\ifArgumentEmpty{##1}\relax{##1}\algocf@group{##3}%
1871 \KwSty{#3}\algocf@scond% until keyword and start condition typo
1872 \advance\skiptotal by\algocf@skipuntil%
1874 \advance\skiptotal by-\algocf@skipuntil%
1876 \algocf@skipuntil=0pt% reset counter
1877 }{\@endalgocfline}{\strut\par}%
1878 \algocf@newcmdside{l#1}3{\KwSty{#2} ##3 \KwSty{#3}\algocf@scond\ArgSty{##2}\algocf@ucond\@endalgocfline\ifArgumentEmpty{##1}\relax{ ##1}\strut\par}%
1883 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1884 %%%%%%%%%%%%%%%%%%%% Environments definitions %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1888 %% Caption management
1890 % for the following macros:
1891 % #1 is given by caption and is equal to fnum@algocf
1892 % #2 is the text given in argument by the user in the \caption macro
1894 %%%%% text of caption
1895 \newcommand{\algocf@captionlayout}[1]{#1}%
1896 \newcommand{\SetAlgoCaptionLayout}[1]{%
1897 \renewcommand{\algocf@captionlayout}[1]{\csname #1\endcsname{##1}}}%
1898 \newcommand{\algocf@capseparator}{:}%
1899 \newcommand{\SetAlgoCaptionSeparator}[1]{\renewcommand{\algocf@capseparator}{#1}}%
1900 \newcommand{\algocf@captiontext}[2]{%
1901 \algocf@captionlayout{\AlCapSty{\AlCapFnt #1\algocf@typo\algocf@capseparator}\nobreakspace%
1902 \AlCapNameSty{\AlCapNameFnt{}#2}}}% text of caption
1904 %%%%% default caption of algorithm: used if no specific style caption is defined
1905 \newcommand{\algocf@makecaption}[2]{%
1906 \addtolength{\hsize}{\algomargin}%
1907 \sbox\@tempboxa{\algocf@captiontext{#1}{#2}}%
1908 \ifdim\wd\@tempboxa >\hsize% % if caption is longer than a line
1909 \hskip .5\algomargin%
1910 \parbox[t]{\hsize}{\algocf@captiontext{#1}{#2}}% then caption is not centered
1912 \global\@minipagefalse%
1913 \hbox to\hsize{\hfil\box\@tempboxa\hfil}% else caption is centered
1915 \addtolength{\hsize}{-\algomargin}%
1918 \newsavebox\algocf@capbox%
1919 \newcommand{\algocf@makecaption@plain}[2]{%
1920 \global\sbox\algocf@capbox{\algocf@makecaption{#1}{#2}}}%
1921 \newcommand{\algocf@makecaption@boxed}[2]{%
1922 \addtolength{\hsize}{-\algomargin}%
1923 \global\sbox\algocf@capbox{\algocf@makecaption{#1}{#2}}%
1924 \addtolength{\hsize}{\algomargin}%
1927 \newcommand{\algocf@makecaption@plainruled}[2]{\algocf@makecaption@plain{#1}{#2}}%
1928 \newcommand{\algocf@makecaption@tworuled}[2]{\algocf@makecaption@ruled{#1}{#2}}%
1929 \newcommand{\algocf@makecaption@algoruled}[2]{\algocf@makecaption@ruled{#1}{#2}}%
1930 \newcommand{\algocf@makecaption@boxruled}[2]{\algocf@makecaption@ruled{#1}{#2}}%
1931 \newcommand{\algocf@makecaption@ruled}[2]{%
1932 \global\sbox\algocf@capbox{\hskip\AlCapHSkip% .5\algomargin%
1933 \parbox[t]{\hsize}{\algocf@captiontext{#1}{#2}}}% then caption is not centered
1936 \newlength{\algoheightruledefault}\setlength{\algoheightruledefault}{0.8pt}%
1937 \newlength{\algoheightrule}\setlength{\algoheightrule}{\algoheightruledefault}%
1938 \newlength{\algotitleheightruledefault}\setlength{\algotitleheightruledefault}{0.8pt}%
1939 \newlength{\algotitleheightrule}\setlength{\algotitleheightrule}{\algotitleheightruledefault}%
1940 \newcommand{\algocf@caption@plain}{\vskip\AlCapSkip\box\algocf@capbox}%
1941 \newcommand{\algocf@caption@plainruled}{\algocf@caption@plain}%
1942 \newcommand{\algocf@caption@boxed}{\vskip\AlCapSkip\box\algocf@capbox}%
1943 \newcommand{\algocf@caption@ruled}{\box\algocf@capbox\kern\interspacetitleruled\hrule height\algotitleheightrule depth0pt\kern\interspacealgoruled}%
1944 \newcommand{\algocf@caption@tworuled}{\box\algocf@capbox\hrule height0pt depth0pt\kern\interspacealgoruled}%
1945 \newcommand{\algocf@caption@algoruled}{\algocf@caption@ruled}%
1946 \newcommand{\algocf@caption@boxruled}{%
1947 \addtolength{\hsize}{-0.8pt}%
1949 \vrule%\hskip-0.35pt%
1951 \hrule\vskip\interspacetitleboxruled%
1952 \hbox to\hsize{\unhbox\algocf@capbox\hfill}\vskip\interspacetitleboxruled%
1957 \addtolength{\hsize}{0.8pt}%
1961 %%%% set caption for the environment
1962 \newcommand{\algocf@captionref}{%
1963 \renewcommand{\fnum@algocf}[1]{\AlCapSty{\AlCapFnt\algorithmcfname\nobreakspace\algocf@algocfref}}%
1964 \addtocounter{algocf}{-1}% \caption do a refstepcounter, so we restore the precedent value
1965 \let\old@thealgocf=\thealgocf\renewcommand{\thealgocf}{{\relsize{\algocf@refrelsize}\algocf@algocfref}}%
1966 \gdef\@currentlabel{\algocf@algocfref}% let the label use the new ref
1969 % Unfortunatly, we also need our own caption to set some specific stuff for special references. But after these
1970 % settings, we call the original caption.
1972 \long\def\algocf@caption@algo#1[#2]#3{%
1973 \ifthenelse{\equal{\algocf@algocfref}{\relax}}{}{\algocf@captionref}%
1974 \@ifundefined{hyper@refstepcounter}{\relax}{% if hyper@refstepcounter undefind, no hyperref, else...
1975 \ifthenelse{\equal{\algocf@algocfref}{\relax}}{\renewcommand{\theHalgocf}{\thealgocf}}{% take algocf as Href
1976 \renewcommand{\theHalgocf}{\algocf@algocfref}}%else if SetAlgoRefName done, take this name as ref.
1977 \hyper@refstepcounter{algocf}%set algocf as category of ref
1979 \algocf@latexcaption{#1}[{#2}]{{#3}}% call original caption
1982 % beamer define is own caption overrinding latex caption!
1983 % as we need it, we have put here the original definition
1984 % to handle manual ref, unfortunately we have to add one line to handle algocf@algocfref
1985 \long\def\algocf@latexcaption#1[#2]#3{% original definition of caption
1987 \addcontentsline{\csname ext@#1\endcsname}{#1}%
1988 {\protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
1995 \@makecaption{\csname fnum@#1\endcsname}{\ignorespaces #3}\par%
1999 % \ifx\beamer@makecaption\undefined%
2000 % \else% beamer detected
2001 \ifx\@makecaption\undefined%
2002 \newcommand{\@makecaption}[2]{\relax}%
2007 % more and more packages redefine \@caption instead of just \@makecaption which makes algorithm2e
2008 % caption not works since based on standard \@caption. So we force the definition of \@caption to be
2009 % the standard one (the one from LaTeX) inside algorithm environment.
2011 % unfortunately, makecaption is called with \ignorespace #3 so
2012 % we can't do the @currentlabel definition inside \algocf@captionproctext
2013 \long\def\algocf@caption@proc#1[#2]#3{%
2014 \ifthenelse{\boolean{algocf@nokwfunc}}{\relax}{%
2015 \SetKwFunction{\algocf@captname#3@}{\algocf@captname#3@}%
2017 % we tell hyperref to use algocfproc as category and to take the appropriate ref.
2018 \ifthenelse{\boolean{algocf@func}}{\def\@proc@func{algocffunc}}{\def\@proc@func{algocfproc}}%
2019 \@ifundefined{hyper@refstepcounter}{\relax}{% if hyper@refstepcounter undefind, no hyperref, else...
2020 \ifthenelse{\boolean{algocf@procnumbered}}{%
2021 \expandafter\def\csname theH\@proc@func\endcsname{\algocf@captname#3@}%if procnumbered, take \thealgocf as ref
2023 \expandafter\def\csname theH\@proc@func\endcsname{\algocf@captname#3@}%else take procedure or function name
2025 \hyper@refstepcounter{\@proc@func}%
2027 \ifthenelse{\boolean{algocf@procnumbered}}{\relax}{%
2028 \addtocounter{algocf}{-1}% \caption do a refstepcounter, so we restore the precedent value
2029 \gdef\@currentlabel{\algocf@captname#3@}% let the label be the name of the function, not the counter
2031 \ifthenelse{\equal{\algocf@captparam#2@}{\arg@e}}{% if no paramater, we remove the ()
2032 \algocf@latexcaption{#1}[\algocf@procname\nobreakspace\algocf@captname#2@]{#3}%
2033 }{% else we give the complete name
2034 \algocf@latexcaption{#1}[\algocf@procname\nobreakspace#2]{#3}%
2039 \newcommand{\algocf@setcaption}{%
2040 \ifthenelse{\boolean{algocf@procenvironment}}{% if proc environment, caption text must be changed
2041 \let\algocf@oldcaptiontext=\algocf@captiontext%
2042 \renewcommand{\algocf@captiontext}[2]{%
2043 \algocf@captionproctext{##1}{##2}%
2046 \let\algocf@savecaption=\@caption%
2047 \ifthenelse{\boolean{algocf@procenvironment}}{\let\@caption=\algocf@caption@proc}{\let\@caption=\algocf@caption@algo}%
2048 \let\algocf@oldmakecaption=\@makecaption%
2049 \renewcommand{\@makecaption}[2]{%
2050 \expandafter\csname algocf@makecaption@\algocf@style\endcsname{##1}{##2}%
2056 % since we have force the LaTeX caption for algorithm environment, we must go back to the caption
2058 \newcommand{\algocf@resetcaption}{%
2059 \ifthenelse{\boolean{algocf@procenvironment}}{% if proc environment
2060 \let\thealgocf=\old@thealgocf% restore normal counter printing
2061 \let\algocf@captiontext=\algocf@oldcaptiontext% restore normal caption text
2063 \let\@caption=\algocf@savecaption% now restore caption outside algo/proc/func environment
2064 \let\@makecaption=\algocf@oldmakecaption% and restore makecaption outside outside algo/proc/func environment
2068 %%%%% nocaptionofalgo and restorecaptionofalgo --
2069 \newcommand{\NoCaptionOfAlgo}{%
2070 \let\@old@algocf@captiontext=\algocf@captiontext%
2071 \renewcommand{\algocf@captiontext}[2]{\AlCapNameSty{\AlCapNameFnt{}##2}}%
2073 \newcommand{\RestoreCaptionOfAlgo}{%
2074 \let\algocf@captiontext=\@old@algocf@captiontext%
2077 % ---------------------- algocf environment
2079 \newcounter{algocfline}% % new counter to make lines numbers be internally
2080 \setcounter{algocfline}{0}% % different in different algorithms
2081 \newcounter{algocfproc}% counter to count all algo environment (proc, func), just used by hyperref to avoir "same
2082 \setcounter{algocfproc}{0}% identifier" error caused by algocf being set to '-' for procedure or function or not
2083 % changed if no caption is given.
2085 \expandafter\ifx\csname algocf@within\endcsname\relax% if \algocf@within doesn't exist
2086 \newcounter{algocf}% % just define a new counter
2087 \renewcommand{\thealgocf}{\@arabic\c@algocf}% and the way it is printed
2089 \newcounter{algocf}[\algocf@within]% % counter is numbered within \algocf@within
2090 \renewcommand\thealgocf{\csname the\algocf@within\endcsname.\@arabic\c@algocf}%
2093 \def\fps@algocf{htbp}% % default
2094 \def\ftype@algocf{10}% % float type
2095 \def\ext@algocf{\algocf@list} % loa by default, lof if figure option used
2096 \newcommand{\fnum@algocf}{\AlCapSty{\AlCapFnt\algorithmcfname\nobreakspace\thealgocf}}%
2097 \newcommand{\algocf@resetfnum}{\renewcommand{\fnum@algocf}{\AlCapSty{\AlCapFnt\algorithmcfname\nobreakspace\thealgocf}}}%
2098 \newenvironment{algocf}% % float environment for algorithms
2101 \newenvironment{algocf*}% % float* environment for algorithms
2102 {\@dblfloat{algocf}}%
2105 \def\algocf@seclistalgo{}%
2106 \ifx\l@chapter\undefined\let\algocf@seclistalgo=\section\else\let\algocf@seclistalgo=\chapter\fi%
2107 \@ifundefined{if@restonecol}{\newif\if@restonecol}\relax%
2108 \newcommand\listofalgocfs{%
2109 \ifx\algocf@seclistalgo\chapter%
2110 \if@twocolumn\@restonecoltrue\onecolumn\else\@restonecolfalse\fi%
2112 \algocf@seclistalgo*{\listalgorithmcfname}%
2113 \@mkboth{\MakeUppercase\listalgorithmcfname}%
2114 {\MakeUppercase\listalgorithmcfname}%
2116 \ifx\algocf@seclistalgo\chapter%
2117 \if@restonecol\twocolumn\fi%
2121 \newcommand*\l@algocf{\@dottedtocline{1}{1em}{2.3em}}% line of the list
2123 % ---------------------- algorithm environment
2127 %% Algorithm environment definition
2132 \newsavebox\algocf@algoframe%
2133 \def\@algocf@pre@plain{\relax}% action to be done before printing the algo.
2134 \def\@algocf@post@plain{\relax}% action to be done after printing the algo.
2135 \def\@algocf@capt@plain{bottom}% where the caption should be localized.
2136 \def\@algocf@pre@boxed{\noindent\begin{lrbox}{\algocf@algoframe}}
2137 \def\@algocf@post@boxed{\end{lrbox}\framebox[\hsize]{\box\algocf@algoframe}\par}%
2138 \def\@algocf@capt@boxed{under}%
2139 \def\@algocf@pre@ruled{\hrule height\algoheightrule depth0pt\kern\interspacetitleruled}%
2140 \def\@algocf@post@ruled{\kern\interspacealgoruled\hrule height\algoheightrule\relax}%
2141 \def\@algocf@capt@ruled{top}%
2142 \def\@algocf@pre@algoruled{\hrule height\algoheightrule depth0pt\kern\interspacetitleruled}%
2143 \def\@algocf@post@algoruled{\kern\interspacealgoruled\hrule height\algoheightrule \relax}%
2144 \def\@algocf@capt@algoruled{top}%
2145 \def\@algocf@pre@tworuled{\hrule height\algoheightrule depth0pt\kern\interspacetitleruled}%
2146 \def\@algocf@post@tworuled{\kern\interspacealgoruled\hrule height\algoheightrule\relax}%
2147 \def\@algocf@capt@tworuled{top}%
2148 \def\@algocf@pre@boxruled{\noindent\begin{lrbox}{\algocf@algoframe}}%
2149 \def\@algocf@post@boxruled{\end{lrbox}\framebox[\hsize]{\box\algocf@algoframe}\par}%
2150 \def\@algocf@capt@boxruled{above}%
2151 \def\@algocf@pre@plainruled{\@algocf@pre@ruled}% action to be done before printing the algo.
2152 \def\@algocf@post@plainruled{\@algocf@post@ruled\kern\interspacealgoruled}% action to be done before printing the algo.
2153 \def\@algocf@capt@plainruled{under}%
2155 \newcommand{\noalgocaption}{\def\@algocf@capt@ruled{none}}
2157 %% before algocf or figure environment
2158 \newcommand{\@algocf@init@caption}{%
2159 \ifthenelse{\boolean{algocf@procenvironment}}{% if we are inside a procedure/function environment
2160 \@algocf@proctitleofalgo% set Titleofalgo to Procedure: or Function:
2161 % accordingly to the environment
2162 \let\old@thealgocf=\thealgocf\ifthenelse{\boolean{algocf@procnumbered}}{\relax}{%
2163 \renewcommand{\thealgocf}{-}}%
2164 }{% else inside environment algorithm
2165 \@algocf@algotitleofalgo% fix name for \Titleofalgo to \algorithmcfname
2167 \algocf@setcaption% set caption to our caption style
2170 \newcommand{\@algofloatboxreset}{\@setminipage}
2171 \newcommand{\@algocf@init}{%
2172 \refstepcounter{algocfline}%
2173 \stepcounter{algocfproc}%to have a different counter for each environment and being abble to make the difference
2174 %between href of algoline in different algorithms.
2175 \ifthenelse{\boolean{algocf@optnoend}}{%
2176 \renewcommand{\algocf@block}[2]{\algocf@group{##1}}%
2178 \renewcommand{\algocf@block}[2]{\algocf@@block{##1}{##2}}%
2181 %% after the end of algocf or figure environment
2182 \newcommand{\@algocf@term@caption}{%
2183 \algocf@resetcaption% restore original caption
2186 \newcommand{\@algocf@term}{%
2187 \setboolean{algocf@algoH}{false}% no H by default
2188 \ifthenelse{\boolean{algocf@optnoend}}{%
2189 \renewcommand{\algocf@block}[2]{\algocf@@block{##1}{##2}}%
2191 \renewcommand{\algocf@block}[2]{\algocf@group{##1}}%
2193 \SetAlgoRefName{\relax}%
2197 %% makethealgo: macro which print effectively the algo in its box
2199 \newsavebox\algocf@algobox%
2200 \newcommand{\algocf@makethealgo}{%
2202 % place caption above if needed bye the style
2203 \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{above}}%
2204 {\csname algocf@caption@\algocf@style\endcsname}{}%
2206 % precommand according to the style
2207 \csname @algocf@pre@\algocf@style\endcsname%
2208 % place caption at top if needed bye the style
2209 \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{top}}%
2210 {\csname algocf@caption@\algocf@style\endcsname}{}%
2212 \box\algocf@algobox% the algo
2213 % place caption at bottom if needed bye the style
2214 \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{bottom}}%
2215 {\csname algocf@caption@\algocf@style\endcsname}{}%
2216 % postcommand according to the style
2217 \csname @algocf@post@\algocf@style\endcsname%
2218 % place caption under if needed bye the style
2219 \ifthenelse{\equal{\csname @algocf@capt@\algocf@style\endcsname}{under}}%
2220 {\csname algocf@caption@\algocf@style\endcsname}{}%
2225 %% at the beginning of algocf or figure environment
2226 \newenvironment{algomathdisplay}{\[}{\@endalgocfline\]\ifthenelse{\boolean{algocf@linesnumbered}}{\nl}{\relax}}%
2227 \newcommand{\@algocf@start}{%
2229 \begin{lrbox}{\algocf@algobox}%
2230 \setlength{\algowidth}{\hsize}%
2231 \vbox\bgroup% save all the algo in a box
2232 \hbox to\algowidth\bgroup\hbox to \algomargin{\hfill}\vtop\bgroup%
2233 \ifthenelse{\boolean{algocf@slide}}{\parskip 0.5ex\color{black}}{}%
2235 \addtolength{\hsize}{-1.5\algomargin}%
2236 \let\@mathsemicolon=\;\def\;{\ifmmode\@mathsemicolon\else\@endalgoln\fi}%
2237 \raggedright\AlFnt{}%
2238 \ifthenelse{\boolean{algocf@slide}}{\IncMargin{\skipalgocfslide}}{}%
2240 % \let\@emathdisplay=\]\def\]{\algocf@endline\@emathdisplay\nl}%
2243 %% at the end of algocf or figure environment
2244 \newcommand{\@algocf@finish}{%
2246 \egroup%end of vtop which contain all the text
2247 \hfill\egroup%end of hbox wich contains [margin][vtop]
2248 \ifthenelse{\boolean{algocf@slide}}{\DecMargin{\skipalgocfslide}}{}%
2250 \egroup%end of main vbox
2252 \algocf@makethealgo% print the algo
2254 % restore dimension and macros
2255 \setlength{\hsize}{\algowidth}%
2256 \lineskip\normallineskip\setlength{\skiptotal}{\@defaultskiptotal}%
2257 \let\;=\@mathsemicolon%
2258 \let\]=\@emathdisplay%
2261 %%%%%%%%%%%%%%%%%%%%
2262 %% basic definition of the environment algorithm
2265 \newboolean{algocf@procenvironment}\setboolean{algocf@procenvironment}{false}%
2266 \newboolean{algocf@func}\setboolean{algocf@func}{false}%
2267 \newboolean{algocf@algoH}\setboolean{algocf@algoH}{false}%
2268 \newboolean{algocf@algostar}\setboolean{algocf@algostar}{false}%
2270 %%% environment for {algorithm}[H]
2271 \newenvironment{algocf@Here}{\noindent%
2272 \def\@captype{algocf}% if not defined, caption exit with an error
2273 \begin{minipage}{\hsize}%
2275 \end{minipage}%\par%
2277 %%% real algorithm environment which manages H and * option
2278 % \let\algocf@originalfloatboxreset=\@floatboxreset%
2279 % \let\@floatboxreset=\@algofloatboxreset%
2280 \newenvironment{algocf@algorithm}[1][htbp]{
2282 \ifthenelse{\equal{\algocf@float}{figure}}{% if option figure set
2283 \ifthenelse{\boolean{algocf@algostar}}{% if algorithm* with figure option
2284 \begin{figure*}[#1]% call figure*
2285 }{% else algorithm environment with figure option
2286 \begin{figure}[#1]% call figure
2288 }{% else normal algorithm environment
2289 \@algocf@init@caption%
2290 \ifthenelse{\equal{#1}{H}}{% if [H] algorithm
2291 \if@twocolumn\@latex@error{[H] in two columns mode is not allowed for algorithms}\fi% TODO: SCREAM if H in two colums!
2292 \setboolean{algocf@algoH}{true}\begin{algocf@Here}% call corresponding environment
2293 }{% else floating algorithm environment
2294 \ifthenelse{\boolean{algocf@algostar}}{% if algorithm*
2295 \begin{algocf*}[#1]% call algocf*
2296 }{% else algorithm environment
2297 \begin{algocf}[#1]% call algcf
2300 }% fin test option figure ou pas
2302 \@ResetCounterIfNeeded%
2303 \algocf@linesnumbered\ignorespaces%
2306 \ifthenelse{\equal{\algocf@float}{figure}}{%
2307 \ifthenelse{\boolean{algocf@algostar}}{% if algorithm* with figure option
2308 \end{figure*}% call figure*
2309 }{% else algorithm environment with figure option
2310 \end{figure}% call figure
2313 \@algocf@term@caption%
2314 \ifthenelse{\boolean{algocf@algoH}}{% if [H] algorithm
2315 \end{algocf@Here}\par% call corresponding environment
2316 }{% else floating algorithm environment
2317 \ifthenelse{\boolean{algocf@algostar}}{% if algorithm*
2318 \end{algocf*}% call algocf*
2319 }{% else algorithm environment
2320 \end{algocf}% call algocf
2324 \@algocf@term\ignorespacesafterend%
2327 %%% user algorithm environment
2328 \newenvironment{\algocf@envname}[1][htbp]{%
2329 \setboolean{algocf@algostar}{false}%
2330 \setboolean{algocf@procenvironment}{false}\gdef\algocfautorefname{\algorithmautorefname}%
2331 \begin{algocf@algorithm}[#1]\ignorespaces%
2333 \end{algocf@algorithm}\ignorespacesafterend%
2335 %%% user algorithm* environment
2336 \newenvironment{\algocf@envname*}[1][htbp]{%
2337 \setboolean{algocf@algostar}{true}%
2338 \setboolean{algocf@procenvironment}{false}\gdef\algocfautorefname{\algorithmautorefname}%
2339 \begin{algocf@algorithm}[#1]\ignorespaces%
2341 \end{algocf@algorithm}\ignorespacesafterend%
2344 %%%%%%%%%%%%%%%%%%%%%%%
2347 \expandafter\newcommand\csname\algocf@listofalgorithms\endcsname{%
2348 \ifthenelse{\equal{\algocf@float}{figure}}{\listoffigures}{\listofalgocfs}%
2353 % ---------------------- procedure and function environments
2356 % -- new style (used in particular in the caption of function and procedure environments)
2358 % three macros to extract parts of the caption
2359 \gdef\algocf@captname#1(#2)#3@{#1} % keep characters before the first brace
2360 \gdef\algocf@captparam#1(#2)#3@{#2} % keep character in between the braces
2361 \gdef\algocf@captother#1(#2)#3@{#3} % keep character after the braces
2363 %%% Text of caption for Procedure or Function
2364 \newcommand{\algocf@captionproctext}[2]{%
2366 \ProcSty{\ProcFnt\algocf@procname\ifthenelse{\boolean{algocf@procnumbered}}{\nobreakspace\thealgocf\algocf@typo\algocf@capseparator}{\relax}}%
2367 \nobreakspace\ProcNameSty{\ProcNameFnt\algocf@captname #2@}% Name of the procedure in ProcName Style.
2368 \ifthenelse{\equal{\algocf@captparam #2@}{\arg@e}}{}{% if no argument, write nothing
2369 \ProcNameSty{\ProcNameFnt(}\ProcArgSty{\ProcArgFnt\algocf@captparam #2@}\ProcNameSty{\ProcNameFnt)}%else put arguments in ProcArgSty:
2371 \algocf@captother #2@%
2376 % -- procedure and function environments are defined from algocf@algorithm environment
2378 \newenvironment{procedure}[1][htbp]{%
2379 \setboolean{algocf@algostar}{false}%
2380 \setboolean{algocf@procenvironment}{true}\setboolean{algocf@func}{false}%
2381 \newcommand{\algocf@procname}{\@algocf@procname}\gdef\algocfprocautorefname{\procedureautorefname}%
2382 \begin{algocf@algorithm}[#1]\ignorespaces%
2384 \end{algocf@algorithm}\ignorespacesafterend%
2386 \newenvironment{function}[1][htbp]{%
2387 \setboolean{algocf@algostar}{false}%
2388 \setboolean{algocf@procenvironment}{true}\setboolean{algocf@func}{true}%
2389 \newcommand{\algocf@procname}{\@algocf@funcname}\gdef\algocffuncautorefname{\functionautorefname}%
2390 \begin{algocf@algorithm}[#1]\ignorespaces%
2392 \end{algocf@algorithm}\ignorespacesafterend%
2395 \newenvironment{procedure*}[1][htbp]{%
2396 \setboolean{algocf@algostar}{true}%
2397 \setboolean{algocf@procenvironment}{true}\setboolean{algocf@func}{false}%
2398 \newcommand{\algocf@procname}{\@algocf@procname}\gdef\algocfprocautorefname{\procedureautorefname}%
2399 \begin{algocf@algorithm}[#1]\ignorespaces%
2401 \end{algocf@algorithm}\ignorespacesafterend%
2403 \newenvironment{function*}[1][htbp]{%
2404 \setboolean{algocf@algostar}{true}%
2405 \setboolean{algocf@procenvironment}{true}\setboolean{algocf@func}{true}%
2406 \newcommand{\algocf@procname}{\@algocf@funcname}\gdef\algocffuncautorefname{\functionautorefname}%
2407 \begin{algocf@algorithm}[#1]\ignorespaces%
2409 \end{algocf@algorithm}\ignorespacesafterend%
2413 %%%%%%%%%%%%%%%%%%%%
2414 %% definition of algondfloat environment
2416 \ifthenelse{\boolean{algocf@endfloat}}{% if endfloat option then
2417 \newcommand{\algoplace}{% macro which is used to writhe algorithm about there
2419 [\algorithmcfname~\thepostfig\ about here.]%
2422 \newcommand{\algoendfloat}{% use as a \begin{algoendfloat} environment to start scanning of line
2423 % \immediate\openout\@mainfff\jobname.fff%
2424 \efloat@condopen{fff}
2425 \efloat@iwrite{fff}{\string\begin{\algocf@envname}}%
2427 \ifthenelse{\equal{\algocf@list}{lof}}{%
2428 \addtocounter{postfig}{1}%
2430 \addtocounter{postalgo}{1}%
2435 \let\do\ef@makeinnocent\dospecials%
2436 \ef@makeinnocent\^^L% and whatever other special cases
2437 \endlinechar`\^^M \catcode`\^^M=12 \ef@xalgocfendfloat}%
2438 }{\relax}%%%% end of endfloat option ifthenelse
2439 %% some macros useful for endfloat option that cannot be defined inside the ifthenelse
2440 %scan algoendfloat algorithm and write the text into .fff file
2441 {\catcode`\^^M=12 \endlinechar=-1 %
2442 \gdef\ef@xalgocfendfloat#1^^M{% scan the lines inside algoendfloat environment being read by latex
2443 \def\test{#1}% test is the line being currently scan by latex
2444 \ifx\test\ef@endalgocftest% if it is \end{algoendfloat}
2445 \def\next{% define next as to not continue the scan and write \end{algorithm} into .fff file
2446 \egroup\end{algoendfloat}%
2447 \efloat@iwrite{fff}{\string\end{\algocf@envname}}%
2448 \efloat@iwrite{fff}{\string\efloatseparator}%
2449 \efloat@iwrite{fff}{ }%
2451 \else% else write the current line being scanned by latex and set next to continue the scan
2452 \efloat@iwrite{fff}{#1}%
2453 \let\next\ef@xalgocfendfloat%
2455 \next}% next is continue if it was else condition, else it does not continue the scan and write end to file
2457 % test if the scan is finish by looking at the string \end{algoendfloat}
2459 \xdef\ef@endalgocftest{\string\\end\string\{algoendfloat\string\}}%
2463 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2466 \newcommand{\TitleOfAlgo}[1]{\@titleprefix\
2467 \TitleSty{#1}\par\smallskip}%
2469 \newcommand{\SetAlgorithmName}[3]{%
2470 \renewcommand{\listalgorithmcfname}{#3}%
2471 \renewcommand{\algorithmcfname}{#1}%
2472 \renewcommand{\algorithmautorefname}{#2}%
2475 \newcommand{\algocf@refrelsize}{-2}\newcommand{\SetAlgoRefRelativeSize}[1]{\renewcommand{\algocf@refrelsize}{#1}}%
2476 \newcommand{\SetAlgoRefName}[1]{%
2477 \renewcommand{\algocf@algocfref}{#1}%
2482 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2485 % ------------------------- Default Definitions
2490 \SetKwComment{tcc}{/* }{ */}%
2491 \SetKwComment{tcp}{// }{}%
2493 %\newcommand{\algocf@defaults@common}{
2498 %\SetKwInOut{AlgDonnees}{Donn\'ees}\SetKwInOut{AlgRes}{R\'esultat}
2499 \SetKwHangingKw{HDonnees}{Donnees$\rightarrow$}
2500 \SetKwInput{Donnees}{Donn\'ees}%
2501 \SetKwInput{Res}{R\'esultat}%
2502 \SetKwInput{Entree}{Entr\'ees}%
2503 \SetKwInput{Sortie}{Sorties}%
2505 \SetKw{Retour}{retourner}%
2506 \SetKwBlock{Deb}{d\'ebut}{fin}%
2507 \SetKwRepeat{Repeter}{r\'ep\'eter}{jusqu'\`a}%
2509 \SetKwIF{Si}{SinonSi}{Sinon}{si}{alors}{sinon si}{sinon}{fin si}%
2510 \SetKwSwitch{Suivant}{Cas}{Autre}{suivant}{faire}{cas o\`u}{autres cas}{fin cas}{fin d'alternative}%
2511 \SetKwFor{Pour}{pour}{faire}{fin pour}%
2512 \SetKwFor{PourPar}{pour}{faire en parall\`ele}{fin pour}%
2513 \SetKwFor{PourCh}{pour chaque}{faire}{fin pour chaque}%
2514 \SetKwFor{PourTous}{pour tous les}{faire}{fin pour tous}%
2515 \SetKwFor{Tq}{tant que}{faire}{fin tq}%
2519 \SetKwHangingKw{KwHData}{Data$\rightarrow$}
2520 \SetKwInput{KwIn}{Input}%
2521 \SetKwInput{KwOut}{Output}%
2522 \SetKwInput{KwData}{Data}%
2523 \SetKwInput{KwResult}{Result}%
2525 \SetKw{KwRet}{return}%
2526 \SetKw{Return}{return}%
2527 \SetKwBlock{Begin}{begin}{end}%
2528 \SetKwRepeat{Repeat}{repeat}{until}%
2530 \SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{end if}%
2531 \SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{end case}{end switch}%
2532 \SetKwFor{For}{for}{do}{end for}%
2533 \SetKwFor{ForPar}{for}{do in parallel}{end forpar}
2534 \SetKwFor{ForEach}{foreach}{do}{end foreach}%
2535 \SetKwFor{ForAll}{forall the}{do}{end forall}%
2536 \SetKwFor{While}{while}{do}{end while}%
2538 % --- German keywords
2540 \SetKwInput{Ein}{Eingabe}%KwIn
2541 \SetKwInput{Aus}{Ausgabe}%KwOut
2542 \SetKwInput{Daten}{Daten}%KwData
2543 \SetKwInput{Ergebnis}{Ergebnis}%KwResult
2544 \SetKw{Bis}{bis}%KwTo
2545 \SetKw{KwZurueck}{zur\"uck}%KwRet
2546 \SetKw{Zurueck}{zur\"uck}%Return
2547 \SetKwBlock{Beginn}{Beginn}{Ende}%Begin
2548 \SetKwRepeat{Wiederh}{wiederhole}{bis}%Repeat
2550 \SetKwIF{Wenn}{SonstWenn}{Sonst}{wenn}{dann}{sonst wenn}{sonst}{Ende wenn}%gIf
2551 \SetKwSwitch{Unterscheide}{Fall}{Anderes}{unterscheide}{tue}{Fall}{sonst}{Ende Fall}{Ende Unt.}%Switch
2552 \SetKwFor{Fuer}{f\"ur}{tue}{Ende f\"ur}%For
2553 \SetKwFor{FuerPar}{f\"ur}{tue gleichzeitig}{Ende gleichzeitig}%ForPar
2554 \SetKwFor{FuerJedes}{f\"ur jedes}{tue}{Ende f\"ur}%ForEach
2555 \SetKwFor{FuerAlle}{f\"ur alle}{tue}{Ende f\"ur}%ForAll
2556 \SetKwFor{Solange}{solange}{tue}{Ende solange}%While
2558 % --- Czech keywords
2560 \SetKwInput{Vst}{Vstup}%
2561 \SetKwInput{Vyst}{V\'{y}stup}%
2562 \SetKwInput{Vysl}{V\'{y}sledek}%
2564 % --- Portuguese keywords
2566 \SetKwInput{Entrada}{Entrada}%
2567 \SetKwInput{Saida}{Sa\'{i}da}%
2568 \SetKwInput{Dados}{Dados}%
2569 \SetKwInput{Resultado}{Resultado}%
2570 \SetKw{Ate}{at\'{e}}
2571 \SetKw{KwRetorna}{retorna}%
2572 \SetKw{Retorna}{retorna}%
2573 \SetKwBlock{Inicio}{in\'{i}cio}{fim}%
2574 \SetKwRepeat{Repita}{repita}{at\'{e}}%
2576 \SetKwIF{Se}{SenaoSe}{Senao}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{fim se}%
2577 \SetKwSwitch{Selec}{Caso}{Outro}{selecione}{fa\c{c}a}{caso}{sen\~{a}o}{fim caso}{fim selec}%
2578 \SetKwFor{Para}{para}{fa\c{c}a}{fim para}%
2579 \SetKwFor{ParaPar}{para}{fa\c{c}a em paralelo}{fim para}
2580 \SetKwFor{ParaCada}{para cada}{fa\c{c}a}{fim para cada}%
2581 \SetKwFor{ParaTodo}{para todo}{fa\c{c}a}{fim para todo}%
2582 \SetKwFor{Enqto}{enquanto}{fa\c{c}a}{fim enqto}%
2584 % --- Italian keywords
2586 \SetKwInput{KwIng}{Ingresso}%
2587 \SetKwInput{KwUsc}{Uscita}%
2588 \SetKwInput{KwDati}{Dati}%
2589 \SetKwInput{KwRisult}{Risultato}%
2591 \SetKw{KwRitorna}{ritorna}%
2592 \SetKw{Ritorna}{ritorna}%
2593 \SetKwBlock{Inizio}{inizio}{fine}%
2594 \SetKwRepeat{Ripeti}{ripeti}{finch\'e}%
2596 \SetKwIF{Sea}{AltSe}{Altrimenti}{se}{allora}{altrimenti se}{allora}{fine se}%
2597 \SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{end case}{endsw}%
2598 \SetKwFor{Per}{per}{fai}{fine per}%
2599 \SetKwFor{PerPar}{per}{fai in parallelo}{fine per}%
2600 \SetKwFor{PerCiascun}{per ciascun}{fai}{fine per ciascun}%
2601 \SetKwFor{PerTutti}{per tutti i}{fai}{fine per tutti}%
2602 \SetKwFor{Finche}{finch\'e}{fai}{fine finch\'e}%
2604 % --- Spanish keywords
2606 \SetKwInput{Datos}{Datos}
2607 \SetKwInput{Resultado}{Resultado}
2608 \SetKwInput{Entrada}{Entrada}
2609 \SetKwInput{Salida}{Salida}
2611 \SetKw{KwDevolver}{devolver}
2612 \SetKw{Devolver}{devolver}
2613 \SetKwBlock{Inicio}{inicio}{fin}
2614 \SetKwIF{SSi}{EnOtroCasoSi}{EnOtroCaso}{si}{entonces}{sin\'o, si}{sin\'o}{fin si}
2615 \SetKwSwitch{Seleccionar}{Caso}{Otro}{seleccionar}{hacer}{caso}{sin\'o}{fin caso}{fin seleccionar}
2616 \SetKwFor{Para}{para}{hacer}{fin para}
2617 \SetKwFor{ParaPara}{par}{hacer en paralelo}{fin para}
2618 \SetKwFor{EnParalelo}{para}{hacer en paralelo}{fin para}
2619 \SetKwFor{Mientras}{mientras}{hacer}{fin mientras}
2620 \SetKwFor{ParaCada}{para cada}{hacer}{fin para cada}
2621 \SetKwFor{ParaTodo}{para todo}{hacer}{fin para todo}
2622 \SetKwRepeat{Repetir}{repetir}{hasta que}
2626 \SetKwInput{KwUlaz}{Ulaz}%KwIn
2627 \SetKwInput{KwIzlaz}{Izlaz}%KwOut
2628 \SetKwInput{KwPodaci}{Podaci}%KwData
2629 \SetKwInput{KwRezultat}{Rezultat}%KwResult
2630 \SetKw{KwDo}{do}%KwTo
2631 \SetKw{KwVrati}{vrati}%KwRet
2632 \SetKw{Vrati}{vrati}%Return
2633 \SetKwBlock{Pocetak}{po\v{c}etak}{kraj}%Begin
2634 \SetKwRepeat{Ponavljaj}{ponavljaj}{dok ne bude}%Repeat
2636 \SetKwIF{Ako}{InaceAko}{Inace}{ako}{onda}{ina\v{c}e ako}{ina\v{c}e}{kraj}%gIf
2637 \SetKwSwitch{Granaj}{Slucaj}{Inace}{granaj}{\v{c}ini}{slu\v{c}aj}{ina\v{c}e}{kraj}{kraj}%Switch
2638 \SetKwFor{Za}{za}{\v{c}ini}{kraj}%For
2639 \SetKwFor{ZaPar}{za}{izvr\v{s}avaj paralelno}{kraj}%ForPar
2640 \SetKwFor{ZaSvaki}{za svaki}{\v{c}ini}{kraj}%mForEach
2641 \SetKwFor{ZaSvaku}{za svaku}{\v{c}ini}{kraj}%fForEach
2642 \SetKwFor{ZaSvako}{za svako}{\v{c}ini}{kraj}%nForEach
2643 \SetKwFor{ZaSve}{za sve}{\v{c}ini}{kraj}%ForAll
2644 \SetKwFor{Dok}{dok}{\v{c}ini}{kraj}%While
2649 %\algocf@defaults@common
2651 % option onelanguage redefinition
2653 \ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{french}}{%
2654 \SetKwInput{KwIn}{Entr\'ees}%
2655 \SetKwInput{KwOutSortie}{Sorties}%
2656 \SetKwInput{KwData}{Donn\'ees}%
2657 \SetKwInput{KwResult}{R\'esultat}%
2659 \SetKw{KwRet}{retourner}%
2660 \SetKw{Return}{retourner}%
2661 \SetKwBlock{Begin}{d\'ebut}{fin}%
2662 \SetKwRepeat{Repeat}{r\'ep\'eter}{jusqu'\`a}%
2664 \SetKwIF{If}{ElseIf}{Else}{si}{alors}{sinon si}{sinon}{fin si}%
2665 \SetKwSwitch{Switch}{Case}{Other}{suivant}{faire}{cas o\`u}{autres cas}{fin cas}{fin d'alternative}%
2666 \SetKwFor{For}{pour}{faire}{fin pour}%
2667 \SetKwFor{ForPar}{pour}{faire en parall\`ele}{fin pour}%
2668 \SetKwFor{ForEach}{pour chaque}{faire}{fin pour chaque}%
2669 \SetKwFor{ForAll}{pour tous les}{faire}{fin pour tous}%
2670 \SetKwFor{While}{tant que}{faire}{fin tq}%
2672 \ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{german}}{%
2673 \SetKwInput{KwIn}{Eingabe}%KwIn
2674 \SetKwInput{KwOut}{Ausgabe}%KwOut
2675 \SetKwInput{KwData}{Daten}%KwData
2676 \SetKwInput{KwResult}{Ergebnis}%KwResult
2677 \SetKw{KwTo}{bis}%KwTo
2678 \SetKw{KwRet}{zur\"uck}%KwRet
2679 \SetKw{Return}{zur\"uck}%Return
2680 \SetKwBlock{Begin}{Beginn}{Ende}%Begin
2681 \SetKwRepeat{Repeat}{wiederhole}{bis}%Repeat
2683 \SetKwIF{If}{ElseIf}{Else}{wenn}{dann}{sonst wenn}{sonst}{Ende wenn}%gIf
2684 \SetKwSwitch{Switch}{Case}{Other}{unterscheide}{tue}{Fall}{sonst}{Ende Fall}{Ende Unt.}%Switch
2685 \SetKwFor{For}{f\"ur}{tue}{Ende f\"ur}%For
2686 \SetKwFor{ForPar}{f\"ur}{tue gleichzeitig}{Ende gleichzeitig}%ForPar
2687 \SetKwFor{ForEach}{f\"ur jedes}{tue}{Ende f\"ur}%ForEach
2688 \SetKwFor{ForAll}{f\"ur alle}{tue}{Ende f\"ur}%ForAll
2689 \SetKwFor{While}{solange}{tue}{Ende solange}%While
2691 \ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{portuguese}}{%
2692 \SetKwInput{KwIn}{Entrada}%
2693 \SetKwInput{KwOut}{Sa\'{i}da}%
2694 \SetKwInput{KwData}{Dados}%
2695 \SetKwInput{KwResult}{Resultado}%
2696 \SetKw{KwTo}{at\'{e}}
2697 \SetKw{KwRet}{retorna}%
2698 \SetKw{Return}{retorna}%
2699 \SetKwBlock{Begin}{in\'{i}cio}{fim}%
2700 \SetKwRepeat{Repeat}{repita}{at\'{e}}%
2702 \SetKwIF{If}{ElseIf}{Else}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{fim se}%
2703 \SetKwSwitch{Switch}{Case}{Other}{selecione}{fa\c{c}a}{caso}{sen\~{a}o}{fim caso}{fim selec}%
2704 \SetKwFor{For}{para}{fa\c{c}a}{fim para}%
2705 \SetKwFor{ForPar}{para}{fa\c{c}a em paralelo}{fim para}
2706 \SetKwFor{ForEach}{para cada}{fa\c{c}a}{fim para cada}%
2707 \SetKwFor{ForAll}{para todo}{fa\c{c}a}{fim para todo}%
2708 \SetKwFor{While}{enquanto}{fa\c{c}a}{fim enqto}%
2710 \ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{italiano}}{%
2711 \SetKwInput{KwIn}{Ingresso}%
2712 \SetKwInput{KwOut}{Uscita}%
2713 \SetKwInput{KwData}{Dati}%
2714 \SetKwInput{KwResult}{Risultato}%
2716 \SetKw{KwRet}{ritorna}%
2717 \SetKw{Return}{ritorna}%
2718 \SetKwBlock{Begin}{inizio}{fine}%
2719 \SetKwRepeat{Repeat}{ripeti}{finch\'e}%
2721 \SetKwIF{If}{ElseIf}{Else}{se}{allora}{altrimenti se}{allora}{fine se}%
2722 \SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{end case}{endsw}%
2723 \SetKwFor{For}{per}{fai}{fine per}%
2724 \SetKwFor{ForPar}{per}{fai in parallelo}{fine per}%
2725 \SetKwFor{ForEach}{per ciascun}{fai}{fine per ciascun}%
2726 \SetKwFor{ForAll}{per tutti i}{fai}{fine per tutti}%
2727 \SetKwFor{While}{finch\'e}{fai}{fine finch\'e}%
2729 \ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{spanish}}{%
2730 \SetKwInput{KwIn}{Entrada}%
2731 \SetKwInput{KwOut}{Salida}%
2732 \SetKwInput{KwData}{Datos}%
2733 \SetKwInput{KwResult}{Resultado}%
2735 \SetKw{KwRet}{devolver}%
2736 \SetKw{Return}{devolver}%
2737 \SetKwBlock{Begin}{inicio}{fin}%
2738 \SetKwRepeat{Repeat}{repetir}{hasta que}%
2740 \SetKwIF{If}{ElseIf}{Else}{si}{entonces}{sin\'o, si}{en otro caso}{fin si}
2741 \SetKwSwitch{Switch}{Case}{Other}{seleccionar}{hacer}{caso}{sin\'o}{fin caso}{fin seleccionar}
2742 \SetKwFor{For}{per}{fai}{fine per}%
2743 \SetKwFor{ForPar}{par}{hacer in paralelo}{fin para}%
2744 \SetKwFor{ForEach}{para cada}{hacer}{fin para cada}
2745 \SetKwFor{ForAll}{para todo}{hacer}{fin para todo}
2746 \SetKwFor{While}{mientras}{hacer}{fin mientras}
2749 \ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{croatian}}{%
2750 \SetKwInput{KwIn}{Ulaz}%KwIn
2751 \SetKwInput{KwOut}{Izlaz}%KwOut
2752 \SetKwInput{KwData}{Podaci}%KwData
2753 \SetKwInput{KwResult}{Rezultat}%KwResult
2754 \SetKw{KwTo}{do}%KwTo
2755 \SetKw{KwRet}{vrati}%KwRet
2756 \SetKw{Return}{vrati}%Return
2757 \SetKwBlock{Begin}{po\v{c}etak}{kraj}%Begin
2758 \SetKwRepeat{Repeat}{ponavljaj}{dok ne bude}%Repeat
2760 \SetKwIF{If}{ElseIf}{Else}{ako}{onda}{ina\v{c}e ako}{ina\v{c}e}{kraj}%gIf
2761 \SetKwSwitch{Switch}{Case}{Other}{granaj}{\v{c}ini}{slu\v{c}aj}{ina\v{c}e}{kraj}{kraj}%Switch
2762 \SetKwFor{For}{za}{\v{c}ini}{kraj}%For
2763 \SetKwFor{ForPar}{za}{izvr\v{s}avaj paralelno}{kraj}%ForPar
2764 \SetKwFor{ForEach}{za svaki}{\v{c}ini}{kraj}%ForEach
2765 \SetKwFor{ForAll}{za sve}{\v{c}ini}{kraj}%ForAll
2766 \SetKwFor{While}{dok}{\v{c}ini}{kraj}%While
2769 %%%% old commands compatibility
2771 \ifthenelse{\boolean{algocf@oldcommands}}{%
2772 \newcommand{\SetNoLine}{\SetAlgoNoLine}%
2773 \newcommand{\SetNoline}{\SetAlgoNoLine}%
2774 \newcommand{\SetVline}{\SetAlgoVlined}%
2775 \newcommand{\SetLine}{\SetAlgoLined}%
2777 \newcommand{\dontprintsemicolon}{\DontPrintSemicolon}%
2778 \newcommand{\printsemicolon}{\PrintSemicolon}%
2779 \newcommand{\incmargin}[1]{\IncMargin{#1}}%
2780 \newcommand{\decmargin}[1]{\DecMargin{-#1}}%
2781 \newcommand{\setnlskip}[1]{\SetNlSkip{#1}}%
2782 \newcommand{\Setnlskip}[1]{\SetNlSkip{#1}}%
2783 \newcommand{\setalcapskip}[1]{\SetAlCapSkip{#1}}%
2784 \newcommand{\setalcaphskip}[1]{\SetAlCapHSkip{#1}}%
2785 \newcommand{\nlSty}[1]{\NlSty{#1}}%
2786 \newcommand{\Setnlsty}[3]{\SetNlSty{#1}{#2}{#3}}%
2787 \newcommand{\linesnumbered}{\LinesNumbered}%
2788 \newcommand{\linesnotnumbered}{\LinesNotNumbered}%
2789 \newcommand{\linesnumberedhidden}{\LinesNumberedHidden}%
2790 \newcommand{\showln}{\ShowLn}%
2791 \newcommand{\showlnlabel}[1]{\ShowLnLabel{#1}}%
2792 \newcommand{\nocaptionofalgo}{\NoCaptionOfAlgo}%
2793 \newcommand{\restorecaptionofalgo}{\RestoreCaptionOfAlgo}%
2794 \newcommand{\restylealgo}[1]{\RestyleAlgo{#1}}%
2796 \newcommand{\Titleofalgo}[1]{\TitleOfAlgo{#1}}%
2797 % \SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}
2798 \newcommand{\SetKwIf}[6]{\SetKwIF{#1}{#2#1}{#2}{#3}{#4}{#5 #1}{#5}{#6}}
2800 \SetKwIF{gSi}{gSinonSi}{gSinon}{si}{alors}{sinon si}{sinon}{fin si}%
2801 \SetKwIF{gIf}{gElsIf}{gElse}{if}{then}{else if}{else}{end if}%
2802 \SetKwIF{gIf}{gElseIf}{gElse}{if}{then}{else if}{else}{end if}%
2803 \SetKwIF{gWenn}{gSonstWenn}{gSonst}{wenn}{dann}{sonst wenn}{sonst}{Ende wenn}%gIf
2804 \SetKwIF{gSe}{gSenaoSe}{gSenao}{se}{ent\~{a}o}{sen\~{a}o se}{sen\~{a}o}{fim se}%
2805 \SetKwIF{gSea}{gAltSe}{gAltrimenti}{se}{allora}{altrimenti se}{allora}{fine se}%
2806 \SetKw{Ret}{return}%
2807 \SetKwInput{Data}{Data}%
2808 \SetKwInput{Result}{Result}%