home page

my blog posts

Writing simple algorithms in LateX

Latex has several plugins that can be used to format your documents into scientific standards. The algorithm package brings well aligned and styled looking algorithms into any paper. the following example shows an algorithm tag for a recursive method.

\begin{algorithm}[H]
 \SetAlgoLined
  \KwIn{$  $\Comment{model.ump}}  
  \KwOut{$  $\Comment{model_{mutationOperator}.ump}} 
  $filesToMutate.add(model)$\newline
  $searchForLinkedFiles(model)$ \newline
  \SetKwFunction{FMain}{searchForLinkedFiles}
     \SetKwProg{Fn}{Function}{:}{}
     \Fn{\FMain{$file$}}{
   \eIf{\exists model \ni linkedFiles }   {   \ForEach{$ k \in linkedFiles $}      {\eIf{$ k \ni linkedFiles $}         {$ searchForLinkedFiles(k) \newline            filesToMutate.add(k)            $}         { $ filesToMutate.add(k) $}     }   }   {\tcp{model has no linked files}}    R $\in filesToMutate$\newline   $mutate(R)$\newline \textbf{return} $ mutant $ 
 }
 \caption{Mutating Umple model with linked files}
 \end{algorithm}

This should render the following result:


Share:

Let's keep in touch