...

A_gsw_latex.pdf

by user

on
Category: Documents
2

views

Report

Comments

Transcript

A_gsw_latex.pdf
Academic & Research Computing
Getting Started with LATEX
$
'
LATEX Class
You can get started by doing the following:
1. login
2. Open a UNIX window
3. Enter the following UNIX commands:
mkdir latex (make a directory called “latex”)
cd latex
(change to your latex directory)
cp ∼bortonh/public/latex/*.tex
.
(copy all .tex files from my directory
public/latex to your latex directory.)
ls
(list the files you have copied)
&
%
1
Academic & Research Computing
Getting Started with LATEX
$
'
Using LATEX on UNIX Systems
.tex file
latex program
→
(creates .dvi file)
Preview .dvi file
→ (use xdvi)
&
Print .dvi file
(use dvips)
1. While in your latex directory, use an editor such as
emacs, vi or nedit to look at the file basic.tex.
If you don’t already know emacs or vi, open nedit (on the
RCS Applications menu).
2. Run LATEX by issuing the UNIX command:
latex basic.tex
(you may omit the “.tex”)
3. Preview the resulting DVI (device independent) file:
xdvi basic.dvi &
(you may omit the “.dvi”)
4. If/when you want to print the file, the command is:
dvips basic.dvi
(you may omit the “.dvi”)
Don’t do this now!
&
%
2
Academic & Research Computing
Getting Started with LATEX
$
'
Structure of a LATEX File
\documentclass[options]{article}
Preamble
(for LATEX commands only)
\begin{document}
Document text
(text with embedded LATEX commands)
\end{document}
The Document class determines the overall layout of the
document. In addition to article class, which is a good
all-purpose class, other commonly-used classes are:
report – for longer documents containing chapters
thesis – for writing an RPI thesis (see memo RPI.110).
book – for books
letter – for letters
slides – for making transparencies
Among other things, the classes provide heading
commands, such as \part, \chapter, \section.
&
%
3
Academic & Research Computing
Getting Started with LATEX
$
'
Document Class Options & Packages
A document class may be modified by using options:
\documentclass[options]{article}
Commonly-used options include:
11pt Prints document in 11pt type (default 10pt)
12pt Prints document in 12pt type
Example: \documentclass[11pt]{article}
LATEX Packages contain extra definitions that provide
additional formatting features. To load a package, include in
the preamble the command:
\usepackage{packagename}
Some commonly-used packages are:
setspace Provides easy way to change linespacing
fullpage
Sets 1-inch margins all around
graphicx Provides commands to include eps files
fancyhdr Customizes headers and footers
&
%
4
Academic & Research Computing
Getting Started with LATEX
$
'
LATEX Basics
The backslash “\” is used to begin all LATEX commands.
In the input file (.tex file), words are separated by one or
more blank spaces, paragraphs are separated by one (or
more) blank lines.
Commands are case-sensitive. Commands are all
lowercase unless there’s a good reason to use uppercase.
For example: \Delta → ∆ \delta → δ
Some commands take arguments, which are enclosed in
braces: \textbf{this text will be bold}
Certain characters have special meaning to LATEX. The
complete list is in Memo RPI.109, page 3; the most common
are listed below.
Input
Special TEX meaning
#
\#
Parameter in a macro
$
\$
Used to begin and end math mode
%
\%
Used for comments in the input file
&
\&
Tab mark, used in alignments
\
Used in math mode for subscripts
Char
&
%
5
Academic & Research Computing
Getting Started with LATEX
$
'
Some LATEX Vocabulary
Commands produce text or space:
\hspace{2in} and \textit{some italic words}
Declarations affect the following text:
\large prints the following text in a larger font.
Grouping { } is often used to limit the scope of a
declaration: {\large only this text is big}
Environments receive special processing and are defined
by \begin{name} ... \end{name}.
Example: \begin{quote} ... \end{quote}
Mandatory arguments are included in braces :
\hspace{2in} needs the information provided by the
argument to generate the space.
Optional arguments are enclosed in brackets [ ]:
\documentclass[11pt]{article} gives you 11-point
type. (The default is 10-point type.)
* indicates a variation on a command or environment.
\\ indicates a line break
\\* indicates a line break where a page cannot be
broken.
&
%
6
Academic & Research Computing
Getting Started with LATEX
$
'
Exercise 1
1. In your latex directory, open the file exart.tex with
your editor.
2. Note the following:
• use of the heading commands
• use of \textit{..}, \textbf{..}, {\small..}
• how to get various dashes and quotes
3. Run latex by issuing the command:
latex exart (don’t need the .tex extension)
4. Preview the result:
xdvi exart & (don’t need the .dvi extension)
5. In the exart.tex file, make the following changes:
• add the option [12pt] to \documentclass
• add to the preamble the commands:
\usepackage{fullpage} % 1-inch margins
\raggedright % do not right justify
\setlength{\parindent}{0pt} % no par. ind.
\setlength{\parskip}{10pt} % 10pt par. sep.
\pagestyle{empty} % no pagenumbers
• change headings to: \section*,\subsection*
6. Save the changes, run latex and preview again.
Note the differences in the formatted result.
&
%
7
Academic & Research Computing
Getting Started with LATEX
$
'
Responding to Error Messages
When LATEX finds an error, it emits a message such as:
! Undefined control sequence.
l.9 \secton
{Introducing LaTeX}
?
This means the \section command was misspelled, and the
error occurred on line 9 of the input file.
Other common errors include unmatched braces and a
special character (e.g., $, #, %) in the text. You can respond
with:
h for help
x for exit
press the Return key to ignore it, hope for the best.
If it stops with a * prompt, it often means you have forgotten
\end{document}. Enter it at the prompt (and fix your file
later).
If you mistyped the file name or for some other reason LATEX
cannot find a file, it will ask you for another filename. If you
don’t want to enter a new filename, quit the program by
pressing Ctrl-d. Another handy “Emergency stop sequence”
is Ctrl-c.
&
%
8
Academic & Research Computing
Getting Started with LATEX
$
'
Exercise 2
1. Still in your latex directory, edit the file ex2.tex
2. Note the following:
• How to use the center environment
• How to use the quote environment
• How to make 3 kinds of lists
3. Run latex by issuing the command:
latex ex2
4. Preview the result:
xdvi ex2 &
5. In the file ex2.tex, add a section at the end illustrating
the itemize environment.
HINT: See the comments at the end of the file.
&
%
9
Academic & Research Computing
Getting Started with LATEX
$
'
Tables
To make a table, use the tabular environment. This
environment requires an additional parameter that specifies
the alignment of each column:
\begin{tabular}{ccc}
% 3 centered columns
Apples & Oranges & Pears\\
Bananas & Mangos & Melons
\end{tabular}
l
c
r
p
|
||
Left-justified column entry
Centered column entry
Right-justified column entry
Paragraph column entry
Vertical rule column
Double vertical rule column
The width of each column is determined automatically from
the widest entry.
Inside the tabular environment:
& (the tab character) moves to the next column
\\ is used to end each line (except the last one)
&
%
10
Academic & Research Computing
Getting Started with LATEX
$
'
Example: A Ruled Table
\begin{tabular}{|l|p{2.8in}|}
\multicolumn{2}{c}{Various Column Alignments}\\
\hline
llll
& 4 columns, all left justified
(yes, those are ‘‘L’’s not ‘‘1’’s)\\
lcr
& 3 columns with the first entry
left justified, the second centered,
and the third right justified.\\
lp\{2in\} & 2 columns, the second is
a paragraph 2 inches wide.\\
\hline
\end{tabular}
Various Column Alignments
llll
4 columns, all left justified (yes, those are
“L”s not “1”s)
lcr
3 columns with the first entry left justified,
the second centered, and the third right
justified.
lp{2in}
2 columns, the second is a paragraph 2
inches wide.
&
%
11
Academic & Research Computing
Getting Started with LATEX
$
'
Mathematics
LATEX has several modes for formatting equations. When in a
math mode, LATEX follows different rules:
• All letters are set in the math italic font.
• There are many commands to print special symbols
(e.g.,\pi). Most work only in math mode.
• All spaces in the input are ignored.
• new paragraphs are not allowed. (No blank lines!)
To use roman type or retain spaces put the text in an “mbox”:
\mbox{this is normal text}.
The simplest mode is in-line math. The formulas are about
the same size as the text they’re in. To use it:
$ math expression
$
The equation $ax^2+bx+c = 0$ has 2 roots.
produces:
The equation ax2 + bx + c = 0 has 2 roots.
&
%
12
Academic & Research Computing
Getting Started with LATEX
$
'
Displayed Equations
There are four environments for formatting equations that
are to be set off from surrounding text.
1. Display Math (for unnumbered equations)
It can be invoked using either of the following:
$$ ... $$
\begin{displaymath} ... \end{displaymath}
2. Equation Environment (for numbered equations)
Just like displaymath except it numbers the equation. It
is invoked with \begin{equation}...\end{equation}
3. Eqnarray Environment (for multiline equations)
Formats a series of equations, aligning them on the “=”
or some other point of your choosing. It is invoked with
\begin{eqnarray}...\end{eqnarray}
4. Array Environment (for matrices, etc.)
Builds rectangular arrays of numbers, matrices, etc. It is
invoked with \begin{array}...\end{array}
NOTE: This environment must be enclosed in another math
environment, such as displaymath or equation.
&
%
13
Academic & Research Computing
Getting Started with LATEX
$
'
Math Examples
Display Math (for unnumbered equations)
The quadratic equation $ax^2+bx+c=0$ has 2
roots: $$x=\frac{-b \pm \sqrt{b^2-4ac}}{2a}$$
produces:
The quadratic equation ax2 + bx + c = 0 has 2 roots:
√
−b ± b2 − 4ac
x=
2a
Equation Environment (for numbered equations)
\begin{equation}
\frac{a^2 - b^2}{a + b} = a - b
\end{equation}
produces:
a 2 − b2
=a−b
a+b
&
(1)
%
14
Academic & Research Computing
Getting Started with LATEX
$
'
Eqnarray Environment (for multiline equations)
This environment builds a 3-column array of equations. It
numbers each line by default, but the command \nonumber
suppresses the number.
\begin{eqnarray}
(a+b)(a+b) & = & a^2+ab+ba+b^2 \nonumber\\
& = & a^2+2ab+b^2
\end{eqnarray}
(a + b)(a + b)
= a2 + ab + ba + b2
= a2 + 2ab + b2
(1)
Array Environment (for matrices, etc.)
This environment uses the same syntax as tabular.
$$\begin{array}{ccc}
x-\lambda & 1
& 0
\\
0
& x-\lambda & 1
\\
0
& 0
& x-\lambda
\end{array}$$
x−λ
1
0
0
x−λ
1
0
0
x−λ
&
%
15
Academic & Research Computing
Getting Started with LATEX
$
'
Exercise 3
1. Still in your latex directory, edit the file ex3.tex
2. Study the LATEX commands used.
3. Run latex by issuing the command:
latex ex3
4. Preview the result:
xdvi ex3 &
If you’re looking for more...
1. Still in your latex directory, edit the file ex2a.tex
2. Look at how to use the fancyhdr package.
3. Read the section on including PostScript graphics.
4. On an SGI workstation, issue the command:
export DISPLAY=‘hostname‘:0.0
5. Run latex by issuing the command:
latex ex2a
6. Preview the result:
xdvi ex2a &
&
%
16
Fly UP