98
LaTeX Basics Aubry Verret October 22, 2013

La tex basics

Embed Size (px)

DESCRIPTION

Contains info on Latex, a motivation for using it, and everything you need to know in order to create your first document.

Citation preview

Page 1: La tex basics

LaTeX Basics

Aubry Verret

October 22, 2013

Page 2: La tex basics

What is LATEX?

Definition

La-tex [lah-tek or lay-tek]-nounA powerful document markup system that uses theTeX typesetting program. The current version isLaTeX2e.

Page 3: La tex basics

LATEXPhilosophy

Content and Styling should remain separate.

The author writes the content. LaTeX takes care offormatting details like margins, indentation, andlayout.

Page 4: La tex basics

Who uses LATEX?

Users include:

I Journals and conferences primarily in scientificand technical disciplines

I Researchers publishing in a scientific, technicalfield(mathematics, physics, computer science,engineering), or humanities field

I Students studying in a scientific, technical, orhumanities discipline

Page 5: La tex basics

How does it work?

Page 6: La tex basics

Why use LATEX?

LATEXis:

I Free and easy to get

I Platform independent

I Flexible

I Capable of superior typographical output

I Well suited to typesetting mathematics

Page 7: La tex basics

When should you use LATEX?

Page 8: La tex basics

Getting LaTeX

