Latex

Dr. Tom V. Mathew

August 21, 2013

Installation

ubundu

Explain the text editor vim and latex installtion in an ubundu system.
  1. Enable proxy
    sudo vi /etc/apt/apt.conf
    
    and make the following changes
    Acquire::http::proxy "http://userid:passsword@netmon.iitb.ac.in:80/";
    Acquire::ftp::proxy "ftp://userid:passsword@netmon.iitb.ac.in:80/";
    Acquire::https::proxy "https://userid:passsword@netmon.iitb.ac.in:80/";
    
  2. update the settings
    sudo apt-get update
    
  3. Install vim almost full set (put Y when promoted)
    sudo apt-get install vim vim-scripts vim-doc vim-latexsuite vim-gui-common vim-gnome
    
  4. Install latex
    sudo apt-get install texlive-full
    
  5. Install html converter, figure editor, pdfreader etc.
    sudo apt-get install latex2html
    sudo apt-get install xfig
    sudo apt-get install acroread
    suod apt-get install ghostscript gv gsfonts gsfonts-x11 gsfonts-other
    sudo fc-cache -f -v
    

Basics

Latex is like a programming and it works on the principle of what you want is what you get (WYWIWYG) unlike the what you see is what you get (WYSIWIG). Why latex? Let the experts speak.

Quick Compilation

This section will tell how to get you first tex page and its out put in pdf format.
  1. First create a file, say vim file.tex as follows.
    \documentclass{article}
    \begin{document}
    My First Tex File
    \end{document}
    
  2. Then compile this file as follows:
    pdflatex file.tex
    
  3. This will generate file.pdf which will produce file.pdf which can be viewed using xpdf, kghostview, or Adobe's Acrobat reader and threre by print.

Full Compilation

The above is latest quick way of using latex. The traditional way of using latex is as follows. This is recommended for several resons.
  1. First create a file, say vim file.tex as above.
  2. Then compile this file as follows:
    latex file.tex
    
    This will generate file.aux, file.log and file.dvi. Ignore .aux and .log file for now.
  3. The dvi file can be viewed using xdvi command as:
    xdvi file.dvi
    
  4. The dvi file can be converted to ps (postscript) file using 'dvips command
    dvips file.dvi -o file.ps
    
  5. This can be viewed using some post script viewer like say kghostview or ghostview. (this step is optional)
    kghostview file.ps
    
  6. The postscript file can be converted to pdf file using 'ps2pdf' command.
    ps2pdf file.ps
    
    which will produce file.pdf which can be viewed using xpdf, kghostview, or Adobe's Acrobat reader and threre by print.
  7. Sometime you would like to publish your document into a web page. This done by 'latex2html' command as follows
    latex2html file.tex
    
    This will create a folder by name 'file' and inside you will see a file callex index.html. This can be viewed by any browser, say:
    firefox file/file.html
    
The essential command can be summerised as
vim file.tex
latex file.tex
xdvi file.dvi
dvips file.dvi -o file.ps
ps2pdf file.ps

Formating

Title, sections

Save the following into a file.tex and complie and get the out put.

\documentclass{article}
\begin{document}

% The % symbole is comment line and text beyond this is not compliled

\title{First Document}
\author{Myself}
\date{\today} % sets todays date
\maketitle

The title field can be replaced with text of your choice. Similarly author and
date. Notice that the today command give today's date from the system. This is
the date this document is complied.

\section{First}

This is my first section.
%
Although not required, to get a good source code, it is good idea to keep each
sentenses separated by \% indicating comment.
%
For, example this is sepated from the previous sentence by \% sign. This will
be treated as one paragraph.
%
This is another line, part of the same paragraph.

But this is a different paragraph since it is separated from the previous by a
bew line character.  This forms my second section.  The next will be my last
section.

\subsection{Apple}
This shows a sub section.
\subsubsection{Red}
This shows a sub sub section. Normal documents has three levels.
\end{document}

Items (Bullets and Numbered)

