SIGNewGrad: Intro to LaTeX

Download Report

Transcript SIGNewGrad: Intro to LaTeX

SIGNewGrad:
Intro to LaTeX
Ben Breech
[email protected]
http://www.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
Running LaTeX
doc.tex
latex
pdflatex
doc.dvi
dvipdf
dvips
doc.pdf
doc.ps
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
Environments
• Affects all text within env
• Conveniently hides tons of commands
• Format:
\begin{name}[opts]{args}
% text…
\end{name}
Example Document [ex1.tex]
Sets doc. type
preamble
\documentclass{article}
class type
% comments in LaTeX start with a %. anything after it is ignored.
% this section is the preamble..
\begin{document}
body
This is the first paragraph.
For \LaTeX, a paragraph is a continuous sequence
of lines, ending with a blank line. This means
you can put
one word
per
line
if 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}
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
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
Sectioning Examples
\section{Top Level Section}
\subsection{2nd Level Section}
% second \subsection not shown
\subsubsection{3rd Level Section}
\paragraph{Paragraph.}
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
Example Document
\section{Labels and References}
\label{sec:lab-ref}
% other stuff cut out…
For example, in section~\ref{sec:tls}, we
discussed sectioning commands.
Section~\ref{sec:3rd-ls} was a 3rd level
section.
In section~\ref{sec:lab-ref}, we discussed
labels and references.
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}
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}
Font Sizes
Affect 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}
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 ()
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)
Math Examples
(equation)
Creates a
{ big enough
to match what
follows.
Array env.
(just like a table)
Finally, here's a more complicated equation.
The Ackermann function $A$ is defined as,
\mathrm to
\begin{equation}
make if appear
\label{eq:ack-def}
as normal text
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}
Matching right
\right.
. = don’t print
\end{equation}
\[space] to force
anything
a space here
Math Examples
(equation)
(equation number was removed. See example.pdf)
(If you’re bored, compute A (4, 3))
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
Tables
Start table
Table body
Caption
& label
Table template
one letter/column
l = left justify
r = right justify
c = center
| = draw vert. Bar
between two cols
\begin{table}
\centering
\begin{tabular}{|l|c|r|}
\hline
left justified & center justified
& right justified \\
& separate
\hline\hline
columns
row 2, col 1
& row 2, col 2
& row 2 col 3 \\
\\ ends
row 3, col 1
& & \\
each row
\hline
\end{tabular}
\hline draws
\caption{Example Table}
horizontal
line between rows
\label{tab:ex}
\end{table}
Tables
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!
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)
Example Bib File
Define string
abbreviation
BibTeX entry
for article.
@String{cl = "Computer Languages"}
Citation key
for \cite
@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},
Authors separated
number={1},
by and
pages={47--57},
year={1981}
}
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
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)
Other Resources
• AucTeX - major mode for Emacs
http://www.gnu.org/software/auctex
• LyX - “GUI” for LaTeX
http://www.lyx.org
• Various packages
– Subfig, natbib, algorithms,epsfig