Você está na página 1de 54

A tutorial on

Prof T.N.Nagabhushan M.E(IISc), Ph.D(IISc)


Special Officer
VTU Elearning Center
Objectives of this workshop
 To empower all researchers use Latex for
preparing technical reports, papers and
thesis.
 Improve the quality of presentation in a well
structure format
 Provide basics of the Latex environment and
guide through practical sessions
 Develop enough confidence in using Latex

1/4/2010 2
What You Need ….
 REDHAT LINUX OS Ver 4
 Any PC ( PIV, PV, ,,,,)
 Latex Manual

1/4/2010 3
COVERAGE
 Basic structure and  Generating
essentials of Latex Figure/Graphs,
 Syntax and Symantics  Structure of the VTU
of Latex – template,
 Dr T.N.Nagabhushan  Actual compilation,
Running through the
Thesis tex file
 Hands on
 Dr S.K.Padma

1/4/2010 4
Preface
 LaTeX is a typesetting system (not a word
processor).
 It is most suited to producing scientific and
mathematical documents of high
typographical quality.

1/4/2010 5
Why not MS Word?

1/4/2010 6
Advantages and Disadvantages (1)
 Advantages of LaTeX over WYSIWYG:

 professionally crafted layouts are available


 the typesetting of mathematical formulae is
supported in a convenient way
 users need only to learn a few simple commands,
which specify the logical structure of a document.

1/4/2010 7
Advantages and Disadvantages (2)
 Advantages of LaTeX
 complex structures such as footnotes,
references, table of contents, and bibliographies
can be generated easily
 for many typographical tasks not directly supported by
basic LaTeX, there exist free add-on packages
 LaTeX is highly portable and free

1/4/2010 8
Advantages and Disadvantages (3)
 LaTeX also has some disadvantages:
 What you see is not what you get.
 Is this really a disadvantage? Why are you thinking about
layout instead of content?
 The design of a whole new layout is difficult and takes
a lot of time.
 Templates help you here

1/4/2010 9
LaTeX Input Files
 The input for LaTeX is a plain ASCII text file.
 You can create it with any text editor.
 It contains
 the text of the document
 commands which tell LaTeX how to typeset the text.
 Spaces
 Special Characters
 LaTeX Commands
 Comments

1/4/2010 10
Spaces
 Whitespace characters (e.g. blank, tab, single
line break) are treated uniformly as “space”
by LaTeX.
 Several consecutive whitespace characters are
treated as one “space”.
 An empty line between two lines of text
defines the end of a paragraph.
 Several empty lines are treated in the same way
as one empty line.
It does not matter whether you enter one or It does not matter whether you
several spaces after a word. enter one of several spaces after a
word.
An empty line starts a new paragraph. An empty line starts a new
paragraph.

1/4/2010 11
Spaces

It does not matter It does not


whether you enter one matter whether
or several spaces you enter one of
after a word. several spaces
after a word.
An empty line starts a An empty line
new paragraph. starts a new
paragraph.

1/4/2010 12
Special Characters
 The following symbols are reserved
characters, that
 have a special meaning in LaTeX
$&%#_{}~^\
 Some of these characters can be used in
your documents by adding a prefix backslash
(escape character):
$ & % # _ { } \$ \& \% \# \_ \{ \}
 The other symbols (and many more!) can be
printed with special commands in
mathematical formulae.

1/4/2010 13
LaTeX Commands (1)
 LaTeX commands are case sensitive and
take one of two formats:
 They start with a backslash \ and have a name
consisting only of letters.
 They consist of a backslash and exactly one special
character.

1/4/2010 14
LaTeX Commands (2)
I read that Knuth divides I read that Knuth
people working with TeX divides people
into TeXnicians and working with
TeXperts. Today is March \TeX{} into
25th, 2004. \TeX{}nicians and
\TeX perts. Today
is \today.

1/4/2010 15
LaTeX Commands (3)
 Some commands take a parameter which has to be
