CMSC 601 LaTeX Spring 2011 Tim Finin finin@cs.umbc.edu

Preview:

Citation preview

CMSC 601LaTeX

Spring 2011

Tim Fininfinin@cs.umbc.edu

Objective

• Understand the role of LaTeX in your research• Learn how to create a simple LaTeX2e

document–Create a LaTeX source file–Create and include figures–Reference figures and sections–Create lists– Include other tex files–Generate pdf output–Cite bibliographic references

History: TeX and LaTeX• Donald Knuth created TeX in the late 70s

so he could typeset his famous Art of Computer Programming books

• TeX produced great output and was very powerful (and programmable) but also very obscure

• Leslie Lamport of SRI produced LaTeX in the ealry 80s as a macro package making TeX easy to use

• I’ve never know anyone who used TeX directly

Other Options• Microsoft Word is a great product

–Track changes is a great feature–You can’t beat it for small documents

• HTML is fine if your target is a screen–The W3C does all of its documentation in HTML–The Kindle ebook format is HTML

• Google Docs is up and coming–great for real-time collaboration

• That’s about it these days–No one uses Tj6, Scribe, Pub, troff, WordPerfect, …

Why LaTeX?

Why LaTeX• It’s good for complex documents

like a dissertation• It’s the standard for Computer Science,

Mathematics and many other STEM fields–Many conferences have their own LaTex document–Elsevier uses LaTeX to typeset all their journals

• LaTeX’s bibliography system, BibTex, is the best• LaTex is programmable!• LaTeX is open source software, has a large

community of users and developers and a good infrastructure (e.g., CTAN)

Accessing LaTeX

• Latex and associated tools are typically pre-installed on Linux and Mac OS X

• They are also on the CSEE servers and gl• Use Miktex for Windows

sample.tex\documentclass[12pt]{article}

\usepackage{times}

\begin{document}

\title{Hello World in LaTeX}

\author{My Name Goes Here}

\maketitle

Hello, world!

{\em Hello, world!}

{\bf Hello, world!}

{\Large \bf Hello, world!!!}

\end{document}

Start by declaring the document type (article) and use the 12pt option setting the font sizeStart by declaring the document type (article) and use the 12pt option setting the font size

Loads required packages defining commands or setting parametersLoads required packages defining commands or setting parameters

LaTex uses begin|end commands for blocks. Every document must have a document blockLaTex uses begin|end commands for blocks. Every document must have a document block

The title and author command set document variables and the maketitle command generates the output text

The title and author command set document variables and the maketitle command generates the output text

Latex comands start with a backslash, required args are in {}, options in []sLatex comands start with a backslash, required args are in {}, options in []s

Paragraphs are separated by blank linesParagraphs are separated by blank lines

{}s introduce un-named blocks and control scope. \em for italics, \bf for bold, \Large to increase font size

{}s introduce un-named blocks and control scope. \em for italics, \bf for bold, \Large to increase font size

f.auxf.aux

Compiling with pdflatex> pdflatex sample

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009)

entering extended mode

(./sample.tex

LaTeX2e <2009/09/24> ...

(/usr/local/texlive/2009/texmf-dist/tex/latex/base/article.cls

Document Class: article 2007/10/19 v1.4h Standard LaTeX document class

(/usr/local/texlive/2009/texmf-dist/tex/latex/base/size12.clo))

...

Output written on sample.pdf (1 page, 29675 bytes).

Transcript written on sample.log.

f.texf.tex

pdflatexpdflatex

f.pdff.pdf

Compiling, old school> latex sample

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009)...

Output written on sample.dvi (1 page, 652 bytes).

Transcript written on sample.log.

> dvips sample -o sample.ps

This is dvips(k) 5.98 Copyright 2009 Radical Eye Software (www.radicaleye.com)

' TeX output 2011.01.31:0857' -> sample.ps

...

> ps2pdf sample.ps

>

f.texf.tex

latexlatex

dvipsdvips

f.dvif.dvi

f.psf.ps

ps2pdfps2pdf

f.pdff.pdf

Output files

> ls -l sample*

-rw-r--r-- 1 finin staff 8 Jan 31 08:57 sample.aux

-rw-r--r-- 1 finin staff 652 Jan 31 08:57 sample.dvi

-rw-r--r-- 1 finin staff 3363 Jan 31 08:57 sample.log

