Introduction Introduction to LTEXweb.mit.edu/belzner/Public/latex/sipb-latex.pdf · Introduction to...

Post on 18-Oct-2020

22 views 0 download

Transcript of Introduction Introduction to LTEXweb.mit.edu/belzner/Public/latex/sipb-latex.pdf · Introduction to...

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Introduction to LATEXIAP 2014

Megan Belznerbelzner@mit.edu

Student Information Processing Board

Massachusetts Institute of Technology

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Table of Contents

Introduction

A Basic DocumentWriting LaTeX CodeBasic Formatting

Making it Look NiceStructureMath ModeFigures and TablesMacros

Beamer

Conclusion

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

LATEX is. . .

. . . a sophisticated document preparation sytem.

LATEX has. . .

I Stylistic uniformity

I Bibliography support

I Sophisticated structuring abilities

I Reference tracking

I Highly extendible capabilities

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

LATEX is not. . .

. . . a word processor.

LATEX does not. . .

I Spell-check your documents

I Give you complete control over formatting

I Provide a graphical interface for editing

“You take care of writing, and we’ll take care ofpresentation.”

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

A Brief History

It all started with Donald Knuth and The Art of ComputerProgramming. . .

I TEX - a computer language used for typesetting mathand other technical material.

I Created in the late 1970s by Donald Knuth

I LATEX - a higher-level method of accessing the power ofTEX

I Created in the early 1980s by Leslie Lamport

LATEX is pronounced lah-tech or lay-tech.

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Why LATEX?

Presentation shouldn’t get in the way of content.

For example. . .

I With a word processor, you spend valuable time agonizingover what font size to make the section headings.

I With LATEX, you just tell it to start a new section.

I With a word processor, changing the formatting means youhave to change each instance individually.

I With LATEX, you just redefine the relevant commands.

I With a word processor, you have to carefully match anyprovided templates.

I With LATEX, you can be sure you’ve fit the template, andswitch templates easily.

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Table of Contents

Introduction

A Basic DocumentWriting LaTeX CodeBasic Formatting

Making it Look NiceStructureMath ModeFigures and TablesMacros

Beamer

Conclusion

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

”Hello LATEX!”

Creating a LATEX Document

I Write a .tex file using any text editor

% this is hello.tex

\documentclass{article}\begin{document}

Hello, \LaTeX!\end{document}

I Compile using latex or pdflatex$ cd path/to/folder/containing/file

$ pdflatex hello.tex

I Preview the results

$ evince hello.pdf &

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

documentclass

LATEX has several templates, selected using \documentclass

Classes:

I book

I report

I article

I letter

I beamer

Etc.

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Declarations and Environments

Declarations. . .

I Are stated once

I Take effect until further notice

I Can optionally be constrained

Ex. \documentclass, \small

Environments. . .

I Have matching begin and end declarations

I Must be constrained

Ex. \begin{document} ...\end{document}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Arguments

Required arguments. . .

I Are contained in curly braces

I Must be included

Ex. \documentclass{article}

Optional arguments. . .

I Are contained in square brackets

I Can be left out

I Give you more control over the commands

Ex. \documentclass[12pt]{article}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Special Characters

I Another type of command

I Don’t define any formatting or structure

I Print non-standard characters or characters whichusually mean something else

Ex. \LaTeX, \textbackslash, \&

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Packages

Packages allow you to further customize LATEX.

The command:\usepackage{name}

Some packages:

graphicx, epsfig, geometry, fancyhdr, setspace, amsmath,listings, xcolor, url. . .

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Font Types

Font face:\emph{Text}, \textbf{Text}, \texttt{Text},\textrm{Text}, \textsf{Text}, \textsc{Text}

Font size:{\tiny Text}, {\scriptsize Text}, {\footnotesize Text},{\small Text}, {\normalsize Text}, {\large Text},{\Large Text}, {\LARGE Text}, {\hugeText},{\HugeText}Alignment:

\begin{center/flushright/flushleft}...

\end{center/flushright/flushleft}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Spacing

MarginsThe default: between 1.5 inches and 1.875 inches

Setting margins: \usepackage[margin=0.5in]{geometry}

