0

Could you please help in the following issues with the algorithme package, the French version of algorithm?

  1. I wanted to number the lines; but the option linesnumbered does not work, like in algorithm.

  2. There is an extra space after the parenthesis (in the resulting code), which I tried to remove but it does not work.

Unfortunately, I could not use the algorithm package, I need my pseudo-code to be written in French.

Here is a MWE followed by the image of the result:

\documentclass[12pt,A4paper]{article}
\usepackage{algorithme}
\begin{document}
\begin{algorithme}
\Function{Pair}
{\Type{Donnée x}{entier}}
{booléen}
{
    \IfThenElse{x mod 2 = 0}
    {
    \Return{Vrai};      
    }
    {
    \Return{Faux};      
    }\\
}
\end{algorithme}
\end{document}

Resulting pseudo-code:

Werner
  • 603,163

1 Answers1

1

You can use the following definitions made from algorithm2e to replicate your output for the unknown algorithme.sty:

enter image description here

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[linesnumbered,plain,lined]{algorithm2e}
\usepackage{amsmath}

\newcommand{\Mod}[1]{\ (\text{mod}\ #1)}% http://tex.stackexchange.com/a/137076/5764

\newenvironment{algorithme}[1][htbp]
  {\begin{algorithm}[#1]}
  {\end{algorithm}}
\SetKwProg{Fonction}{Fonction}{}{Fin}
\newcommand{\FName}[1]{#1\setcounter{fargs}{0}}
\newcounter{fargs}% Count number of arguments per function
\newcommand{\FInput}[2]{\unskip
  \stepcounter{fargs}% A new argument
  \ifnum\value{fargs}=1 (\else, \fi% Separator between arguments
  {#1}: {\KwSty{#2}}}
\newcommand{\FOutput}[1]{\unskip\ifnum\value{fargs}>0)\fi: {\KwSty{#1}}}

\SetKwIF{Si}{SinonSi}{Sinon}% LaTeX macros
  {Si}{Alors}{Sinon Si}{Sinon}{Fin Si}% Text set
\SetKw{Retourner}{Retourner}

\renewcommand{\ProgSty}[1]{{\textnormal #1}\unskip}
\renewcommand{\ArgSty}[1]{{\textnormal #1}\unskip}
\SetAlgorithmName{Algorithme}{Liste des Algorithmes}

\begin{document}

\begin{algorithme}
  %\caption{Some algorithm}
  \Fonction{\FName{Pair} \FInput{Donnée x}{entier} \FInput{Donnée y}{entier} \FOutput{booléen}}
  {
    \eSi{\mbox{$x \Mod{2} = 0$}}{
      \Retourner{Vrai}\;
    }{
      \Retourner{Faux}\;
    }
  }
\end{algorithme}

\end{document}

If you truly want a red styled algorithm, you can update the algorithme environment in the following way:

\usepackage{xcolor}

\newenvironment{algorithme}[1][htbp]
  {\begin{algorithm}[#1]
     \color{red!70!black}}
  {\end{algorithm}}

enter image description here

I made a slight change to the interface, which should be more intuitive.

Werner
  • 603,163