0% found this document useful (0 votes)
12 views

LaTeX Lecture

This document provides an introduction to LaTeX, a typesetting program used to write scientific documents. It discusses the software needed, how to get started with a basic LaTeX file structure, and some basic commands. It also covers writing mathematics in LaTeX, including equations, alignments, rational expressions, cases, and more. The goal is to teach the reader how to write and structure a LaTeX document, as well as insert mathematical expressions.

Uploaded by

Selina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

LaTeX Lecture

This document provides an introduction to LaTeX, a typesetting program used to write scientific documents. It discusses the software needed, how to get started with a basic LaTeX file structure, and some basic commands. It also covers writing mathematics in LaTeX, including equations, alignments, rational expressions, cases, and more. The goal is to teach the reader how to write and structure a LaTeX document, as well as insert mathematical expressions.

Uploaded by

Selina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

An introduction to LATEX

Research Methodology

Mattias Nilsson

17 November
1 Introduction
2 Software
3 Getting started
4 Some basics
5 Mathematics
6 Tables
7 Pictures
8 References
9 Cross-reference
10 Error-handling
11 Help

Mattias Nilsson () An introduction to LATEX 17 November 2 / 37


Introduction

LATEX is a typesetting program, not a word processing program.


LATEX is free.
LATEX is good to use when you want to write scientific documents.
LATEX is a programming language.
You write your text in an editor and then compile it. After compilation
you get a document in PS-, DVI- or PDF-format.

Mattias Nilsson () An introduction to LATEX 17 November 3 / 37


Software

The software you need is free and available on internet.


Distributors
Miktex - Windows http://www.miktex.org/
Tex Live - Linux http://www.tug.org/texlive/
Mactex - Mac OSX http://tug.org/mactex/
Text editors
Texniccenter - Windows http://www.texniccenter.org/
Gnu Emacs http://www.gnu.org/software/emacs/
Kile - Linux http://www.kile.sourceforge.net/
Texshop - Mac OSX http://www.uoregon.edu/~koch/texshop/
Moreover
Adobe reader
Ghostscript

Mattias Nilsson () An introduction to LATEX 17 November 4 / 37


Getting started

The file where you are writing your document in should be named *.tex.
The document should have the following structure:

\documentclass[a4paper]{article}

%Load packages

\usepackage[T1]{fontenc}
\usepackage[swedish,english]{babel}
\usepackage[latin1]{inputenc}

\begin{document}
A short example of how to structure your document.
\end{document}

Text after \end{document} will be ignored.

Mattias Nilsson () An introduction to LATEX 17 November 5 / 37


Getting started

You can load different packages with the command \usepackage{}


All commands starts with the symbol \
The command \\ gives a new line. (But it is recommended to insert a
blank line to mark where a new part begins)
To insert a space after a command, type \ directly after the command. For
example \LaTeX\ generates:
LATEX with a space, compare with \LaTeX, which gives LATEXwithout space.

Mattias Nilsson () An introduction to LATEX 17 November 6 / 37


Getting started

Some signs are reserved by LATEX. All of them are presented in the table
below

Sign Command in LATEX


\ \textbackslash
{ \{
} \}
% \%
~ \textasciitilde
$ \$
_ \_
^ \textasciicircum
& \&
# \#

Mattias Nilsson () An introduction to LATEX 17 November 7 / 37


Some basics

Here is an example of how to create a front page with title, date and
author:
\title{Name of the report}
\author{Student1 \and Student2}
\date{\today}
\maketitle

The result is presented on next page.


You can also add subtitle with the command \subtitle{} and more
authors with the command \and.

Mattias Nilsson () An introduction to LATEX 17 November 8 / 37


Some basics

Name of the report


Student1 Student2

August 9, 2010

Mattias Nilsson () An introduction to LATEX 17 November 9 / 37


Some basics

A table of contents are genereted with the command \tableofcontents.


You can devide your paper into different sections and subsections with the
commands \section{} and \subsection{}. If you want further
subsections, just type \subsubsection{}.

Mattias Nilsson () An introduction to LATEX 17 November 10 / 37


Some basics

If you want to make your text bold, use the command \textbf{}
If you want to make your text italic, use the command \textit{}
If you want to underline your text, use the command \underline{}

Mattias Nilsson () An introduction to LATEX 17 November 11 / 37


Some basics

A centered text is created with the commands \begin{center } and


\end{center }.
A left aligned text is created with the commands \begin{flushleft} and
\end{flushleft}.
A right aligned text is created with the commands \begin{flushright} and
\end{flushright}.
For example the code
\begin{center}
Centered text
\end{center}

gives the result

Centered text

Mattias Nilsson () An introduction to LATEX 17 November 12 / 37