Paragraphs and other breaksParagraphs are separated by a blank line.You can force a new line using \\To force a new page, use \newpage or \clearpage

Other spacingForce a space using ∼Add space using \hspace{1in} or \vspace{1in}Fill space using \hfill or \vfill

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Lists

There are two main types. . .

Bulleted lists:\begin{itemize}\item Text\item Text

\end{itemize}

I Text

I Text

Numbered lists:\begin{enumerate}\item Text\item Text

\end{enumerate}

1. Text

2. Text

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Table of Contents

Introduction

A Basic DocumentWriting LaTeX CodeBasic Formatting

Making it Look NiceStructureMath ModeFigures and TablesMacros

Beamer

Conclusion

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Getting Started

Downloadhttp://web.mit.edu/belzner/Public/latex/scigen.zip

and open scigen.tex in your favorite text editor

% this is scigen.tex

\documentclass[12pt]{article}\begin{document}

...

\end{document}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Title

I Declare the title, author, and date

\documentclass[12pt]{article}\title{The Effect of Wearable Technology}\author{John Doe and Jane Doe}\date{}

I Add the title page\begin{document}\maketitle

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Sections

LATEX is built off of the idea of structure over formatting

\section{Introduction}

Layers of sectioning

part (books only)chapter (books and reports only)

sectionsubsection

subsubsection

paragraph

subparagraph

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Abstract and ToC

Abstracts\begin{abstract}

The implications of secure methodologies...

\end{abstract}

Table of Contents\end{abstract}

\tableofcontents

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

References and Appendices

Footnotes...telephony\footnote{Phony telephones}

Bibliographies

\bibliography{scigen}\bibliographystyle{acm}

Appendices

\appendix\section{Appendix}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Bibliographies

BibTEX@Article{cite:0,

Author = {John Backus},Title = {Symmetric Encryption},Journal = {Journal of Modalities},Month = jul,

Year = 1993,

Volume = 46,

Pages = {44--57}}

CitationsRedundancy \cite{cite:0}

For multiple citations:

...methodology \cite{cite:1, cite:2}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Typesetting Math

LATEX allows you to typeset any sort of equations.

LATEX math support∫ b

a

1 + θ2= tan−1 b − tan−1 a

Using math mode

Inline math mode: $...$∫∞1 e−xdx

∑∞n=0 n!

Display math mode: $$...$$

Numbered equations: \begin{equation}...\end{equation}A useful package: \usepackage{amsmath}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Some Commands

974 974

4 + 2 4+23√

5 \sqrt[3]{5}xy \frac{x}{y}

Axy A^{x} {y}∑n

k=1 k \sum {k=1}^n k

2 6= 4 2 \ne 4

φ ∈ Ψ \phi \in \Psiı̂× ̂ = k̂ \hat{\i} \times \hat{\j} = \hat{k}

f ′′(ξ) f’’(\xi)CH3COOH CH$ 3$COOH

180◦C 180$^{\circ}$C

...runs in $\Theta(\log n)$ time...

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Figures and Tables

Both are environments:

Figures

\begin{figure}...

\end{figure}

Tables\begin{table}

...

\end{table}

Positioning can be defined as an optional argument:\begin{figure}[htbp]

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

includegraphics

Required Packages\documentclass[12pt]{article}

\usepackage{graphicx}

The Commands\subsection{Hardware Configuration}

\begin{figure}[ht]\centering\includegraphics[width=3in]{figure0.jpg}

\end{figure}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Formatting Tables

The table environment defines the figure style. Thetabular environment defines the table itself.

The Commands\section{Related Work}

\begin{table}[ht]\centering\begin{tabular}{|r||c|c|} \hline\textbf{Trial} & $n$ & $t$ \\ \hline\textbf{1} & 23 & 2 \\ \hline\textbf{2} & 15 & 10 \\ \hline\textbf{3} & 100 & 20 \\ \hline

\end{tabular}\end{table}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Captions and Labels

Captioning

\end{tabular}\caption{The data.}

Labeling

\caption{The data.}\label{tab:label0}

Referencing

...in Table \ref{tab:label0}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

What are Macros?

I LATEX allows you to define or redefine commands as youplease

I In fact, LATEX itself is a set of macros on top of TEX