This example shows some more formatting enumerate, itemize and footnote.
\documentclass{article}
\begin{document}
Example of Items (Bullets and Numbered).
\begin{enumerate}
\item Apple
\item Oranges
\item Mangos 
\end{enumerate} 
\begin{itemize}
\item Apple
\item Oranges \footnote{Not to be confused with color}
\item Mangos
\end{itemize} 
\end{document}
Look at the pdf out put of the document. Who did the formating?

Equation

In line equations

In line equation is produced by giving $ sign before and after an equation. Few simple equation are given below.
\documentclass{article}
\begin{document}
A simple equation with english alphabets $z=x+y$,
another simple equation with greek alphabets $\alpha=\beta+\gamma$,
and an equation with some special notation $\sum z=\frac{\delta}{y^2}$.
\end{document}
This will produce equations like this: A simple equation with english alphabets $z=x+y$, another simple equation with greek alphabets $\alpha=\beta+\gamma$, and an equation with some special notation $\sum z=\frac{\delta}{y^2}$.

A simple equation with english alphabets $z=x+y$, another simple equation with greek alphabets $\alpha=\beta+\gamma$, and $\sum z=\frac{\delta}{y^2}$. Note that the equation number is generated automatically.

equation Environment

The equation environment will create an equation similar to above, but not in-line. The equation will be placed next line, justified middle, places some space above and below; and auotmatically generate an equation number. To get the equation below, use the source code in:
\begin{equation}
\Pi_{i=0}^{n^{2}}=\frac{\alpha^{\sqrt{y}}}{\sqrt{y-x}}
\end{equation}

\begin{displaymath}
\Pi_{i=0}^{n^{2}}=\frac{\alpha^{\sqrt{y}}}{\sqrt{y-x}}
\end{displaymath} (1)

eqnarray Environment

The eqnarray environment is similar to the equation; but it can support equation spanning to many lines.
\begin{eqnarray}
z = (x+1)+(y-2) \\
  = x+y+1-2 \\
  = x+y-1\\
\end{eqnarray}

$\displaystyle z = (x+1)+(y-2)$     (2)
$\displaystyle = x+y+1-2$     (3)
$\displaystyle = x+y-1$     (4)

Note that this environment has generated equation on all lines. However, the aligment of the equation is not proper. See the follwoing example which shows a nice alignment as well numbering for only once.
\begin{eqnarray}
\Pi_{i=0}^{n^{2}}&=&\frac{\alpha^{\sqrt{y}}}{\sqrt{y-x}}\\
&=&e^{25\beta}-1\nonumber\\
&=&\Delta+\Gamma\nonumber
\end{eqnarray}
This code will produce the follwing output.
$\displaystyle \Pi_{i=0}^{n^{2}}$ $\textstyle =$ $\displaystyle \frac{\alpha^{\sqrt{y}}}{\sqrt{y-x}}$ (5)
  $\textstyle =$ $\displaystyle e^{25\beta}-1$  
  $\textstyle =$ $\displaystyle \Delta+\Gamma$  

Table

Simple table

A simple table is given below.
\documentclass{article}
\begin{document}
\begin{tabular}{|c|c|}
Col One & Col Two \\ \hline
1 & 11 \\
2 & 22 \\
3 & 33 \\ \hline
\end{tabular}
\end{document}
This will produce a table like this:
Column One Column Two
1 11
2 22
3 33
The effect of hline is not clear in an html file.

Table Environment

The Table 1 shows a simple table.

Table 1: Simple Table Showing the Layout and Syntax
Left Center Paragraph Right
1 12.3 This portions is in a paragraph mode 1234
22 17.1 Again the same 234
333 77.7 Text 2

The above text is produced by the following code. Please also note how the table is referred using a label.
The Table~\ref{qtTabA} shows a simple table.
\begin{table}
\caption{Simple Table Showing the Layout and Syntax}
\label{qtTabA}
\begin{center}
\begin{tabular}{|l|c|p{2in}|r}\hline
Left & Center & Paragraph & Right \\ \hline
1    & 12.3   & This portions is in a paragraph mode & 1234 \\
22   & 17.1   & Again the same & 234 \\
333  & 77.7   & Text & 2  \\\hline
\end{tabular}
\end{center}
\end{table}