Some basics

A page break can be inserted with one of the following commands:


\newpage
\clearpage
\cleardoublepage
A foot note is made with the command \footnote{text}

Mattias Nilsson () An introduction to LATEX 17 November 13 / 37


Some basics

A numbered list is inserted with the command \begin {enumerate}.


Every new item in the list is created with the command \item.
1 Some text.
2 Some more text.
3 Even more text.
To create a list without numbers, use the command \begin{itemize}.
The above example where made with the following code:
\begin{enumerate}
\item Some text.
\item Some more text.
\item Even more text.
\end{enumerate}

Mattias Nilsson () An introduction to LATEX 17 November 14 / 37


Mathematics

To be able to write mathematics you need to load the following package


\usepackage{amsmath,amssymb,amsthm,upref}
When you write mathematics. You have two choices:
Directly in the text, between dollar signs, examples:
$f(x)$ gives the result f (x)
$e^t + 3$ gives the result et + 3
$ \sin(x) $ gives the result sin(x)
Independently in a environment.
equation - gives a number on the equation
align - several rows, with the possibility to adjust
gather - several rows, centered

Mattias Nilsson () An introduction to LATEX 17 November 15 / 37


Mathematics

It now follows some examples of the different environments. The code


\begin{equation}
\int_{0}^{\infty}{\frac{\sin x}{x}}dx=\frac{\pi}{2}.
\end{equation}

Generates the following:



sin x
Z
π
dx = . (1)
0 x 2

If you want to create equations without a number, type \[ and \] instead of


\begin{equation} and \end{equation}.

Mattias Nilsson () An introduction to LATEX 17 November 16 / 37


Mathematics
The environment align can be used to adjust several lines. Note how the
signs & and \\ is used in the following code. The signs & will lie on a
vertical line. The sign \\ indicates a new row.
\begin{align}
f^2 + g^4 & = 4 \\
2f^2 + 5g^4 & = 6\\
7f^2 + 3g^4 & = 8
\end{align}

This generates the following:


f 2 + g4 = 4 (2)
2f 2 + 5g 4 = 6 (3)
2 4
7f + 3g = 8 (4)
To write several equations without numbers, just use the symbol * in the
name of the enviroment. For example \begin{align*} generates the same
code as above, but without numbering.
Mattias Nilsson () An introduction to LATEX 17 November 17 / 37
Mathematics

If you use the environment gather then will every row be centered.
\begin{gather}
x^2 = 4 \\
\sin^2 (x) + \cos^2(x) = 1
\end{gather}

The above code generates the following:

x2 = 4 (5)
2 2
sin (x) + cos (x) = 1 (6)

Mattias Nilsson () An introduction to LATEX 17 November 18 / 37


Mathematics

Rational expressions are typed with the command


\frac{numerator }{denominator }.
The code
\[
\frac{1+\cos2x}{2} = \cos^2x.
\]

gives
1 + cos 2x
= cos2 x.
2

Mattias Nilsson () An introduction to LATEX 17 November 19 / 37


Mathematics

To get parenthesis in the correct size, use \left and \right. Compare
√ √ 
x x
( ) with .
2 2

This example was made with the following code:


\[
(\frac{\sqrt{x}}{2}) \text{ with } \left(\frac{\sqrt{x}}{2}\
right).
\]

Mattias Nilsson () An introduction to LATEX 17 November 20 / 37


Mathematics

Cases are typed with the command \begin{cases}. The code


\[
f(x)=
\begin{cases}
x & \text{ if } x>2 \\
x−4 & \text{ if } x \leq 2.
\end{cases}
\]