given between curly braces { } after the command
name.
 Some commands support optional parameters
which are added after the command name in
square brackets [ ].
 The next example uses some LaTeX commands.

1/4/2010 16
LaTeX Commands (4)

This is This is emphasized


\emph{emphasized} text. text.

Please start a new line Please start a new line


right here!\linebreak right here!
Thank you! Thank you!

1/4/2010 17
Comments
 When LaTeX encounters a % character while
processing an input file, it ignores the rest of
the present line.
 This is useful for adding notes to the input
file, which will not show up in the printed
version.
This text is processed. % A comment
isn’t

This text is
processed.
1/4/2010 18
Input File Structure (1)
 When LaTeX2e processes an input file it expects it
to follow a certain structure. Every input file starts
with the command:
\documentclass{...}
 This specifies what sort of document you intend to write
(article, letter, book, thesis, etc.)
 After that, you can include global style commands or
you can load packages which add new features to
the LaTeX system. To load a package you use the
command:
\usepackage{...}

1/4/2010 19
Input File Structure (2)
 When all the setup work is done, you start the
body of the text with the command:
\begin{document}

 Now you enter the text mixed with some


useful LaTeX commands.
 At the end of the document you use the
\end{document}

command, which tells LaTeX to finish.


Anything which follows this command will be
ignored by LaTeX
1/4/2010 20
Parts of a LaTeX Document:
\documentclass
{article}
{report} Basic Classes
{book}
{letter}
 First line of all LaTeX documents specifies
the {type} of the document and the
[stylesheet] used.

\documentclass[ieee]{article}

1/4/2010 21
A Simple LaTeX Document

\documentclass{article}
\begin{document}
This is some sample text.
\end{document}

1/4/2010 22
A more realistic LaTeX file
\documentclass[a4paper,11pt]{article}
\usepackage{latexsym}
\author{XYZ}
\title{Dependable Nanocomputing Lab}
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
Here begins my first article \ldots
\section{Conclusions}
\ldots{} and here it ends.
\end{document}

1/4/2010 23
Sections
\section{Section Title}

\subsection{Title}

\subsubsection{Title}

1/4/2010 24
Font size
\tiny \scriptsize \footnotesize

\small \normalsize

\large \Large

\LARGE \huge
\Huge

1/4/2010 25
Page Styles
 LaTeX supports three predefined header/footer
combinations. These are known as page styles.
 The style parameter of the \pagestyle{style}
command defines which one to use:
 plain prints the page numbers on the bottom of the page
in the middle of the footer (default page style)
 headings prints the current chapter heading and the page
number on each page. Footer is empty
 empty - both header and footer empty
 More elaborate headers and footers can be created
using the fancyheadings package

1/4/2010 26
Typesetting Mathematics
 LaTeX has a special mode for typesetting
mathematics, called “math mode”.
 Within a paragraph, math mode is entered
between $ characters, or by using the
\begin{math} and \end{math} commands

To find the square of To find the square of


the hypotenuse, add a the hypotenuse, add a
squared to b squared to squared to b squared
find c squared, e.g. to find c squared,
$a^2 + b^2 = c^2$. It’s e.g. a 2 + b 2 = c 2 .
as easy as that! It’s as easy as that!

1/4/2010 27
Typesetting Mathematics
Greek Symbols
\alpha, \beta, \gamma
Superscript, Subscript
x^y x_y x_y^z
Calculus
\int_0^\infty \int{\int}

\frac{\partial u}{\partial x}

1/4/2010 28
Typesetting Mathematics

x = \frac{-b \pm \sqrt{b^2-4ac} } {2a}

1/4/2010 29
Some more Math equations
\begin{center}
{\large
$$ y=\frac{a^3+2c_{x}}{1+\sqrt{b_{x}}} $$ \\
\vspace{0.2in}
$$ Q=\sum_{i=1}^{j}\int_{\mu}^{\infty}f(x_{j})dx
$$ \\
\vspace{0.2in}
$$ \Psi = \oint_{-
\infty}^{\infty}f_{xy}({\frac{\partial
Qx}{\partial Qy}})^{\Im_{\pi}^ \prime} $$ \\ }

