Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using this code in LaTeX

\documentclass[12pt,a4paper]{report}
\usepackage[spanish]{babel}
\selectlanguage{spanish} 
\usepackage{algorithm2e} %for psuedo code
\usepackage[lmargin=3.81cm,tmargin=2.54cm,rmargin=2.54cm,bmargin=2.52cm]{geometry}
\begin{document}

\begin{algorithm}[H] %or another one check
 \caption{How to write algorithms}
     \SetAlgoLined

     \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\;
      }
     }

\end{algorithm}

\end{document}

But I need that statements like 'if .. then .. else' to be changed to 'si.. entonces ... de lo contrario'.

I tried that but doesn't work, I mean the output is the same as if I didn't select a language.

share|improve this question
    
i tried that but doesn't work, i mean the output is the same as if i didn't selected a language, i found this might be handy for other people, unfortunately only have a keywords in portugese , german and french tug.org/texlive/Contents/live/texmf-dist/doc/latex/algorithm2e/… –  B.J. A.A. Nov 20 '13 at 18:17

2 Answers 2

up vote 7 down vote accepted

Option spanish only translates algorithm to algoritmo but option onelanguage also translates keywords.

\documentclass[12pt,a4paper]{report}
\usepackage[spanish]{babel}
\selectlanguage{spanish} 
\usepackage[spanish,onelanguage]{algorithm2e} %for psuedo code
\usepackage[lmargin=3.81cm,tmargin=2.54cm,rmargin=2.54cm,bmargin=2.52cm]{geometry}
\begin{document}

\begin{algorithm}[H] %or another one check
 \caption{How to write algorithms}
     \SetAlgoLined

     \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\;
      }
     }

\end{algorithm}

\end{document}

enter image description here

share|improve this answer

In addition to Ignasi's answer, the file algorithm2e.sty contains (for Spanish language) the following definitions:

\ifthenelse{\boolean{algocf@optonelanguage}\AND\equal{\algocf@languagechoosen}{spanish}}{%
\SetKwInput{KwIn}{Entrada}%
\SetKwInput{KwOut}{Salida}%
\SetKwInput{KwData}{Datos}%
\SetKwInput{KwResult}{Resultado}%
\SetKw{KwTo}{a}%
\SetKw{KwRet}{devolver}%
\SetKw{Return}{devolver}%
\SetKwBlock{Begin}{inicio}{fin}%
\SetKwRepeat{Repeat}{repetir}{hasta que}%
%
\SetKwIF{If}{ElseIf}{Else}{si}{entonces}{sin\'o, si}{en otro caso}{fin si}
\SetKwSwitch{Switch}{Case}{Other}{seleccionar}{hacer}{caso}{sin\'o}{fin caso}{fin seleccionar}
\SetKwFor{For}{per}{fai}{fine per}%
\SetKwFor{ForPar}{par}{hacer in paralelo}{fin para}%
\SetKwFor{ForEach}{para cada}{hacer}{fin para cada}
\SetKwFor{ForAll}{para todo}{hacer}{fin para todo}
\SetKwFor{While}{mientras}{hacer}{fin mientras}
}{}%

So if you want to customize one of these terms (e.g. change "en otro caso" to "de lo contrario" you can add the following line in the preamble:

\SetKwIF{If}{ElseIf}{Else}{si}{entonces}{sin\'o, si}{de lo contrario}{fin si}

so that the MWE

\documentclass[12pt,a4paper]{report}
\usepackage[spanish]{babel}
\selectlanguage{spanish}
\usepackage[spanish,onelanguage]{algorithm2e} %for psuedo code
\usepackage[lmargin=3.81cm,tmargin=2.54cm,rmargin=2.54cm,bmargin=2.52cm]{geometry}
\SetKwIF{If}{ElseIf}{Else}{si}{entonces}{sin\'o, si}{de lo contrario}{fin si}

\begin{document}

\begin{algorithm}[H] %or another one check
 \caption{How to write algorithms}
     \SetAlgoLined

     \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\;
      }
     }

\end{algorithm}

\end{document} 

yields

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.