16

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.

1

2 Answers 2

17

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

7

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .