The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part...

21
The L A T E X Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract Over the next three lectures this course will deal with the basics of L A T E X using specific examples relevant to report writing to aid understanding. This first lecture will deal with getting started, though it will not follow these notes; they are designed as a quick lookup for the basic commands. L A T E X itself can seem rather overwhelming, so we shall instead begin writing an example report, to hopefully show how easily one can build one’s knowledge of the program.

Transcript of The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part...

Page 1: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

The LATEX Lectures

Part 1: Getting Started

Robert Anderson, Tom Bullock, Samuel Coveney

Spring 2011

Abstract

Over the next three lectures this course will deal with the basics of LATEX using specific examplesrelevant to report writing to aid understanding. This first lecture will deal with getting started, though itwill not follow these notes; they are designed as a quick lookup for the basic commands. LATEX itself canseem rather overwhelming, so we shall instead begin writing an example report, to hopefully show howeasily one can build one’s knowledge of the program.

Page 2: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

Contents

1 Introduction 11.1 Finding LATEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Reserved Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

2 Preamble 22.1 Document Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22.2 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22.3 Additional Environments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

3 Environments 43.1 Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43.2 Text Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

4 Document Structure 54.1 Line Breaks and New Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54.2 Title Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54.3 Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54.4 Table of Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54.5 Sections and Subsections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54.6 Appendices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64.7 Equation Numbering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64.8 Quoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64.9 Bulleted Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

5 Inserting Figures 75.1 Wrapping Text Around Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

6 Additional Formatting 96.1 Ligatures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96.2 The Fullpage Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96.3 Paragraph Indenting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96.4 French Spacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96.5 Superscript and Subscript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96.6 Chemical Formulae . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96.7 The Smash Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96.8 Page Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106.9 Changing the Font . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

7 Referencing 117.1 The .bib File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117.2 Reference Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117.3 Inserting References Into Your Report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127.4 Compiling Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

8 Creating Presentations 148.1 Title Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148.2 Frames and Frame Title . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148.3 Background Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148.4 Justifying Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

2

Page 3: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

Appendices 15

A Common Diacritics 15

B Additional Text Formats 15

C Example Title Pages 15C.1 Simple Title Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15C.2 Advanced Title Page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

D Example Preamble 18

Page 4: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

1 Introduction

LATEX is a word processing program commonly used by physicists and mathematicians (and psychologists,musicians, chemists, book writers, and pretty much anyone else who likes pretty reports) due to the ease withwhich one can make professional looking documents. Documents are created by essentially coding the output.

These notes will cover pretty much everything you will need to write a report as an undergraduate (andhopefully a lot of what you need as a post grad) in three sections:

• Start up and formatting;

• Equation writing;

• Referencing and GNU plot.

GNU plot has been included since, although not part of LATEX, it is a professional and free package to makegraphs.

If you require any more help, you can find an excellently written wikibooks page athttp://en.wikibooks.org/wiki/LaTeX/.It goes into far more advanced topics and contains additional information and examples on the subjectscovered here.

1.1 Finding LATEX

LATEX requires two programs to run: the basic library of commands, the actual LATEX; and a compiler inwhich to write your report. You can find both of these at http://www.latex-project.org/ftp.html. Ifyou are running Linux, you can type latex into the command line terminal and it’ll find it automatically.My compiler of choice is TeXworks, which can be found either on the website above or using those funkyLinux commands.

1.2 Reserved Symbols

Certain symbols are used in LATEX that cannot be used in the script. These symbols are %, &, \ and $. Ifyou wish to use them, you must prefix them with a \, such as \%. (Except in the case of the \, which needsto be used within the verb environment.)

1.3 Comments

Comments can be used in your compiler by using %

I very much enjoyed working with my supervisor.% even though he is a total tool I very much enjoyed working with my supervisor

1

Page 5: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

2 Preamble

The preamble is the first thing that appears in a LATEX document. It contains the definition of the document(A4, presentation, etc...), and packages. Much like a coding compiler, certain commands need to be loadedfrom a library before they are recognised by the compiler. Other formats which you wish to effect the wholedocument can also be defined here. An example preamble, with all the commands detailed in this report, isin appendix D.

2.1 Document Class

\documentclass{article}

A document class defines the basic layout of your report. Although you can define every aspect of the layout,by using a preset and changing the parts you want, you can save a lot of time. For report writing, articlewould be the best choice. You can also define the paper size and other such things.

2.2 Packages

Packages are normally libraries of commands which will be used during the writing, and much like librariesin C++, need to be loaded before the compiler attempts to compile. Some packages, such as fullpage willimmediately affect the look of the document and don’t need to be called again to take effect.

\usepackage{mathtools}

\usepackage{graphicx}

\usepackage{fullpage}

\usepackage{appendix}

\usepackage{microtype}

These packages are responsible for (in order): loading the mathematical commands library; loading the libraryfor importing graphics; making the margin sizes larger; loading the library for creating appendices; allows thedisabling of ligatures1.

1Though, unless you specifically wish to (for reasons discussed later) you should not disable ligatures.

2

Page 6: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

2.3 Additional Environments

Sometimes we wish to create environments that aren’t available as standard in LATEX. Luckily, since thisis free software there is an army of nerds willing to do the hard work for us. For example, we may wish toinclude acknowledgements, but there isn’t a simple package available. However, a simple Google search takesus to a forum and reveals that a (not very simple) chunk of code can be copied into our preamble:

\makeatletter

\newcommand\ackname{Acknowledgements}

\if@titlepage

\newenvironment{acknowledgements}{%

\titlepage

\null\vfil

\@beginparpenalty\@lowpenalty

\begin{center}%

\bfseries \ackname

\@endparpenalty\@M

\end{center}}%

{\par\vfil\null\endtitlepage}

\else

\newenvironment{acknowledgements}{%

\if@twocolumn

\section*{\abstractname}%

\else

\small

\begin{center}%

{\bfseries \ackname\vspace{-.5em}\vspace{\z@}}%

\end{center}%

\quotation

\fi}

{\if@twocolumn\else\endquotation\fi}

\fi

\makeatother

3

Page 7: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

3 Environments

Environments are enclosed sections surrounded by \begin{EXAMPLE} and \end{EXAMPLE} commands, whoseformatting is defined in the opening of the section. For example, to create an equation environment:

\begin{equation}

1 + 1 = 2

\end{equation}

Small environments can also be used in line. To make bold font, such as this, we write \textbf{this}

3.1 Document

The document environment is where your report is written. Anything you wish to appear in your outputmust be contained within this environment:

\begin{document}

Everything goes here.

\end{document}

3.2 Text Format

The text formats you will probably use most are:

• As already mentioned, to create bold font, we use \textbf{bold}

• To emphasise text we use the \emph{emphasise} environment.

• Diacritics can be added to letters by placing the symbol after the slash, and the letter you wish it toappear over in curly brackets. So to create o, we use \’{o}. A list of common diacritics is contained inappendix A.

• Footnotes are added using the \footnote{} environment. Simply place the footnote command immedi-ately after the word you wish to place the note at, and it will be referenced2. Additional formattingoptions can be found in appendix B.

2at the bottom of the page.

4

Page 8: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

4 Document Structure

4.1 Line Breaks and New Page

To create a line break use double back-slash \\ and to start a new page simply use \newpage, as has beendone liberally throughout this handout. TeX documents will also recognise blank lines, so place a line breakat the end of the line and then leave a second blank line to create a line’s gap between paragraphs.

4.2 Title Page

The title page is the first thing that should be written after beginning the document environment. It shouldcontain your project title, your name, your partner’s and supervisor’s name, and student ID. The title pagefor these notes was created with the following code chunk:

\title{The \LaTeX\, Lectures\\

Part 1: Getting Started}} % Yes, \LaTeX has its own command.

\author{Robert Anderson, Tom Bullock, Samuel Coveney}

\date{Spring 2011}

\maketitle

Note the maketitle line to bring it together. A new page command would be required after this to preventthe document starting on this page. You can get far more elaborate titles if you wish, and some simplegoogling will give you many possibilities.

Appendix C contains examples of title pages that may be useful for your reports.

4.3 Abstract

All good papers have an abstract, will be normally be included just underneath the title. These are madeusing the abstract environment, such as:

\begin{abstract}

In this report I will detail the findings of my

year long project, that has sucked out my

very soul, and if I am really lucky will end

up as a footnote in my supervisor’s final report.

\end{abstract}

In this report I will detail the findings of myyear long project, that has sucked out my soul,and if I am really lucky will end up as a foot-note in my supervisor’s final report.

4.4 Table of Contents

