signewgrad: intro to latex ben breech [email protected] breech/signewgrad-fall07

27
SIGNewGrad: SIGNewGrad: Intro to LaTeX Intro to LaTeX Ben Breech Ben Breech [email protected] [email protected] http://www.cis.udel.edu/~breech/ http://www.cis.udel.edu/~breech/ signewgrad-fall07 signewgrad-fall07

Upload: philip-atkinson

Post on 04-Jan-2016

224 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

SIGNewGrad:SIGNewGrad:Intro to LaTeXIntro to LaTeXSIGNewGrad:SIGNewGrad:Intro to LaTeXIntro to LaTeX

Ben BreechBen Breech

[email protected]@cis.udel.edu

http://www.cis.udel.edu/~breech/signewgrad-http://www.cis.udel.edu/~breech/signewgrad-fall07fall07

Page 2: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

What is LaTeX• Based on TeX

– hard to use (like prog. in assembly)

• Markup language for documents– You write. LaTeX typesets

• LaTeX compiles your document– Each letter/word/sentence/paragraph is

a box. LaTeX arranges the boxes.– Commands and environments instruct

LaTeX to change layout

• LaTeX is case sensitive

Page 3: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Running LaTeX

doc.tex latex doc.dvi

dvipsdvipdf

doc.pdf doc.ps

pdflatex

Page 4: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Commands• Change layout of text• Format:

\command[opt_arg1]{req_arg1}

• Command names are only letters– Command ends with last {} or non-letter

(exception: some commands have special -* form)

– May need empty {} for spacing if command has no args

Page 5: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Environments• Affects all text within env• Conveniently hides tons of

commands• Format:

\begin{name}[opts]{args} % text… \end{name}

Page 6: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Example Document [ex1.tex]

\documentclass{article}

% comments in LaTeX start with a %. anything after it is ignored.% this section is the preamble..

\begin{document}

This is the first paragraph. For \LaTeX, a paragraph is a continuous sequenceof lines, ending with a blank line. This meansyou can putone wordperlineif you wish and \LaTeX{} will treat the text as one paragraph.

This is the second paragraph. Just put in here to show how paragraphs separate.\end{document}

preamble

body

Sets doc. type class type

Page 7: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Example Document [ex1.pdf]

• Notice margins.– Designed for typesetters– Add \usepackage{fullpage} in preamble to

get 1.0” margins

• Spacing between words/paragraphs– 1 space = 10 spaces = 100 spaces, etc– Paragraph is contiguous text separated by

blank lines

Page 8: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Sectioning Commands• Let you break document into sections• Each section has running counter (e.g.,

section 1, section 2, section 2.3.4)• Commands:

– \section{title}, \subsection{title}, \subsubsection{title}

– Others available depending on style file

Page 9: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Sectioning Examples

\section{Top Level Section}

\subsection{2nd Level Section}

% second \subsection not shown

\subsubsection{3rd Level Section}

\paragraph{Paragraph.}

Page 10: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Labels and references• \label{string} after sectioning

command to save a label• \ref{string} where you want number for

section with label string – May want ~\ref{string}

• ~ = non-breakable space

• \pageref{string} -- gives page number where section with label string appears

Page 11: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Example Document

\section{Labels and References}\label{sec:lab-ref}

% other stuff cut out…

For example, in section~\ref{sec:tls}, wediscussed sectioning commands. Section~\ref{sec:3rd-ls} was a 3rd level section.In section~\ref{sec:lab-ref}, we discussedlabels and references.

Page 12: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Lists• Bulleted Lists:

\begin{itemize}\item First item.\end{itemize}

• Enumerated Lists (automatically counted):\begin{enumerate}\item \label{it1} This is the first item.\end{enumerate}

Page 13: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Font Styles• Change appearance of text• Forms:

\texttt{TeleType text} \textbf{BoldFace text} \textsl{Slanted text} \textit{ITalicized text.} \textrm{RoMan} \textsc{Small Caps} \textsf{Sans Serif}

Page 14: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Font SizesAffect everything after until end of

