## Tuesday, June 3, 2014

### Working with LaTeX

While working with LaTeX for my master thesis, I found so many useful packages and commands in making the paper more attractive. I am listing some of them here. Please reply in comments, if you have some other suggestions on these.

1. Labelled Matrix.

 1. Labelled Matrix
\bordermatrix{\text{}&Exp_1&Exp_2& Exp_3 &Exp_4 & Exp_5 & Exp_6\cr
Node_1&  S+C  & I & 0 & 0 & 0 & 0\cr
Node_2& S+C & I & 2I  &  0 & 0 & 0\cr
Node_3& I & 0 & S & I & 0 & 0\cr
Node_4& 0 & 0 & I & 0 & 0 & 0 \cr
Node_5& 0  & 0 & 0 & S+I & 0  & 0\cr
Node_6& 0  & 0 & 0 & 0 & I  & I}


2. Code Segments
Java, C++, pseudo codes, or whatever that you would like to highlight and pretty print.
 2. Code Segments

In the definitions,
\usepackage{listings}
\usepackage{color}
\usepackage{textcomp}
\definecolor{listinggray}{gray}{0.98}
\definecolor{lbcolor}{rgb}{0.98,0.98,0.98}
\lstset{
backgroundcolor=\color{lbcolor},
tabsize=4,
rulecolor=,
language=java,
basicstyle=\scriptsize,
upquote=true,
aboveskip={1.5\baselineskip},
columns=fixed,
showstringspaces=false,
extendedchars=true,
breaklines=true,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\color[rgb]{0,0,1},
stringstyle=\color[rgb]{0.627,0.126,0.941},
}

Then, wherever you want it,
\begin{lstlisting}
String clusterGroup = HzConstants.MAIN_HZ_CLUSTER + id;

// Initialize the CloudSim library
\end{lstlisting}

3. Equations
Use the Equations package, to include some equations or formulae. It is much convenient.
 3. Equations


$$\label{eq:iequation} T_{p} = \frac{k.T_{1}}{n} + (1-k).T_{1} + f(n) + S + F$$

Speedup,
$$\label{eq:baseequation} S_{p} = \frac{T_{1}}{T_{p}}$$

From equations \ref{eq:iequation} and \ref{eq:baseequation},
$$\label{eq:finalequation} S_{p} = \frac{T_{1}}{\frac{k.T_{1}}{n} + (1-k).T_{1} + f(n) + S + F}$$


Having difficulty in generating the equations in LaTeX form? Don't worry. Use this web service, and pick LaTeX as the output format. Have a look at this guide, for an introduction to LaTeX Math. Have problems with the location of images in the output PDF? Have a look at this. Also if you have problems with Unicode characters, take a look at this. Specifically, the below error message is common with Unicode characters such as accented letters (e.g: é).
! Package inputenc Error: Unicode char \u8:�cn not set up for use with LaTeX.

Also consider using utf8x instead of utf8, as below, in the preamble, for Unicode characters.
\usepackage[utf8x]{inputenc}

Hope this post was useful. Will add more in a later post, probably. If you are looking for how to install LaTeX, have a look at this post.