\newcommand{name}[num]{definition}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Resetting Commands

Changing lengths

\setlength{command}{length}

Ex.\setlength{\parindent}{1cm}\setlength{\parskip}{1cm plus4mm minus3mm}

Changing titles

Ex.\renewcommand{\abstractname}{Summary}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Adding Commands

AbbreviationsCode:

\newcommand{\MIT}{the Massachusetts Institute of Technology}The mission of \MIT∼is to advance knowledge...

Output:The mission of the Massachusetts Institute of Technology is to

advance knowledge. . .

Getting more complex

Ex.\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Table of Contents

Introduction

A Basic DocumentWriting LaTeX CodeBasic Formatting

Making it Look NiceStructureMath ModeFigures and TablesMacros

Beamer

Conclusion

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Slides

Beamer allows all the same commands as a normalLATEX document, plus some.

Getting started\documentclass{beamer}\begin{document}

\begin{frame}{Title}...

\end{frame}

Special slides

Title slide:\titlepage

Table of contents:\tableofcontents[currentsection]

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Formatting

Some special environments can be useful for presentations

Blocks\begin{block}

...

\end{block}

Columns\begin{columns}\column{0.5\textwidth}

Column 1

\column{0.5\textwidth}Column 2

\end{columns}

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Animation

You can also do some basic animation in beamer.

I \pause puts a pause before revealing the rest of theslide

I command<num-num> makes the command apply onlyfor some number of the “frames”

I The previous bullet is defined by \item<3-4>I The bullet disappears after the fourth “frame”

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Animation

You can also do some basic animation in beamer.

I \pause puts a pause before revealing the rest of theslide

I command<num-num> makes the command apply onlyfor some number of the “frames”

I The previous bullet is defined by \item<3-4>I The bullet disappears after the fourth “frame”

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Animation

You can also do some basic animation in beamer.

I \pause puts a pause before revealing the rest of theslide

I command<num-num> makes the command apply onlyfor some number of the “frames”

I The previous bullet is defined by \item<3-4>I The bullet disappears after the fourth “frame”

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Animation

You can also do some basic animation in beamer.

I \pause puts a pause before revealing the rest of theslide

I command<num-num> makes the command apply onlyfor some number of the “frames”

I The previous bullet is defined by \item<3-4>

I The bullet disappears after the fourth “frame”

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Animation

You can also do some basic animation in beamer.

I \pause puts a pause before revealing the rest of theslide

I command<num-num> makes the command apply onlyfor some number of the “frames”

I The previous bullet is defined by \item<3-4>I The bullet disappears after the fourth “frame”

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Themes

You can also choose different themes for beamer.

Design

\usetheme{theme}Antibes, Berkeley, Berlin, Goettingen, Malmoe, Szeged,Warsaw. . .

Color\usecolortheme{theme}

beaver, crane, lily, rose, seahorse, whale. . .

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Table of Contents

Introduction

A Basic DocumentWriting LaTeX CodeBasic Formatting

Making it Look NiceStructureMath ModeFigures and TablesMacros

Beamer

Conclusion

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

So, why LATEX?

I LATEX allows you to worry about the content and thestructure, rather than the presentation.

I LATEX has one of the most advanced math typesettingsystems around.

I LATEX is incredibly extendible.

I LATEX keeps track of references so you don’t have to.

I LATEX allows you to make more consistent, and moreeasily changeable, documents.

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

LATEX on your own

Get LATEX on your own computer:

WindowsMiKTEX

miktex.org/

Mac OS XMacTEX

tug.org/mactex/

LinuxTEX Live

tug.org/texlive/

Introduction toLATEX

Megan Belzner

Introduction

A Basic Document

Writing LaTeX Code

Basic Formatting

Making it LookNice

Structure

Math Mode

Figures and Tables

Macros

Beamer

Conclusion

Resources

I The Not So Short Introduction to LATEX 2ε:www.ctan.org/tex-archive/info/lshort/english/

lshort.pdf

I LATEX Wikibooks:en.wikibooks.org/wiki/LaTeX

I A Short Math Guide for LATEX:ftp://ftp.ams.org/pub/tex/doc/amsmath/

short-math-guide.pdf