0% found this document useful (0 votes)
117 views21 pages

Main Latex

This document provides an introduction and overview of LaTeX documentation. It discusses LaTeX's origins and how it differs from word processors. The document is structured into sections on document structure, typesetting text, and features like fonts, colors, and lists. It provides examples of LaTeX code for formatting text and creating lists, sections, and tables of contents. The document is intended to help new LaTeX users understand how to set up documents and use basic formatting and structural elements.

Uploaded by

Akram Sharieff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views21 pages

Main Latex

This document provides an introduction and overview of LaTeX documentation. It discusses LaTeX's origins and how it differs from word processors. The document is structured into sections on document structure, typesetting text, and features like fonts, colors, and lists. It provides examples of LaTeX code for formatting text and creating lists, sections, and tables of contents. The document is intended to help new LaTeX users understand how to set up documents and use basic formatting and structural elements.

Uploaded by

Akram Sharieff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

LATEX DOCUMENTATION

LATEX DOCUMENTATION
1. INTRODUCTION

LATEX (pronounced lay-tek) is a document preparation system for producing


professional-looking documents; it is not a word processor. It is particularly suited to producing
long, structured documents, and is very good at typesetting equations. It is available as free
software for most operating systems. LATEX is based on TEX, a typesetting system designed by
Donald Knuth in 1978 for high quality digital typesetting. TEX is a low-level language that
computers can work with, but most people would find difficult to use; so LATEX has been
developed to make it easier.

If we are used to producing documents with Microsoft Word, we will find that LATEX is a very
different style of working. Microsoft Word is ‘What You See Is What You Get’ (WYSIWYG),
this means that you see how the final document will look as you are typing. When working in
this way you will probably make changes to the document’s appearance (such as line spacing,
headings, page breaks) as you type. With LATEX you do not see how the final document will
look while you are typing it — this allows you to concentrate on the content rather than
appearance.

A LATEX document is a plain text file with a .tex file extension. It can be typed in a simple text
editor such as Notepad, but most people find it is easier to use a dedicated LATEX editor. As we
type you mark the document structure (title, chapters, subheadings, lists etc.) with tags. When the
document is finished you compile it — this means converting it into another format. Several
different output formats are available, but probably the most useful 1 is Portable Document
Format (PDF), which appears as it will be printed and can be transferred easily between
computers

SKIT, Dept of CSE Page 1


LATEX DOCUMENTATION

2. DOCUMENT STRUCTURE
2.1 Essentials:

 Start TeXworks.

A new document will automatically open.

 Go to the Format menu and select Line Numbers.

Line numbers are not essential, but will make it easier to compare your code with the
screenshots and find errors.

 Go to the Format menu and select Syntax Coloring, then LaTeX.

Syntax colouring will highlight commands in blue and can make it easier to spot mistakes.

 Type the following:

\documentclass[a4paper,12pt]{article}

\begin{document}

A sentence of text.

\end{document}

The \documentclass command must appear at the start of every LATEX document.

The text in the curly brackets specifies the document class.

The article document class is suitable for shorter documents such as journal articles and short
reports.

Other document classes include report (for longer documents with chapters, e.g. PhD theses),
proc (conference proceedings), book and slides.

The text in the square brackets specifies options — in this case it sets the paper size to A4 and
the main font size to 12pt.

the \begin{document} and \end{document} commands enclose the text and commands that
make up your document.

Anything typed before \begin {document} is known as the


preamble, and will affect the whole document. Anything typed after \end{document} is ignored.

 Click on the Save button.


 Create a new folder called LaTeX course in Libraries>Documents.

SKIT, Dept of CSE Page 2


LATEX DOCUMENTATION

 Name your document Doc1 and save it as a TeX document in this folder. It is a good idea
to keep each of your LATEX documents in a separate folder as the compiling process
creates multiple files.
 Make sure the typeset menu is set to pdfLaTeX.
 Click on the Typeset button. There will be a pause while your document is being
converted to a PDF file. When the compiling is complete TeXworks’ PDF viewer will
open and display your document. The PDF file is automatically saved in the same folder
as the .tex file.

2.2 Creating a Title:

The \maketitle command creates a title. You need to specify the title of the document. If the
date is not specified today’s date is used. Author is optional.

 Type the following directly after the \begin{document} command:

\title{My First Document}

\author{My Name}

\date{\today}

\maketitle

 Click on the Typeset button and check the PDF.

Points to note:

• \today is a command that inserts today’s date.

• Article documents start the text immediately below the title on the same page. Reports put the
title on a separate page.

