Algorithm2e PDF
Algorithm2e PDF
Contents
1 Introduction 3
5 Compatibility issues 12
1
8 Typesetting 21
13 Known bugs 49
2
1 Introduction
Algorithm2e is an environment for writing algorithms in LATEX2e. An algorithm is defined as a
floating object like figures. It provides macros that allow you to create different sorts of key words,
thus a set of predefined key words is given. You can also change the typography of the keywords.
See section 3 for two long examples of algorithms written with this package.
You can subscribe to algorithm2e-announce mailing list to receive announcements about
revisions of the package and to algorithm2e-discussion to discuss, send comments, ask questions
about the package. In order to subscribe to the mailing lists you have to send an email to
[email protected] with subscribe algorithm2e-announce Firstname Name or
subscribe algorithm2e-discussion Firstname Name in the body of the message.
Changes from one release to the next are indicated in release notes at the beginning of the
packages. For this release (5.0), changes are indicated at the end of this document.
\begin{algorithm}[H]
\SetAlgoLined
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
1 For longer and more complexe examples see section 3
3
which gives
Data: this text
Result: how to write algorithm with LATEX2e
initialization;
while not at end of this document do
read current section;
if understand then
go to next section;
current section becomes this one;
else
go back to the beginning of current section;
end
end
Algorithm 1: How to write algorithms
Very Important : each line MUST end with \; only those with a macro beginning a block
should not end with \;. Note then that you can always use the \; command in math mode to set
a small space.
The caption works as in a figure environment, except that it should be located at the end of
the algorithm. It is used by \listofalgorithms as a reference name for the list of algorithms.
You can also use the title macro given with the package, but this macro doesnt insert an entry
in the list of algorithms.
4
input : A bitmap Im of size w l
output: A partition of the bitmap
1 special treatment of the first line;
2 for i 2 to l do
3 special treatment of the first element of line i;
4 for j 2 to w do
5 left FindCompress(Im[i, j 1]);
6 up FindCompress(Im[i 1, ]);
7 this FindCompress(Im[i, j]);
8 if left compatible with this then // O(left,this)==1
9 if left < this then Union(left,this);
10 else Union(this,left);
11 end
12 if up compatible with this then // O(up,this)==1
13 if up < this then Union(up,this);
14 // this is put under up to keep tree as flat as possible
15 else Union(this,up);
16 // this linked to up
17 end
18 end
19 foreach element e of the line i do FindCompress(p);
20 end
Algorithm 2: disjoint decomposition
\IncMargin{1em}
\begin{algorithm}
\SetKwData{Left}{left}\SetKwData{This}{this}\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}\SetKwFunction{FindCompress}{FindCompress}
\SetKwInOut{Input}{input}\SetKwInOut{Output}{output}
The LATEX2e code on next page gives algorithm 3. Here lines are not autonumbered but you
can number them individually with \nl command as for line 1 or line 2. You even can set your
own reference with \nlset command and get back this reference by simply using classical \ref.
For example \ref{InResR} gives REM.
Algorithm 3: IntervalRestriction
Data: G = (X, U ) such that Gtc is an order.
Result: G0 = (X, V ) with V U such that G0tc is an interval order.
begin
V U
S
for x X do
N bSuccInS(x) 0
N bP redInM in(x) 0
N bP redN otInM in(x) |ImP red(x)|
for x X do
if N bP redInM in(x) = 0 and N bP redN otInM in(x) = 0 then
AppendT oM in(x)
1 while S 6= do
REM remove x from the list of T of maximal index
2 while |S ImSucc(x)| = 6 |S| do
for y S ImSucc(x) do
{ remove from V all the arcs zy : }
for z ImP red(y) M in do
remove the arc zy from V
N bSuccInS(z) N bSuccInS(z) 1
move z in T to the list preceding its present list
{i.e. If z T [k], move z from T [k] to T [k 1]}
N bP redInM in(y) 0
N bP redN otInM in(y) 0
S S {y}
AppendT oM in(y)
RemoveF romM in(x)
6
\begin{algorithm}
\DontPrintSemicolon
\KwData{$G=(X,U)$ such that $G^{tc}$ is an order.}
\KwResult{$G=(X,V)$ with $V\subseteq U$ such that $G^{tc}$ is an
interval order.}
\Begin{
$V \longleftarrow U$\;
$S \longleftarrow \emptyset$\;
\For{$x\in X$}{
$NbSuccInS(x) \longleftarrow 0$\;
$NbPredInMin(x) \longleftarrow 0$\;
$NbPredNotInMin(x) \longleftarrow |ImPred(x)|$\;
}
\For{$x \in X$}{
\If{$NbPredInMin(x) = 0$ {\bf and} $NbPredNotInMin(x) = 0$}{
$AppendToMin(x)$}
}
\nl\While{$S \neq \emptyset$}{\label{InRes1}
\nlset{REM} remove $x$ from the list of $T$ of maximal index\;\label{InResR}
\lnl{InRes2}\While{$|S \cap ImSucc(x)| \neq |S|$}{
\For{$ y \in S-ImSucc(x)$}{
\{ remove from $V$ all the arcs $zy$ : \}\;
\For{$z \in ImPred(y) \cap Min$}{
remove the arc $zy$ from $V$\;
$NbSuccInS(z) \longleftarrow NbSuccInS(z) - 1$\;
move $z$ in $T$ to the list preceding its present list\;
\{i.e. If $z \in T[k]$, move $z$ from $T[k]$ to
$T[k-1]$\}\;
}
$NbPredInMin(y) \longleftarrow 0$\;
$NbPredNotInMin(y) \longleftarrow 0$\;
$S \longleftarrow S - \{y\}$\;
$AppendToMin(y)$\;
}
}
$RemoveFromMin(x)$\;
}
}
\caption{IntervalRestriction\label{IR}}
\end{algorithm}
7
4 Genericity and example of languages
In this section, we will try to show you main macros and how you can use this package to suit
your need. Based on one example using most popular algorithms expressions, we will show you
how it can be configured to be display in pseudo-code, in python or in C.
The following code shows how is typeset the generic example well use in this section:
\Fn(\tcc*[h]{algorithm as a recursive function}){\FRecurs{some args}}{
\KwData{Some input data\\these inputs can be displayed on several lines and one
input can be wider than lines width.}
\KwResult{Same for output data}
\tcc{this is a comment to tell you that we will now really start code}
\If(\tcc*[h]{a simple if but with a comment on the same line}){this is true}{
we do that, else nothing\;
\tcc{we will include other if so you can see this is possible}
\eIf{we agree that}{
we do that\;
}{
else we will do a more complicated if using else if\;
\uIf{this first condition is true}{
we do that\;
}
\uElseIf{this other condition is true}{
this is done\tcc*[r]{else if}
}
\Else{
in other case, we do this\tcc*[r]{else}
}
}
}
\tcc{now loops}
\For{\forcond}{
a for loop\;
}
\While{$i<n$}{
a while loop including a repeat--until loop\;
\Repeat{this end condition}{
do this things\;
}
}
They are many other possibilities and customization possible that you have to
discover by reading the documentation.
}
To handle if condition, use a macro to be abble to change it according to language syntax,
in particular we will change it for python-style and c-style. We also define a function to write
algorithm as a recursive function. These macros are defined as:
\newcommand{\forcond}{$i=0$ \KwTo $n$}
\SetKwFunction{FRecurs}{FnRecursive}%
The algorithm 4 shows how algorithm is displayed in pseudo-code with default behaviour and
options boxed, commentsnumbered and longend set. Note that by default, lines are used to show
block of code. Note also that longend option makes package use special end keyword for each
command2 .
2 Default behaviour uses short end keywords, it means typeseting only end.
8
1 Function FnRecursive(some args) /* algorithm as a recursive function */
Data: Some input data
these inputs can be displayed on several lines and one input can be wider than lines
width.
Result: Same for output data
2 /* this is a comment to tell you that we will now really start code */
3 if this is true then /* a simple if but with a comment on the same line */
4 we do that, else nothing;
5 /* we will include other if so you can see this is possible */
6 if we agree that then
7 we do that;
8 else
9 else we will do a more complicated if using else if;
10 if this first condition is true then
11 we do that;
12 else if this other condition is true then
13 this is done; /* else if */
14 else
15 in other case, we do this; /* else */
16 end if
17 end if
18 end if
19 /* now loops */
20 for i = 0 to n do
21 a for loop;
22 end for
23 while i < n do
24 a while loop including a repeatuntil loop;
25 repeat
26 do this things;
27 until this end condition;
28 end while
29 They are many other possibilities and customization possible that you have to discover
by reading the documentation.
30 end
9
The algorithm 5 shows how you can have each block tagged with begin-end keywords. This is
done by using automatic block display (new feature since release 5.0). To achieve this display, we
only add following macros at start of the algorithm:
\AlgoDisplayBlockMarkers\SetAlgoBlockMarkers{begin}{end}%
\SetAlgoNoEnd
First one tells package to display blocks with keyword markers. Note that the definition of block
markers are the one by default. Last macro remove end keywords of commands to avoid a double
end (the one of block marker and the one of command).
Not that since release 5.1, you can also have block tagged for one line display. The algo-
rithm 6 is based on algorithm 5 but uses l macros as e.g. \lIf to display command on one
line ; \AlgoDisplayGroupMarkers is added to have also block tagged with markers defined by
\SetAlgoBlockMarkers. To achieve this display, we replace preamble of algorithm 5 by:
\AlgoDisplayBlockMarkers\AlgoDisplayGroupMarkers\SetAlgoBlockMarkers{ \{}{ \}\ }%
\SetAlgoNoEnd\SetAlgoNoLine
The algorithm 7 shows how algorithm looks like with a python-style syntax. To achieve this
display, we need to make following changes before the algorithm:
\SetStartEndCondition{ }{}{}%
\SetKwProg{Fn}{def}{\string:}{}
\SetKwFunction{Range}{range}%%
\SetKw{KwTo}{in}\SetKwFor{For}{for}{\string:}{}%
\SetKwIF{If}{ElseIf}{Else}{if}{:}{elif}{else:}{}%
\SetKwFor{While}{while}{:}{fintq}%
\renewcommand{\forcond}{$i$ \KwTo\Range{$n$}}
\AlgoDontDisplayBlockMarkers\SetAlgoNoEnd\SetAlgoNoLine%
SetStartEndCondition is used to display alternatives and loops conditions according to python
syntax: it means a space before condition, and no space after since : marks end of condition.
Functions are defined with def in python, so we redefine \Fn macro. Range is a new macro for
range python function. Next are redefined For, If and While commands accordingly to python
syntax. Note that we do nothing for repeat-until command since it doesnt exist in python. For
condition is redefined to match python behaviour. At last we tell package to not display block, to
not display end keyword and to not print line according to python syntax.
The algorithm 8 shows how algorithm looks like with a c-style syntax. To achieve this display,
we need to make following changes before the algorithm:
\SetStartEndCondition{ (}{)}{)}\SetAlgoBlockMarkers{\{}{\}}%
\SetKwProg{Fn}{}{}{}\SetKwFunction{FRecurs}{void FnRecursive}%
\SetKwFor{For}{for}{}{}%
\SetKwIF{If}{ElseIf}{Else}{if}{}{elif}{else}{}%
\SetKwFor{While}{while}{}{}%
\SetKwRepeat{Repeat}{repeat}{until}%
\AlgoDisplayBlockMarkers\SetAlgoNoLine%
SetStartEndCondition set braces around conditions like in C. We want that each block is marked
with { at start and } at end, so we set it thanks to \SetAlgoBlockMarkers macro. \Fn is redefined
with no keyword since in C, name of function defines it. Then we redefin FnRecursive with its
type. Next, For, If, While and Repeat are redefined accordingly to C syntax. At last, we tell the
package to display block markers.
The algorithm 9 shows how algorithm looks like with a c-style syntax and a more compact way
to mark blocks. To achieve this display, we need to make following changes before the algorithm:
\SetStartEndCondition{ (}{)}{)}\SetAlgoBlockMarkers{}{\}}%
\SetKwProg{Fn}{}{\{}{}\SetKwFunction{FRecurs}{void FnRecursive}%
\SetKwFor{For}{for}{\{}{}%
\SetKwIF{If}{ElseIf}{Else}{if}{\{}{elif}{else\{}{}%
\SetKwFor{While}{while}{\{}{}%
\SetKwRepeat{Repeat}{repeat\{}{until}%
\AlgoDisplayBlockMarkers\SetAlgoNoLine%
10
1 Function FnRecursive(some args) /* algorithm as a recursive function */
2 begin
Data: Some input data
these inputs can be displayed on several lines and one input can be wider than lines
width.
Result: Same for output data
3 /* this is a comment to tell you that we will now really start code */
4 if this is true then /* a simple if but with a comment on the same line */
5 begin
6 we do that, else nothing;
7 /* we will include other if so you can see this is possible */
8 if we agree that then
9 begin
10 we do that;
11 end
12 else
13 begin
14 else we will do a more complicated if using else if;
15 if this first condition is true then
16 begin
17 we do that;
18 end
19 else if this other condition is true then
20 begin
21 this is done; /* else if */
22 end
23 else
24 begin
25 in other case, we do this; /* else */
26 end
27 end
28 end
29 /* now loops */
30 for i = 0 to n do
31 begin
32 a for loop;
33 end
34 while i < n do
35 begin
36 a while loop including a repeatuntil loop;
37 repeat
38 begin
39 do this things;
40 end
41 until this end condition;
42 end
43 They are many other possibilities and customization possible that you have to discover
by reading the documentation.
44 end
Algorithm 5: Generic example in pseudo-code with begin-end block set
11
1 Function FnRecursive(some args) /* algorithm as a recursive function */
2 {
Data: Some input data
Result: Same for output data
3 if this is true then /* a simple if but with a comment on the same line */
4 {
5 we do that, else nothing;
6 if we agree that then { we do that; }
7 else
8 {
9 if this first condition is true then { we do that; }
10 else if this other condition is true then { this is done; } /* else if */
11 else { in other case, we do this; } /* else */
12 }
13 }
14 for i = 0 to n do { a for loop; }
15 while i < n do
16 {
17 a while loop including a repeatuntil loop;
18 repeat { do this things } until this end condition; /* a comment */
19 }
20 They are many other possibilities and customization possible that you have to discover
by reading the documentation.
21 }
Algorithm 6: algorithm 5 with {} block set even for one line command.
If you look at algorithm 4, you can see that some command doesnt put a end. For example, it is
a case for a if followed by an else, same thing for a else if. In C, there is always an end marker.
So, to achieve our goal we need to use end marker of blocks. But we dont want displaying begin
marker as in algorithm 5 or algorithm 8. If begin block marker is set to empty, then nothing
is written (especially not a blank line). So we tell package to use block markers with an empty
marker for begin and a } for end. Now we have to tell package to write a { on the same line as
commands. This is achieve by redefining If, For, While and Repeat command.
5 Compatibility issues
Compatibily with other packages improven by changing name of internal macros. Algorithm2e
can now be used with almost all package, as elsart, hermes, arabtex for example, if this last
is loaded after algorithm2e package. So, at this time, release 5.2has few known compatibility
problem with other packages. The packages or classes that are known to be not compatible with
algorithm2e package is:
ascelike
pstcol
Nevertheless, when use with some packages, some of their options cannot be used, or you need to
specify some particular options (as algo2e to change name of environment if algorithm is already
defined by the class), either from algorithm2e package or from the other packages.
hyperref if you want to compile in PdfLATEX, you must not use naturalnames option. Beware
this has changed from release 3 where you should use it!
12
1 def FnRecursive(some args): /* algorithm as a recursive function */
Data: Some input data
these inputs can be displayed on several lines and one input can be wider than lines
width.
Result: Same for output data
2 /* this is a comment to tell you that we will now really start code */
3 if this is true: /* a simple if but with a comment on the same line */
4 we do that, else nothing;
5 /* we will include other if so you can see this is possible */
6 if we agree that:
7 we do that;
8 else:
9 else we will do a more complicated if using else if;
10 if this first condition is true:
11 we do that;
12 elif this other condition is true:
13 this is done; /* else if */
14 else:
15 in other case, we do this; /* else */
16 /* now loops */
17 for i in range(n):
18 a for loop;
19 while i < n:
20 a while loop including a repeatuntil loop;
21 repeat
22 do this things;
23 until this end condition;
24 They are many other possibilities and customization possible that you have to discover
by reading the documentation.
Algorithm 7: Generic example in python-style like syntax
13
1 void FnRecursive(some args) /* algorithm as a recursive function */
2 {
Data: Some input data
these inputs can be displayed on several lines and one input can be wider than lines
width.
Result: Same for output data
3 /* this is a comment to tell you that we will now really start code */
4 if (this is true) /* a simple if but with a comment on the same line */
5 {
6 we do that, else nothing;
7 /* we will include other if so you can see this is possible */
8 if (we agree that)
9 {
10 we do that;
11 }
12 else
13 {
14 else we will do a more complicated if using else if;
15 if (this first condition is true)
16 {
17 we do that;
18 }
19 elif (this other condition is true)
20 {
21 this is done; /* else if */
22 }
23 else
24 {
25 in other case, we do this; /* else */
26 }
27 }
28 }
29 /* now loops */
30 for (i to range(n))
31 {
32 a for loop;
33 }
34 while (i < n)
35 {
36 a while loop including a repeatuntil loop;
37 repeat
38 {
39 do this things;
40 }
41 until (this end condition);
42 }
43 They are many other possibilities and customization possible that you have to discover
by reading the documentation.
44 }
Algorithm 8: Generic example in c-style like syntax
14
1 void FnRecursive(some args){ /* algorithm as a recursive function */
Data: Some input data
these inputs can be displayed on several lines and one input can be wider than lines
width.
Result: Same for output data
2 /* this is a comment to tell you that we will now really start code */
3 if (this is true){ /* a simple if but with a comment on the same line */
4 we do that, else nothing;
5 /* we will include other if so you can see this is possible */
6 if (we agree that){
7 we do that;
8 }
9 else{
10 else we will do a more complicated if using else if;
11 if (this first condition is true){
12 we do that;
13 }
14 elif (this other condition is true){
15 this is done; /* else if */
16 }
17 else{
18 in other case, we do this; /* else */
19 }
20 }
21 }
22 /* now loops */
23 for (i to range(n)){
24 a for loop;
25 }
26 while (i < n){
27 a while loop including a repeatuntil loop;
28 repeat{
29 do this things;
30 }
31 until (this end condition);
32 }
33 They are many other possibilities and customization possible that you have to discover
by reading the documentation.
34 }
Algorithm 9: Generic example in c-style like syntax with compact block
15
article-hermes is not compatible with relsize used by algorithm2e package, so you have to use
norelsize option to get algorithm works with article-hermes class.
Note also that, if you use packages changing the way references are printed, you must define labels
of algorithm after the caption to ensure a correct printing. You cannot use \label inside a caption
without errors.
From release 4.0, some commands have been renamed to have consistent naming (CamlCase
syntax) and old commands are no more available. If you doesnt want to change your mind or use
old latex files, you have to use oldcommands option to enable old commands back. Here are these
commands:
\SetNoLine becomes \SetAlgoNoLine
\SetVline becomes \SetAlgoVlined
16
6 Environments defined in the package
This package provides 4 environments :
algorithm: the main environment, the one you will used most of the time.
algorithm*: same as the precedent, but used in a two columns text, puts the algorithm across
the two columns.
procedure*: same as the precedent, but used in a two columns text outs the procedure across
the two columns.
function: as the precedent but with Function instead of procedure in the title.
function*: same as the precedent, but used in a two columns text outs the function across the
two columns.
If you dont like algorithm or look for something else, you can change the name of algorithm
by using command below:
\SetAlgorithmName{algorithmname}{algorithmautorefname}{list of algorithms name} which
redefines name of the algorithms and the sentence list of algorithms. Example:
\SetAlgorithmName{Protocol}{List of protocols} if you prefer protocol than algorithm.
Second argument is the name that \autoref, from hyperref package, will use.
The same exists for procedure and function environment, the difference is that list of algorithms
is not change and keep its original name:
17
7 The options of the package
7.1 language option
There are predefined keywords in different languages already defined (see section 12 or in the
.sty file) that you can activate by using appropriate option. You can also activate these localized
keywords by using same option followed by kw. In this case, you keep all localized keywords
already defined and add the new ones. Note that this option is not robust, and there are macros
in differents language that are the same. In this case, last defined is the one staying. But this
allow you to have predefined keywords in multiple languages.
english: the default.
french: to have French keywords, for example algorithme : instead of algorithm:.
frenchkw: to add French keywords definition.
german: to have German keywords, for example Prozedur : instead of procedure:.
18
7.2 compatibility issue
algo2e: changes the name of environment algorithm into algorithm2e and so allows to use the
package with some journal style which already define an algorithm environment. Changes
also the command name for the list of algorithms, it becomes \listofalgorithmes
endfloat: endfloat packages doesnt allow float environment inside other environment. So using
it with figure option of algorithm2e makes error. This option enables a new environment
algoendfloat to be used instead of algorithm environment that put algorithm at the end. al-
goendfloat environment make algorithm acting as endfloat figures. This option load endfloat
package, so it is required to have it.
norelsize: starting from this release (v4.00), algorithm2e package uses relsize package in order to
get relative size for lines numbers; but it seems that some rare classes (such as inform1.cls)
are not compatible with relsize; to have algorithm2e working, this option makes algorithm2e
not to load relsize package and go back to previous definition by using \scriptsize font for
lines numbers.
slide: require package color. To be used with slide class in order to have correct margins.
nokwfunc disable the setting in \KwFunction of procedures or functions name (see section 6) of
function and procedure environment. Useful if you use name of procedure or function that
cannot be a command name as a math display for example.
19
7.4 code typesetting
7.4.1 indentation of long statements
noalgohanging By default, long statement are indented on subsequent lines (see to know how to
control length of indentation); with this option you get old behavior and lines are no more
indented.
hangingcomment Comment that are alone on a line (not side comment) are not driven by algo-
rithm hanging: subsequent lines of long comments are indented according to width of start
comment marker. With this option, comment are indented like normal statement.
opthanginginout As for comment, by default, in/out keywords and input keywords (defined
by \SetKwInOut or \SetKwInput) are not indented by algorithm hangindent. They are
indented according to width of input keyword. If you want that these keywords acts like
other statements, use this option.
lined: \SetAlgoLined becomes the default, see section 9.6 for explanations about the \SetAlgoLined
macros.
vlined: \SetAlgoVlined becomes the default, see section 9.6 for explanations about the \SetAlgoVlined
macros.
noline: \SetNoline becomes the default, see section 9.6 for explanations about the \SetNoline
macros.
block markers
displayblockmarkers \AlgoDisplayBlockMarkers becomes the default, see section 9.6 for expla-
nations about the \AlgoDisplayBlockMarkers macro.
displaygroupmarkers \AlgoDisplayGroupMarkers becomes the default, see section 9.6 for ex-
planations about the \AlgoDisplayGroupMarkers macro.
7.4.4 comments
scright (default) right justified side comments (side comments are flushed to the right)
scleft left justified side comments (side comments are put right after the code line)
fillcomment (default) end mark of comment is flushed to the right so comments fill all the width
of text
nofillcomment end mark of comment is put right after the comment
20
7.4.5 lines numbers
linesnumbered: lines of the algorithms are numbered except for comments and input/output
(KwInput and KwInOut). You must use \nllabel{label} to label thoses lines.
linesnumberedhidden: lines of the algorithms are numbered as linesnumbered but numbers are
not shown. \ShowLn and \ShowLnLabel{label} show the number on line they are put.
commentsnumbered: makes comments be numbered if numbering is active.
inoutnumbered: makes data input/output be numbered if numbering is active.
rightnl: put lines numbers to the right of the algorithm instead of left.
resetcount the line numbers are reset to 0 at the beginning of each algorithm (by default).
noresetcount the contreverse of the precedent. To reset the line counter to 0 do:
\setcounter{AlgoLine}{0}
algonl the line numbers will be prefixed with the number of the current algorithm. Take care
to set the caption of the algorithm at the beginning of the environnement, else you will have
the precedent algorithm number as the current one.
8 Typesetting
There are eight text types in an algorithm environment:
1. The keywords (Kw): Macros which usually indicate words of the language. Some are
predefined and given with the algorithm package.
The user can define his own language keywords by using the different macros presented in
section 11 (see below for a short, non exhaustive list). He can also define simple keywords
with the \SetKw{Kw}{thetext} macro.
2. The Functions: (Func) Macros defined by the user which denote local functions or other
algorithms defined in the text. (See also function environment at section 6, which defines
not only function keyword but algorithm of the function.
They are defined using \SetKwFunction{KwFn}{Fn} where \KwFn will be the macro and Fn
the text printed.
21
6. Data (Data): A type of text different from the default. You can use it as you want, and can
be useful for example to emphasize a Data structure or denotes some important variables.
They are defined with the help of the \SetKwData{KwDat}{data} macro, where \KwDat will
be the macro and data the text printed.
7. Block markers : BlockMarkersSty is style of keywords that are print at begin and end of
block when displayblockmarkers and/or displaygroupmarkers option are set, or \AlgoDisplayBlockMarkers
and/or \AlgoDisplaygroupMarkers macro are used. By default, \BlockMarkersSty is set
to \KwSty.
8. The text (the default): All the remaining text of the algorithm.
22
\caption{thetitle} works as classical caption of figures. It inserts an entry in the list of algo-
rithms. Should be the standard way to put title of algorithms.
\TitleOfAlgo{thetitle} prints: Algorithm n : thetitle in the typography and size defined by
\SetTitleSty. Puts a vertical space below.
Beware: \TitleOfAlgo doesnt insert an entry in the list of algorithms. So dont use
\TitleOfAlgo with \caption. Both increment the counter of the algorithms.
note:with the french option prints Algorithme n :
\SetAlCapSkip{length} sets the lenght of \AlCapSkip) dimension between algorithm body and
caption.
\SetAlCapHSkip{length} sets the horizontal skip before Algorithm: in caption when used in
ruled algorithm.
\SetTitleSty{type style}{type size} sets the typography and size of the titles defined with
the macro \TitleOfAlgo{} (not with \caption).
\NoCaptionOfAlgo doesnt print Algorithm and its number in the caption. This macros is ONLY
active for algoruled or ruled algorithms and for the next algorithm. For example, it is
useful when the algorithm just describes a function and you only want to display the name
of the function in the caption.
\RestoreCaptionOfAlgo restores correct captions that was corrupted by a \NoCaptionOfAlgo
macro.
\SetAlgoCaptionLayout{style} sets global style of the caption; style must be the name of a
macro taking one argument (the text of the caption). Examples below show how to use it:
\SetAlgoCaptionLayout{centerline} to have centered caption;
\SetAlgoCaptionLayout{textbf} to have bold caption.
23
If you want to apply two styles in the same time, such as centered bold, you have to de-
fine you own macro and then use \SetAlgoCaptionLayout with its name. \AlCapFnt and
\AlCapNameFnt can change the font used in caption, beware of interactions between this
three commands.
Note that two length control the layout of ruled, algoruled, boxruled algorithms caption.
\interspacetitleruled and \interspacetitleboxruled are described section 9.6.
\LinesNumbered makes lines of the following algorithms be auto-numbered. This command cor-
responds to linesnumbered option.
\LinesNumberedHidden makes lines of the following algorithms be auto-numbered, but numbers
stay hidden. You have to use \ShowLn and \ShowLnLabel to see them. This command
corresponds to linesnumberedhidden option.
\LinesNotNumbered makes lines of the following algorithms no be auto-numbered.
\nllabel{label} macro for labelling lines when auto-numbering is active.
\nl numbers the line: must begin the line. You can use \label to label the line and reference it
further.
\lnl{label} numbers and labels the line : must begin the line. Do a Beware this has changed
from release 3\nl\label{label} in one time. Prefer to use a classical \label as it is more
readable.
\nlset{text} works as \nl except that the additional argument is the text to put at the beginning
of the line. This text becomes the reference if you label it and \ref will print it instead of
classical number.
\lnlset{text}{label} works for \nlset as \lnl for \nl. Prefer to use a classical \label as it
is more readable.
24
\SetAlgoNLRelativeSize{number} sets the relative size of line numbers. By default, line num-
bers are two size smaller than algorithm text. Use this macro to change this behavior. For ex-
ample, \SetAlgoNlRelativeSize{0} sets it to the same size, \SetAlgoNlRelativeSize{1}
to one size smaller and \SetAlgoNlRelativeSize{1} to one size bigger.
Example below shows use of these macros:
\SetNlSty{texttt}{[}{]}
\SetAlgoNlRelativeSize{0} [2]Input: input data
[2]
\SetNlSkip{0em} [4]Output: output data
[4]
\nl\KwIn{input data} [6]/* a comment line in C-style
[6]
\nl\KwOut{output data} */
\nl\tcc{a comment line in C-style} [8]repeat
[8]
=
\nl\Repeat{\nl$e<\tau$}{ [10] fn Y1 ;
\nl$f_n\leftarrow Y_1$\; [12] fn+1 fn fn1 ;
\nl$f_{n+1}\leftarrow f_n\times f_{n-1}$\;[14] e f2n ;
\nl$e\leftarrow \frac{f_n}{2}$\; [16]e < ;
[15]until
} [18]return e
[18]
\nl\KwRet{$e$}
25
\ProcFnt{<text>} sets <text> in procedure typography of procedure and function environment
(by default the same as \AlCapFnt{)}. (see section 9.5.2 for more explanations and details)
\ProcArgSty{<text>} sets <text> in argument style of procedure and function environment
(by default the same as \AlCapNameSty{)}. (see section 9.5.2 for more explanations and
details)
\AlCapSty{<text>} sets <text> in caption title typography, that is the same used, together
with \AlCapFnt, to print Algorithm #:, more precisely it is printed as follow:
\AlCapSty{\AlCapFnt Algorithm #:}
which gives actually Algorithm #:. By default \AlCapSty is textbf.
\AlCapNameSty{<text>} sets <text> in caption name typography, that is the same used, to-
gether with \AlCapNameFnt to print the name of caption you set by calling \caption{name}.
More precisely it is printed as follow:
\AlCapNameSty{\AlCapNameFnt name}
which gives name. By default \AlCapNameSty is textnormal which means print in stan-
dard text.
\AlCapFnt{<text>} sets <text> in font shape of caption title, that is the same used, together
with \AlCapSty, to print Algorithm #:, more precisely it is printed as follow:
\AlCapSty{\AlCapFnt Algorithm #:}
which gives actually Algorithm #:. By default \AlCapFnt is \relax which means keep
text as it is.
26
\AlCapNameFnt{<text>} sets <text> in caption name typography, that is the same used, to-
gether with \AlCapNameSty to print the name of caption you set by calling \caption{name}.
More precisely it is printed as follow:
\AlCapNameSty{\AlCapNameFnt name}
which gives name. By default \AlCapNameFnt is \relax which means keep text as it is.
\ProcSty{<text>} sets <text> in procedure/function caption title typography, that is the same
used, together with \ProcFnt, to print Procedure, more precisely it is printed as follow:
\ProcSty{\ProcFnt Procedure}
which gives actually Procedure. By default \ProcSty is \AlCapSty.
\ProcNameSty{<text>} sets <text> in procedure name typography, that is the same used, to-
gether with \ProcNameFnt to print the name of caption you set by calling \caption{Proc(int
i)}. More precisely it is printed as follow:
\ProcNameSty{\ProcNameFnt Proc(}
which gives Proc(. By default \ProcNameSty is \AlCapNameSty which means print in
standard text.
\ProcArgSty{<text>} sets <text> in argument of procedure/function typography, that is the
same used, together with \ProcArgFnt, to print int i if \caption{Proc(int i)} was
called. More precisely it is printed as follow:
\ProcArgSty{\ProcArgFnt int i}
which gives actually int i. By default \ProcArgSty is \AlCapNameSty;
\ProcFnt{<text>} sets <text> in font shape of caption title, that is the same used, together
with \ProcSty, to print Procedure, more precisely it is printed as follow:
\ProcSty{\ProcFnt Procedure}
which gives actually Procedure. By default \ProcFnt is \relax which means keep text
as it is.
\ProcNameFnt{<text>} sets <text> in procedure/function name typography, that is the same
used, together with \ProcNameSty to print the name of caption you set by calling \caption{Proc(int
i)}. More precisely it is printed as follow:
\ProcNameSty{\ProcNameFnt Proc(}
which gives Proc(. By default \ProcNameFnt is \relax which means keep text as it is.
\ProcArgFnt{<text>} sets <text> in font shape of argument of procedure/environment caption,
that is the same used, together with \ProcArgSty, to print int i if \caption{int i} was
called. More precisely it is printed as follow:
\ProcArgSty{\ProcFnt int i}
which gives actually int i. By default \ProcArgFnt do nothing.
27
You have to give commands to set the font in argument. You can use it elsewhere you want to
typeset text as algorithm. For example you can do \SetAlFnt{\small\sf} to have algorithms
typeset in small sf font.
The next ones require to give in parameter name of a macro (whithout \) which takes one
argument. For example, \SetAlCapFnt{textbf} (see section 9.2.2) defines the default behaviour
of \AlCapFnt. If you want to do more complicated thing, you should define your own macro and
give it to \SetAlCapFnt or \SetAlCapNameFnt. Here are two examples:
\newcommand{\mycapfn}[1]{\tiny #1}\SetAlCapNameFnt{mycapfnt}
\newcommand{\mycapfn}[1]{\textsl{\small #1}}\SetAlCapNameFnt{mycapfnt}
Here is the complete list of these macros:
\SetKwSty{<font>} sets the Kw typography to <font> (by default: textbf ).
\SetFuncSty{<font>} sets the function typography (by default: texttt).
\SetFuncArgSty{<font>} sets the typography of function argument (by default: emph).
\SetProgSty{<font>} sets the KwProg typography to <font> (by default: emph).
\SetArgSty{<font>} sets the argument typography (by default: emph).
\SetDataSty{<font>} sets the data typography (by default: textsf ).
\SetCommentSty{<font>} sets the comment text typography (by default: texttt).
\SetNlSty{<font>} sets the number line typography (by default: \relsize{-2})
28
\SetAlCapNameFnt{\tiny} set font to tiny size.
if you combine \SetAlCapNameSty{mycapsty} and \SetAlCapNameFnt{\tiny} will give tiny
bold empased caption.
Now the commands:
Note that by combining Fnt and Sty macros you can define almost all styles easily. For
example, the last example above can be define in a simplier way that previously presented by
doing:
\SetAlCapNameSty{textsl}\SetAlCapNameFnt{\small}
\RestyleAlgo{style} sets the style of the following algorithms to that given by this macro (plain,
boxed, ruled, algoruled) unlike those indicated in the options of the package (see options of
the package).
\SetAlgoVlined prints a vertical line followed by a little horizontal line between the start and
the end of each block. Looks like that :
\SetNoline Doesnt print vertical lines (by default). The block is marked with keywords such as
begin, end.
\SetAlgoLined prints vertical lines between bloc start-end keywords as begin, end.
\SetAlgoLongEnd acts like longend option.
29
\SetAlgoSkip{skip command} Algorithms puts extra vertical space before and after to avoid
having text bumping lines of boxed or ruled algorithms. By default, this is a . You can
change this value with this macro. The four possibilities are:
\SetAlgoSkip{}] for no extra vertical skip
\SetAlgoSkip{smallskip}] to act as the default behaviour
\SetAlgoSkip{medskip}] to have a bigger skip
\SetAlgoSkip{bigskip}] to have the bigger skip
Note that you can apply the skip you want by defining a macro doing it and passing its
name (without \) to \SetAlgoSkip
\SetAlgoInsideSkip{skip command} Algorithms puts no extra vertical space before and after
the core of the algorithm. So text is put right after the lines in boxed or ruled style. To put an
extra space, use \SetAlgoInsideSkip{skip command}, for example \SetAlgoInsideSkip{smallskip},
like for \SetAlgoSkip{skip command}.
\algomargin this is the value of the margin of all algorithms. You can change it by setting:
\setlength{\algomargin}{2em} for example. The default value is the sum of the two
dimensions \leftskip and \parindent when the algorithm2e package is loaded. Note that
if you change this value, it will take effect with the next algorithm environment. So even if
you change it inside an algorithm environment, it will not affect the current algorithm.
\IncMargin{length} increases the size of the \algomargin by the length given in argument.
\DecMargin{length} decreases the size of the \algomargin by the length given in argument.
\DecMargin{length} decreases the size of the \algomargin by the length given in argument.
\SetAlgoNlRelativeSize{number} sets the relative size of line number (see section 9.3) for more
details on this command.
\SetAlgoCaptionLayout{style} sets the global style of caption (see section 9.2 for more details).
\DisplayBlockMarkers acts like displayblockmarkers option: each block will be started by a begin
keyword and be ended by an end keywords. This is tricky to use but allows to customize
syntax to match almost every language (see section 4 for examples showing how to use it).
\SetAlgoBlockMarkers{begin keyword}{end keyword} defines begin and end keywords
that will be used by \DisplayBlockMarkers. Default keywords are begin and end. but for
example you can set \DisplayBlockMarkers{\{}{\}} to match c-style syntax.
\DisplayGroupMarkers acts like displaygroupmarkers option: each block of single line command
will be started by a begin keyword and be ended by an end keywords. \SetAlgoBlockMarkers{begin
keyword}{end keyword} defines begin and end keywords that will be used by \DisplayGroupMarkers.
Note that begin-end group markers are necessarly the same as \DisplayBlockMarkers.
Some length are used to set the layout of ruled, algoruled and boxruled algorithms caption.
These length have no particular macro to set them but can be changed by classical \setlength
commmand:
interspacetitleruled (2pt by defaut) which controls the vertical space between rules and title
in ruled and algoruled algorithms.
interspacetitleboxruled (2\lineskip by default) which controls the vertical space between
rules and title in boxruled algorithms.
30
9.7 comments
There are two ways to do comments in algorithm :
1. by using a comment macro defined by \SetKwComment{command}{right mark}{left mark}
(see below) like \tcc;
2. by using side comment, it means comment put in between ( ) after control command like
if-then-else, for, ... macros.
At section 10.3, you can see how \tcc is defined and at section 10.4 you can look at some
examples how to use it with if then else like commands and finally you can look at section 11.4
how to define comments and explanations on the different macros and ways of printing comments.
Note also that comments are not numbered by default when using linesnumbered option. You have
to set commentsnumbered to number them also.
The following macro control how comment are typeseted.
\SetSideCommentLeft right justified side comments (side comments are flushed to the right),
equivalent to scleft option.
\SetSideCommentRight left justified side comments (side comments are put right after the code
line) , equivalent to scright option.
\SetFillComment end mark of comment is flushed to the right so comments fill all the width of
text, equivalent to fillcomment option.
\SetNoFillComment end mark of comment is put right after the comment, equivalent to nofill-
comment option.
31
10.3 comments
\tcc{line(s) of comment}: comment la C
\tcc*{right justified side comment}: comment la C
\tcc*[f]{right justified comment, without end line; useful with if-then-else macros for ex-
ample}: comment la C
\tcp{line(s) of comment}: comment la C++
\tcp*{right justified side comment}: comment la C++
\tcp*[r]{right justified side comment, ends the line (default)}: comment la C++
\tcp*[l]{left justified side comment, ends the line}: comment la C++
\tcp*[h]{left justified comment, without end line; useful with if-then-else macros for ex-
ample}: comment la C++
\tcp*[f]{right justified comment, without end line; useful with if-then-else macros for
example}: comment la C++
You can see some examples of this macros with if then else at the end of section 11.5
\Else{else block}
\Else(else comment){else block}
\uElse{else block without end}
32
\uElse(else comment){else block without end}
\lElse{elses line text}
\lElse(else comment){elses line text}
\eIf{condition}{then block}{else block}
\eIf(then comment){condition}{then block}(else comment){else block}
\eIf(then comment){condition}{then block}{else block}
\eIf{condition}{then block}(else comment){else block}
\leIf{condition}{then block}{else block}
\leIf(comment){condition}{then block}{else block}
\While{condition}{text loop}
\While(while comment){condition}{text loop}
\lWhile{condition}{line text loop}
\lWhile(while comment){condition}{line text loop}
\ForEach{condition}{text loop}
33
\ForEach(foreach comment){condition}{text loop}
\lForEach{condition}{line text loop}
\lForEach(foreach comment){condition}{line text loop}
\ForAll{condition}{text loop}
\ForAll(forall comment){condition}{text loop}
2. \SetKw{KwTo}{to}
3. \SetKw{KwRet}{return}
\SetKw{Return}{return}
4. \SetKwBlock{Begin}{begin}{end}
5. \SetKwComment{tcc}{/*}{*/}
\SetKwComment{tcp}{//}{}
6. \SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif}
7. \SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{endcase}endsw
8. \SetKwFor{For}{for}{do}{endfor}
\SetKwFor{While}{while}{do}{endw}
\SetKwFor{ForEach}{foreach}{do}{endfch}
\SetKwAll{ForEach}{forall}{do}{endfall}
9. \SetKwRepeat{Repeat}{repeat}{until}
34
11 To define your own language keywords
Note that all these macros verify if the keywords are already defined and do a renewcommand if
they are. So you can overload the default definitions of this package with your own.
35
11.3 to define keywords as function
If you want describe the function by an algorithm, use instead function or procedure environment.
36
\ElseIf(comment){ElseIfs text(comment)}
the same with comment.
\Else{Elses text}
Elses text is writen in a block and terminating by the endif.
\Else(comment){Elses text}
the same with comment.
\Else{(}comment)Elses text(comment)
the same with comment.
\lIf{cond}{Thens text}
Thens text is written on the same line as then. No endif is printed. Do not put \;
after Thens text neither after \lIf.
\lIf(comment){cond}{Thens text}
the same with comment.
\lIf*{cond}{Thens text}
Thens text is written on the same line as then. No endif and no end of line are
printed. Do not put \; after Thens text neither after \lIf.
\lElseIf{ElseIfs text}
ElseIfs text is written on the same line as else if. No endif is printed.
\lElseIf(comment){ElseIfs text}
the same with comment.
\lElseIf*{ElseIfs text}
ElseIfs text is written on the same line as else if. No endif and no end of line are
printed.
\lElse{Elses text}
Elses text is written on the same line as else. No endif is printed.
\lElse(comment){Elses text}
the same with comment.
\lElse*{Elses text}
Elses text is written on the same line as else. No endif is printed and no end of line
are printed.
\uIf{cond}{Thens text} (for uncomplete if)
defines a If block unterminated like in a \eIf block, i.e. dont print the endif or dont
put the little horizontal line in Vline mode (see examples below).
\uIf(comment){cond}{Thens text}
the same with comment.
\uElseIf{ElseIfs text} (for uncomplete elseif)
Same explanation as for \uIf but with else if.
\uElseIf(comment){ElseIfs text}
the same with comment.
\uElse{Elses text} (for uncomplete else)
Same explanation as for \uElseIf but with else.
\uElse{Elses text}
the same with comment.
\eIf{cond}{Thens text}{Elses text}
equivalent to the use of \uIf followed by \Else.
The macros which begin with a l (l as line) denote that the text passed in argument will be
printed on the same line while with the others the text is printed in a block and shifted. You
should put \; at the end of l macros.
37
The macros which begin with a u (u as uncomplete) denote that the text passed in argument
will be printed in a block not terminated by endif. They are useful to chain different alternatives.
The keywords then and else are automatically printed. cond is always printed in argument
typography just behind the keyword if.
All this macros can be combined with () and \Comment* macros to put comments after main
keywords as If, Else or ElseIf (see list of predefined keywords above and example below).
Some examples with \SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{endif} the
default definition given in the package:
\SetAlgoVlined
\eIf{cond1}{ 1 if cond1 then
a line\; 2 a line;
a line\; 3 a line;
= 4 else
}{
another line\; 5 another line;
another line\; 6 another line;
}
\SetAlgoNoLine 1 if cond2 then
\If{cond2}{ 2 second if;
second if\; =
3 second if;
second if\;
4 end
}
1 if cond4 then ok;
\lIf{cond4}{ok} \lElse{wrong}
= 2 else wrong;
\leIf{cond4}{ok}{wrong}
3 if cond4 then ok else wrong;
\SetAlgoVlined
\lIf{cond5}{cond5 true} 1 if cond5 then cond5 true;
\uElseIf{cond51}{ 2 else if cond51 then
cond 5 false\; 3 cond 5 false;
but cond51 true\; 4 but cond51 true;
=
} 5 else if then
\ElseIf{}{ 6 all is wrong;
all is wrong\; 7 return result52;
\Return result52\;
}
\SetAlgoLined
\uIf{cond6}{ 1 if cond6 then
cond6 is ok\; 2 cond6 is ok;
always ok\; 3 always ok;
} 4 else if cond62 then
\uElseIf{cond62}{ 5 choose result62;
choose result62\; =
6 return result62;
\Return result62\;
7 else
}
8 all is wrong;
\Else{
9 do something else;
all is wrong\;
10 end
do something else\;
}
38
Lets have a look at what we can do
1 Lets have a look at what we can do
with if-then-else and side comments\;
with if-then-else and side
\eIf{if-then-else test}{
comments;
no comment here\;
2 if if-then-else test then
neither in then\;
3 no comment here;
}{
4 neither in then;
nor in else\;
5 else
}
6 nor in else;
\eIf(\tcc*[f]{then comment}){test}{
7 end
then with a comment\;
8 if test then /* then comment */
}(\tcc*[f]{comment in else})
9 then with a comment;
{
10 else /* comment in else */
here we are in else\;
11 here we are in else;
}
12 end
\eIf(\tcc*[f]{then comment}){test}{
13 if test then /* then comment */
again a comment in then\;
14 again a comment in then;
}{
15 else
but not in else\; =
16 but not in else;
}
17 end
\eIf{if-then-else test}{
18 if if-then-else test then
this time, no comment in then\;
19 this time, no comment in then;
}(\tcc*[f]{else comment})
20 else /* else comment */
{
21 but one comment in else;
but one comment in else\;
22 end
}
23 Lets try with other if possibilities;
Lets try with other if possibilities\;
24 if test then text; /* lif comment
\lIf(\tcc*[h]{lif comment}){test}{text}
*/
\uIf(\tcc*[f]{uif comment}){test}{
25 if test then /* uif comment */
then text\;
26 then text;
}
27 else if test then /* comment */
\uElseIf(\tcc*[f]{comment}){test}{
28 elseif text;
elseif text\;
29 else if test then text; /* comment
}
*/
\lElseIf(\tcc*[h]{comment}){test}{text}
30 else text; /* comment */
\lElse(\tcc*[f]{comment}){text}
39
\lCase{cond}{Cases text}
\lCase*{cond}{Cases text}
\lCase(comment){cond}{Cases text}
\Other{Otherwises block}
\Other(comment){Otherwises block}
\Other{Otherwises block(comment)}
\Other(comment){Otherwises block(comment)}
\lOther{Otherwises text}
\lOther*{Otherwises text}
\lOther(comment){Otherwises text}
\uOther{Otherwises text}
\uOther{(}comment)Otherwises text
The keywords do and endsw are automatically printed. iden and cond are always printed in
argument typography just behind the keywords Switch, Case and Otherwise. Here is an example
with the default keywords:
\Switch{the value of T}{ 1 switch the value of T do
\uCase{a value}{ 2 case a value do
do this\; 3 do this;
do that\; 4 do that;
} 5 case another value do one line;
\lCase{another value}{one line} 6 case last value do
\Case{last value}{ 7 do this;
do this\; = 8 break;
break\;
9 end
}
10 otherwise do
\Other{
11 for the other values;
for the other values\;
12 do that;
do that\;
13 end
}
14 end
}
As for If-then-elseif-else-endif macro, you can use () to put comments after main keywords.
40
The keywords do and endfor are automatically printed. The loop condition is printed in
argument typography. For example:
It prints the loop condition behind the until after the text of the loop.For example:
1. \Donnees{donnees}
\Res{resultats}
\Entree{entrees}
\Sortie{sorties}
2. \KwA
\Retour{[valeur]}
41
3. \Deb{interieur du bloc}
4. \eSi{condition}{bloc du alors}{bloc du sinon}
\Si{condition}{bloc du alors}
\uSi{condition}{bloc du alors sans fin}
\lSi{condition}{ligne du alors}
\SinonSi{condition}{bloc du sinonsi}
\uSinonSi{condition}{bloc du sinonsi sans fin}
\lSinonSi{condition}{ligne du sinonsi sans fin}
\Sinon{bloc du sinon}
\uSinon{bloc du sinon sans fin}
\lSinon{ligne du sinon}
5. \Suivant{condition}{bloc du Suivant-cas-alors} \uCas{cas ou}{bloc de ce cas sans fin}
\Cas{cas ou}{bloc de ce cas}
\lCas{cas ou}{ligne de ce cas}
\Autre{bloc de lalternative}
\lAutre{ligne de lalternative}
6. \Pour{condition}{bloc de la boucle}
\lPour{condition}{ligne de la boucle}
7. \Tq{condition}{bloc de la boucle}
\lTq{condition}{ligne de la boucle}
8. \PourCh{condition}{bloc de la boucle}
\lPourCh{condition}{ligne de la boucle}
9. \PourTous{condition}{bloc de la boucle}
\lPourTous{condition}{ligne de la boucle}
10. \Repeter{condition darret}{bloc de la boucle}
\lRepeter{condition darret}{ligne de la boucle}
1. \SetKwInput{Donnes}{Donnees}
\SetKwInput{Res}{Resultat}
\SetKwInput{Entree}{Entrees}
\SetKwInput{Sortie}{Sorties}
2. \SetKw{KwA}{a}
\SetKw{Retour}{retourner}
3. \SetKwBlock{Deb}{debut}{fin}
4. \SetKwIF{Si}{SinonSi}{Sinon}{si}{alors}{sinon si}{alors}{finsi}
5. \SetKwSwitch{Suivant}{Cas}{Autre}{suivant}{faire}{cas ou}{autres cas}{fin cas}fin dalternative
6. \SetKwFor{Pour}{pour}{faire}{finpour}
42
7. \SetKwFor{Tq}{tant que}{faire}{fintq}
8. \SetKwFor{PourCh}{pour chaque}{faire}{finprch}
9. \SetKwFor{PourTous}{pour tous}{faire}{finprts}
10. \SetKwRepeat{Repeter}{repeter}{jusqua}
\FuerPar{condition}{loop}
\lFuerPar{condition}{line}
\FuerJedes{condition}{loop}
\lFuerJedes{condition}{line}
43
\FuerAlle{condition}{loop}
\lFuerAlle{condition}{line}Ende
\Solange{condition}{loop}Ende
\lSolange{condition}{line}
\SetKwInput{Ein}{Eingabe}
\SetKwInput{Aus}{Ausgabe}
\SetKwInput{Daten}{Daten}
\SetKwInput{Ergebnis}{Ergebnis}
\SetKw{Bis}{bis}
\SetKw{KwZurueck}{zuruck}
\SetKw{Zurueck}{zuruck}
\SetKwBlock{Beginn}{Beginn}{Ende}
\SetKwRepeat{Wiederh}{wiederhole}{bis}
\SetKwIF{Wenn}{SonstWenn}{Sonst}{wenn}{dann}{sonst wenn}{sonst}{Ende}
\SetKwSwitch{Unterscheide}{Fall}{Anderes}{unterscheide}{tue}{Fall}{sonst}{Ende
Fall}Ende.
\SetKwFor{Fuer}{fur}{tue}{Ende}
\SetKwFor{FuerPar}{fur}{tue gleichzeitig}{Ende}
\SetKwFor{FuerJedes}{fur jedes}{tue}{Ende}
\SetKwFor{FuerAlle}{fur alle}{tue}{Ende}
\SetKwFor{Solange}{solange}{tue}{Ende}
44
\lEnOtroCasoSi{condition}{elseif line without end}
\EnOtroCaso{else block}
\uEnOtroCaso{else block without end}
\lEnOtroCaso{else line}
5. \Seleccionar{condition}{Seleccionar caso block} \uSeleccionar{seleccionar}{caso block with-
out end}
\Caso{seleccionar}{caso block}
\lCaso{seleccionar}{caso line}
\Otro{sino block}
\lOtro{sino line}
6. \Para{condition}{loop block}
\lPara{condition}{loop line}
7. \ParaPara{condition}{loop block}
\lParaPara{condition}{loop line}
8. \Mientras{condition}{loop block}
\lMientras{condition}{loop line}
9. \ParaCada{condition}{loop block}
\lParaCada{condition}{loop line}
10. \ParaTodo{condition}{loop block}
\lParaTodo{condition}{loop line}
11. \Repetir{stop condition}{loop block}
\lRepetir{stop condition}{line loop}
Here we describe how they are obtained:
1. \SetKwInput{Datos}{Datos}
\SetKwInput{Resultado}{Resultado}
\SetKwInput{Entrada}{Entrada}
\SetKwInput{Salida}{Salida}
2. \SetKw{KwA}{a}
\SetKw{Devolver}{devolver}
3. \SetKwBlock{Inicio}{inicio}{fin}
4. \SetKwIF{SSi}{EnOtroCasoSi}{EnOtroCaso}{si}{entonces}{sino, si}{sino}{fin si}
5. \SetKwSwitch{Seleccionar}{Caso}{Otro}{seleccionar}{hacer}{caso}{sino}{fin caso}fin seleccionar
6. \SetKwFor{Para}{para}{hacer}{fin para}
7. \SetKwFor{ParaPara}{par}{hacer en paralelo}{fin para}
8. \SetKwFor{Mientras}{mientras}{hacer}{fin mientras}
9. \SetKwFor{ParaCada}{ParaCada}{hacer}{fin para cada}
10. \SetKwFor{ParaTodo}{para todo}{hacer}{fin para todo}
11. \SetKwRepeat{Repetir}{repetir}{hasta que}
45
12.4 Italian keywords
\KwIng{Ingresso}
\KwUsc{Uscita}
\KwDati{Dati}
\KwRisult{Risultato}
\KwA
\KwRitorna{ritorna}
\Ritorna{ritorna}
\Inizio{inside block}
\Ripeti{stop condition}{text loop}
\lRipeti{stop condition}{line of the loop}
\eSea{condition}{then block}{else block}
\{condition}{then block}
\uSea{condition}{then block without end}
\lSea{condition}{thens line text}
\AltSe{else block}
\uAltSe{else block without else}
\lAltSe{elses line text}
\Altrimenti{condition}{elseif block}
\uAltrimenti{condition}{elseif block without end}
\lAltrimenti{condition}{elseifs line text}
\Switch{condition}{Switch block}
\Case{a case}{case block}
\uCase{a case}{case block without end}
\lCase{a case}{cases line}
\Other{otherwise block}
\lOther{otherwises line}
\Per{condition}{text loop}
\lPer{condition}{line text loop}
\PerPar{condition}{text loop}
\lPerPar{condition}{line text loop}
\PerCiascun{condition}{text loop}
\lPerCiascun{condition}{line text loop}
\PerTutti{condition}{text loop}
\lPerTutti{condition}{line text loop}
\Finche{stop condition}{text loop}
\lFinche{stop condition}{text loop}
46
1. \SetKwInput{KwIng}{Ingresso}
2. \SetKwInput{KwUsc}{Uscita}
3. \SetKwInput{KwDati}{Dati}
4. \SetKwInput{KwRisult}{Risultato}
5. \SetKw{KwA}{a}
6. \SetKw{KwRitorna}{ritorna}
7. \SetKw{Ritorna}{ritorna}
8. \SetKwBlock{Inizio}{inizio}{fine}
9. \SetKwRepeat{Ripeti}{ripeti}{finch}
10. \SetKwIF{Sea}{AltSe}{Altrimenti}{se}{allora}{altrimenti se}{allora}{fine se}
11. \SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{endcase}endsw
\Ate
\KwRetorna{[val]}
\Retorna{[val]}
\Iniciob{inside block}
47
\Selec{condition}{Switch block}
\Caso{a case}{case block}
\uCaso{a case}{case block without end}
\lCaso{a case}{cases line}
\Outro{otherwise block}
\lOutro{otherwises line}
\Para{condition}{text loop}
\lPara{condition}{line text loop}
\ParaPar{condition}{text loop}
\lParaPar{condition}{line text loop}
\ParaCada{condition}{text loop}
\lParaCada{condition}{line text loop}
\ParaTodo{condition}{text loop}
\lParaTodo{condition}{line text loop}
\Enqto{stop condition}{text loop}
\lEnqto{stop condition}{text loop}
1. \SetKwInput{Entrada}{Entrada}
\SetKwInput{Saida}{Sada}
\SetKwInput{Dados}{Dados}
\SetKwInput{Resultado}{Resultado}
2. \SetKw{Ate}{ate} \SetKw{KwRetorna}{retorna}
\SetKw{Retorna}{retorna}
3. \SetKwBlock{Inicio}{incio}{fim}
4. \SetKwIF{Se}{SenaoSe}{Senao}{se}{ent~
ao}{sen~
ao se}{sen~
ao}{fim se}
5. \SetKwSwitch{Selec}{Caso}{Outro}{selecione}{faca}{caso}{sen~
ao}{fim caso}fim selec
6. \SetKwFor{Para}{para}{faca}{fim para}
7. \SetKwFor{ParaPar}{para}{faca em paralelo}{fim para}
8. \SetKwFor{ParaCada}{para cada}{faca}{fim para cada}
48
12.6 Some Czech keywords
Here are some czech keywords, please feel free to send me the others.
\Vst
\Vyst
\Vysl
1. \SetKwInput{Vst}Vstup
2. \SetKwInput{Vyst}Vystup
3. \SetKwInput{Vysl}Vysledek
13 Known bugs
no more known bugs actually; if you find one, please send it to me.
49
Release notes
% - July 18 2017 - revision 5.2
% * FIX: There was an overfull box 0.8pt with boxruled algorithm. This
% is fixed.
% * FIX: problem when mixing caption package and figure option. This bug
% was partially corrected in 5.0 for one side document but with
% false indentation and not working for two side document. This
% is now fully fixed.
% * FIX: misaligned lines numbers with noline option
% * FIX: Fix croation keywords thanks to Ivan Kolan
% * FIX: there was an overfull hbox of 8.5pt when using [H] and ruled
% caption. This is fixed.
% * FIX: \SetCustomAlgoRuledWidth only changed midrule. This is fixed,
% it changes all the rules
% - October 19 2015 - revision 5.1
% * CHANGE/ADD: l commands (the ones as \lIf) can now be used with a
% star. If done, no end of line are done, so you can enclose
% l command into another one. For example, you can write:
% \lForEach{$i$}{\lIf*{foo}{bar}}.
% Note that when you use a star, side comments are not allowed.
% * CHANGE/ADD: Now you can have a side comment at end of macros which
% have a block. For example you can do :
% \Begin(\tcc*[h]{side comment for begin}{
% text}(\tcc*[h]{side comment after end})
% Note: there are some side effects for some commands:
% \SetKwProg : macro defined thanks to \SetKwProg are allowed
% to have no end marker. In this case,
% beware to end side comment, this can
% do weird output (but no error)
% * CHANGE: \SetKwSwitch defines also an \uOther command which was not
% the case until this release.
% * CHANGE: \SetStartEndCondition{typo1}{typo2}{typo3} defined two end
% conditions (type2 and typo3) : typo3 is no more used for
% case condition as typo2 is used which is more consistent
% since there is a condition followed by a keyword as for
% if-then or other command that are defined using typo2.
% * CHANGE: keywords was not language dependant to allow to use multiple
% languages in the same document, but some keywords in
% different language were having the same keyword that lead
% last one declared to replace first one and so you could have some
% spanish keywords printed as you were in portuguese. So
% this behavior is changed from now:
% - localized keywords are defined if according language
% option is defined ;
% - if you want to keep old behaviour and use localized
% keywords without using language option (keep old
% behavior), you can use languagekw option
% (e.g. frenchkw, germankw, ...). Note that you can use
% multiple languagekw options at the same time, in
% contrary of language option. Note also that if you use
% multiple languagekw options, you can get back the same
% problem as previously when keywords was not language
% dependant.
50
% * ADD: new typo styles:
% - Arguments of functions have now their own style. By
% default, FuncArgSty is the same as ArgSty.
% - Name of KwProg have now their own sty (they used ArgSty
% previously). By default, ProgSty is still ArgSty.
% As usual, \SetFuncArgSty{}, FuncArgSty{} and
% \SetProgSty{}, ProgSty{} are macros to set and use these
% typo styles.
% * ADD: Options to manage algorithm hangindent
% Until this revision, long statement acts as classical text and
% continue on next line starting from the same point. This makes
% difficult to notice that the new lines of text is not a new
% statement. Now, hangindent is managed and when a long
% statement continue on next lines, lines, except the first,
% are indented.
% Option: noalgohanging
% By default, long statement are indented on subsequent
% lines; with this option you get old behavior and lines are
% no more indented
% Option: hangingcomment
% Comment that are alone on a line (not side comment) are
% not driven by algo hanging: subsequent lines of long
% comments are indented according to width of start comment
% marker. With this option, comment are indented like normal
% statement.
% Option: hanginginout
% As for comment, by default, in/out keywords and input
% keywords (defined by \SetKwInOut or \SetKwInput) are not
% indented by algorithm hangindent. They are indented
% according to width of input keyword. If you want that these
% keywords acts like normal statement, use this option.
% \SetAlgoHangIndent{length}
% This macro allows you to set your own indent length. By
% default, \SetAlgoHangIndent{0.5em}
% * ADD: Group markers.
% This option is related to block markers of release 5.0. Some
% have ask to put also block markers for single line
% command. This new feature has been implemented to do this.
% So, you can now ask package to put begin and end keywords
% automatically at start and end of single line command (see
% example in documentation).
% These new group markers macros are:
% - \AlgoDisplayGroupMarkers and \AlgoDontDisplayGroupMarkers
% Note that a new option has also been added: displaygroupmarkers
% * ADD: \SetCustomAlgoRuledWidth{length}
% set a custom ruled width of ruled and algoruled options ;
% note that by the moment you use this macro, rules will have
% this fixed length: this can cause strange behavior in
% multicolumn mode or other layout that change the line
% width.
% * ADD: turkish language option
% * FIX: a spurious whitespace which results in a spurious indent in the
% users text right after the end of the algorithm environment
% was introduced in release 5.0. This is fixed now thanks to
51
% Alexander Malkis.
% * FIX: there was a problem with margins in caption when option figure
% was use with caption package. This is fixed.
% * FIX: when changing font size in caption with, interline skip stayed
% unchanged and so with a small font was to large. This is fixed.
% * FIX: in contrary of that is written in the documentation, : what
% not in KwSty typo for KwIn and KwOut command. This is fixed.
% * FIX: strange behaviour with label and lines numbered: @currentlabel
% was updated according to algo line number not in all
% situation. For e.g, with hyperref package, always updated ;
% with \nlset also updated, but with \nl or linesnumbered
% option, not updated. This "feature" causes different output
% with \label command according to options used which is not
% that one want. This is solved now, and @currentlabel is
% always updated so \label command works always is the same way.
% * FIX: some czech keywords
% * FIX: some spanish keywords
% * FIX: some croatian keywords
% * FIX: krantz class changes definition of chapter and get one more
% option that classical classes as book.cls or report.cls and
% broke fix for hyperref on chapter definition. This is now
% fixed and algorithm detects use of krantz class and use then
% a definition of chapter working with krantz class.
% * FIX: an issue with internal macro which causes ([Q]) use as argument
% of some environment to be misprinted (thanks to Martin Schrder).
% * FIX: mispelled name of hyperrefcounter inside internal macro.
%
% - January 6 2013 - revision 5.0
% * CHANGE: SetKwSwith takes now 9 args: 9th arg is the same as
% previous 8th arg (end of switch keyword). New 8th arg is
% end of case keyword. This is due to change of release
% 3.2 which introduce end after case block... as I never
% test with longend option, I never see that the end
% switch used for case was not good.
% * CHANGE: when no end keyword is defined in a block macro, then
% algorithm2e does no more try to print it. So even with lined or noline
% option, no empty line is printed (before: a blank end was
% printed, so a blank line appeared)
% * Internal Change: add some internal function to improve readibility
% (thanks to Philip K. F. H\lzenspies)
% * ADD: Block markers.
% You can now ask package to put begin and end keywords automatically at begin
% and end of blocks, it means each group of commands shifted and enclosed in
% braces.
% This is tricky to use but, combined with \SetStartEndCondition and
% redefinition of keywords, you should be abble to simulate any syntax. See
% examples in documentation where a generic example is derived in pseudo-code,
% python and C by keeping code and changing only style using block markers
% macros, \SetStartEndCondition and some redefinition of keywords.
% These new block markers macros are:
% - \AlgoDisplayBlockMarkers and \AlgoDontDisplayBlockMarkers
% - \SetAlgoBlockMarkers{begin marker}{end marker}
% - \BlockMarkersSty{text} and \SetBlockMarkersSty
% Note that a new option has also been added: displayblockmarkers
52
% * ADD: \leIf macro automatically defined by \SetKw: allow to define
% an if-then-else on a single line.
% * ADD: new macro \SetStartEndCondition{typo1}{typo2}{typo3} which
% sets typo around condition in For, If, Switch, Case and
% Repeat macros. First two are used around For, If, Swith
% conditions, First and third are used for Case and Repeat
% condition. Default definition is \SetStartEndCondition{ }{ }{}.
% A common alternative is \SetStartEndCondition{ (}{) }{)}
% Can also be used to remove space around condition, for
% example if you want python style commands:
% \SetStartEndCondition{ }{}{} and \SetKwFor{For}{for}{:}{}
% * ADD: new environment algomathdisplay which allow display math (like inside \[ \] or $$ $$)
% handling end line and line number
% * ADD: new command \SetKwProg{Env}{Title}{ is}{end} which defines a macro
% \Env{args}{text}. Env is a block with Title (in \CapSty) at the beginning
% followed by args followed by is then text is put below inside a block ended
% by end. If no end is specified, nothing is written (no
% blank line is inserted). Useful to typeset function or prog for example:
% \SetKwProg{Fn}{Function}{ is}{end} makes \Fn{afunc(i: int) : int}{return 0\;}
% writes:
% Function afunc(i: int) : int is
% | return 0;
% end
% or \SetKwProg{Def}{def}{:}{} makes \Def{afunc(i: int)}{return 0\;} writes:
% def afunc(i: int):
% | return 0
% Tip: combine it with \SetKwFunction to write recursive function algorithm. With
% example above, you could define \SetKwFunction{\Afunc}{afunc} and then write:
% Def{\Afunc{i:int}{\eIf{i>0}{\KwRet \Afunc{i-1}}{\KwRet 0\;}} that writes:
% def afunc(i: int):
% | if(i>0):
% | return afunc(i-1)
% | else:
% | return 0
% with appropriate typo.
% * ADD: option croatian: croatian keywords (thanks to Ivan Gavran)
% * ADD: option ngerman: same as german option but so can be used with global option ngerman
% of babel
% * ADD: option spanish: Spanish support (thanks to Mario Abarca)
% * ADD: unterminated block: useful to add part separator that doesnt necessary need an end
% keyword.
% Designed on the pattern of unterminated if (see \uIf macro) allowing to
% add a block that is not terminated by a keyword. Such block are defined in the same
% time as a block is defined by adding a macro beginning with u. So, for example,
% predefined \SetKwBlock{Begin}{begin}{end} defines now two commands:
% - \Begin{} as previously which print a begin - end block
% - \uBegin{} that defines a begin only block
% * FIX: dotocloa option which was broken
% * FIX: uIf and uCase didnt have same behavior when used with
% noline, vlined or lined option. This is fixed. Side effect: no empty
% line after an uIf or uCase when used with options lined or vlined
% * FIX: a bug with Repeat Until command when use with side comment on Until
% * FIX: a bug with side text -- text put into () -- of command macro (SetKwIf and so on)
% which was always setting a ; even after a \DontPrintSemicolon
53
% * FIX: a bug with hyperref and chapter definition (thanks to Hubert Meier)
% * FIX: bugs with l macro and side comment
% * FIX: revision number
% * FIX: fix non ascii character (utf8 not yet recognized by all latex engine)
% * FIX: fnum@algocf had an useless parameter which sometimes broke expansion and output an error
% * FIX: works now with multicol package
54
List of Algorithms
1 How to write algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 disjoint decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 IntervalRestriction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4 Generic example with most classical expressions derived in pseudo-code . . . . . . . 9
5 Generic example in pseudo-code with begin-end block set . . . . . . . . . . . . . . . 11
6 algorithm 5 with {} block set even for one line command. . . . . . . . . . . . . . . . 12
7 Generic example in python-style like syntax . . . . . . . . . . . . . . . . . . . . . . . 13
8 Generic example in c-style like syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 14
9 Generic example in c-style like syntax with compact block . . . . . . . . . . . . . . 15
55
Index
\;, 4, 22, 37 \DataSty, 25, 35
\Daten, 43
\a, 46 \Datos, 44
\AlCapFnt, 24, 26, 26, 28 \Deb, 41
\AlCapNameFnt, 24, 26, 27, 27 \DecMargin, 16, 30
\AlCapNameSty, 26, 2629 \decmargin, 16
\AlCapSkip, 23, 23 \Devolver, 44
\AlCapSty, 25, 26, 2629 \DisplayBlockMarkers, 30
\AlFnt, 25 displayblockmarkers, 20, 22, 30
\AlgoDisplayBlockMarkers, 20, 22, 22 \DisplayGroupMarkers, 30
\AlgoDisplayGroupMarkers, 20, 22 displaygroupmarkers, 20, 22, 30
\AlgoDisplaygroupMarkers, 22 \Donnees, 41
\algomargin, 30, 30 \DontPrintSemicolon, 16, 22, 22
algomathdisplay, 25 \dontprintsemicolon, 16
algonl, 21 \DoThat, 36
algoruled, 19, 23, 29 dotocloa, 19
\AlTitleFnt, 27, 27
\AlTitleSty, 27, 27, 29 \eIf, 33, 37
\Altrimenti, 46 \Ein, 43
\AltSe, 46 elsart, 12
\Anderes, 43 \Else, 32, 37
arabtex, 12 \Else(comment), 37
\ArgSty, 25, 35, 36 \ElseIf, 32, 36
article-hermes, 16 \ElseIf(comment), 36, 37
ascelike, 12 endfloat, 19
\ate, 47 english, 18
\Aus, 43 \EnOtroCaso, 44
\autoref, 17 \EnOtroCasoSi, 44
\Autre, 42 \Enqto, 48
\Entrada, 44
\Begin, 31, 35 \Entree, 41
\Beginn, 43 \Ergebnis, 43
\Bis, 43 \eSe, 47
\BlankLine, 22 \eSea, 46
\BlockMarkersSty, 22, 26 \eSi, 42
boxed, 19, 29 \eSSi, 44
boxruled, 19 \eWenn, 43
\caption, 17, 22, 23, 23, 26, 27 \Fall, 43
\Cas, 42 figure, 19
\Case, 33, 39, 46 fillcomment, 20, 31
\Case(comment), 39 \Finche, 46
\Caso, 45, 48 \Fn, 36
\Comment, 36 \For, 33, 40
\Comment*, 36, 38 \For(comment), 40
commentsnumbered, 21, 24, 31 \ForAll, 34
\CommentSty, 25 \ForEach, 33, 34
croatian, 18 algo2e, 12, 19
croatiankw, 18 algochapter, 19
czech, 18 algopart, 19
czechkw, 18 algosection, 19
56
french, 18, 23 \KwSty, 22, 25, 26, 28
slide, 19 \KwTo, 31
frenchkw, 18 \KwUsc, 46
\Fuer, 43 \KwZurueck, 43
\FuerAlle, 43
\FuerJedes, 43 \label, 4, 16, 22, 24
\FuerPar, 43 \lAltrimenti, 46
\FuncArgSty, 25 \lAltSe, 46
\FuncSty, 25, 36 \lAnderes, 43
\lAutre, 42
german, 18 \lCas, 42
germankw, 18 \lCase, 33, 39, 46
\gIf, 16 \lCase(comment), 40
\gSonstWenn, 43 \lCase*, 40
\lCaso, 45, 48
hangingcomment, 20 \leftskip, 30
hermes, 12 \lElse, 33, 37
hyperref, 12, 17 \lElse(comment), 37
\lElse*, 37
\If, 32, 36 \lElseIf, 32, 37
\If(comment), 36 \lElseIf(comment), 37
\If(comment1), 36 \lElseIf*, 37
\IncMargin, 16, 30 \lEnOtroCaso, 44
\incmargin, 16 \lEnOtroCasoSi, 44
\Indm, 22 \lEnqto, 48
\Indp, 22 \lFall, 43
\Inicio, 44 \lFinche, 46
\Iniciob, 47 \lFor, 33, 40
\Inizio, 46 \lFor(comment), 40
inoutnumbered, 21 \lFor*, 40
\Input, 35 \lForAll, 34
\interspacetitleboxruled, 24 \lForEach, 34
\interspacetitleruled, 24 \lFuer, 43
italiano, 18 \lFuerAlle, 43
italianokw, 18 \lFuerJedes, 43
\lFuerPar, 43
\Kw, 35
\lIf, 32, 37
\KwA, 41, 44
\lIf(comment), 37
\KwDados, 47
\lIf*, 37
\KwData, 31
\Line, 35
\KwDati, 46
lined, 20
\KwEntrada, 47
\lineskip, 30
\KwFn, 36
\LinesNotNumbered, 16, 24
\KwFunction, 19
\linesnotnumbered, 16
\KwIn, 31
\LinesNumbered, 16, 24
\KwIng, 46
linesnumbered, 21, 21, 24, 31, 35
\KwOut, 31
\linesnumbered, 16
\KwResult, 31
\LinesNumberedHidden, 16, 24
\KwResultado, 47
linesnumberedhidden, 21, 24
\KwRet, 31
\linesnumberedhidden, 16
\KwRetorna, 47
\listofalgorithmes, 19
\KwRisult, 46
\listofalgorithms, 4, 22, 23
\KwRitorna, 46
\lMientras, 45
\KwSaida, 47
\lnl, 24, 24
57
\lnlset, 24 nofillcomment, 20, 31
longend, 20, 29 nokwfunc, 17, 19
\lOther, 33, 40, 46 \NoLine, 29
\lOther(comment), 40 noline, 20
\lOther*, 40 norelsize, 16, 19
\lOtro, 45 noresetcount, 21
\lOutro, 48
\lPara, 45, 48 oldcommands, 16
\lParaCada, 48 onelanguage, 18
\lParaPar, 48 opthanginginout, 20
\lParaPara, 45 \Other, 33, 40, 46
\lParaTodo, 45, 48 \Other(comment), 40
\lPer, 46 \Otro, 45
\lPerCiascun, 46 \Output, 35
\lPerPar, 46 \Outro, 48
\lPerTutti, 46
\lPour, 42 \Para, 45, 48
\lPourCh, 42, 45 \ParaCada, 45, 48
\lPourTous, 42 \ParaPar, 48
\lRepeat, 34, 41 \ParaPara, 45
\lRepeat(comment), 41 \ParaTodo, 45, 48
\lRepeat*, 41 \parindent, 30
\lRepeter, 42 \Per, 46
\lRepetir, 45 \PerCiascun, 46
\lRepita, 48 \PerPar, 46
\lRipeti, 46 \PerTutti, 46
\lSe, 47 plain, 19, 29
\lSea, 46 portuguese, 18
\lSenao, 47 portuguesekw, 18
\lSenaoSe, 47 \Pour, 42
\lSi, 42 \PourCh, 42
\lSinon, 42 \PourTous, 42
\lSinonSi, 42 \PrintSemicolon, 16, 22
\lSolange, 43 \printsemicolon, 16
\lSonst, 43 \ProcArgFnt, 21, 26, 27, 27
\lSonstWenn, 43 \ProcArgSty, 21, 26, 26, 27, 27
\lSSi, 44 \ProcFnt, 26, 26, 27, 27
\lTq, 42 \ProcNameFnt, 21, 26, 27, 27
\lWenn, 43 \ProcNameSty, 21, 25, 26, 27, 27
\lWhile, 33 procnumbered, 19
\lWiederh, 43 \ProcSty, 26, 27, 27
\ProgArgFnt, 26
\Mientras, 45 \ProgArgSty, 26
\ProgSty, 25
ngerman, 18 pstcol, 12
\nl, 6, 24, 24
\nllabel, 21, 24 \ref, 6, 24
\nlset, 6, 24, 24 \relax, 2628
\NlSty, 16, 25 \Repeat, 34, 41
\nlSty, 16 \Repeat(comment after repeat), 41
noalgohanging, 20 \Repeter, 42
\NoCaptionOfAlgo, 16, 23, 23 \Repetir, 45
\nocaptionofalgo, 16 \Repita, 48
noend, 20, 29 \Res, 41
58
resetcount, 21 \SetAlTitleFnt, 28
\ResetInOut, 35 \SetAlTitleSty, 29, 29
\RestoreCaptionOfAlgo, 16, 23 \SetArgSty, 28
\restorecaptionofalgo, 16 \SetBlockMarkersSty, 28
\RestyleAlgo, 16, 29 \SetCommentSty, 28
\restylealgo, 16 \SetCustomAlgoRuledWidth, 23
\Resultado, 44 \SetDataSty, 28
\Retorna, 47 \SetFillComment, 31
\Retour, 41 \SetFuncArgSty, 28
\Return, 31 \SetFuncSty, 28
rightnl, 21 \SetInd, 29
\Ripeti, 46 \SetKw, 21, 34, 35, 35, 42, 44, 45, 47, 48
\Ritorna, 46 \SetKwAll, 34
ruled, ,vlined6 \SetKwArray, 35
ruled, 19, 23, 29 \SetKwBlock, 34, 35, 42, 44, 45, 47, 48
\SetKwComment, 31, 34, 36
\Salida, 44 \SetKwData, 22, 35
scleft, 20, 31 \SetKwFor, 34, 40, 42, 44, 45, 47, 48
scright, 20, 31 \SetKwFunction, 21, 36, 36
\Se, 47 \SetKwHangingKw, 35
\Sea, 46 \SetKwIF, 34, 36, 42, 44, 45, 47, 48
\Selec, 48 \SetKwInOut, 35, 35
\Seleccionar, 45 \SetKwInput, 34, 35, 35, 42, 44, 45, 4749
\Senao, 47 \SetKwProg, 35
\SetAlCapFnt, 26, 28, 28 \SetKwRepeat, 34, 41, 42, 44, 45, 47, 48
\SetAlCapHSkip, 16, 23 \SetKwSty, 28
\setalcaphskip, 16 \SetKwSwitch, 34, 39, 42, 44, 45, 47, 48
\SetAlCapNameFnt, 26, 28, 28, 29 \setlength, 30
\SetAlCapNameSty, 26, 28, 29, 29 \SetLine, 16
\SetAlCapSkip, 16, 23, 23 \SetNlSkip, 16, 24
\setalcapskip, 16 \Setnlskip, 16
\SetAlCapSty, 26, 29, 29 \setnlskip, 16
\SetAlFnt, 27, 28 \SetNlSty, 16, 24, 24, 28
\SetAlgoBlockMarkers, 30 \Setnlsty, 16
\SetAlgoBlockMarkersbegin keywordsend keywords,
\SetNoFillComment, 31
22 \SetNoLine, 16
\SetAlgoCaptionLayout, 23, 23, 24, 30 \SetNoline, 20, 29
\SetAlgoCaptionSeparator, 23 \SetProcArgSty, 28
\SetAlgoFuncName, 17 \SetProcFnt, 26
\SetAlgoHangIndent, 29 \SetProcNameFnt, 26
\SetAlgoInsideSkip, 30 \SetProcNameSty, 26, 28
\SetAlgoLined, 16, 20, 29 \SetProcSty, 26
\SetAlgoLongEnd, 29 \SetProgArgFnt, 26
\SetAlgoNLRelativeSize, 25 \SetProgArgSty, 26
\SetAlgoNlRelativeSize, 25, 30 \SetProgSty, 28
\SetAlgoNoEnd, 29 \SetSideCommentLeft, 31
\SetAlgoNoLine, 16 \SetSideCommentRight, 31
\SetAlgoProcName, 17 \SetStartEndCondition, 22
\SetAlgoRefName, 22, 23, 23 \SetTitleSty, 23, 23
\SetAlgoRefRelativeSize, 23, 23 \SetVline, 16
\SetAlgorithmName, 17 \SetVlineSkip, 16
\SetAlgoShortEnd, 29 \Setvlineskip, 16, 29
\SetAlgoSkip, 30 shortend, 20, 29
\SetAlgoVlined, 16, 20, 29 \ShowLn, 16, 21, 24, 24
59
\showln, 16 \uSeleccionar, 45
\ShowLnLabel, 16, 21, 24 \uSenao, 47
\showlnlabel, 16 \uSenaoSe, 47
\Si, 42 \uSi, 42
\Sinon, 42 \uSinon, 42
\Solange, 43 \uSinonSi, 42
\Sonst, 43 \uSonst, 43
\Sortie, 41 \uSonstWenn, 43
spanish, 18 \uSSi, 44
spanishkw, 18 \uWenn, 43
\SSi, 44
\Suivant, 42 \Vline, 35
\Switch, 33, 39, 46 vlined, 20, 29
\Switch(comment), 39 \Vst, 49
\Vysl, 49
\tcc, 31, 32, 36 \Vyst, 49
\tcc*, 32
\tcc*[f], 32, 35 \Wenn, 43
\tcc*[h], 32 \While, 33
\tcc*[l], 32 \Wiederh, 43
\tcc*[r], 32
\tcp, 32, 36 \Zurueck, 43
\tcp*, 32
\tcp*[f], 32
\tcp*[h], 32
\tcp*[l], 32
\tcp*[r], 32
titlenotnumbered, 21
titlenumbered, 21
\TitleOfAlgo, 21, 22, 23, 23, 28, 29
\Tq, 42
turkish, 18
turkishkw, 18
tworuled, 19
\uAltrimenti, 46
\uAltSe, 46
\uBegin, 35
\uCas, 42
\uCase, 33, 39, 46
\uCase(comment), 39
\uCaso, 48
\uElse, 32, 33, 37
\uElseIf, 32, 37
\uElseIf(comment), 37
\uEnOtroCaso, 44
\uEnOtroCasoSi, 44
\uFall, 43
\uIf, 32, 37
\uIf(comment), 37
\Unterscheide, 43
\uOther, 40
\uSe, 47
\uSea, 46
60