Introduction to LaTeX

Category : Uncategorized

Introduction to LaTeX

We use LaTeX for our documents. It is scientific, it is free, and it is system independent.
To contribute to the free scientific learning, we provide LaTeX resources in this page.

LaTeX Editor

A simple notepad works as a LaTeX editor. We use TextWrangler (Mac) as our editor. It is free!

LaTeX Compiler

LaTeX documents need to be compiled (converted) into PDF files. So, you need a compiler.

We use MikTeX as our computer installed LaTeX compiler.
You need to donwload and install this software on your computer. It is free!

LaTeX template file

In this sections, we provide details of writing with LaTex.
The following code snippets make up a LaTeX template file.

1) Preliminaries:

LaTeX works in fields. A field can be a command, definition, special character, section, paragraph, font definition etc.

In this example, the field, section, defines a section. The field content is included within the { and }.
In the text, this command would define a section: Introduction.


In this example, the field, bf, defines a bold face. The content to be bold faced is included within the { and }.


The fields start with a \. These also define special characters. Since % sign defines comments in LaTeX and they do not get compiled, if we need to include % sign and not a comment, then we need to include \ in front of the % sign.
The $ and & signs are also special characters in LaTeX. $ sign defines in-line equation, begin and end. Thus, if we need the $ or & signs then we would need to include \ in front of them.


In some instances, fields are defined with \begin and \end. The actual field definition would go in between { and }.
The content of the field would be between the \begin and \end.

2) Preparation:

Copy-paste the following snippets into a notepad file.
Save it with .tex file extension (i.e. myfile.tex)
Shut down the notepad
Double-click on your newly created LaTeX file (i.e. myfile.tex)
It will open in MikTeX.
Choose pdfLaTeX+MakeIndex+BibTex (that is what I choose).
TypeSet

3) Declare what your document class is.


This can be an “article”, “book”, “beamer” etc.
There are many more. I only used these three. The “article” and “book” are obvious.
“beamer” is for presentations.

4) Declare your “preamble”

The preamble is where you declare your packages. These packages help you define your LaTeX styles (in a way).
For instance, natbib helps you define bibliography. color helps you include color schemes to all your styles.
pdfpages allows you to include pages from pdf documents into your LaTeX document.
hyperref allows you to include hyper links to your LaTeX document.
There are many packages. CTAN is contains descriptions of many packages (if not all).

You can also have new definitions in your preamble.

Options for the packages goto preamble as well.

LaTeX documents hyphenate. Sometimes, word get cut off in undesirable places. You can include hyphenation rules in your preample.
There is a list of hyphenation made available by ctan. You can download it
here.

You can define new commands. These can also be used like variable definitions, shorthands etc.

Entire contents of the preamble can be saved in a TeX file. Then, this TeX file can be included into your main LaTeX document.
This would make your main LaTeX document tidy. Note tough, you either include your preamble as an outside file or type them as they are to your LaTeX document.
The preamble.tex file includes all we wrote above for the preamble section.

5) Define the start of your LaTeX document content.

From this point on, your actual text starts.

6) Cover page


Notice the double back slashes (\\). These mean line breaks.

7) Table of contents, figures etc.


Notice the \newpage, which starts a new page.

8) Chapters and sections


The chapter field will only work if your document style is report.
Your sections will have automatic numbering. However, the literature review section will not have a number
because we put a * in it. This will also exclude this section from the table of contents.

9) Citations


Before we continue, notice the (the character to the left of 1 on your keyboard) and ” (single quote, twice). These are the double quotes for the LaTeX.
LaTeX will not see “.
Citations and references are one of the reasons we use LaTeX.
While writing your text, use \citet{} for in-line citations and \citep{} for citations within paranthesis.
At the end of your document, include the following where you want your list of references to appear.


The list of all citations you included in your text will be prepared for you.
The bibliography style can be changed as per the journal style requirements.
Using this method, you will never have citations without references or vice-versa.
We will explain how to prepare bibliography (bibliography.bib) files later.

10) Define the end of your LaTeX document content.

Your LaTeX document content ends here.

11) Download a template

This file contains what we did so far.
This file contains the PDF outcome of what we did so far.