Knowledge base dedicated to Linux and applied mathematics.
Accueil > Latex > FAQ > Latex - FAQ > Comment écrire un algorithme en Latex ?\usepackagealgorithm,\usepackagealgorithm
Toutes les versions de cet article : <English> <français>
On doit tout d’abord utiliser les packages suivants
\usepackage{algorithm}
\usepackage{algorithmic}
Voici un example :
\begin{algorithm}
\caption{Calculate $y = x^n$}
\begin{algorithmic}
\REQUIRE $n \geq 0 \vee x \neq 0$
\ENSURE $y = x^n$
\STATE $y \leftarrow 1$
\IF{$n < 0$}
\STATE $X \leftarrow 1 / x$
\STATE $N \leftarrow -n$
\ELSE
\STATE $X \leftarrow x$
\STATE $N \leftarrow n$
\ENDIF
\WHILE{$N \neq 0$}
\IF{$N$ is even}
\STATE $X \leftarrow X \times X$
\STATE $N \leftarrow N / 2$
\ELSE[$N$ is odd]
\STATE $y \leftarrow y \times X$
\STATE $N \leftarrow N - 1$
\ENDIF
\ENDWHILE
\end{algorithmic}
\end{algorithm}
Les commandes suivantes vous seront très utiles !!!
\STATE <text>
\IF{<condition>} <text> \ENDIF
\IF{<condition>} <text> \ELSE <text> \ENDIF
\IF{<condition>} <text> \ELSIF{<condition>} <text> \ELSE <text> \ENDIF
There are two forms
\FOR{<condition>} <text> \ENDFOR
\FORALL{<condition>} <text> \ENDFOR
\WHILE{<condition>} <text> \ENDWHILE
\REPEAT <text> \UNTIL{<condition>}
\LOOP <text> \ENDLOOP
\REQUIRE <text>
\ENSURE <text>
\RETURN <text>
\PRINT <text>
Note : Due to a bug, the algorithmic package is not compatible with hyperref.