Latex

Dr. Tom V. Mathew

October 22, 2016

1 Installation

1.1 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 xfig  
    sudo apt-get install acroread  
    suod apt-get install ghostscript gv gsfonts gsfonts-x11 gsfonts-other  
    sudo fc-cache -f -v

  6. Latex editor (optional, one of them)
    sudo apt-get install texmaker

    OR

    sudo apt-add-repository ppa:blahota/texstudio  
    sudo apt-get update  
    sudo apt-get install texstudio

2 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.

2.1 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.

2.2 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

3 Formating

3.1 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} 

3.2 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?

4 Equation

4.1 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 α = β + γ, and an equation with some special notation z = -δ
y2.

A simple equation with english alphabets z = x + y, another simple equation with greek alphabets α = β + γ, and z =  δ
y2. Note that the equation number is generated automatically.

4.2 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}

  2      α√y-
Πni=0 = √-------
         y - x
(1)

4.3 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}

z = (x + 1) + (y - 2 )                         (2)
     = x + y + 1 - 2                          (3)

         = x + y - 1                          (4)
                                              (5)
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.

              √y
Πn2    =  √-α-----                         (6)
  i=0        y - x
       =  e25β - 1

       =  Δ  + Γ

5 Table

5.1 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 OneColumn Two


1 11
2 22
3 33


The effect of hline is not clear in an html file.

5.2 Table Environment

The Table 1 shows a simple table.


Table 1: Simple Table Showing the Layout and Syntax





LeftCenter

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}

5.3 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




LeftCenter

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}

5.4 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}

    (  ∂2f(¯α)  ∂2f(¯α)  ∂2f(¯α)       ∂2f(¯α) )
    |   ∂α21    ∂α1α2  ∂α1α3  ...  ∂α1αn |
    ||  ∂2f(¯α)  ∂2f(¯α2)  ∂2f(¯α)  ...  ∂2f(¯α) ||
a = ||   ∂α2α1    ∂α2   ∂α2α3       ∂α2αn ||
    |( --2...----.2..----.2..---...---.2..--|)
       ∂∂αfn(α¯α1)  ∂∂fα(n¯αα)2  ∂∂αfn(¯αα)3  ...  ∂∂fα(¯α2)
                                     n
(7)

6 Tables

6.1 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 OneColumn Two


1 11
2 22
3 33


6.2 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





LeftCenter

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





6.3 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




LeftCenter

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





7 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

8 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

9 Links

9.1 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

9.2 latex2html

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

10 Miscelaneous

10.1 VMT-PJG Bibtex format

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

11 Article Style File

11.1 Sample Article Document 1

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

11.2 Sample Report Document 1

2ce753reportSample.tgz

11.3 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

12 Mislaneous

12.1 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"

13 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}  
%


1 formulate initial population

2 repeat

3 evaluate objective function

4 update statistics if solution improved

5 find fitness function

6 generate new population

7 Ifa = b then

8 c = β

9 d = β

10 else if a = b

11  e = β

12 else

13 f = β

14 Second Level

15 Third Level

16 Fourth Level

17 Fifth Level

18 until stopping criteria


Figure 1: Working Principle of


\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}


/*Algorithm SRFC */

formulate initial population

repeat

evaluate objective function

update statistics if solution improved

find fitness function

generate new population

until stopping criteria


Figure 2: Working Principle