latex tutorial

43
LaTeX tutorial Eileen Kraemer CSCI 6950 September 30 th , 2011

Upload: ethel

Post on 17-Jan-2016

32 views

Category:

Documents


0 download

DESCRIPTION

LaTeX tutorial. Eileen Kraemer CSCI 6950 September 30 th , 2011. What is LaTeX?. LaTeX a document markup language and document preparation system for the TeX typesetting program to create a document in LaTeX, a .tex file must be created using some form of text editor . - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: LaTeX tutorial

LaTeX tutorial

Eileen Kraemer

CSCI 6950

September 30th, 2011

Page 2: LaTeX tutorial

What is LaTeX? LaTeX

a document markup language and document preparation system for the TeX typesetting program

to create a document in LaTeX, a .tex file must be created using some form of text editor.

is widely used in academia, because of the high quality of typesetting achievable by TeX

Page 3: LaTeX tutorial

Creation, distribution originally written in the early 1980s by Leslie

Lamport at SRI International. current version is LaTeX2e Free software, distributed under the terms of

the LaTeX Project Public License (LPPL),

Page 4: LaTeX tutorial

Why not MS Word?

Page 5: LaTeX tutorial

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.

Page 6: LaTeX tutorial

Advantages and Disadvantages (2) Advantages of LaTeX over WYSIWYG:

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

Page 7: LaTeX tutorial

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

Page 8: LaTeX tutorial

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

Page 9: LaTeX tutorial

Example …\documentclass[12pt]{article}

\usepackage{amsmath}

\title{\LaTeX}

\date{}

\begin{document}

\maketitle

\LaTeX{} is a document preparation system for the \TeX{} typesetting program. It offers programmable desktop publishing features and extensive facilities for automating most aspects of typesetting and desktop publishing, including numbering and cross-referencing, tables and figures, page layout, bibliographies, and much more. \LaTeX{} was originally written in 1984 by Leslie Lamport and has become the dominant method for using \TeX; few people write in plain \TeX{} anymore. The current version is \LaTeXe.

% This is a comment; it will not be shown in the final output.

% The following shows a little of the typesetting power of LaTeX:

\begin{align}

E &= mc^2 \\

m &= \frac{m_0}{\sqrt{1-\frac{v^2}{c^2}}}

\end{align}

\end{document}

Page 10: LaTeX tutorial

Spaces Whitespace characters (e.g. blank, tab, single

linebreak) 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 of several spaces after a word.An empty line starts a new paragraph.

It does not matter whether you enter one or several spaces after a word.

An empty line starts a new paragraph.

Page 11: LaTeX tutorial

Spaces

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

It does not matter whether you enter one or several spaces after a word.

An empty line starts a new paragraph.

Page 12: LaTeX tutorial

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.

Page 13: LaTeX tutorial

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.

Page 14: LaTeX tutorial

LaTeX Commands (2)

I read that Knuth divides people working with TeX into TeXnicians and TeXperts. Today is March 25th, 2004.

I read that Knuth divides people working with \TeX{} into \TeX{}nicians and \TeX perts. Today is \today.

Page 15: LaTeX tutorial

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.

Page 16: LaTeX tutorial

LaTeX Commands (4)

This is emphasized text.

Please start a new line right here!Thank you!

This is \emph{emphasized} text.

Please start a new line right here!\linebreak Thank you!

Page 17: LaTeX tutorial

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.

This text is processed. % A comment isn’t

Page 18: LaTeX tutorial

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, cssethesis, 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{...}

Page 19: LaTeX tutorial

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

Page 20: LaTeX tutorial

Parts of a LaTeX Document: \documentclass

First line of all LaTeX documents specifies the {type} of the document and the [stylesheet] used.

{article}{report}{book}{letter}

Basic Classes

\documentclass[ieee]{article}

Page 21: LaTeX tutorial

A Simple LaTeX Document

\documentclass{article}

\begin{document}

This is some sample text.

\end{document}

Page 22: LaTeX tutorial

A more realistic LaTeX file\documentclass[a4paper,11pt]{article}\usepackage{latexsym}\author{S.~Shazli}\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}

Page 23: LaTeX tutorial

Sections\section{Section Title}

\subsection{Title}

