LaTeX_Tutorial

Download Report

Transcript LaTeX_Tutorial

Quick LaTeX Tutorial
Winter Quarter 2005
Rolando V. Raqueño
1
LaTeX Tutorial
• Why do you want to learn LaTeX?
• Nuts and Bolts of LaTex
• Examples
Winter Quarter 2005
Rolando V. Raqueño
2
Why you want to learn LaTeX
• Powerful control of document creation
– particularly large technical documents
• Minimizes the drudgery
– formatting, numbering, and referencing
• Disadvantage:
– Steep Learning Curve
Winter Quarter 2005
Rolando V. Raqueño
3
LaTeX Platforms
• Scientific Workplace
– (Commercial Package)
• UNIX Systems (LyX)
– (Free)
• MikTex and WinEdt
– PC Shareware
– Needs wmf2eps
– ghostview
Winter Quarter 2005
Rolando V. Raqueño
4
LaTeX Resources
• http://www.ctan.org
• http://www.colorado.edu/ITS/docs/latex/Ref/
• LaTeX for Complete Novices
– (Nicola Talbot)
• The Not So Short Introduction to LaTeX 2e
– (Tobias Oetiker)
• Math Into LaTeX
– (George Gratzer)
• Learning LaTeX
– (Griffiths & Higham)
• A Guide to LaTeX
– (Kopka & Daly)
Winter Quarter 2005
Rolando V. Raqueño
5
The LaTeX Process
1. Create a text file (with your favorite text
editor) with LaTeX commands
2. “Compile” or “Build” your document using
the LaTeX program
3. Display resulting Document
4. Continue writing and go to 1 until finished
5. Convert Document to Postscript or PDF
Winter Quarter 2005
Rolando V. Raqueño
6
Flow of LaTeX Process
Winter Quarter 2005
Rolando V. Raqueño
7
Source code of your
first LaTeX document
(fish.tex)
\documentclass{article}
\begin{document}
My mother is a fish.
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
8
Commands to Build and
View Document
To use xdvi viewer
% latex fish.tex
…
% xdvi fish.dvi
Winter Quarter 2005
To use acroread
% pdflatex fish.tex
…
% acroread fish.pdf
Rolando V. Raqueño
9
Winter Quarter 2005
Rolando V. Raqueño
10
Emphasizing words
(fish.tex)
\documentclass{article}
\begin{document}
\emph{My mother} is a fish.
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
11
Winter Quarter 2005
Rolando V. Raqueño
12
Underlining words
(fish.tex)
\documentclass{article}
\begin{document}
\emph{My mother} is a
\underline{fish}.
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
13
Winter Quarter 2005
Rolando V. Raqueño
14
Other font modification
commands
• Bold face
\textbf{}
• Teletype or typewriter face
\texttt{}
• Italic face
\textit{}
Winter Quarter 2005
Rolando V. Raqueño
15
Making references in LaTeX
(fish.tex)
\documentclass{article}
\begin{document}
\emph{My mother} is a
\underline{fish} \cite{WF}.
\begin{thebibliography}{99}
\bibitem{WF}
William Falkner, \emph{As I Lay
Dying}
\end{thebibliography}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
16
Need to compile the document
twice
• Using symbolic references requires
second pass
– \cite{WF}
• The second pass will resolve references
Winter Quarter 2005
Rolando V. Raqueño
17
Winter Quarter 2005
Rolando V. Raqueño
18
Sum Equation Example
(sum.tex)
\documentclass{article}
\begin{document}
\begin{equation} \label{E:sum}
s = \sum_{i=1}^{n}x_{i}
\end{equation}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
19
Winter Quarter 2005
Rolando V. Raqueño
20
Sum of Squares Equation
Example (sum_squares.tex)
\documentclass{article}
\begin{document}
\begin{equation}
\label{E:sum_squares}
s2 = \sum_{i=1}^{n}x_{i}^{2}
\end{equation}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
21
Winter Quarter 2005
Rolando V. Raqueño
22
Mean Equation Example
(mean.tex)
\documentclass{article}
\begin{document}
\begin{equation} \label{E:mean}
\bar{x} =
\frac{\sum_{i=1}^{n}x_{i}} {n}
\end{equation}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
23
Winter Quarter 2005
Rolando V. Raqueño
24
Mean Equation Example
with limits (mean_limits.tex)
\documentclass{article}
\begin{document}
\begin{equation} \label{E:mean}
\bar{x} =
\frac{\sum\limits_{i=1}^{n} x_{i}}
{n}
\end{equation}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
25
Winter Quarter 2005
Rolando V. Raqueño
26
Variance Equation Example
(variance.tex)
\documentclass{article}
\begin{document}
\begin{equation} \label{E:variance}
\sigma^{2} =
\frac{\sum\limits_{i=1}^{n}
\left(x_{i} - \bar{x}\right)^{2}}
{n-1}
\end{equation}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
27
Winter Quarter 2005
Rolando V. Raqueño
28
Standard Deviation Equation
Example (sd.tex)
\documentclass{report}
\begin{document}
\chapter{Standard Deviation}
\begin{equation} \label{E:sd}
\sigma =
\sqrt{\frac{\sum\limits_{i=1}^{n}
\left(x_{i} - \bar{x}\right)^{2}}
{n-1}}
\end{equation}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
29
Winter Quarter 2005
Rolando V. Raqueño
30
Changing the document styles
\documentclass{article}
\documentclass{book}
\documentclass{letter}
\documentclass{report}
Winter Quarter 2005
Rolando V. Raqueño
31
Report document style
(main.tex)
\documentclass{report}
\title{Assignment 2 for SIMG726}
\author{Rolando V. Raque\~no}
\begin{document}
\maketitle
\tableofcontents
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
32
Winter Quarter 2005
Rolando V. Raqueño
33
Create the following chapters
chapter_sum.tex
chapter_mean.tex
chapter_sd.tex
Winter Quarter 2005
Rolando V. Raqueño
34
chapter_mean.tex
\chapter{Mean} \label{C:Mean}
\begin{equation} \label{E:mean}
\bar{x} =
\frac{\sum_{i=1}^{n}x_{i}}
{n}
\end{equation}
Winter Quarter 2005
Rolando V. Raqueño
35
chapter_sum.tex
\chapter{Sum} \label{C:Sum}
\begin{equation} \label{E:sum}
s = \sum_{i=1}^{n}x_{i}
\end{equation}
Winter Quarter 2005
Rolando V. Raqueño
36
chapter_sd.tex
\chapter{Standard Deviation}
\label{C:SD}
\begin{equation} \label{E:sd}
\sigma =
\sqrt{\frac{\sum\limits_{i=1}^{n}
\left(x_{i} - \bar{x}\right)^{2}}
{n-1}}
\end{equation}
Winter Quarter 2005
Rolando V. Raqueño
37
Modify main.tex to include
chapters
\documentclass{report}
\title{Assignment 2 for SIMG726}
\author{Rolando V. Raque\~no}
\begin{document}
\maketitle
\tableofcontents
\include{chapter_sum}
\include{chapter_mean}
\include{chapter_sd}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
38
Winter Quarter 2005
Rolando V. Raqueño
39
Modify chapter_sd.tex
\chapter{Standard Deviation} \label{C:SD}
…
\end{equation}
We can see that equation \ref{E:sd} uses
equation
\ref{E:mean} to compute the mean and that
the \emph{Mean}
function uses equation \ref{E:sum} both of
which are defined
in Chapter \ref{C:Sum} and \ref{C:Mean},
respectively
Winter Quarter 2005
Rolando V. Raqueño
40
Winter Quarter 2005
Rolando V. Raqueño
41
Modify main.tex to include
chapters
\documentclass{report}
\title{Assignment 2 for SIMG726}
\author{Rolando V. Raque\~no}
\begin{document}
\maketitle
\tableofcontents
\include{chapter_mean}
\include{chapter_sum}
\include{chapter_sd}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
42
Winter Quarter 2005
Rolando V. Raqueño
43
Miscellaneous LaTeX Topics
Winter Quarter 2005
Rolando V. Raqueño
44
Comments in LaTeX
%
– Ignores the rest of the line
Winter Quarter 2005
Rolando V. Raqueño
45
To protect special characters
• Use the \ character
– e.g.
My\_Cat.raw
• To typeset a section as typed
\begin{verbatim}
\end{verbatim}
Winter Quarter 2005
Rolando V. Raqueño
46
Verbatim command
• OK for small sections that can be typed
into document
• What about including entire source code
of programs
– Use verbatim package
Winter Quarter 2005
Rolando V. Raqueño
47
Including Source code in
LaTeX documents
\documentclass{article}
\usepackage{verbatim}
\begin{document}
\begin{equation} \label{E:sum}
s = \sum_{i=1}^{n}x_{i}
\end{equation}
The code as implemented in idl
in vectorized form looks like
\verbatiminput{sum.pro}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
48
Winter Quarter 2005
Rolando V. Raqueño
49
Including image graphics into
you LaTeX document
• Need to convert your image graphics into
EPS (encapsulated postscript).
– For images, use pnmtops, e.g.
% pnmtops MyCat.pgm > MyCat.ps
• Need to include an extension package to
LaTeX called “graphicx” using command
\usepackage{graphicx}
• N.B. In CIS systems, following example works
for latex but not for pdflatex
Winter Quarter 2005
Rolando V. Raqueño
50
Including image graphics into
you LaTeX document
• Need to convert your image graphics into EPS
• For images, use pnmtops, e.g.
% pnmtops –norotate –nosetpage MyCat.pgm > MyCat.ps
• -norotate keeps from auto-rotating the image
• -nosetpage keeps from setting to a specific device
• Need to include an extension package to LaTeX called
graphics using command
\usepackage{graphics}
• N.B. In CIS systems, following example works for latex but
not for pdflatex
Winter Quarter 2005
Rolando V. Raqueño
51
Image Graphics Example
(image.tex)
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\includegraphics{MyCat.ps}
\caption{This is My Cat}
\label{F:MyCat}
\end{figure}
\end{document}
Winter Quarter 2005
Rolando V. Raqueño
52
Winter Quarter 2005
Rolando V. Raqueño
53
Flowchart Figures
• Create Flowchart in PowerPoint
• Export as a bmp file
• Convert from bmp to postscript
% bmptoppm figure.bmp | pnmtops –
norotate –nosetpage > figure.ps
• OR User xfig because it will export to EPS
• Shareware utility called WMF2EPS
– Windows clipboard objects to EPS
Winter Quarter 2005
Rolando V. Raqueño
54
Because current pdflatex
cannot include Encapsulated
Postscript Files (EPS)…
• Need to go from dvi to postscript to pdf
using the following commands
% dvips image.dvi
% ps2pdf image.ps
• Some degradation in quality is observed
Winter Quarter 2005
Rolando V. Raqueño
55
Winter Quarter 2005
Rolando V. Raqueño
56