\tableofcontents It’s that easy. Sections and sub sections will be listed there automatically. You have tocompile your source twice after adding a new section; once to discover the section and twice to then writethat section into the table.

4.5 Sections and Subsections

These create the titles, and also link to the table of contents. They are created with the \section and\subsection commands. Sections and subsections are automatically numbered. Our example shows theopening of this section:

\section{Document Structure}

\subsection{Title Page}

5

Page 9: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

4.6 Appendices

Appendices are used for additional information not directly relevant to what is being covered, but may be ofinterest to the reader, or necessary to understand a particular point. They may also be used for mathematicalderivations deemed too long for the main report. They are created by simply stating \appendix in a separateline of code, and then marking the appendices with \section eg:

\appendix

\section{That Bit that Ended up Taking me Three Weeks}

MATHS

4.7 Equation Numbering

By default, LATEX will number all equations (Tom will discuss how to stop this in the next lecture). However, itwill simply number them consecutively from 1 to however many you have, continuing through the appendices.To stop this, we add the following line of code to our preamble: \numberwithin{equation}{section}. Youmay change section to subsection, depending on how you wish to number.

We also wish to change the numbering for our appendices, since equation numbers here are precursored withthe letter of the appendix in literature. To do this we must use \numberwithin{equation}{section} asabove, and also add \usepackage{appendix} to the preamble. Then, we must change the call to appendixby adding more commands:

\appendix %Begins the appendix

\appendixpage %Adds "Appendices" to the top of the first page

\addappheadtotoc %Defines appendices in the contects

\section{That Bit that Ended up Taking me Three Weeks}

MATHS

4.8 Quoting

We can use a \begin{quote} and \end{quote} environment to contain a block of text, such as a physicalprinciple:

The world line of a free test particle between two timelike separated points extremises the propertime between them.

4.9 Bulleted Lists

Bulleted lists are made within the \begin{itemize} environment. Each point is marked by the \item

\begin{itemize}

\item This is a point.

\item This is another point

• This is a point.

• This is another point

\end{itemize}

We can also create numerated lists using \begin{enumerate}3

3It is possible to change the style of the bullet points, however this has been omitted for clarity, as these lectures are designedto get people started.

6

Page 10: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

5 Inserting Figures

Figures can be inserted at any point in text, and are best illustrated though an example.

\begin{figure}[h]

\begin{center}

\includegraphics{xkcd}

\caption{And what better example than an xkcd?}

\label{xkcd}

\end{center}

\end{figure}

Figure 1: And what better example than an xkcd?

You can simply copy and paste this and it’ll work fine (with a few names changed), but for those who areinterested we’ll run through what the commands do:

• The begin and end commands are for the environment as ever, but we have also included [h] on the topline. When inserting figures, LATEX will normally put it at the top of the appropriate page, no matterwhere the code is inserted. By including [h], it tells LATEXto put it here, between the previous and nextthing that is written. Other options are [t] for top of the page and [b] for bottom.

• We then make sure it is centered by placing a center environment in there. It doesn’t have to be, butif you have a standalone figure with no text wrapped around it, this normally looks better.

• \includegraphics{PICTURE NAME} gives the title of the image to be imported. LATEX will acceptmost file types, and no path is necessary because the file will be searched for in the directory that yourpdf is saved. Remember this when importing images!

• \caption{} is fairly self-explanatory. It can be left blank, but all good physicists caption their figures.

7

Page 11: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

• \label{xkcd} is a label for the figure so we may refer to it later. Rather than saying ‘the above figure’or typing out ‘figure 1’, we can now use the \ref{xkcd} command, so we get ‘figure 4’. This way, ifwe include another figure above and the number of this one changes, we don’t have to worry aboutre-writing our references.

5.1 Wrapping Text Around Figures

First, we have to use the wrapfig package. The entire structure is then placed within the wrapfigure

environment. So the following:

\begin{wrapfigure}{l}{10cm} % "l" or "r" for the side on the page.

\centering

\includegraphics[scale=0.5]{xkcd}

\caption{And what better example than xkcd?}

\label{xkcd}

\end{wrapfigure}

Figure 2: And what better example than the same xkcd?

should place our image on the left of thepage, and this text should appear on theright of it.

Please note the {10cm} after the\begin{wrapfigure} command. Thissets the width of the box aroundwhich our text will be wrapped, notthe width of the image. If you setthis too small, your text will be writ-ten on the image. Also, this can-not be left out; if you do not set anumber you will receive a syntax er-ror.

The text immediately following thewrapfigure environment is what will bewrapped around the image.

8

Page 12: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

6 Additional Formatting

6.1 Ligatures

Ligatures are special symbols used when two letters can naturally be joined together, such as the two f’sin Sheffield, compared to Sheffield. For some people, their addition or removal is simply a matter of taste,but it should be noted that if you copy and paste your pdf into another program (such as word or onto theinternet), this character cannot be recognised. To remove it on a case by case basis, we insert a set of curlybrackets between the ligatured letters. For example to create Sheffield, we write Shef{}field.

Ligatures can be disabled permanently, by using the package microtype and inserting the command\DisableLigatures{encoding = *, family = *} into the preamble, though this also disables other liga-tures such as turning -- into –. (As mentioned earlier, things look nicer if you leave them enabled.)

6.2 The Fullpage Package

By default, the outputs of LATEX have a fairly large borders, and using the fullpage package sets these tothe width you see in this document. Simply call it in the preamble and no further work is needed.

6.3 Paragraph Indenting

LATEX will normally indent paragraphs. If you prefer your layout to have gaps between unindented paragraphs,you can add the command \setlength{\parindent}{0cm} to the preamble.

6.4 French Spacing

LATEX places extra space after full stops at the end of sentences. If you prefer not to have this, place thecommand \frenchspacing in your preamble.

6.5 Superscript and Subscript

When working outside of a mathematical environment, we use the \textsuperscript{} and \textsubscript{}.Please note that while superscipt may be used by default in LATEX, subscript requires you to load the fixltx2e

package.

6.6 Chemical Formulae

There is a special package for the quick writing of chemical formulae. Simply add:\usepackage[version=3]{mhchem}

to your preamble, and you can use the \ce{} command. So we can have \ce{(NH4)2SO4} appear as(NH4)2SO4.

6.7 The Smash Command

If you are using a lot of superscripts and subscripts in your text, then the lines can get a little messy, as LATEXgivesthese characters a little more space, increases the width of a line. For example, dates such as 6th increase thewidth of this line.

By using the smash command, we tell LATEX to push the lines together, and give no extra room for superscriptsand subscripts. So smash and smash are given no extra room. If any of your symbols have both superscipt andsubscript, then using \smash can make things a little messy, so be careful.

9

Page 13: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

6.8 Page Numbers

We don’t really want page numbers on our title or contents page; to remove page numbers from particularpages we use the \thispagestyle{empty} command on each page we don’t want a number. We then startthe numbering from the appropriate page using the \setcounter{page}{1} command. So an example of thefirst three pages of a LATEX document would be:

\begin{document}

\title{The \LaTeX Lectures\\

Part 1: Getting Started}} % Yes, \LaTeX has its own command.

\author{Robert Anderson, Tom Bullock, Samuel Coveney}

\date{Spring 2011}

\maketitle

\thispagestyle{empty}

\begin{abstract}

Something goes here

\end{abstract}

\newpage

\tableofcontents

\thispagestyle{empty}

\newpage

\setcounter{page}{1}

\section{Introduction}

6.9 Changing the Font

Of all the things one can do in LATEX with relative ease, it is surprising that changing the font is not one ofthem. If you do wish to change it, please read this .pdf:http://www.tug.org/pracjourn/2006-1/schmidt/schmidt.pdf

to get you started.

10

Page 14: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

7 Referencing

Referencing in LATEX is fairly simple, and requires a second file of references which is used to build yourreference section at the end of your report. We shall start by building this library of references.

7.1 The .bib File

Seperate to your report file, you open a new file and select save as, and in the save as type drop-downbox, select *.bib. I suggest then naming it the same as the report, to avoid confusion. Please note it mustbe saved in the same path as your report. bib files require no preamble, environments or anything else, youjust kick off with the references as outlined below.can now begin adding your references in any order you please, since they will all have a unique name thatyou call in your report (we’ll come to that later). Depending on what you are referencing (book, journal,website), certain formats and information must be included. This all sounds a little vague, so let’s kick offwith the examples.

7.2 Reference Types

In all the examples, fields that are commented out aren’t necessary, all others are. In all cases, the name onthe first line (in the first case Xarticle) is how we will call the reference in the report.