Multi column and cline

The Table 2 shows a table with multi column feature.

Table 2: Table Showing the Multi-Column Layout and cline
Different justification possible
Left Center Paragraph Right
1 12.3 This portions is in a paragraph mode 1234
22 17.1 Again the same 234
333 Total Text 2

The above text is produced by the following code. Note that the cline command will not be clear in html mode.
The Table~\ref{qtTabB} shows a table with multi column feature.
\begin{table}
\caption{Table Showing the Multi-Column Layout and cline}
\label{qtTabB}
\begin{center}
\begin{tabular}{|l|c|p{2in}|r}\hline
\multicolumn{4}{c|}{Different justification possible}\\ \hline
Left & Center & Paragraph & Right \\ \hline
1    & 12.3   & This portions is in a paragraph mode & 1234 \\
22   & 17.1   & Again the same & 234 \\ \cline{2-3}
333  & \multicolumn{2}{l|}{Total Text} & 2  \\\hline
\end{tabular}
\end{center}
\end{table}

Matrix

\begin{equation}
\newcommand{\cellaa}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_1^2}}}
\newcommand{\cellab}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_1\alpha_2}}}
\newcommand{\cellac}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_1\alpha_3}}}
\newcommand{\cellan}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_1\alpha_n}}}
\newcommand{\cellba}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_2\alpha_1}}}
\newcommand{\cellbb}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_2^2}}}
\newcommand{\cellbc}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_2\alpha_3}}}
\newcommand{\cellbn}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_2\alpha_n}}}
\newcommand{\cellna}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_n\alpha_1}}}
\newcommand{\cellnb}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_n\alpha_2}}}
\newcommand{\cellnc}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_n\alpha_3}}}
\newcommand{\cellnn}{\frac{\partial^2{f(\bar{\alpha})}}{\partial{\alpha_n^2}}}
\Beta=\left(
\begin{array}{ccccc}
\cellaa&\cellab&\cellac&\dots&\cellan\\
\cellba&\cellbb&\cellbc&\dots&\cellbn\\
\dots  &\dots  & \dots &\dots&\dots\\\hline 
\cellna&\cellnb&\cellnc&\dots&\cellnn\\
\end{array}
\right)
\end{equation}

\begin{displaymath}%
\providecommand{\cellaa}{\frac{\partial^2{f(\bar{\alpha})}}...
...{f(\bar{\alpha})}}{\partial{\alpha_n^2}}\\
\end{array}\right)
\end{displaymath} (6)

Tables

Simple able

A simple table is given below.
\begin{tabular}{|c|c|}
%
Column One & Column Two \\\hline
1 & 11 \\
2 & 22 \\
3 & 33 \\\hline
%
\end{tabular}

This will produce a table like this:

Column One Column Two
1 11
2 22
3 33

Table environment

The Table 3 shows a simple table. This is produced by the follwing command.

\begin{table}
%
\caption{Simple Table Showing the Layout and Syntax}
%
\label{qtTabC}
%
\begin{center}
%
\begin{tabular}{|l|c|p{2in}|r|}\hline
%
Left & Center & Paragraph & Right \\ \hline
1    & 12.3   & This portions is in a paragraph mode.
                We can write long sentences here. & 1234 \\
22   & 17.1   & Again the same & 234 \\
333  & 77.7   & Text & 2  \\\hline
\end{tabular}
%
\end{center}
%
\end{table}
Please note how the caption and lable is given. Also the placement of the table.

Table 3: Simple Table Showing the Layout and Syntax
Left Center Paragraph Right
1 12.3 This portions is in a paragraph mode. We can write long sentences here. 1234
22 17.1 Again the same 234
333 77.7 Text 2

Multi column and cline

The Table 4 shows a table with multi column feature. The code is:
\begin{table}
%
\caption{Table Showing the Multi-Column Layout and cline}
%
\label{qtTabD}
%
\begin{center}