Gives this result: (


x if x > 2
f (x) =
x −4 if x ≤ 2.

Mattias Nilsson () An introduction to LATEX 17 November 21 / 37


Mathematics

When you write mathematics note that the sentences has to be complete.
Formulas and symbols have to be a part of a sentence.
We will talk more about this later.

Mattias Nilsson () An introduction to LATEX 17 November 22 / 37


Tables

This is an example of how to insert a table:


\begin{tabular}{columns}
text
\end{tabular}

Where columns can be one or several of the following:


l - align left
c - centered
r - align right
| - vertical line

Mattias Nilsson () An introduction to LATEX 17 November 23 / 37


Tables

If you want to insert a horizontal line, type \hline.


The commands \\ and & is used to mark when a new row and column
begins.

Mattias Nilsson () An introduction to LATEX 17 November 24 / 37


Tables

The code
\begin{tabular}{|c|cr|}
\hline
AB & CD & DE \\
\hline
12 & 34 & 56 \\
45 & 24 & 61 \\
\hline
\end{tabular}

Generates this table:


AB CD DE
12 34 56
45 24 61

Mattias Nilsson () An introduction to LATEX 17 November 25 / 37


Pictures

To be able to insert pictures, you have to load one of the following


packages, depending on the compiler:
\usepackage[dvips]{graphicx}
\usepackage[pdftex]{graphicx}
The recommended image format is
LATEX - .eps, .mps.
pdfLATEX - .jpg, .mps, .pdf, png.
You can use the schools computers to convert pictures to desired format.
Pictures are inserted with the command
\includegraphics[parameters]{filename}
The picture should be in the same folder as your document.

Mattias Nilsson () An introduction to LATEX 17 November 26 / 37


Pictures

With [parameters] can we manipulate the picture. Some of the commands


are
height - Change the height of the picture
width - Change the width of the picture
scale - Scale the picture with a given factor
For example, if we want to insert the picture, testpicture.eps, with the
height and width 4.8cm and 3.7cm respective. We write
\includegraphics[height=4.8cm,width=3.7cm]{testpicture.eps}

Mattias Nilsson () An introduction to LATEX 17 November 27 / 37


Pictures

It is recommended to insert pictures and tables in a floating environment.


That means that the object is inserted either in the top or bottom of the
page.
There are two different standard environment, figure and table. The
code
\begin{floatingobject}[where]
picture or table
\end{floatingobject}

inserts a picture or table, depending on your choice. The command where


should be replaced with one of the following
h - Here, the object is placed where you insert it
t - Top, the object is placed on the top of the page
b - Bottom, the object is placed on the bottom of the page
p - Page, the object is placed on a new page.
Mattias Nilsson () An introduction to LATEX 17 November 28 / 37
Pictures

Picture- and table text is inserted with the command


\caption{text}
To center the object, use \centering.
We are now ready for an example. To insert a graph in the format .jpg,
type the following code
\begin{figure}[b]
\centering
\includegraphics[width=6cm]{graph.jpg}
\caption{The graph $f(x)=x^2$.}
\end{figure}

Mattias Nilsson () An introduction to LATEX 17 November 29 / 37


Pictures

Figure: The graph f (x) = x 2 .

Mattias Nilsson () An introduction to LATEX 17 November 30 / 37


References

A bibliography are typed with the environment


\begin{thebibliography}{9}
\bibitem[text]{tag}
\end{thebibliography}

To refer to a reference, use the command \cite{tag}.

Mattias Nilsson () An introduction to LATEX 17 November 31 / 37


References

The code generates the bibliography on next page


\begin{thebibliography}{9}
\bibitem{brockwell}
Brockwell, Peter \& Davis, Richard (2002), \emph{
Introduction to Time Series and Forecasting}, Second
edition, New York: Springer−Verlag.
\bibitem{resnick}
Resnick, S.I. (1987), \emph{Extreme Values, Regular Variation
, and Point Processes}, New York: Springer−Verlag.
\end{thebibliography}

Mattias Nilsson () An introduction to LATEX 17 November 32 / 37


References

Brockwell, Peter & Davis, Richard (2002), Introduction to Time Series


and Forecasting, Second edition, New York: Springer-Verlag.
Resnick, S.I. (1987), Extreme Values, Regular Variation, and Point
Processes, New York: Springer-Verlag.

Mattias Nilsson () An introduction to LATEX 17 November 33 / 37


Cross-reference

To be able to refer to an object, the object first needs an label. This is


done with the command \label{tag }.
To refer to an object write
\ref{tag } - refer to an object, for example picture or table.
\pageref{tag } - refer to a page.
\eqref{tag } - refer to an equation.

Mattias Nilsson () An introduction to LATEX 17 November 34 / 37


Cross-reference

Example of how to refer to an equation:


\begin{equation}
a^2+b^2=c^2
\label{eq: pyth}
\end{equation}
We all know the meaning of equaion~\eqref{eq: pyth}.

The above code gives the result:

a2 + b 2 = c 2 . (7)
We all know the meaning of equation (7).

Mattias Nilsson () An introduction to LATEX 17 November 35 / 37


Error-handling

Sometimes when you compile, you will note that the code does not work.
Then you have to search for errors.
Some common errors are
Misspelling
Forgot a right parenthesis.
Using wrong commands in wrong environment. For example
\frac{}{} when you write text.
Forgot to close an environment.

Mattias Nilsson () An introduction to LATEX 17 November 36 / 37


Help

Don’t be afraid to use internet to find out more about LATEX.


There are a lot of litterature available in the library and on internet.
The Not So Short Introduction to LATEX 2ε
http://www.ctan.org/tex-archive/info/lshort/english/lshort.pdf
Contains almost all information you need to know about LATEX.

Mattias Nilsson () An introduction to LATEX 17 November 37 / 37

You might also like