current text block (e.g. } or \end{}) {\tiny really small } {\scriptsize next smallest} {\footnotesize size used in footnotes} {\small smaller than normal } {\normalsize regular sized text} {\large larger than normal } {\Large larger } {\LARGE larger still } {\huge very large } {\Huge extremely large}

Page 15: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Math Mode• In normal text, $math formula$• In displayed math mode,

\begin{displaymath} math formula \end{dispalymath}

\begin{equation} math formula \end{equation}– Equation adds an equation number in ()

Page 16: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Math Examples (text mode)

• superscripts (^) -- x^2 + y^2• subscript (_) -- x_i + y_i• \sqrt{x^2_i + y_i^2}• \frac{x}{y}• Greek letters -- \alpha, \beta, \pi, \Pi, • \sum_{i=0}^n i

(different in display mode)

Page 17: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Math Examples(equation)

Finally, here's a more complicated equation. The Ackermann function $A$ is defined as,

\begin{equation} \label{eq:ack-def} A (m, n) = \left\{ \begin{array}{ll} n + 1 & \mathrm{if}\ m = 0 \\ A (m - 1, 1) & \mathrm{if }\ m > 0 \mathrm{\ and\ } n = 0 \\ A (m - 1, A (m, n - 1)) & \mathrm{if}\ m > 0 \mathrm{\ and\ } n > 0 \end{array} \right.\end{equation}

Creates a { big enoughto match what follows.

Matching right. = don’t printanything

Array env. (just like a table)

\mathrm to make if appearas normal text

\[space] to forcea space here

Page 18: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Math Examples(equation)

(equation number was removed. See example.pdf)

(If you’re bored, compute A (4, 3))

Page 19: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Floating Environments• Certain environments can “float”

– Do not appear exactly where you put them

– LaTeX moves them for better placement– Can be frustrating if LaTeX picks bad

spot

• Tables/Figures are most common

Page 20: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Tables\begin{table} \centering \begin{tabular}{|l|c|r|} \hline left justified & center justified & right justified \\ \hline\hline row 2, col 1 & row 2, col 2 & row 2 col 3 \\ row 3, col 1 & & \\ \hline \end{tabular} \caption{Example Table} \label{tab:ex}\end{table}

Start table

Table body

Caption& label

Table templateone letter/columnl = left justifyr = right justifyc = center| = draw vert. Bar between two cols

& separate columns

\\ endseach row

\hline drawshorizontalline between rows

Page 21: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Tables

Page 22: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Paper Citations• Place \cite{key} where you want

citation to appear– key is unique citation key– generates reference label at that spot

• Need to add special bibliography environment with papers – DON’T BOTHER! USE BibTeX instead!

Page 23: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

BibTeX• BibTeX manages citations• Add following to body of your doc

– \bibliographstyle{type}• type = style (plain, abbrv, alpha)• Other styles available (see natbib)

– \bibliography{bib-files}• bib-files are your BibTeX files with citations• This command appears where you the

bibliography (usually end of document)

Page 24: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Example Bib File@String{cl = "Computer Languages"}

@Article{ChaitinEA-CL81, title={Register Allocation Via Coloring}, author={G.J. Chaitin and Auslander, M.A. and Chandra, A.K. and Cocke, J. and Hopkins, M.E. and Markstein, P.W.}, journal=cl, volume={6}, number={1}, pages={47--57}, year={1981}}

Define string abbreviation

BibTeX entryfor article.

Citation keyfor \cite

Authors separated by and

Page 25: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

BibTeX Examples• Create document:

- latex doc.tex- bibtex doc- latex doc.tex- latex doc.tex

• Since I’m out of time, see examples in– Example.tex– Example.pdf– Ex.bib

Page 26: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Other Resources• Books

– “A Guide to LaTeX2e”, Kopka and Daly – “LaTeX: A Document Preparation System”,

Lamport

• Web– http://www.ctan.org– Google (tons of pages provide help on

LaTeX)

Page 27: SIGNewGrad: Intro to LaTeX Ben Breech breech@cis.udel.edu breech/signewgrad-fall07

Other Resources• AucTeX - major mode for Emacs

http://www.gnu.org/software/auctex

• LyX - “GUI” for LaTeXhttp://www.lyx.org

• Various packages– Subfig, natbib, algorithms,epsfig