I Windows - Miktex(http://www.miktex.org/ or ProTeXhttp://www.tug.org/protext/)

I Mac - MacTeX(http://www.tug.org/mactex/2009/)

I Linux - TeX Live(http://www.tug.org/texlive/)

Page 9: La tex basics

Getting LaTeX

I Windows - Miktex(http://www.miktex.org/ or ProTeXhttp://www.tug.org/protext/)

I Mac - MacTeX(http://www.tug.org/mactex/2009/)

I Linux - TeX Live(http://www.tug.org/texlive/)

Page 10: La tex basics

Getting LaTeX

I Windows - Miktex(http://www.miktex.org/ or ProTeXhttp://www.tug.org/protext/)

I Mac - MacTeX(http://www.tug.org/mactex/2009/)

I Linux - TeX Live(http://www.tug.org/texlive/)

Page 11: La tex basics

Specialized Editors

Many free editors are available:

I LED (http://www.latexeditor.org/)

I TeXnicCenter (http://www.texniccenter.org/)

I TeXWorks (http://www.tug.org/texworks/)

I TeXMaker (http://www.xm1math.net/texmaker/)

I Winedt (http://www.winedt.com/)

I TeXlipse-Eclipse plug-in(http://texlipse.sourceforge.net/)

Page 12: La tex basics

LED

Page 13: La tex basics

TeXWorks

Page 14: La tex basics

Lyx

The Lyx document processor:

I Utilizes the TeX language

I Offers a graphical user interface

I Offers full support for document features such as equations,bibliographies, indexes, etc.

I Is designed for those who prefer to use LaTeX like a wordprocessor

www.lyx.org

Page 15: La tex basics

Lyx

Page 16: La tex basics

Getting Started

To open the TeXnic Center program go to:

Start → Programs → TeXnic Center

Open a new document and save it.

Page 17: La tex basics

TeX files

Download tex files here:http://www2.lib.virginia.edu/brown/

rescomp/latex/practice.zip

Page 18: La tex basics

TeXnicCenter

Page 19: La tex basics

LATEXCommands

Example: \documentclass[10pt]{article}

Example: \begin{document}

Page 20: La tex basics

LATEXCommands

Example: \documentclass[10pt]{article}

Example: \begin{document}

Page 21: La tex basics

LATEXCommands

Example: \documentclass[10pt]{article}

Example: \begin{document}

Page 22: La tex basics

Preamble - particle.tex

Page 23: La tex basics

Building the project

Page 24: La tex basics

Preamble Output

Page 25: La tex basics

Document Classes

I article - shorter works such as papers for class,conference submissions, and journal articles

I report - longer works such as dissertations,theses, or short books

I book - long works with many sections orchapters

I letter - provides special structure for variousaspects of a letter

Page 26: La tex basics

Adding Text - particle2.tex

Page 27: La tex basics

Output

Page 28: La tex basics

Sectioning Commands

\section{}\subsection{}\subsubsection{}

\paragraph{}\subparagraph{}\subsubparagraph{}

\chapter{}\part{}

Page 29: La tex basics

Sectioning Commands Example - particle3.tex

Page 30: La tex basics

Output

Page 31: La tex basics

Itemized Lists

\begin{itemize}

\item One

\item Two

\item Three

\end{itemize}

I One

I Two

I Three

Page 32: La tex basics

Enumerated Lists

\begin{enumerate}

\item One

\item Two

\item Three

\end{enumerate}

1. One

2. Two

3. Three

Page 33: La tex basics

List Example - particle4.tex

Page 34: La tex basics

Output

Page 35: La tex basics

Footnotes

\footnote[number]{text}

I Automatically numbered

I Provides an optional argument for overridingautomatic numbering

Page 36: La tex basics

Footnote Example - particle5.tex

Page 37: La tex basics

Output

Page 38: La tex basics

Table of Contents

\tableofcontents

I Requires no input

I Is placed where you want the ToC to appear

I Utilizes sectioning commands

Page 39: La tex basics

ToC Example - particle6.tex

Page 40: La tex basics

ToC Output

Page 41: La tex basics

Bibliographies

BibTeX is used with LATEXto generate bibliographies.

1. Place bib entries in a separate .bib file

2. Reference the entries in the .tex file

3. Compile both files to generate the bibliography and references

Page 42: La tex basics

Bib Entries

Bib file entry

@Book{Brooks 03 ,a u t h o r = {Max Brooks } ,t i t l e = {The Zombie S u r v i v a l Guide } ,p u b l i s h e r = {Three R i v e r s P r e s s } ,y e a r = {2003} ,i s b n = {1400049628} ,note = {Complete p r o t e c t i o n from t he l i v i n g dead .}}

Page 43: La tex basics

Citations

Tex file citation

For more information on attack methods, please consult TheZombie Survival Guide\cite{Brooks03}.

Include these commands at the end of the tex file:

\bibliography{bib file name}\bibliographystyle{style name}

Page 44: La tex basics

Building the Bibliography

Page 45: La tex basics

Output

Page 46: La tex basics

Bibliography Example - particle7.tex

Page 47: La tex basics

Bibliography Example - particle.bib

Page 48: La tex basics

Running BibTeX in TeXnicCenter

Page 49: La tex basics

Output

Page 50: La tex basics

Bibliography Assistance

External bibliography software:

I Jabref - free, easy to use with BibTeX

I RefWorks

I Endnote

Page 51: La tex basics

Jabref

Page 52: La tex basics

Mathematics

LATEXmust be put into math mode before usingmathematical symbols

Math environments:

I Math - short in-line equations

I Displaymath - equations set apart in text

I Equation - numbered and centered equations

Page 53: La tex basics

Mathematics

LATEXmust be put into math mode before usingmathematical symbols

Math environments:

I Math - short in-line equations

I Displaymath - equations set apart in text

I Equation - numbered and centered equations

Page 54: La tex basics

Mathematics

LATEXmust be put into math mode before usingmathematical symbols

Math environments:

I Math - short in-line equations

I Displaymath - equations set apart in text

I Equation - numbered and centered equations

Page 55: La tex basics

Mathematics

LATEXmust be put into math mode before usingmathematical symbols

Math environments:

I Math - short in-line equations

I Displaymath - equations set apart in text

I Equation - numbered and centered equations

Page 56: La tex basics

Math Environments

Math

I \begin{math}...\end{math}I $...$

Displaymath

I \begin{displaymath}...\end{displaymath}I $$...$$

Equation

I \begin{equation}...\end{equation}

Page 57: La tex basics

Mathematical Notation

Example:

∮∂S

B · dl = µo IS + µoεo∂ΦE ,S

∂t

$$\ o int {\ p a r t i a l S}B\cdotp d l = \mu o I S + \mu o\ e p s i l o n o \ f r a c {\ p a r t i a l \Phi {E , S}}{\ p a r t i a l t } $$

Page 58: La tex basics

More Examples

Example:

∞∑n=0

f n(a)

n!(x − a)n

$$\sum^{\infty}_{n=0} \frac{f^{n}(a)}{n!}(x - a)^n$$

¬(p ∨ q)⇐⇒ (¬p) ∧ (¬q)

$$\neg (p \vee q) \Longleftrightarrow (\neg p)

\wedge (\neg q) $$

Page 59: La tex basics

More Examples

Example (Matrices)a11 a12 · · · a1na21 a22 · · · a2n

......

. . ....

an1 an2 · · · ann

x1x2...xn

=

00...0

$$\left[ \begin{array}{cccc}

a_{11} & a_{12} & \cdots & a_{1n} \\

a_{21} & a_{22} & \cdots & a_{2n} \\

\vdots & \vdots & \ddots & \vdots \\

a_{n1} & a_{n2} & \cdots & a_{nn} \end{array} \right]

\left[ \begin{array}{c}

x_1 \\ x_2 \\ \vdots \\

x_n \end{array} \right] = \left[ \begin{array}{c}

0 \\ 0 \\ \vdots \\ 0 \end{array} \right]$$

Page 60: La tex basics

Math Assistance

You can find:

I Binary operators

I Trig functions

I Set notation

I Greek Symbols

I Delimeters

and more here : http://web.ift.uib.no/

Fysisk/Teori/KURS/WRK/TeX/symALL.html

Page 61: La tex basics

Math Example - particle8.tex

Page 62: La tex basics

Output

Page 63: La tex basics

Amsmath Package

If you use mathematics heavily in your documents,you might consider using the amsmath package. Itprovides some enhancements to the normal LaTeXmath capabilities which make typesetting formulaseasier and more attractive.

Go here for more info:

http://www.ams.org/tex/amslatex.html

Page 64: La tex basics

Packages

LATEXpackages are add-ons that provide added ormodified styling features to your document

I color- enables you to typeset in color

I babel- offers support for other languages

I hyperref- provides support for url’s in adocument

Include the following command in the preamble:

\usepackage{package name}

Page 65: La tex basics

Graphics

LATEXuses the package graphicx to manage graphics

\include{graphicx}

This package allows you to:

I Use several file formats

I Scale images

I Crop images

I Rotate images

Page 66: La tex basics

Image formats

Using the latex command:

I EPS format

Using the pdflatex command:

I JPG

I PNG

I PDF

Page 67: La tex basics

Inserting Graphics

Insert graphics using:

\includegraphics[options]{image file}

Options include:

I width and height

I scale

I rotation angle

I trim

Page 68: La tex basics

Example Graphic:

\includegraphics[scale = .5]{science cat}

Page 69: La tex basics

Example Graphic:

\includegraphics[scale = .5, angle = 90]{science cat}

Page 70: La tex basics

Figures

Include figures using the figure environment:

\begin{figure}...\end{figure}

Placement options:

I h - here

I t - top of page

I b - bottom of page

I p - separate page

Page 71: La tex basics

Example Figure

\begin{figure}

\centering

\includegraphics{graphics/participants-pie}

\caption{Registrants for this class}

\end{figure}

Page 72: La tex basics

Output

Figure: Registrants for this class

Page 73: La tex basics

Example Figure - particle9.tex

Page 74: La tex basics

Output

Page 75: La tex basics

Referencing Figures

Inside the figure environment include:\label{fig:Figure name}

\begin{figure}

\centering

\includegraphics{figure}

\caption{Place caption here}

\label{fig:figure}

\end{figure}

Reference the figure in text with:\ref{fig:Figure name}

Page 76: La tex basics

Referencing Figures

Inside the figure environment include:\label{fig:Figure name}

\begin{figure}

\centering

\includegraphics{figure}

\caption{Place caption here}

\label{fig:figure}

\end{figure}

Reference the figure in text with:\ref{fig:Figure name}

Page 77: La tex basics

Referencing Figures

Inside the figure environment include:\label{fig:Figure name}

\begin{figure}

\centering

\includegraphics{figure}

\caption{Place caption here}

\label{fig:figure}

\end{figure}

Reference the figure in text with:\ref{fig:Figure name}

Page 78: La tex basics

How to Make A Table

To make a table in LATEX use the tabular environment:

\begin{tabular}...\end{tabular}

Separate columns with the ”&” symbol

Separate rows with the double backslash ”\\”

Page 79: La tex basics

How to Make A Table

To make a table in LATEX use the tabular environment:

\begin{tabular}...\end{tabular}

Separate columns with the ”&” symbol

Separate rows with the double backslash ”\\”

Page 80: La tex basics

Tabular Layout

Specify the column layout when you call tabular:

\begin{tabular}{l|l|l}

Vertical bars produce vertical lines between columns.

Alignment Symbols

I l - align left

I r - align right

I c - centered

Page 81: La tex basics

Tables

\begin{tabular}{ l | l | l }

Class & Species & Lays eggs? \\

mammal & lion & \XSolidBrush \\

mammal & tiger & \XSolidBrush \\

mammal & platypus & \Checkmark \\

reptile & iguana & \Checkmark \\

reptile & snake & \Checkmark \\

aves & flamingo & \Checkmark \\

\end{tabular}

Class Species Lays eggs?

mammal lion %

mammal tiger %

mammal platypus !

reptile iguana !

reptile snake !

aves flamingo !

Page 82: La tex basics

TablesChange alignments:

\begin{tabular}{| l | r | c | }

Class & Species & Lays eggs? \\

mammal & lion & \XSolidBrush \\

mammal & tiger & \XSolidBrush \\

mammal & platypus & \Checkmark \\

reptile & iguana & \Checkmark \\

reptile & snake & \Checkmark \\

aves & flamingo & \Checkmark \\

\end{tabular}

Class Species Lays eggs?

mammal lion %

mammal tiger %

mammal platypus !

reptile iguana !

reptile snake !

aves flamingo !

Page 83: La tex basics

TablesAdd horizontal lines:

\begin{tabular}{| l | r | c | } \hline

Class & Species & Lays eggs? \\ \hline\hline

mammal & lion & \XSolidBrush \\ \hline

mammal & tiger & \XSolidBrush \\ \hline

mammal & platypus & \Checkmark \\ \hline

reptile & iguana & \Checkmark \\ \hline

reptile & snake & \Checkmark \\ \hline

aves & flamingo & \Checkmark \\ \hline

\end{tabular}

Class Species Lays eggs?

mammal lion %

mammal tiger %

mammal platypus !

reptile iguana !

reptile snake !

aves flamingo !

Page 84: La tex basics

TablesNot so many:

\begin{tabular}{| l | r | c | } \hline

Class & Species & Lays eggs? \\ \hline\hline

mammal & lion & \XSolidBrush \\

& tiger & \XSolidBrush \\

& platypus & \Checkmark \\ \hline

reptile & iguana & \Checkmark \\

& snake & \Checkmark \\ \hline

aves & flamingo & \Checkmark \\ \hline

\end{tabular}

Class Species Lays eggs?

mammal lion %

tiger %

platypus !

reptile iguana !

snake !

aves flamingo !

Page 85: La tex basics

TablesPartial hlines

\begin{tabular}{| l | r | c | } \hline

Class & Species & Lays eggs? \\ \hline\hline

mammal & lion & \XSolidBrush \\ \cline{2-3}

& tiger & \XSolidBrush \\ \cline{2-3}

& platypus & \Checkmark \\ \hline

reptile & iguana & \Checkmark \\ \cline{2-3}

& snake & \Checkmark \\ \hline

aves & flamingo & \Checkmark \\ \hline

\end{tabular}

Class Species Lays eggs?

mammal lion %

tiger %

platypus !

reptile iguana !

snake !

aves flamingo !

Page 86: La tex basics

Tables

The table enviroment:

\begin{table} ... \end{table}

allows you to:

I Turn a table into a float

I Add a caption

I Number the table for referencing

Page 87: La tex basics

Tables

table environment

Table: Who lays eggs?

Class Species Lays eggs?

mammallion %

tiger %

platypus !

reptileiguana !

snake !

aves flamingo !

Page 88: La tex basics

Example Table - particle10.tex

Page 89: La tex basics

Table Output

Page 90: La tex basics

Decoding Error Messages

Steps to decode error messages:

I Begin with the first error message

I Look for line numbers (l.43 for example)

I Line number indicates where error was firstdetected

I Check spelling!

Page 91: La tex basics

Common Errors

I Undefined control sequence - you used acommand that doesn’t exist

I Runaway argument - you left off a ”}”I Missing $ inserted - some of your text needs to

be in math mode

I Paragraph ended before \end was complete -missing ”}”

I LATEXWarning: Reference ... undefined on -recompile so LATEXcan get all of your references

Page 92: La tex basics

Where To Get Help

I Books - LATEXConcisely by Adrian Johnstone

I Online - numerous manuals available

I Research Computing Lab -www2.lib.virginia.edu/brown/rescomp/

help/index.html

Page 93: La tex basics

Most Commonly Used Commands

Figure: Top 10 Commands Out of 37,400 .tex Files

Page 94: La tex basics

Special Characters

Some characters have a special significance in LATEX

\ # $ % & ˆ { }

They must be preceded by the escape character ”\”

For example:\ $

Page 95: La tex basics

Special Characters

Some characters have a special significance in LATEX

\ # $ % & ˆ { }

They must be preceded by the escape character ”\”

For example:\ $

Page 96: La tex basics

Fonts

Default Font: Computer modern

Default font size: 10pt

How to change the default font:

I Additional fonts are available for installation(http://www.tug.dk/FontCatalogue/)

How to change the default font size:

I \documentclass command accepts [11pt] and [12pt] as options

I fix-cm package overrides font size defaults

I special commands

Page 97: La tex basics

Fonts

Default Font: Computer modern

Default font size: 10pt

How to change the default font:

I Additional fonts are available for installation(http://www.tug.dk/FontCatalogue/)

How to change the default font size:

I \documentclass command accepts [11pt] and [12pt] as options

I fix-cm package overrides font size defaults

I special commands

Page 98: La tex basics

Font Size Commands

\tiny(5pt)

\scriptsize(7pt)

\footnotesize(8pt)

\small(9pt)

\normalsize(10pt)

\large(12pt)

\Large(14pt)

\LARGE(18pt)

\huge(20pt)\Huge(24pt)