@article{Xarticle,

author = "",

title = "",

journal = "",

%volume = "",

%number = "",

%pages = "",

year = "XXXX",

%month = "",

%note = "",

}

@book{Xbook,

author = "",

title = "",

publisher = "",

%volume = "",

%number = "",

%series = "",

%address = "",

%edition = "",

year = "XXXX",

%month = "",

%note = "",

}

11

Page 15: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

@mastersthesis{Xthesis,

author = "",

title = "",

school = "",

%type = "diploma thesis",

%address = "",

year = "XXXX",

%month = "",

%note = "",

}

@MISC{Xwebsite,

AUTHOR = "",

TITLE = "",

MONTH = "",

YEAR = XXXX,

HOWPUBLISHED = "\url{en.wikipedia.org}"

}

@inbook{Xbook,

author = "",

title = "",

publisher = "",

chapter = "",

%volume = "",

%number = "",

%series = "",

%address = "",

%edition = "",

year = "XXXX",

%month = "",

%note = "",

}

7.3 Inserting References Into Your Report

At the end of your report, the following two lines must be placed just before the end of the document:

\bibliographystyle{plain}

\bibliography{REFERNCES}

where REFERENCES is the name of your reference file. This is where the references will start, and it is ofcourse good practice to put this on a new page. You can change the style to whatever you want, and a list ofthem is available on the wikibooks. To cite the references we use the \cite{Xarticle} command in the text.So, I have a file currently called james.bib which looks like this:

@MISC{latex,

AUTHOR = "Robert Anderson",

TITLE = "The LaTeX Lectures; Part 1.",

MONTH = "January",

YEAR = 2011,

}

and I can now cite my lecture here[1] by typing \cite{latex} and by including those two important linesoutlined above, I can finish this report with my references.

12

Page 16: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

7.4 Compiling Order

This section is largely irrelevant if you are a user a specialist compiler such as TeXworks, but may beimportant for Linux users who enjoy the command line. The order in which we compile our document to getthe references correct is important. We must do it in this order:

latex name (latex will compile name.tex, producing a .aux file)bibtex name (bibtex will compile name.bib, producing a .bbl file)latex name (latex recompiles name.tex, using the .bbl file to insert references)latex name (latex recompiles name.tex to get all the cross-referencing correct)

TeXworks and other compilers will do this for us though. If in doubt, just hit the compile button a few times.

References

[1] Robert Anderson. The latex lectures part 1, January 2011.

13

Page 17: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

8 Creating Presentations

LATEX comes with a package for making presentations known as beamer. You start by setting your documentclass as \documentclass{beamer}. What follows is a brief outline of the main commands (as always,everything is contained within the document environment):

8.1 Title Page

Your title page is created in exactly the same way as in a standard document, only we replace the \maketitlewith the command \frame{\titlepage}.

8.2 Frames and Frame Title

Frames are separated by using separate frame environments. \frametitle{TITLE} should be the first linein the environment, and the rest of the text is what will appear in the slide. If you want it bulleted, simplycreate a bulleted list environment. For example, our first frame after the title slide may look something like:

\begin{frame}

\frametitle{The Wormhole Metric}

\begin{align}

dS^{2} = -dt^{2} + dr^{2} + (b^{2} + r^{2})(d\theta^{2} + \sin^{2}\theta d\phi^{2}) \notag

\end{align}

This is one possible, albeit very simple, metric for a wormhole. We note that it tends to

flat space at large $r$.

$b$ has units of length, and will turn out to be the radius of the neck of the wormhole.

\end{frame}

8.3 Background Images

If you wish to make your presentation a little prettier by using a background image, simply include thefollowing code in the preamble:

\usebackgroundtemplate{\includegraphics[width=\paperwidth]{IMAGE NAME}}

8.4 Justifying Text

Annoyingly, text in the beamer package is not justified. To change this, add the following two lines to youpreamble:

\usepackage{ragged2e}

\justifying

14

Page 18: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

Appendices

A Common Diacritics

Command Output Command Output\‘{o} o \’{o} o\"{o} o \H{o} o\^{o} o \~{o} o\v{o} o \={o} o\b{o} o

¯\.{o} o

\d{o} o. \c{o} o\r{o} o \t{oo} �oo\i ı

Note that if you want to add diacritics to an i, you must first remove the dot above it with the \i command,eg: \"{\i}.

