Friday, July 19, 2013

Algorithms in IEEE latex paper manuscripts

While preparing a manuscript on a IEEE latex paper template, I wanted to add a pseudo code of an algorithm to it. I write it down here to avoid forgetting it and also for the benefit of somebody somewhere in this world.

First of all I should have installed the full package of latex on my Ubuntu 12.04 machine to avoid the problems of different missing packages. I do it by the following command.

sudo apt-get install texlive-full

For preparing the manuscript I used the bare_conf.tex file coming with the latex templates which can be downloaded from IEEE website here. So, following commands should be added to that file in the appropriate places to make an example algorithm.

1:  \usepackage{algpseudocode}  
3:  \begin{figure}  
4:  \begin{algorithmic}[1]  
5:  \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}  
6:  \State $r\gets a\bmod b$  
7:  \While{$r\not=0$}\Comment{We have the answer if r is 0}  
8:  \State $a\gets b$  
9:  \State $b\gets r$  
10:  \State $r\gets a\bmod b$  
11:  \EndWhile\label{euclidendwhile}  
12:  \State \textbf{return} $b$\Comment{The gcd is b}  
13:  \EndProcedure  
14:  \end{algorithmic}  
15:  \caption{Euclid's algorithm}  
16:  \label{euclid}  
17:  \end{figure}

After this if we generate the PDF file, our algorithm should appear in the paper like the following.

So, have a nice time with preparing research papers!

1 comment:

  1. Since I am drafting my paper using MS Word, any idea how to embed this algorithm format in a MS Word file?