You are on page 1of 22

LATEX for Netsoc

Simon Dardis
dalamar@netsoc.tcd.ie

February 22, 2011


Setup

Login to Spoon or Cube, there will be small amounts of


interactivity.

You’ll probably want to be running screen or some NX client.


Overview

LATEX is a typesetting language for reports, documents and


presentations.

LATEX is a macro package for TeX, a type setting language.


Getting started

Open your favourite editor (Nano, Vim, Emacs, ...)

\documentclass{article}
\begin{document}
Hello World!
\end{document}

Save as “test.tex” and run “pdflatex test.tex”. pdflatex will spit


back a PDF of your document.
LATEX distros

For your own home machine or laptop:


OS LATEX distro
Windows MikTex
Linux TeXLive
OSX TeXShop (though macports)
LATEXdocuments

Document classes describe the sort of document that TeX will


produce and have different environments associated with them.

Standard ones are article, report, book, letter. More unusual


ones exist such as beamer for presentations.

We can pass options to the document class in braces ( [. . . ] ) like:


\documentclass[11pt]{report}
In that example we’re setting the text size to 11pt.
LATEXdocuments

LATEX expects each .tex file to start with either a comment (%) or
a \documentclass{$CLASS}.

The “\begin{document}” and “\end{document}” delimit the


contents of our document.

We’ll repeatedly see the use of “\begin{$SOMETHING}


. . . \end{$SOMETHING}” for various things. These are called
environments.
Text

For text, LATEX will effectively collapse all tabs and spaces between
two words to the standard word spacing for that document class
and expects two newlines between paragraphs.

Certain symbols are interpreted as control sequences as we’ve


seen—\documentclass—the short list is “\ $ % { } # &”. These
need to be escaped with \, except for \ which has to be written as
\textbackslash{}.
More text

Changing the text style can be done with a variety of commands


such as:

\emph{} { \em } emphasis


\textrm{} {\rmfamily } roman font family
\textsf{} {\sffamily } sans serif font family
\texttt{} {\ttfamily } teletypefont family
\textup{} {\upshape } upright shape
\textit{} {\itshape } italic shape
\textsc{} {\scshape } Small Capitals
\uppercase{} none UPPERCASE (all caps)
\textbf{} {\bfseries } bold
Chapters and Sections

Chapters which can occur in document, book type document


classes are started with the chapter command—\chapter{chapter
title}. Sections can also occur within chapters.

Articles are made up of sections. The section command


“\section{section title}” will give you section with that optional
title. Subsections can be created with \subsection{. . . } and
sub-subsections with \subsubsection{. . . }.

Finally, \tableofcontents will give you a table of contents where


that command occurs.
Titles, abstracts, authors

LATEX has commands to set the title, author and date of a


document—\title, \author and \date respectively. \maketitle will
produce a title page with those details.

If we want to attach an abstract to our document,


\begin{abstract} . . . \end{abstract} will do that for us. This
should be written within the document environment.
Lists

LATEX gives us several forms of lists out of the box: the list, itemize
and the enumerate environments.

In both cases each item in the list should be prefixed with the
\item command. For the enumerated environment putting what
immediately follows the item command with [ . . . ] will give you a
definition style list with an altered layout.
List example

Enumerate example code:


\begin{enumerate}
\item first
\item second
\item third
\end{enumerate}

Result:
1. first
2. second
3. third
Pictures and graphics

To include graphics in our documents, we need some additional


help from the graphicx package. To use this we’ll need to use the
\usepackage{$PACKAGE} command before the document
environment.

We then have to declare what extensions latex should match with


the \DeclareGraphicsExtensions{. . . } command. PNG and JPG
are the easiest formats to deal with provided you’re using pdflatex.
Otherwise you’ll need to convert your image files to .eps
(encapsulated postscript) format.
Pictures and graphics continued

To actually include an image in our document, we’ll need to use


“\includegraphics{$FILENAME”} where the file name is missing
its’ extension.

That’s somewhat plain, and we can do better by wrapping it in the


figure environment which allows for a “\caption $CAPTION” to
be set as well.

We can give the picture a label with “\label{$LABELNAME}”,


allowing us to write “as per figure \ref{$LABELNAME}” which
LATEX will replace $LABELNAME with a number.
Tables

Tables in LATEX use the tabular environment. For example:


“\begin{tabular}{c c c}
1&2&3
4&5&6
\end{tabular}’ give us:

1 2 3
4 5 6
More Tables!

The number of columns and their justification is set in the { . . . }


that follows the beginning of a tabular environment. l, c, r align
the columns leftwise, center and right as expected.

Use \\ to add a new row.

| in the table specification puts a vertical bar between columns,


while following \\ with \hline will add a horizontal line.

LATEX is extremely picky about tables (among other things) and


will curse you out unless the tables are filled as they’re declared.
Advanced table example

1 2 3
4 5 6

Made with:
\begin{tabular}{ l | c || r}
\hline
1 & 2 & 3 \ \ \hline
4 & 5 & 6 \ \ \hline
\end{tabular}

We can also in \label in tabular environments, allowing us to


\ref{$TABLE} them later.
Biblography

LATEX has support for citations in various styles of presentation.

The simple way is to include: “\bibliographystyle{plain}


\bibliography{$BIBLIOFILE}”. Again, located within the
document environment

Bibtex files have their own layout which is fairly simple.


Biblography files

This is a simple example of a bibtex entry:


@inproceedings{IGA,
author = {H. Chef and J Bloggs.},
title = {Tasty Food},
booktitle = {Proceedings of the 12th international conference on
Food},
year = {2003},
pages = {185–199},
numpages = {15},
publisher = {World Foods},
}

A bibtex file (ending in .bib) is simply a bare list of these.


Biblography files

@inproceedings, @phdthesis, @book, . . . are different entry types.


Components of them such as “year” can be compulsory in some
and optional in others.

To cite our “Tasty Food” document, we use \cite{IGA}. LATEX is


fairly permissive about what characters can occur in a citation
handle, but it’s best to stick to [a-zA-Z0-9:]+.

To get the citations to appear, first run “latex $FILE”, “bibtex


$FILE”, “latex $FILE”, then your choice of driver (pdflatex). latex
and bibtex have to be run multiple times to fix up the references.
Reference, thanks

Dr. Edsko de Vries, http://www.edsko.net , held previous LATEX


talks whose slides are available the web.

Dr. David Wilkins,


http://www.maths.tcd.ie/˜dwilkins/LaTeXPrimer/ , fairly popular
guide to LATEX.

Wikibooks, http://en.wikibooks.org/wiki/LaTeX/, incredibly


useful gude.

And yes, this entire presentation was written in LATEX with beamer.

You might also like