2.3 Sections:

The following sectioning commands are available for the article class:

• \section {...}

• \subsection {...}

• \subsubsection {...}

• \paragraph {...}

• \subparagraph {...}

SKIT, Dept of CSE Page 3


LATEX DOCUMENTATION

The title of the section replaces the dots between the curly brackets. With the report and book
classes we also have \chapter {...}.

2.4 Labelling:

We can label any of the sectioning commands so they can be referred to in other parts of
the document.

Label the section with \label {labelname}. Then type \ref{labelname} or \pageref{labelname},
when you want to refer to the section or page number of the label.

 Type \label{sec1} on a new line directly below \subsection{Stage 1}.


 Type Referring to section \ref{sec1} on page \pageref{sec1} in the Results section.

\documentclass[a4paper, 12pt]{article}

\begin{document}

\title{My First Document}

\author{My Name}

\date{\today}

\maketitle

\section{Introduction}

This is the introduction.

\section{Methods}

\subsection{Stage 1}

The first part of the methods.

\subsection{Stage 2}

The second part of the methods.

\section{Results}

Here are my results.

SKIT, Dept of CSE Page 4


LATEX DOCUMENTATION

2.5 Table of Contents:

If we use sectioning commands it is very easy to generate a table of contents.

Type \tableofcontents where you want the table of contents to appear in your document — often
directly after the title page.

We may also want to change the page numbering so that roman numerals (i, ii, iii) are used for
pages before the main document starts. This will also ensure that the main document starts on
page.

Page numbering can be switched between Arabic and roman using \pagenumbering {...}.

 Type the following on a new line below

\maketitle:
\pagenumbering{roman}
\tableofcontents
\newpage
\pagenumbering{arabic}

The \newpage command inserts a page break so that we can see the effect of the page numbering
commands.

3. TYPESETTING TEXT

SKIT, Dept of CSE Page 5


LATEX DOCUMENTATION

3.1 Font Effects:

There are LATEX commands for a variety of font effects:


\textit{words in italics} words in italics
\textsl{words slanted} words slanted
\textsc{words in smallcaps} words in smallcaps
\textbf{words in bold} words in bold
\texttt{words in teletype} words in teletype
\textsf{sans serif words} sans serif words
\textrm{roman words} roman words
\underline{underlined words} underlined words

3.2 Coloured Text:

To put coloured text in your document you need to use a package. There are many
packages that can be used with LATEX to enhance its functionality. Packages are included in the
preamble (i.e. before the \begin{document} command).

Packages are activated using the \usepackage[options]{package} command, where package is the
name of the package and options is an optional list of keywords that trigger special features in
the package.

The following code to produces coloured text: {\color{colour_name}text}

Where colour_name is the name of the colour you want, and text is the text you want to be
coloured.

 Type \usepackage{color} on the line before \begin {document}.


 Type {\color{red}fire} in your document.
The word ‘fire’ should appear in red.

3.2.1 Defining new Colors:

You should use xcolor definition scheme:

 \xdefinecolor{lavendar}{rgb}{0.8,0.6,1}
 \colorlet{mygreen}{green!60!gray}
which means 60% green + 20% gray.
 When a color is needed, you may use directly the method above (e.g., blue!70 for having
a 70% blue).

SKIT, Dept of CSE Page 6


LATEX DOCUMENTATION

3.2.2 Background Color:

 To set solid background color:


\beamersetaveragebackground{<color>)}
\beamertemplatesolidbackgroundcolor{<color>}
 To set gradient background color: \beamertemplateshadingbackground{<color>}
{<color>}
 To set grid background:
\beamertemplategridbackground

3.3 Font Sizes:

There are LATEX commands for a range of font sizes:

{\tiny tiny words} tiny words


{\scriptsize scriptsize words} scriptsize words
{\footnotesize footnotesize words} footnotesize words
{\small small words} small words
{\normalsize normalsize words} normalsize words
{\large large words} large words
{\Large Large words} Large words
{\LARGE LARGE words} LARGE words
{\huge huge words} huge words

3.4 Lists:

LATEX supports two types of lists: enumerate produces numbered lists, while itemize is
for bulleted lists.

Each list item is defined by \item. Lists can be nested to produce sub-lists.

Type the following to produce a numbered list with a bulleted sub-list:

\begin{enumerate}
\item First thing
\item Second thing
\begin{itemize}
\item A sub-thing
\item Another sub-thing
\end{itemize}
\item Third thing
\end{enumerate}

The list should look like this:

SKIT, Dept of CSE Page 7


LATEX DOCUMENTATION

