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.
- 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/";
- update the settings
sudo apt-get update
- 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
- Install latex
sudo apt-get install texlive-full
- 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
- 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.
- First create a file, say vim file.tex as follows.
\documentclass{article}
\begin{document}
My First Tex File
\end{document}
- Then compile this file as follows:
pdflatex file.tex
- 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.
- First create a file, say vim file.tex as above.
- 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.
- The dvi file can be viewed using xdvi command as:
xdvi file.dvi
- The dvi file can be converted to ps (postscript) file using ’dvips
command
dvips file.dvi -o file.ps
- This can be viewed using some post script viewer like say kghostview or
ghostview. (this step is optional)
kghostview file.ps
- 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.
- 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 =
.
A simple equation with english alphabets z = x + y, another simple equation
with greek alphabets α = β + γ, and ∑
z =
. 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}
 | (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}
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.
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 One | Column 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
|
|
|
|
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}
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
|
|
|
|
|
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}
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}
 | (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 One | Column 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
|
|
|
|
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 |
|
|
|
|
|
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
|
|
|
|
|
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 |
|
|
|
|
|
7 References/Bibliography
- First make a bibiliography data base file (see the file ref.bib
- Second cite the references using \cite command in tex file.
- include the ref.bib in the ref.tex file (see the file ref.tex.
- 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.
- Get the bibliography file example.bib
- Get the tex file example.tex
- See the out put example.html
- Compiling and basic formating: HTML.
- Equations HTML
- Tables: HTML
- References: HTML
9 Links
9.1 Latex
- Getting to grips with Latex
- Latex2e Help 1.4 All commands in order.i For an average user.
- About the (La)TeX Navigator A site from france well documented
for an average user including documentation on history, future and
installation.
- Math symbols and commands
- Math using ams pacakges Must for heavy math usage
- The Comprehensive Latex Symbol List
- The LaTeX PageHas lot of links, tex related commands, Documentation
sites etc.
- Text Processing using LaTeXCambridge University Site: Different Level
Links are given
- The Comprehensive LATEX Symbol List
- Bibliography and indexes tools Good info on Bib Tex.
- Bib Tex Tools Only for large bib data bases
9.2 latex2html
- Latex2html Breif Intro
- 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}
%
\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}