# Latex Tutorial

This report should help you to understand and learn LATEXin less than 30 minutes. If you follow the instruction in this paper, you should be able to install and create a sample LATEXfile with all important features. Please feel free to use this document and simply steal from this document! More information available from [1], [2].

This tutorial is prepared in three parts:

• Learn LaTeX in 30 Minutes!
• Writing a Scientific Paper in LaTeX
• Writing a PhD Thesis in LaTeX

### Online LaTeX

The following websites are recommended if you do not want to work online.

You can download a copy of the powerpoint presentation and example files from the links provided below. For the other two tutorials, please use the PDF files provided below.

### Introduction

LATEX (pronounced La-Tech) is a document markup language and document preparation system for the TeX typesetting program. LATEXis a flexible typesetting package. Various fonts and sizes are available. For example typewriter, italic, emphasised, san serif, bold as well as the default roman. Combinations of some are possible emphasised san serif, for example. LATEXis an excellent package to deal with equations and graphics.

### What Do I Need?

To start working with LATEX, you will need LATEXcompiler and a text editor!

#### 2.1 LATEXCompiler

To convert your LATEXsource file, you will need a compiler to make real documents out of your latex source file. MiKTeX is a free LATEXcompiler for windows and its installation is extremely simple. LaTeX compiler produces so-called DVI file or PDF which can be then inspected and printed by YAP viewer or Adobe Reader.

#### 2.2 LATEXEditor

You will also need a LATEXEditor to write your text in, because you cannot just write it in MS Word or OpenOffice Writer and compile it from there. Just to set the record straight, LATEXis a markup language, which uses commands to make your text look bold, coloured or any other text alignments you want to put it in. Assuming that you are using Windows, you might want to TeXnicCenter available from:

or LEd available from:

http://www.latexeditor.org/

### 3 Producing a LaTeX LATEXDocument

The first line of the input file should normally consist of an appropriate \documentclass command. If an article (or similar document) is to be produced on A4 paper, and if the main body of the text is to be set with a font whose natural size is ‘12 point’, then the appropriate \documentclass command is: \documentclass[a4,12pt]{article}

Other forms of the \documentclass command can be used for letters, reports or books. If 12pt is omitted from the \documentclass command (with the preceding comma), then the document will be set in a ‘10 point’ size. One may also replace 12pt with 11pt.

After the \documentclass command and these other optional commands, we place the command \begin{document}. This command is then followed by the main body of the text, in the format prescribed by the rules of LaTeX. Finally, we end the input file with a line containing the command \end{document}.

Your first LATEXfile could be something like this:

\documentclass[a4,12pt]{article}
\begin{document}
Hello World.
\end{document}

#### 3.1 Document Classes

The way your document will look and be structured depends on the \documentclass command at the top of the file. Useful classes are: letter, article, for reports and journal articles and book for theses and books. For a specific publication, if you are given a document class, then replace the documentclass name to your class file.

#### 3.2 Sections

Articles are usually structured into sections, and books into chapters and chapter sections. To create a new section use \section{Section Title}. Subsection or Sub-sub-section can also be used. Sections can be cross-referenced, if you \label them. For example, the Introduction is section 1 in this document.

If you prefer a section without a number, then you should use * after the section i.e. \section*{Title}.

\documentclass[a4,12pt]{article}
\begin{document}
\section{Introduction}
Hello World.\\
\section{More Text}
More Text here.
\end{document}

#### 3.3 Spaces, Gaps, Breaks, etc.

Sometimes you want to override the default formatting in various ways. Here are a few common examples. If you leave a blank line between two lines of text LATEXassumes that you want a new paragraph and indents accordingly.

Sometimes you don’t want this indentation and the \noindent command is useful. Sometimes you may want to break a line in a different place to the default in which case use \\ to insert a line break.

\pagebreak will start a new page.

