# Problem with algorithm2e and portuguese option

I have this little algorithm with two For statements and one if-else. I'm using the option portuguese on the preamble and here's the problem: instead of displaying the words "faça" and "fim" (do and end, respectively), I get "hacer" and "fin".

Here's my preamble:

\documentclass{article}
\usepackage{cmap}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[brazil]{babel}
\usepackage{lastpage}
\usepackage{indentfirst}
\usepackage{color}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{multirow}
\usepackage[brazilian,hyperpageref]{backref}
\usepackage[alf]{abntex2cite}
\usepackage[portuguese]{algorithm2e}


And here's the code:

\begin{document}
\begin{algorithm}[htbp]
\SetAlgoLined
\LinesNumbered
\BlankLine
$inicio \leftarrow 0$\;
$comprimento \leftarrow tamanho$\;
\Para{$i \leftarrow 0$ \Ate $i<nivel$}{
$inicio \leftarrow 0$\;
$comprimento \leftarrow tamanho/2^{i-1}$\;
\Para{$j \leftarrow 0$ \Ate $j<2^{i-1}$}{
\eSe{j é par}{
}{
}
}
}
\caption{A DWT-packet}
\label{alg:dwtp}
\end{algorithm}
\end{document}


The result (i'm using pdfLaTeX on Windows):

...
para i ← 0 até i < nível hacer
...
para j ← 0 até j < 2^(i-1) hacer
...


If I put \SetKwFor{Para}{para}{fa\c{c}a}{fim para} on the TeX file, I get the right output. But this command is on the package already. Why doesn't it work?

-
Hi Luan, welcome to TeX.SX! :) Interesting question. I suspect something related to the later expansion of \Para, since both spanish and portuguese share the same macro name for it. – Paulo Cereda May 9 '13 at 1:25
I get "faça" out of the box. – egreg May 9 '13 at 11:00
I also get hacer (algorithm2e 2013/01/06 v5.00). It seems to be version dependent. – Nicola Talbot May 9 '13 at 20:02
I checked and my system is using an old version: Package algorithm2e' Release 4.01 -- december 14 2009, and I do not get hacer with the old version. – Sergio Parreiras May 9 '13 at 21:33
@NicolaTalbot, I get the correct output using ShareLaTeX: the version used there is 3.10, according to the log. – Luan Resende May 10 '13 at 18:01

This is a nasty bug in algorithm2e. The setting of the "localized keywords" is not language dependent and the same keyword Para is defined for Portuguese and Spanish. The latter has been added in the last revision of the package and

\SetKwFor{Para}{para}{hacer}{fin para}


appears later than the similar definition in the Portuguese section, thus overriding it.

Solving such a bug requires a different treatment of keywords, that keeps track of the language option, which presently the package doesn't do.

The only solution is what you found: issuing

\SetKwFor{Para}{para}{fa\c{c}a}{fim para}


after loading algorithm2e`.

Please, mention this to the package author.

-

Try to use an old version of the package. With algorithm2e Release4.01, december 14, 2009, I do not have this problem as you can see:

-