\begin{tabular}{|l|c|p{2in}|r|}\hline
%
\multicolumn{4}{|c|}{Different justification possible}\\ \hline
Left & Center & Paragraph & Right \\ \hline
1    & 12.3   & This portions is in a paragraph mode & 1234 \\
22   & 17.1   & Again the same & 234 \\ \cline{2-3}
333  & \multicolumn{2}{l|}{Total value is} & 2  \\\hline
\end{tabular}
%
\end{center}
%
\end{table}


Table 4: Table Showing the Multi-Column Layout and cline
Different justification possible
Left Center Paragraph Right
1 12.3 This portions is in a paragraph mode 1234
22 17.1 Again the same 234
333 Total value is 2

References/Bibliography

  1. First make a bibiliography data base file (see the file ref.bib
  2. Second cite the references using \cite command in tex file.
  3. include the ref.bib in the ref.tex file (see the file ref.tex.
  4. compile the file once with latex command and then, the complie with bibitex, then compile twice with latex command.
    latex ref.tex
    bibtex ref
    latex ref.tex
    latex ref.tex
    

Example

Referencing in latex is as below.
  1. Get the bibliography file example.bib
  2. Get the tex file example.tex
  3. See the out put example.html

  1. Compiling and basic formating: HTML.
  2. Equations HTML
  3. Tables: HTML
  4. References: HTML

Links

Latex

  1. Getting to grips with Latex
  2. Latex2e Help 1.4 All commands in order.i For an average user.
  3. About the (La)TeX Navigator A site from france well documented for an average user including documentation on history, future and installation.
  4. Math symbols and commands
  5. Math using ams pacakges Must for heavy math usage
  6. The Comprehensive Latex Symbol List
  7. The LaTeX PageHas lot of links, tex related commands, Documentation sites etc.
  8. Text Processing using LaTeXCambridge University Site: Different Level Links are given
  9. The Comprehensive LATEX Symbol List
  10. Bibliography and indexes tools Good info on Bib Tex.
  11. Bib Tex Tools Only for large bib data bases

latex2html

  1. Latex2html Breif Intro
  2. latex2html by the developer Nikos Drakos

Miscelaneous

VMT-PJG Bibtex format

referencing in latex is as below. template.bib
example.bib
reference.tex
reference.pdf
reference.html

Article Style File

Sample Article Document 1

1latexArticleStyleSample.tgz
1latexArticleStyleSample.pdf
1latexArticleStyleSample.html

Sample Report Document 1

2ce753reportSample.tgz

Conditional if's

\documentclass{article}

% this can be after begin{document} also
%
\newif\iftest
\testtrue

\begin{document}

\iftest
Use this if test is TRUE
\else
Use this if test is FLASE
\fi

Mislaneous

makefile

My makefile for latex compilation is below. Replace file with your tex file without extension and compile using the command make or for help make help
#
#	The make file to make the html 	
#
#	Dr. Tom V. Mathew
#
#	vmtom @ iitb.ac.in
#
#	O = original tex file with .tex extention
#
O = latex02.tex
#
#	F = desired output file without .tex file extention
#
F = latex
#
#	gives the dvi file
#
$F.dvi: $F.tex $O
	latex $F.tex;/bin/true
	bibtex $F;/bin/true
	latex $F.tex;/bin/true
	latex $F.tex;/bin/true
$F.tex: $O
	cp $O $F.tex
#
#	gives the pdf file
#
pdf:
	dvips -t a4 $F.dvi -o $F.ps
	ps2pdf $F.ps

#
#	gives the landscape pdf file
#
lpdf:
	dvips -t a4 -t landscape $F.dvi -o $F.ps
	ps2pdf $F.ps
#
#	make the html of the tex file
#
html:
	latex2html -split 0 -noinfo -nonavigation $F.tex 
#
#	make the pdf and html of the tex file from scratch
#
all: $F.dvi html pdf
#
v: $F.dvi
	xdvi -s 2 $F.dvi &
#
#	cleans up the area
#
c:
	rm -f $F.aux;/bin/true
	rm -f $F.log;/bin/true
	rm -f $F.dvi;/bin/true
	rm -f $F.toc;/bin/true
	rm -f $F.lof;/bin/true
	rm -f $F.lot;/bin/true
	rm -f $F.bbl;/bin/true
	rm -f $F.blg;/bin/true
	rm -fi $F.tex;/bin/true
	rm -fi $F.ps;/bin/true
	rm -fi $F.pdf;/bin/true
	rm -Ri $F;/bin/true
#
#	help commands
#
h: help
help: 
	echo -e "\v\tmakefile\tto get the dvi"; echo -e "\tmakefile pdf\tto get the pdf"; echo -e "\tmakefile lpdf\tto get pdf in landscape"; echo -e "\tmakefile html\tto get the html"; echo -e "\tmakefile c\tto clean all"; echo -e "\tmakefile v\tto view dvi file using xdvi";echo -e "\tmakefile all\tto get html and pdf"; echo -e "\tmakefile h\t=makefile help (to get this) "; echo -e "\t"

Algorithms

\newcounter{latMov}
\begin{figure}[!htb]
\begin{center}
%\fbox{\begin{minipage}[b]{8cm}
\begin{tabbing}
11111\=22222\=33333\=44444\=55555\=\kill
%
\stepcounter{latMov}\thelatMov\def\verA{1}\>formulate initial population \\
\stepcounter{latMov}\thelatMov \> {\bf repeat}\\
\stepcounter{latMov}\thelatMov \>\> evaluate objective function\\
\stepcounter{latMov}\thelatMov \>\> update statistics if solution improved\\
\stepcounter{latMov}\thelatMov \>\> find fitness function\\		
\stepcounter{latMov}\thelatMov \>\> generate new population\\
\stepcounter{latMov}\thelatMov\>{\bf{If}}$a=b$ {\bf{then}}\\
\stepcounter{latMov}\thelatMov\>\>$ c=\beta $ \\
\stepcounter{latMov}\thelatMov\>\>$ d=\beta $ \\
\stepcounter{latMov}\thelatMov\>{\bf{else if}} $a=b$\\
\stepcounter{latMov}\thelatMov\>\>\ $ e=\beta $ \\
\stepcounter{latMov}\thelatMov\>{\bf{else}}\\
\stepcounter{latMov}\thelatMov\>\>$ f=\beta $ \\
\stepcounter{latMov}\thelatMov\>\>\>\>\>Second Level \\
\stepcounter{latMov}\thelatMov\>\>\>\>\>Third Level \\
\stepcounter{latMov}\thelatMov\>\>\>\>\>Fourth Level \\
\stepcounter{latMov}\thelatMov\>\>\>\>\>Fifth Level \\
\stepcounter{latMov}\thelatMov\>{\bf until} stopping criteria\\
%
\end{tabbing}
\end{center}
\caption{Working Principle of }
\label{qfSrfcWp}
\end{figure}
%

Figure 1: Working Principle of
\begin{figure}
% latex2html id marker 335
\begin{center}
\begin{tabbing}
11111\=...
...latMov}\>{\bf until} stopping criteria\\
\end{tabbing}\end{center}
\end{figure}

\begin{figure}[!htb]
\begin{center}
\fbox{ \begin{minipage}[b]{8cm}
\begin{tabbing}
123\=456\=\kill
\centerline{/*Algorithm SRFC */} \\
\> formulate initial population \\
\> {\bf repeat}\\
\>\> evaluate objective function\\
\>\> update statistics if solution improved\\
\>\> find fitness function\\		
\>\> generate new population\\
\> {\bf until} stopping criteria\\
\end{tabbing}
\end{minipage} }
\end{center}
\caption{Working Principle}
\label{qfSrfcWp}
\end{figure}

Figure 2: Working Principle
\fbox{ \begin{minipage}[b]{8cm}
\begin{tabbing}
123\=456\=\kill
\centerline{/*Al...
... population\\
\> {\bf until} stopping criteria\\
\end{tabbing}\end{minipage} }



Prof. Tom V. Mathew 2013-08-21