B Additional Text Formats

Command Output Command Output Command Output\sf{sans serif} sans serif \normalsize{norm} norm \small{small} small

\it{italics} italics \large{large} large \footnotesize{footnote} footnote

\rm{roman} roman \Large{Large} Large \scriptsize{script size} script size

\sl{slanted} slanted \huge{huge} huge \tiny{tiny} tiny

\sc{Nasa} Nasa \Huge{Huge} HugeAlso note that if we have an emphasised word in italics, it returns to plane text.

C Example Title Pages

These examples have been rather botched together with limited knowledge of the maketitle environment.You can google many different examples and change them to suit yourself. These are included simply as anexample of what can be done with said limited knowledge.

C.1 Simple Title Page

\title{The \LaTeX\, Lectures}

\author{Robert Anderson, 070172650\\

Supervisor: Pieter Kok\\

Partner: Tom Bullock}

\date{Spring 2011}

\maketitle

15

Page 19: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

C.2 Advanced Title Page

\begin{center}

\textsc{\LARGE University of Sheffield}\\[1.5cm]

\textsc{\Large The \LaTeX\, Lectures}\\[0.5cm]

{ \huge \bfseries Part 1: Getting Started}\\

% Author and supervisor

\begin{minipage}{0.4\textwidth}

\begin{flushleft} \large

\emph{Author:}\\

Robert Anderson\\

071072650

\end{flushleft}

\end{minipage}

\begin{minipage}{0.4\textwidth}

\begin{flushright} \large

\emph{Supervisor:} \\

Dr.Pieter Kok\\

\emph{Partner:} \\

Tom Bullock

\end{flushright}

\end{minipage}

\vfill

% Bottom of the page

{\large January 2011}

\end{center}

\newpage

There are a lot of commands here we won’t go into, just notice that we don’t require a maketitle command,this page is built entirely from scratch.

16

Page 20: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

Figure 3: Simple Title Page

Figure 4: Advanced Title Page

17

Page 21: The LATEX Lectures Part 1: Getting Started - Pieter Kok · 2011. 2. 25. · The LATEX Lectures Part 1: Getting Started Robert Anderson, Tom Bullock, Samuel Coveney Spring 2011 Abstract

D Example Preamble

The following is my own preamble, if you want your report to look like, and do, all the things mentioned inthis lecture. Certain lines are commented out as they are rarely used or, in the case of ligature removal, areonly used when copying and pasting to the internet. Similar to programming in C, it is good practice tosimply copy and paste your preamble, since you are sure it works and contains most of what you need. Also,using additional packages does not slow the compiling process except on the first run, when they need to befound within the library. After that compiling takes little time.

\documentclass{article} % Defines class, creating certain presets

\usepackage{mathtools} % Allows use of equation environment

\usepackage{graphicx} % Allows you to import pictures

\usepackage{verbatim} % Allows the use of the verbatim environment (necessary printing code)

\usepackage{wrapfig} % Allows use of the wrapfig environment

\usepackage{fixltx2e} % Let’s you use subscript and superscript outside of equations

\usepackage[version=3]{mhchem} % Automatic subscripting of chemical equations

\usepackage{fullpage} % Thinner margins

\usepackage{appendix} % Allows use of appendices

\numberwithin{equation}{section} %Sets numbering style

\setlength{\parindent}{0cm} % Sets paragraph indentation to zero

\usepackage{microtype} % Used to disable ligatures, when combined with next line

%\DisableLigatures{encoding = *, family = *} % Used to disable ligatures

%\frenchspacing % Disables additional spacing after full stops

% All of the below creates the acknowledgements environment

\makeatletter

\newcommand\ackname{Acknowledgements}

\if@titlepage

\newenvironment{acknowledgements}{%

\titlepage

\null\vfil

\@beginparpenalty\@lowpenalty

\begin{center}%

\bfseries \ackname

\@endparpenalty\@M

\end{center}}%

{\par\vfil\null\endtitlepage}

\else

\newenvironment{acknowledgements}{%

\if@twocolumn

\section*{\abstractname}%

\else

\small

\begin{center}%

{\bfseries \ackname\vspace{-.5em}\vspace{\z@}}%

\end{center}%

\quotation

\fi}

{\if@twocolumn\else\endquotation\fi}

\fi

\makeatother

18