我在 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}
但我需要将“if .. then .. else”之类的语句改为“si.. entonces ... de lo contrario”。
我尝试过,但是没有用,我的意思是输出和我没有选择语言时一样。
答案1
选项spanish
不仅翻译algorithm
为,algoritmo
而且选项onelanguage
还翻译关键字。
\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}
答案2
除了 Ignasi 的回答之外,该文件还algorithm2e.sty
包含(针对西班牙语)以下定义:
\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}
}{}%
因此,如果您想自定义其中一个术语(例如,将“en otro caso”更改为“de lo contrario”,您可以在序言中添加以下行:
\SetKwIF{If}{ElseIf}{Else}{si}{entonces}{sin\'o, si}{de lo contrario}{fin si}
因此 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}
产量