1/4/2010 30
Typesetting Mathematics
 In a research paper or thesis, you will often want to number
equations and refer to them in the text
 This is done using the equation environment, and the
commands \label and \ref

… it is clear that \ldots it is clear


that
ε > 0. (1) \begin{equation}
\epsilon > 0.
From Equation 1 it follows that \label{eq:eps}
... \end{equation}
From
Equation~\ref{eq:eps}
it follows that
\ldots
 (note that \label and \ref are used with figures and tables too)
1/4/2010 31
Typesetting Mathematics
 Matrices are produced using the \textbf{array}
environment. Example:

The \emph{characteristic polynomial} $\chi(\lambda)$ of the


$3 \times 3$~matrix
\[ \left( \begin{array}{ccc}
a & b & c \\
d & e & f \\
g & h & i \end{array} \right)\]
is given by the formula
\[ \chi(\lambda) = \left| \begin{array}{ccc}
\lambda - a & -b & -c \\
-d & \lambda - e & -f \\
-g & -h & \lambda - i \end{array} \right|.\]
1/4/2010 32
Including Graphics
 LaTeX2e includes a standard package for
including PostScript graphics in your
document. Load it using
\usepackage{graphics}

 A figure can be included using, for example,


\begin{figure}[ht]
\begin{center}
\includegraphics[width=140mm]{mypic.ps}
\end{center}
\caption{An example of a figure.}
\label{fig:example}
\end{figure}

1/4/2010 33
Figures and Tables
 Figures & Tables cannot be broken between
pages

 They are “floated”


\begin{figure}
\includegraphics{sample}
\caption{A sample figure.}
\end{figure}

1/4/2010 34
Tabular
Two Columns
 Columns
l = automatically adjust
 \begin{tabular}{|…|…|}
size, left justify
 \end{tabular} r = automatically adjust
size, right justify
 Rows p = set size
e.g p{4.7cm}
 & - Split text into columns
c = centre text
 \\ - End a row
 \hline - Draw line under row
 e.g. 123123 & 34.00\\ \hline

1/4/2010 35
Example of table
\begin{tabular}{|l|r|c|} \hline
Date & Price & Size \\ \hline
Yesterday & 5 & Big \\ \hline
Today & 3 & Small \\ \hline
\end{tabular}

Date Price Size


Yesterday 5 Big

Today 3 Small

1/4/2010 36
Cross-referencing
\label{marker}
\ref{marker}
\pageref{marker}

 Example:
\section{Introduction}
\label{intro}

As mentioned in section \ref{intro} in page pageref{intro}

1/4/2010 37
Bibliographies
 Articles can be referred to in the text using
the \cite command
 The details of the cited articles are stored in
BibTeX format, in a “.bib” file.
 BibTeX resolves the citations in the LaTeX
file and generates the required bibliography

1/4/2010 38
Types of Documents BibTex can handle
 ARTICLE  MISC
 BOOK  PHDTHESIS
 BOOKLET  PROCEEDINGS
 INBOOK  TECHREPORT
 INCOLLECTION  UNPUBLISHED
 INPROCEEDINGS
 MANUAL

1/4/2010 39
Each Document type can have the following
entries
 address  month
 author  note
 booktitle  number
 chapter  organization
 crossref  pages
 edition  publisher
 editor  school
 howpublished  series
 institution  title
 journal  type=“Ph.D. dissertation”
 key  volume
 language  year
1/4/2010 40
Sample BibTex
Book Entry
(mybib.bib)

@BOOK{Press,
author="W.H. Press",
title="Numerical Recipes in C: The Art of
Scientific Computing",
publisher="Cambridge University Press",
year=1992,
}