1. First thing
2. Second thing
• A sub-thing
• Another sub-thing
3. Third thing

It is easy to change the bullet symbol using square brackets after the \item, for example, \item[-]
will give a dash as the bullet. You can even use words as bullets, for example, \item [One].

3.5 Comment & Spacing:

Comments are created using %. When LATEX encounters a % character while


processing a .tex file, it ignores the rest of the line (until the [Return] key has been pressed to
start a new line.

Multiple consecutive spaces in LATEX are treated as a single space. Several empty lines are
treated as one empty line.

The main function of an empty line in LATEX is to start a new paragraph. In general, LATEX
ignores blank lines and other empty space in the .tex file. Two backslashes (\\) can be used to
start a new line.

If you want to add blank space into your document use the \vspace {...} command.

This will add blank vertical space of a height specified in typographical points (pt). For example,
\vspace{12pt} will add space equivalent to the height of a 12pt font.

3.6 Special Characters:

The following symbols are reserved characters which have a special meaning in LATEX:

#$%^&_{}~\

All of these apart from the backslash \ can be inserted as characters in your document by adding
a prefix backslash:

\# \$ \% \^{} \& \_ \{ \} \~{}

Note that you need to type a pair of curly brackets {} after the hat ^ and tilde ~, otherwise these
will appear as accents over the following character. For example, “\^ e” produces “ˆe”. The
above code will produce:

#$%ˆ&{}˜

SKIT, Dept of CSE Page 8


LATEX DOCUMENTATION

The backslash character \ cannot be entered by adding a prefix backslash, \\, as this is used for
line breaking. Use the \textbackslash command instead.

4. TABLES

SKIT, Dept of CSE Page 9


LATEX DOCUMENTATION

The tabular command is used to typeset tables. By default, LATEX tables are drawn
without horizontal and vertical lines — you need to specify if you want lines drawn. LATEX
determines the width of the columns automatically. This code starts a table: \begin{tabular}{...}

Where the dots between the curly brackets are replaced by code defining the columns:

• l for a column of left-aligned text (letter el, not number one).


• r for a column of right-aligned text.
• c for a column of centre-aligned text.
• | for a vertical line.

For example, {lll} (i.e. left left left) will produce 3 columns of left-aligned text with no vertical
lines , while {|l|l|r|} (i.e. |left|left|right|) will produce 3 columns — the first 2 are left-aligned, the
third is right-aligned, and there are vertical lines around each column.

The table data follows the \begin command:

• & is placed between columns.


• \\ is placed at the end of a row (to start a new one).
• \hline inserts a horizontal line.
• \cline{1-2} inserts a partial horizontal line between column 1 and column 2.

The command \end{tabular} finishes the table. Examples of tabular code and the resulting
tables:

Eg: \begin{tabular}{|l|l|}
Apples & Green \\
Strawberries & Red \\
Oranges & Orange \\
\end{tabular}

Eg: \begin{tabular}{rc}
Apples & Green \\

SKIT, Dept of CSE Page 10


LATEX DOCUMENTATION

\hline Strawberries & Red \\


\cline{1-1} Oranges & Orange \\
\end{tabular}

Eg: \begin {tabular}{|r|l|}


\hline 8 & here’s \\
\cline{2-2} 86 & stuff \\
\hline \hline 2008 & now \\
\hline \end{tabular}

5. FIGURES
SKIT, Dept of CSE Page 11
LATEX DOCUMENTATION

To insert an image in to your LATEX document, we require the graphicx package.

Images should be PDF, PNG, JPEG or GIF files. The following code will insert an image
called myimage:

\begin{figure}[h]
\centering
\includegraphics[width=1\textwidth]{myimage}
\caption{Here is my image}
\label{image-myimage}
\end{figure}

[h] is the placement specifier. h means put the figure approximately here (if it will fit). -Other
options are t (at the top of the page), b (at the bottom of the page) and p (on a separate page for
figures).

We can also add! Which overrides the rule LATEX uses for choosing where to put the figure,
and makes it more likely it will put it where you want (even if it doesn’t look so good).

\centering centres the image on the page, if not used images are left-aligned by default.

\includegraphics {...} is the command that actually puts the image in your document. The image
file should be saved in the same folder as the .tex file.

[width=1\textwidth] is an optional command that specifies the width of the picture - in this case
the same width as the text. The width could also be given in centimeters (cm).

We could also use [scale=0.5] which scales the image by the desired factor, in this case reducing
by half.

\caption {...} defines a caption for the figure. If this is used LATEX will add “Figure” and a
number before the caption.

If we use captions, we can use \listoffigures to create a table of figures in a similar way to the
table of contents.

\label {...} creates a label to allow you to refer to the table or figure in your text.

6. EQUATIONS
One of the main reasons for writing documents in LATEX is because it is really good at
typesetting equations. Equations are written in ‘math mode’.

SKIT, Dept of CSE Page 12


LATEX DOCUMENTATION

6.1 Inserting Equations:

We can enter math mode with an opening and closing dollar sign $. This can be used to
write mathematical symbols within a sentence — for example,

Typing $1+2=3$
Produces 1 + 2 = 3.

If we want a “displayed” equation on its own line use $$...$$. For example, $$1+2=3$$
produces: 1 + 2 = 3

For a numbered displayed equation, use \begin{equation}...\end {equation}. For example,


\begin{equation}1+2=3\end{equation} produces:

1+2=3

The number 6 refers to the chapter number; this will only appear if you are using a document
class with chapters, such as report.

Use \begin{eqnarray}...\end{eqnarray} to write equation arrays for a series of


equations/inequalities. For example —

\begin{eqnarray}
a & = & b + c \\
&=&y-z
\end{eqnarray}

Produces:
a=b+c
=y−z
For unnumbered equations add the star symbol * after the equation or eqnarray
Command (i.e. use {equation*} or {eqnarray*}).

6.2 Mathematical Symbols:

Although some basic mathematical symbols (+ - =! / ( ) [ ] :) can be accessed directly


from the keyboard, most must be inserted using a command.

SKIT, Dept of CSE Page 13


LATEX DOCUMENTATION

This section is a very brief introduction to using LATEX to produce mathematical symbols
— the Mathematics chapter in the LATEX Wikibook is an excellent tutorial on mathematical
symbol commands, which you should refer to if we want to learn more. If you want to find the
command for a specific symbol try Detexify1, which can recognise hand drawn symbols.

6.2.1 Power & Indices:

Powers are inserted using the hat ^ symbol.

For example, $n^2$ produces n 2. Indices are inserted using an underscore _.

For example,

$2_a$ produces 2a. If the power or index includes more than one character, group them using
curly brackets {...}, e.g. $b_{a-2} $ producesb a−2.

6.2.2 Fractions:

Fractions are inserted using \frac {numerator}{denominator}.

$$\frac{a}{3} $$ produces:

a
b

Fractions can be nested —

$$\frac{y} {\frac {3}{x}+b}$$ produces:

y
3
+b
x

6.2.3 Roots:

SKIT, Dept of CSE Page 14


LATEX DOCUMENTATION

Square root symbols are inserted using \sqrt {...} where ... is replaced by the square root
content. If a magnitude is required it can be added using optional square brackets [...].

$$\sqrt{y^2}$$ produces: √ y2
$$\sqrt[x]{y^2}$$ produces: √x y 2
6.2.4 Sums & Integrals:

The command \sum inserts a sum symbol; \int inserts an integral. For both functions, the
upper limit is specified by a hat ˆ and the lower by an underscore _

$$\sum_{x=1}^5 y^z$$ produces:


5

∑ yz
x=1

$$\int_a^b f(x)$$ produces:


b

∫ f (x)
a

6.2.5 Greeks Letters:

Greek letters can be typed in math mode using the name of the letter preceded by a
backslash \. Many Greek capital letters are used in the Latin 25 alphabet — for those that are
different capitalise the first letter of the name to produce a capital Greek letter.

For example —

$\alpha$ = α

$\beta$ = β

$\delta, \Delta$ = δ, ∆

$\theta, \Theta$ = θ, Θ

$\mu$ = µ $\pi, \Pi$ = π, Π

$\sigma, \Sigma$ = σ, Σ

$\phi, \Phi$ = φ, Φ

$\psi, \Psi$ = ψ, Ψ

$\omega, \Omega$ = ω, Ω

SKIT, Dept of CSE Page 15


LATEX DOCUMENTATION

7. INSERTING REFERENCES
LATEX includes features that allow you to easily cite references and create
bibliographies in your document. This document will explain how to do this using a separate
BibTeX file to store the details of your references.

7.1 The BibTeX File:

The BibTeX file contains all the references you want to cite in your document. It has the
file extension .bib. It should be given the same name as and kept in the same folder as our .tex
file.

The .bib file is plain text - it can be edited using Notepad or your LATEX editor (e.g.
TeXworks). You should enter each of your references in the BibTeX file in the following format:

@article {

Birdetal2001,

Author = {Bird, R. B. and Smith, E. A. and Bird, D. W.},

Title = {The hunting handicap: costly signaling in human foraging strategies},

Journal = {Behavioral Ecology and Sociobiology},

Volume = {50},

Pages = {9-19},

Year = {2001}}

Each reference starts with the reference type (@article in the example above).

Other reference types include

@book, @incollection for a chapter in an edited book and @inproceedings for papers presented
at conferences.

The reference type declaration is followed by a curly bracket, then the citation key.

Each reference’s citation key must be unique - you can use anything you want, but a
system based on the first author’s name and year is probably easiest to keep track of.

SKIT, Dept of CSE Page 16


LATEX DOCUMENTATION

The remaining lines contain the reference information in the format Field name =
{field contents}, we need to include LaTeX commands in your BibTeX file for any special text
formatting - e.g.

italics (\emph{Rattus norvegicus}),

quotation marks (‘‘...’’),

ampersand (\&).

Surround any letters in a journal article title that need to be capitalised with curly brackets {...}.

BibTeX automatically uncapitalises any capital letters within the journal article title.

For example, “Dispersal in the contemporary United States” will be printed as “Dispersal in the
contemporary united states”, but “Dispersal in the contemporary {U}nited {S}tates” will be
printed as “Dispersal in the contemporary United States”.

We can type the BibTeX file yourself, or you can use reference management software such as
EndNote to create it.

7.2 Inserting The Bibliography:

Type the following where you want the bibliography to appear in your document
(usually at the end):

\bibliographystyle{plain}

\bibliography{Doc1}

Where references is the name of your .bib file.

7.3 Citing References:

Type \cite{citationkey} where you want to cite a reference in your .tex document. If you
don’t want an in text citation, but still want the reference to appear in the bibliography, use
\notice {citationkey}.

To include a page number in your in-text citation put it in square brackets before the citation
key:
SKIT, Dept of CSE Page 17
LATEX DOCUMENTATION

\cite [p. 215]{citationkey}.

To cite multiple references include all the citation keys within the curly brackets separated by
commas: \cite{citation01, citation02, citation03}.

7.4 Styles:

7.4.1 Numerical Citations:

LATEX comes with several styles with numerical in-text citations, these include:

Plain:

The citation is a number in square brackets (e.g. [1]). The bibliography is ordered
alphabetically by first author surname. All of the authors’ names are written in full.

Abbrv:

The same as plain except the authors’ first names are abbreviated to an initial.

Unsrt:

The same as plain except the references in the bibliography appear in the order that the
citations appear in the document.

Alpha:

The same as plain except the citation is an alphanumeric abbreviation based on the
author(s) surname(s) and year of publication, surrounded by square brackets (e.g. [Kop10]).

7.4.2 Author-Date Citations:

Use the natbib package if you want to include author-date citations. Natbib uses the
command \citep {...} for a citation in brackets (e.g. [Koppe, 2010]) and \citet {...} for a citation
where only the year is in brackets (e.g. Koppe [2010]). There are lots of other ways that you can
modify citations when using the natbib package - see the package’s reference sheet for full
details3.

Natbib comes with three bibliography styles:

Plainnat, abbrvnat and unsrtnat.

SKIT, Dept of CSE Page 18


LATEX DOCUMENTATION

These format the bibliography in the same way as the plain, abbrv and unsrt styles, respectively.

7.4.3 Other bibliography styles:

If we want to use a different style (e.g. one provided by the journal you are submitting an
article to) you should save the style file (.bst file) in the same folder as your .tex and .bib files.

Include the name of the .bst file in the \bibliographystyle {...} commmand.

8. CONCLUSION
LaTeX gives us flexibility that we don’t need to see how the final document will look
while you are typing it — this allows you to concentrate on the content rather than appearance.

SKIT, Dept of CSE Page 19


LATEX DOCUMENTATION

LaTeX allows you to make more consistent, and more easily changeable, documents. LaTex is a
typesetting and document preparation system that “includes features designed for the production
of technical and scientific documentation.” It means that you can use LaTex to create documents
with text and formatting that would be difficult in a standard word processor.

SKIT, Dept of CSE Page 20


LATEX DOCUMENTATION

9. REFERENCES
[1] http://www.latex-project.org/

[2] http://ctan.tug.org/tex-archive/info/lshort/english/lshort.pdf

[3] https://en.wikibooks.org/wiki/LaTeX

[4] http://edin.ac/17EQPM1

[5] http://en.wikipedia.org/wiki/Comparison_of_TeX_editors

SKIT, Dept of CSE Page 21

You might also like