The real beauty of LATEXis equations. For inline equations like, μ(x1,x2) = 2×1 + 2×2, simply insert the instructions defining the equation between single $signs. ### 5 Figures You will need to include figures. It is best to use .jpg, .eps or .pdf files. Save images in a folder and include them into your document. \begin{figure}[h] \centering \includegraphics[width=8cm]{images/image1} \caption{Figure Caption.} \label{fig:image1} \end{figure} You can control size of figure and by adding a label, they can be referenced any any point. Figure ?? is saved in folder images. Before using \includegraphics you should add graphics package. To add a package, add the following line after \documentclass. \documentclass[a4,12pt]{article} \usepackage{graphicx,epsfig,subfig} \begin{document} Hello World. \end{document} \begin {figure} \centering \subfloat[Rectangle]{\includegraphics [height=3cm]{images/image1}} \hspace{2cm} \subfloat[Circle]{\includegraphics [height=3cm]{images/image2}} \caption{Image caption. a) Rectangle, b) Circle.} \label {fig:image2} \end {figure} ### 6 Tables Nicely placed tables with captions, numbers and labels like table 1 , can be produced with \begin{table} and \end{table}. ### 7 Lists Devotees of the bullet point: • Should use the \begin{itemize} command to start a bulleted list. • Should use the \item command to add items to the list. • Should use the \end{itemize} command to end a bulleted list. Numbered lists can be useful and use \begin{enumerate} and \end{enumerate} to generate the list. 1. the first item. 2. the second item. 3. the third item and possibly some sub-items. 1. examination questions. 2. algorithms. 3. er. ### 8 Including Computer Code Computer code represents a special problem because it often uses characters that have a special meaning in LATEXand is often carefully laid out in a way that the author does not want messed around by automatic text processing. • Little snippets can be included with the \verb command. The first character after \verb is taken as a marker for the beginning of the characters to be reproduced verbatim, the second occurance of this character is taken as the end of the verbatim text. For example \verb+q1<-1:4+ will yield q1<-1:4. • Bigger sections of code require the use of \begin{verbatim} and \end{verbatim} like this: gam<-function (formula, family = gaussian(), data = list(), min.sp = NULL, H = NULL, gamma = 1, ...) { gp <- gam.parser(formula) mf <- match.call(expand.dots = FALSE) ff1 <- paste(gp$v.names[2:n], collapse = "+")
ff <- paste(ff, "+", ff1)
}
.
}

### 9 Bibliography and references

A quite nice bibliography creating facilities are available using the BibTex program. Basically, you create a separate file (‘mybib.bib’) containing all your references, cite them using \cite{ref1} in the document using standard commands and then place a command at the end of your document to create the reference list – only references that you actually cited will appear on this list. For example, a few references added here [3], [4].

If you want to list all your references in the ‘bib’ file, use \nocite{*} just before \end{document}.

\bibliographystyle{plain}
%You can aslo use alpha, unstr, abbrv, IEEE, ...
%You can aslo use IEEEE.bst or Springer.bst or any other publisher.
\bibliography{mybib}
%mybib.bib is your bibliography file.
%Use mybib.bib as your

To create a ‘bib’ file, use your RefWorks and export references in BibTex format. You can format your references using different publishers style. You need a ‘bst’ file and you have to replace the default plain style with the publisher bibliography style file.

#### 9.1 Harvard Citation Style

If you want to use citation styles other than numerical, then you need an extra package. The first job is to add the following to your preamble in order to get Latex to use the Natbib package:

\usepackage{natbib}

Also, you need to change the bibliography style file to be used, so edit the appropriate line at the bottom of the file so that it reads: \bibliographystyle{plainnat}. Once done, it is basically a matter of altering the existing \cite commands to display the type of citation you want.

\citet{lotfi09} for  Lotfi et al. (2009)
\citep{lotfi09} for  (Lotfi et al., 2009)
\citet*{lotfi09} for Lotfi and Langensiepen (2009)

The main commands simply add a t for ‘textual’ or p for ‘parenthesised’, to the basic \cite command. You will also notice how Natbib by default will compress references with three or more authors to the more concise 1st surname et al version. By adding an asterisk (*), you can override this default and list all authors associated with that citation. There is a command called \bibpunct that can be used to override the defaults and change certain settings.

\bibpunct{(}{)}{;}{a}{,}{,}

In summary, you need to add the following:

\usepackage{natbib}
\bibpunct{(}{)}{;}{a}{,}{,}
2. Replace \cite with \citep or \citet.
\bibliographystyle{plainnat} % or abbrvnat or unsrtnat
\bibliography{myBib}

### 10 Misc.

A table of contents can be inserted anywhere with the command \tableofcontents. You can also use \listoffigures or \listoftables.

### References

[1]   Wikipedia, “Latex — Wikipedia, the free encyclopedia”, 2010, [Online; accessed 15-Dec-2010].

[2]   Wikibooks http://upload.wikimedia.org/wikipedia/commons/2/2d/LaTeX.pdf, “Latex”, 2010, [Online; accessed 15-Dec-2010].

[3]   M. J. Akhlaghinia, A. Lotfi, C. Langensiepen, and N. Sherkat, “A fuzzy predictor model for the occupancy prediction of an intelligent inhabited environment”, in 2008 IEEE 16th International Conference on Fuzzy Systems (FUZZ-IEEE), Piscataway, NJ, USA, 1-6 June 2008 2008, pp. 939–46, IEEE.

[4]   M. J. Akhlaghinia, A. Lotfi, C. Langensiepen, and N. Sherkat, “Occupancy monitoring in intelligent environment through integrated wireless localizing agents”, in 2009 IEEE Symposium on Intelligent Agents, Piscataway, NJ, USA, 30 March-2 April 2009 2009, p. 7, IEEE.