1/4/2010 41
Sample BibTex
Technical Report Entry
@TECHREPORT{Berk,
author="Lex A. Berk and L.S. Bernstein
and D.C. Robertson",
title="MODTRAN: a moderate resolution
model for LOWTRAN 7",
number="GL-TR-89-0122",
institution="Spectral Science",
address = "Burlington, MA",
year = 1989
}
1/4/2010 42
Sample BibTex
Ph.D. Dissertation Entry
@PHDTHESIS{Kuo,
author="Jan-Tai Kuo",
title="The Influence of Hydrodynamic
Transport on Phytoplankton Dynamics
in Homogeneous Lakes",
school="Cornell University",
address="Ithaca, NY",
year=1981,
}

1/4/2010 43
Sample BibTex
Master’s Thesis Entry

@MASTERSTHESIS{Knobelspiesse,
author="Kirk D. Knobelspiesse",
title="Atmospheric Compensation for SeaWIFS Images
of Lake Superior Utilizing Spatial Information",
school="Rochester Institute of Technology",
addess="Rochester, NY",
month=Sep,
year=2000,
}

1/4/2010 44
Sample BibTex
Article Entry
@ARTICLE{Vodacek,
author="Anthony Vodacek and F.E. Hoge and R.N. Swift
and J.K. Yungel and E.T. Peltzer and N.V. Blough",
title="The use of in situ and airborne fluorescence
measurements to determine UV absorption
coefficients and DOC concentrations in surface
waters",
journal="Limnology and Oceanography",
volume=40,
number=2,
year=1995,
pages="411--415",
}

1/4/2010 45
Sample BibTex
Booklet Entry
@BOOKLET{Sherwood,
author="D.A. Sherwood",
title="Phosphorus Loads Entering Long Pond, A
Small Embayment of Lake Ontario near
Rochester, New York",
howpublished="USGS Fact Sheet 128-99",
pages=4,
month="November",
year=1999,
}

1/4/2010 46
Sample BibTex
Proceedings Entry
@INPROCEEDINGS{Stoermer,
author="E.F. Stoermer",
title="Nearshore phytoplankton populations in
the Grand Haven, Michigan vicinity during
thermal bar conditions",
booktitle="Proceedings of the 11th Conference
on Great Lakes Research",
pages="137--150",
year=1968,
}

1/4/2010 47
Commands to Build and
View Document
To use xdvi viewer

% latex bib.tex
% bibtex bib.aux
% latex bib.tex
% latex bib.tex
% xdvi bib.dvi

1/4/2010 48
Running LaTeX
 The simplest way to run LaTeX on a source
document is to do so at the UNIX command
line:
>latex test.tex

 There will be:


test.aux # the auxiliary file that LaTeX will use in subsequent
passes to resolve references to figures, tables, citations etc.
test.log # a log file that contains information about the LaTeX
run
test.dvi # the DeVice Independent output file. This is the
typeset document, ready for conversion to postscript or other printable
formats

1/4/2010 49
Running LaTeX
 We can view the document we have
created using a DVI viewer. The most
common one under UNIX is xdvi. Type

>xdvi test
to see the typeset document
 It is important to realise that LaTeX
sometimes needs to be run several times to
resolve all references.

1/4/2010 50
Creating Latex Files

Your Latex File (a text file) Your Bibtex File


Latex compile x3

Bibtex compile x2

Latex compile x3

Device independent dvips compile x1


output .dvi
Your Postscript File
1/4/2010 51
Output Formats
 .dvi Device Independent
 .ps Post Script
 .pdf PDF
 .rtf Rich Text Format
 .html HTML
 .xml XML

1/4/2010 52
How to run LaTeX
myfile.tex

Edit myfile Resolve


Resolve compile
cross- latex myfile error
reference
myfile.dvi
xdvi myfile yap myfile
(UNIX) (Windows)

dvips myfile myfile.ps

print
1/4/2010 53
THANK YOU

1/4/2010 54

Você também pode gostar