latex - 在英语和法语中使用 algorithm2e
问题描述
我正在用两种语言写我的论文,即英语和法语。我用英文写了算法 algorithm2e。但是,在其中一个部分中,我还需要用法语编写算法。我怎样才能做到这一点?我的意思是我只想在一个部分而不是整个乳胶文档中将算法中的所有关键字更改为法语。
解决方案
algorithm2e
提供包选项french
和frenchkw
. 除其他外,前者更改了与\caption
s in相关联的名称algorithm
。后者提供了您可以使用的法语关键字。
如果您想同时使用英语和法语算法,则algorithm2e
在一个选项下加载包,并定义包提供的附加关键字。下面是一个小例子(我不会说法语):
\documentclass{article}
\usepackage{algorithm2e}
% French keywords:
\SetKwInput{KwRes}{R\'esultat}%
\SetKwIF{Si}{SinonSi}{Sinon}{si}{alors}{sinon si}{sinon}{fin si}%
\SetKwFor{Tq}{tant que}{faire}{fin tq}%
\begin{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 in English}
\end{algorithm}
\begin{algorithm}[H]
\renewcommand{\algorithmcfname}{Algorithme}%
\SetAlgoLined
\KwData{this text}
\KwRes{how to write algorithm with \LaTeX2e }
initialization\;
\Tq{not at end of this document}{
read current\;
\eSi{understand}{
go to next section\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms in French}
\end{algorithm}
\end{document}
以下是英文算法内容的完整定义(取自algorithm2e.sty
):
\renewcommand{\listalgorithmcfname}{List of Algorithms}%
\renewcommand{\algorithmcfname}{Algorithm}%
\renewcommand{\algorithmautorefname}{algorithm}%
\renewcommand{\algorithmcflinename}{line}%
\renewcommand{\algocf@typo}{}%
\renewcommand{\@algocf@procname}{Procedure}%
\renewcommand{\@algocf@funcname}{Function}%
\renewcommand{\procedureautorefname}{procedure}%
\renewcommand{\functionautorefname}{function}%
\renewcommand{\algocf@languagechoosen}{english}%
\SetKwHangingKw{KwHData}{Data$\rightarrow$}
\SetKwInput{KwIn}{Input}%
\SetKwInput{KwOut}{Output}%
\SetKwInput{KwData}{Data}%
\SetKwInput{KwResult}{Result}%
\SetKw{KwTo}{to}
\SetKw{KwRet}{return}%
\SetKw{Return}{return}%
\SetKwBlock{Begin}{begin}{end}%
\SetKwRepeat{Repeat}{repeat}{until}%
%
\SetKwIF{If}{ElseIf}{Else}{if}{then}{else if}{else}{end if}%
\SetKwSwitch{Switch}{Case}{Other}{switch}{do}{case}{otherwise}{end case}{end switch}%
\SetKwFor{For}{for}{do}{end for}%
\SetKwFor{ForPar}{for}{do in parallel}{end forpar}
\SetKwFor{ForEach}{foreach}{do}{end foreach}%
\SetKwFor{ForAll}{forall}{do}{end forall}%
\SetKwFor{While}{while}{do}{end while}%
以下是法语算法内容的完整定义(取自algorithm2e.sty
):
\renewcommand{\listalgorithmcfname}{Liste des Algorithmes}%
\renewcommand{\algorithmcfname}{Algorithme}%
\renewcommand{\algorithmautorefname}{algorithme}%
\renewcommand{\algorithmcflinename}{ligne}%
\renewcommand{\algocf@typo}{\ }%
\renewcommand{\@algocf@procname}{Proc\'edure}%
\renewcommand{\@algocf@funcname}{Fonction}%
\renewcommand{\procedureautorefname}{proc\'edure}%
\renewcommand{\functionautorefname}{fonction}%
\renewcommand{\algocf@languagechoosen}{french}%
\SetKwHangingKw{HDonnees}{Donnees$\rightarrow$}
\SetKwInput{Donnees}{Donn\'ees}%
\SetKwInput{Res}{R\'esultat}%
\SetKwInput{Entree}{Entr\'ees}%
\SetKwInput{Sortie}{Sorties}%
\SetKw{KwA}{\`a}%
\SetKw{Retour}{retourner}%
\SetKwBlock{Deb}{d\'ebut}{fin}%
\SetKwRepeat{Repeter}{r\'ep\'eter}{jusqu'\`a}%
%
\SetKwIF{Si}{SinonSi}{Sinon}{si}{alors}{sinon si}{sinon}{fin si}%
\SetKwSwitch{Suivant}{Cas}{Autre}{suivant}{faire}{cas o\`u}{autres cas}{fin cas}{fin d'alternative}%
\SetKwFor{Pour}{pour}{faire}{fin pour}%
\SetKwFor{PourPar}{pour}{faire en parall\`ele}{fin pour}%
\SetKwFor{PourCh}{pour chaque}{faire}{fin pour chaque}%
\SetKwFor{PourTous}{pour tous les}{faire}{fin pour tous}%
\SetKwFor{Tq}{tant que}{faire}{fin tq}%
如果您使用任何包含@
(例如\renewcommand{\@algocf@procname}{Proc\'edure}
,例如)的定义,则必须使用\makeatletter
...\makeatother
对包围重新定义。
推荐阅读
- python - 来自函数对象的静态方法。为什么我不需要静态方法呢?
- installation - Yeoman 生成器未安装在 VDI 中
- python - Plotly Dash 并排图
- jolt - 使用 JOLT 基于过滤器提取 Json 数组中的某些字段
- codeigniter - Codeigniter get_where() 函数某些条件不起作用
- sql - 在列中查找特定匹配项,如果该 id 没有该值,则返回 null
- elasticsearch - 使用 Logstash 和 Filebeat 在弹性搜索中选择文件夹中的每个文件作为单个日志条目
- python - 如何在python中并行化类方法?
- angular8 - Angular - 仅限年份选择器
- c# - Unity Android 将本地 MP3 或 WAV 加载为 AudioClip