-rw-r--r--@ 1 finin staff 3336 Jan 31 09:00 sample.pdf

-rw-r--r-- 1 finin staff 10664 Jan 31 08:58 sample.ps

-rw-r--r-- 1 finin staff 237 Jan 31 08:33 sample.tex

Files LaTeX Uses

• Input source file (.tex)• Files containing structure and layout definitions

(.sty)• Tex formatted output file (.dvi)• Others:

.toc (table of contents), .lof (list of figures), .lot (list of tables), .bib (bibliography)

Document Classes

• There are standard document classes: article, report, book, slides, letter\documentclass[11pt,letterpaper]{article}

• Conferences and journals publish their own\documentclass[10pt,journal,compsoc]{IEEEtran}\documentclass[runningheads,a4paper]{llncs}

• These an be further customized via packages\usepackage{graphicx}\usepackage{algorithm}

–Using additional packages

Including Other LaTeX Files

• Supports modularity–a single LaTeX document can

consist of multiple LaTeX files–Very useful for group work,

e.g., many authors using SVN

• \input{intro}–used to include other Latex

files–Latex filename is intro.tex

\documentclass[letterpaper]{article}\usepackage{aaai}\usepackage{times}\usepackage{graphicx}% comment: more here\begin{document} \include{title} \include{intro} \include{motivation} \include{related} \include{approach} \include{evaluation} \include{conclusion} \include{bibliograph}\end{document}

\documentclass[letterpaper]{article}\usepackage{aaai}\usepackage{times}\usepackage{graphicx}% comment: more here\begin{document} \include{title} \include{intro} \include{motivation} \include{related} \include{approach} \include{evaluation} \include{conclusion} \include{bibliograph}\end{document}

A typical top level file

Fall 1998 CPS 470 Software Engineering

15

More Complex LaTeX File

\documentclass[12pt]{article}\usepackage{doublespace,epsfig}\usepackage{../custom}\begin{document}\input{abstract}\section{Sample Section}\label{s:sample}

Text goes here...

\end{document}

Cross-references

• \label{key-string}–assigns the key key-string to the current element of

the document

• \ref{key-string}– inserts a string identifying the element to which key-

string refers

• \pageref{key-string}– inserts the page number on which the element

referenced by key-string appears

Fall 1998 CPS 470 Software Engineering

17

Cross-reference Example

Figure~\ref{f:figexample} in Section~\ref{s:sample} is on page~\pageref{f:figexample}.

Figure 1 in Section 1 is on page 1.

Including a Figure

\begin{figure} [htbp]

\centerline{\epsfig{figure=figname.eps, height=2.5in,silent=,clip=}}\caption{\label{f:figexample} Example of a figure.}

\end{figure}

Fall 1998 CPS 470 Software Engineering

19

Making a List

\begin{itemize}% \begin{enumerate}

\item Text for this item.

\item Text for this item.

\end{itemize}% \end{enumerate}

Table of Contents

• Contains section headings and page number where each section starts.

• \tableofcontents

Causes LaTeX to generate a .toc file

• Must run LaTeX on the file at least twice:–On the first pass, LaTeX collects information–On the second pass, LaTeX reads back information

and typesets it.

List of Figures

• Contains caption text of the figures and page number where each figure appears.

• \listoffigures

–Causes LaTeX to generate .lof file.

• As for the table of contents, must run LaTeX at least twice.

Bibliographies and BIBTeX

• Must create a bibliography “database”– .bib file– formatted by keyword, readable by BIBTeX

• Bibliographies can have different formats yet the same .bib file (alphabetical, order of citation, etc.)

• BIBTeX formats entries based on the bibliography style chosen (.bst or .sty)– ieeetr, plain, alpha, acm, etc.

BIBTeX Entry

• Entry type–book, article, inproceedings, etc.

• Keyword identifying publication–should be unique for each entry

• Series of fields for each type–author, title, journal, etc.

Referencing .bib entry

• \cite{keyword}• \nocite{key1, key2, key3,…}• example:

In \cite{pressman97}, the characteristics of software are discussed.

In [1], the characteristics of software are discussed.

BIBTex and LaTeX

• Command sequence– latex file.tex–bibtex file– latex file–May have to latex file again if unresolved references

Format• Sections– \section{…} = 1. Latex is Great– \subsection{…} = 1.1 Why Latex is Great– \subsubsection{…} = 1.1.1 Reason One– \appendix - changes numbering scheme– \chapter{…} - To be used with book and report