\subsubsection{Title}

Page 24: LaTeX tutorial

Font size\tiny \scriptsize \footnotesize

\small \normalsize

\large \Large

\LARGE \huge

\Huge

Page 25: LaTeX tutorial

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

Page 26: LaTeX tutorial

To find the square of the hypotenuse, add a squared to b squared to find c squared, e.g. .It’s as easy as that!

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 the hypotenuse, add a squared to b squared to find c squared, e.g. $a^2 + b^2 = c^2$. It’s as easy as that!

222 cba

Page 27: LaTeX tutorial

Typesetting MathematicsGreek Symbols

\alpha, \beta, \gamma

Superscript, Subscript

x^y x_y x_y^z

Calculus

\int_0^\infty \int{\int}

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

Page 28: LaTeX tutorial

Typesetting Mathematics

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

Page 29: LaTeX tutorial

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

(note that \label and \ref are used with figures and tables too)

… it is clear that

From Equation 1 it follows that ...

\ldots it is clear that\begin{equation}\epsilon > 0.\label{eq:eps}\end{equation}From Equation~\ref{eq:eps} it follows that \ldots

Page 30: LaTeX tutorial

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|.\]

Page 31: LaTeX tutorial

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}

Page 32: LaTeX tutorial

Figures and Tables Figures & Tables cannot be broken between

pages

They are “floated”

\begin{figure}

\includegraphics{sample}

\caption{A sample figure.}

\end{figure}

Page 33: LaTeX tutorial

Columns \begin{tabular}{|…|…|} \end{tabular}

Rows & - Split text into columns \\ - End a row \hline - Draw line under row e.g. 123123 & 34.00\\ \hline

Two Columns

l = automatically adjust size, left justifyr = automatically adjust size, right justifyp = set size e.g p{4.7cm}c = centre text

Tabular

Page 34: LaTeX tutorial

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

Page 35: LaTeX tutorial

Cross-referencing\label{marker}

\ref{marker}

\pageref{marker}

Example:

\section{Introduction}

\label{intro}

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

Page 36: LaTeX tutorial

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

Page 37: LaTeX tutorial

BibliographiesBy far the most commonly used feature is color (e.g. [1,2,3]), usually computed in a colour space thought to be “perceptually accurate” (e.g. HSV [3] or CIE [4].

By far the most commonly used feature is color (e.g.\ \cite{NBE1993,JaV1996,SmC1996a}), usually computed in a color space thought to be ``perceptually accurate'' (e.g. HSV \cite{SmC1996a} or CIE \cite{STL1997}).

Page 38: LaTeX tutorial

Bibliographies Example BibTeX entries from a .bib file:@book{AhR1975,

author = {N. Ahmed and K. Rao},title = {Orthogonal transforms for digital signal

processing},publisher = {Springer-Verlag},year = {1975},address = {New York},

}

@inproceedings{Aus1989,author = {James Austin and A. Phantom and

Also Phantom},title = {High Speed Invariant Recognition Using

Adaptive Neural Networks},booktitle = {IEE 3rd International Conference on Image

Processing and its Applications},year = {1989},pages = {28--32},abstract = {A method is described which...},

}

Page 39: LaTeX tutorial

Running LaTeX The simplest way to run LaTeX on a source

document is to do so at the UNIX command line:

These will be:

>latex test.tex

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 runtest.dvi # the DeVice Independent output file. This is the typeset document, ready for conversion to postscript or other printable formats

Page 40: LaTeX tutorial

Running LaTeX We can view the document we have

created using a DVI viewer. The most common one under UNIX is xdvi. Type

>xdvi testto see the typeset document

It is important to realise that LaTeX sometimes needs to be run several times to resolve all references.

Page 41: LaTeX tutorial

Your Latex File Your Bibtex File

Latex compile x3

Bibtex compile x2

Latex compile x3

Your Postscript File

dvips compile x1Device independentoutput .dvi

(a text file)

Creating Latex Files

Page 42: LaTeX tutorial

Output Formats .dvi Device Independent .ps Post Script .pdf PDF .rtf Rich Text Format .html HTML .xmlXML

1

Page 43: LaTeX tutorial

Further reading http://www.ctan.org/tex-archive/info/lshort/english/

Google