270 likes | 502 Views
SIGNewGrad: Intro to LaTeX. Ben Breech breech@cis.udel.edu 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
E N D
SIGNewGrad:Intro to LaTeX Ben Breech breech@cis.udel.edu 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 doc.dvi pdflatex 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] \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 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} class type Sets doc. type preamble body
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} • Equationadds 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) 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 enough to match what follows. \mathrm to make if appearas normal text Array env. (just like a table) Matching right. = don’t printanything \[space] to forcea 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 Table templateone letter/columnl = left justifyr = right justifyc = center| = draw vert. Bar between two cols \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 & separate columns Table body \\ endseach row Caption& label \hline drawshorizontalline between rows
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 @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} } Citation keyfor \cite BibTeX entryfor article. Authors separated by and
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 LaTeXhttp://www.lyx.org • Various packages • Subfig, natbib, algorithms,epsfig