document classes• Titles, Authors and others

– \title{…} \author{…}– \footnote{…}

Lists

• Source–\begin{itemize}–\item Apple–\item Orange–\end{itemize}

• Result–Apple–Orange

Group

• Group is some text between { and }• Many commands work until the end of the

group• Code

–put {one word \bf in bold} here

• Result–put one word in bold here

Alignment

• Environments center, flushleft, flushright

• Example–\begin{flushright}–Right aligned–\end{flushright}

• ResultRight aligned

Font size

\tiny \scriptsize \footnotesize

\small \normalsize \large \Large

\LARGE \huge

\Huge

Example of Latex document

\documentclass{article}

\title{Simple Example}

\author{Andrei Gurtov}

\date{March 2000}

\begin{document}

\maketitle

Hello world!

\end{document}

Tabular• Columns– \begin{tabular}{|…|…|}– \end{tabular}

• Rows– & - Split text into columns– \\ - End a row– \hline - Draw line under row– e.g. 123123 & 34.00\\ \hline

Two Columns

l = automatically adjust size, left justifyr = automatically adjust size, right justifyp = set size e.g p{4.7cm}c = centre text

Example of table

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

Date & Price & Size \\ \hline

Yesterday & 5 & big \\ \hline

Today & 3 & small \\ \hline

\end{tabular}

Date Price Size

Yesterday 5 Big

Today 3 Small

Floating Objects• Floating objects can stop splitting of tables and images over pages.\begin{figure}[options]

\end{figure}

\begin{table}[options]

\end{table}

• They will now appear in the – List of Figures (LOF) and – List of Tables (LOT).

Options (recommendations)h = place table heret = place at top of pageb = place at bottom of page

Example of floating figure

• \begin{figure}[ht]• \centering\epsfig{file=uni.ps, width=5cm}• \caption{University of Helsinki}• \label{uni}• \end{figure}

Figure~\ref{uni} shows...

Images • Use epsfig package• \usepackage{epsfig}

• Including images in main body• \epsfig{file=filename.eps, width=10cm, height=9cm, angle=90}

• Creating EPS - Use xv and/or xfig.• MS Power Point, save as GIF and convert to EPS.

Bibliography by hand

\begin{thebibliography}{} \bibitem[Come95]{Come95} Comer,D. E., {\it Internetworking with TCP/IP:Principles, Protocols and Architecture},volume 1, 3rd edition. Prentice-Hall,1995.\end{thebibliography}

Bibliography using Bibtex

• Bibliography information is stored in a *.bib file, in Bibtex format.

• Include chicago package–\usepackage{chicago}

• Set referencing style–\bibliographystyle{chicago}

• Create reference section by–\bibliography{bibfile with no extension}

Bibliography using Bibtex

@book{Come95,author=“D. E. Comer”,title={Internetworking with TCP/IP: Principles, Protocols

and Architecture},publisher=“Prentice-Hall”,year=1995,volume=1,edition=“Third”}

Bibliography contd.• Citing references in text

– \cite{cuc98} = (Cuce 1998)– \citeN{cru98} = Crud (1998)– \shortcite{tom98} = (Tom, et. al. 1998)

• Creating Bibtex Files–Use Emacs with extensions.–or copy Bibtex entries from bibliography database.

Some Math

\begin{center}{\large$$ y=\frac{a^3+2c_{x}}{1+\sqrt{b_{x}}} $$ \\\vspace{0.2in}$$ Q=\sum_{i=1}^{j}\int_{\mu}^{\

infty}f(x_{j})dx $$ \\\vspace{0.2in}$$ \Psi = \oint_{- \infty}^{\infty}f_{xy}({\frac{\

partialQx}{\partial Qy}})^{\Im_{\pi}^ \prime} $$ \\ }

ToolsUNIX based systems

–xdvi, ghostview, fixps, emacs with latex/bibtex support.

Windows 98/NT–Ghostview, Acrobat Distiller, Acrobat Reader,

Scientific Workplace (not the best), the Bibtex viewer is good. Paint Shop Pro, Latex and Emacs

Conclusions• Latex is optimal for master and phd thesis?• Mathematical formulae are easy. • Use bibtex search engines • Consider converting Postscript files to PDF

(more widespread in Windows world) and to conserve space.

Recommended