Lecture04 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

Introduction to Scientific Typesetting

Lesson 4: Typing Mathematics

Ryan Higginbottom

January 10, 2012

1
An Overview

An Overview
Getting Started
Getting Started

Working With Math


Working With Math
Symbols Symbols
Multiline Mathematics
Multiline Mathematics

2
An Overview

Getting Started

Two Types
The Delimiters

An Example

Working With Math

Symbols
Getting Started
Multiline Mathematics

3
Two Types

An Overview
There are two types of math (or formulas):
Getting Started

Two Types  inline — the formula is part of the current line or paragraph
The Delimiters

An Example

Working With Math  displayed — on a separate line (or lines) with spacing that sets
Symbols it apart
Multiline Mathematics

4
The Delimiters

An Overview
Inline Formulas
Getting Started

Two Types
Use dollar signs to surround a formula like 2 + 2 = 4.
The Delimiters

An Example
Use dollar signs to surround
Working With Math a formula like $2+2=4$.
Symbols

Multiline Mathematics
Displayed Formulas
Use the symbols \[ and \] to enclose a formula like

2 + 2 = 4.

. . . to enclose a formula like \[ 2+2=4. \]

Typing $ or \[ sends LATEX into math mode. Some of the behavior is


different in this mode, so be careful!

5
An Example

Let f be the function f (x) = x2 . This means that f (2) = 4 and


An Overview

Getting Started

Two Types
The Delimiters f (−3) = 9.
An Example

Working With Math Let $f$ be the function $f(x)=x^2$.


Symbols
This means that $f(2)=4$ and \[ f(-3)=9. \]
Multiline Mathematics

Note 1: Remember that formulas are part of your writing, so


punctuation rules need to be observed!

Note 2: \[ and \] are shortcuts for \begin{displaymath} and


\end{displaymath}

6
An Overview

Getting Started

Working With Math

Spacing in Math Mode


The amsmath package
Equations
The Operations of
Arithmetic
Fractions
Working With Math
Subscripts and
Superscripts
Ellipses
Roots

Text in Math
Practice

Symbols

Multiline Mathematics

7
Spacing in Math Mode

An Overview
LATEX treats multiple spaces as one. The following give the same
Getting Started
output:
Working With Math

Spacing in Math Mode


2+2=4
The amsmath package 2 + 2 =4
Equations
The Operations of
Arithmetic The spacing after a comma is different in math and text. Unless the
Fractions
Subscripts and comma is part of the mathematical notation, you generally want it
Superscripts
Ellipses
outside of math mode.
Roots

Text in Math
Example: To write x = a, b, or c type:
Practice

Symbols

Multiline Mathematics
$x=a$, $b$, or $c$

8
The amsmath package

An Overview
Some of what follows requires the amsmath package to be loaded
Getting Started
in your preamble. So, just to be safe, include
Working With Math

Spacing in Math Mode


The amsmath package
\usepackage{amsmath}
Equations
The Operations of in your preamble from now on.
Arithmetic
Fractions
Subscripts and
Superscripts
Here’s a good template for our class at this point:
Ellipses
Roots

Text in Math \documentclass{article}


Practice \usepackage[margin=1in]{geometry}
Symbols
\usepackage{amsmath}
Multiline Mathematics
\begin{document}

\end{document}

9
Equations

An Overview
The equation environment is the same as the displaymath
Getting Started
environment except each equation environment is numbered.
Working With Math

Spacing in Math Mode The quadratic formula is:


The amsmath package
Equations √
The Operations of −b ± b2 − 4ac
Arithmetic x= . (1)
Fractions 2a
Subscripts and
Superscripts
Ellipses
Roots
No blank lines are allowed in an equation environment!
Text in Math
Practice
The equation* environment is the same as displaymath
Symbols
or \[ and \].
Multiline Mathematics

(A good rule of thumb—the starred version of an environment


suppresses the numbering.)

10
The Operations of Arithmetic

An Overview
Here are the ways to type common arithmetic operations:
Getting Started

Working With Math Type Display


Spacing in Math Mode
The amsmath package
$a + b$ a+b
Equations $a - b$ a−b
The Operations of
Arithmetic $a \times b$ a×b
Fractions
Subscripts and
$a \div b$ a÷b
Superscripts
$a \cdot b$ a·b
Ellipses
Roots
$a / b$ a/b
Text in Math
Practice

Symbols

Multiline Mathematics

11
Fractions

An Overview
Fractions are only slightly different than the other mathematical
Getting Started
operators.
Working With Math

Spacing in Math Mode


2+x
The amsmath package
To see this: , you need to type this: \frac{2+x}{6-y}.
Equations 6−y
The Operations of
Arithmetic
2+x
Fractions
Subscripts and
Within text this fraction 6−y
will look small. We can use \dfrac to
Superscripts
fix that inline.
Ellipses
Roots
2+x
Text in Math You know is my favorite . . .
Practice 6−y
Symbols You know $\dfrac{2+x}{6-y}$ is my favorite \ldots
Multiline Mathematics

If you want the (smaller) inline-sized fraction in display mode, use


\tfrac.

12
Subscripts and Superscripts

An Overview
The “caret” ^ is used for superscripts and the underscore _ is used
Getting Started
for subscripts.
Working With Math

Spacing in Math Mode


The amsmath package Type Display
Equations
The Operations of $x^2$ x2
Arithmetic
Fractions
Subscripts and
$x_7$ x7
Superscripts
Ellipses
$x^{10}$ x10
Roots

Text in Math
$x_{17}$ x17
Practice

Symbols

Multiline Mathematics
Note that if your subscript or superscript is more than one character,
you’ll need to enclose it in braces.

13
Ellipses

An Overview
There are several types of ellipses that LATEX provides in math mode:
Getting Started

Working With Math Type Display


Spacing in Math Mode
The amsmath package
\ldots 1, 2, . . .
Equations \cdots 1 + 2 + · · · + 10
The Operations of
..
Arithmetic
\vdots .
Fractions
Subscripts and ..
Superscripts \ddots .
Ellipses
Roots

Text in Math
Practice

Symbols

Multiline Mathematics

14
Roots

An Overview
The square root sign is made with a command in math mode.
Getting Started

Working With Math $\sqrt{51}$ produces 51
Spacing in Math Mode
The amsmath package
Equations
The Operations of This is used for all kinds of roots, not just square roots:
Arithmetic
Fractions √
3
Subscripts and $\sqrt[3]{5}$ produces 5
Superscripts
Ellipses √
10
Roots
$\sqrt[10]{44}$ produces 44
Text in Math
Practice

Symbols

Multiline Mathematics

15
Text in Math

An Overview
Text in math is produced with the \text command.
Getting Started

Working With Math

Spacing in Math Mode


The amsmath package Area of a rectangle = l · w (2)
Equations
The Operations of
Arithmetic \begin{equation}
Fractions
Subscripts and \text{Area of a rectangle} = l\cdot w
Superscripts
Ellipses
\end{equation}
Roots

Text in Math
Practice

Symbols

Multiline Mathematics

16
Practice

An Overview
Let’s practice!
Getting Started

Working With Math


Open up the first example PDF file from Sakai, and reproduce it.
Spacing in Math Mode
The amsmath package
Equations
The Operations of
Arithmetic
Fractions
Subscripts and
Superscripts
Ellipses
Roots

Text in Math
Practice

Symbols

Multiline Mathematics

17
An Overview

Getting Started

Working With Math

Symbols

Greek Letters
Integral Signs
Delimiters

Stretching Delimiters
Symbols
More on Stretching
Delimiters
Specifying Delimiter
Height
Operators

Tables of Operators
Large Operators
Practice

Multiline Mathematics

18
Greek Letters

An Overview
Greek letters are needed frequently within formulas, like
Getting Started

Working With Math


A = πr2 .
Symbols

Greek Letters
. . . within formulas, like \[ A = \pi r^2. \]
Integral Signs
Delimiters

Stretching Delimiters You can find a list of the permitted Greek letters in a table on our
More on Stretching
Delimiters web site. LATEX can do some of the Greek capitals, but not all of
Specifying Delimiter
Height them.
Operators

Tables of Operators
A lot of these are easy to guess:
Large Operators
Practice Type Display Type Display
Multiline Mathematics $\alpha$ α $\phi$ φ
$\beta$ β $\psi$ ψ
$\gamma$ γ $\omega$ ω
$\delta$ δ
19
Integral Signs

An Overview
This is a mathematics-specific symbol, but it illustrates a larger
Getting Started
point. Consider this formula:
Working With Math

Symbols
Z 15
Greek Letters x2 dx.
Integral Signs 2
Delimiters

Stretching Delimiters
formula: \[ \int_2^{15} x^2\,dx. \]
More on Stretching
Delimiters
Specifying Delimiter
Height There are lots of integral symbols available:
Operators

Tables of Operators
Large Operators
Practice Type Display Type Display
R RR
Multiline Mathematics
$\int$ $\iint$
H RRR
$\oint$ $\iiint$

20
Delimiters

An Overview
A delimiter is simply a special math symbol to enclose part of a
Getting Started
formula. The parentheses in the following formula are an example
Working With Math
of delimiters:
(x + y)2 .
Symbols

Greek Letters
Integral Signs
Delimiters
There are all sorts of delimiters available:
Stretching Delimiters
More on Stretching
Delimiters
Specifying Delimiter
Height
Type Display Type Display
Operators

Tables of Operators
$($ ( $[$ [
Large Operators
Practice
$\{$ { $|$ |
Multiline Mathematics
$\langle$ h $\rangle$ i
$\|$ k

21
Stretching Delimiters

An Overview
Sometimes delimiters do not extend up and down enough to fully
Getting Started
enclose what’s inside. You can see that here:
Working With Math
1 6
Symbols
( ) (\frac{1}{5})^6.
Greek Letters 5
Integral Signs
Delimiters Instead, we should have
Stretching Delimiters
 6
More on Stretching
Delimiters 1
Specifying Delimiter \left(\frac{1}{5}\right)^6.
Height 5
Operators

Tables of Operators The \left and \right commands can be applied to most
Large Operators
Practice
delimiters.
 
Multiline Mathematics 1
\left[ \frac{1}{5} \right]
5
 
1
\left\{ \frac{1}{5} \right\}
5
22
More on Stretching Delimiters

An Overview
LATEX requires a pair when stretching delimiters, but they don’t have
Getting Started
to match.
Working With Math  
Symbols 1
\left( \frac{1}{5} \right\}
Greek Letters
5
Integral Signs
Delimiters
If you want to stretch just a single delimiter, you need to “fake” the
Stretching Delimiters
More on Stretching other one.
Delimiters
Specifying Delimiter 
Height 1
Operators \left[ \frac{1}{5} \right.
Tables of Operators 5
Large Operators
Practice
\left. and \right. accomplish this for you.
Multiline Mathematics

23
Specifying Delimiter Height

An Overview
Instead of trusting LATEX to give your delimiter the correct size, you
Getting Started
can specify it yourself in some cases.
Working With Math

Symbols  
Greek Letters
(
Integral Signs
Delimiters

Stretching Delimiters
More on Stretching
Delimiters
( \big( \Big( \bigg( \Bigg(
Specifying Delimiter
Height
Operators
The analogs for right delimiters exist too, and these can be applied
Tables of Operators to most delimiters.
Large Operators b
Practice
Example: in integral problems, you need to write F (x) .

Multiline Mathematics a

\right| isn’t big enough, so I use \Bigr|_a^b.

24
Operators

An Overview
An operator in LATEX is a log-like function, like sin or ln.
Getting Started

Working With Math To get sin x you cannot type $sin x$ or sin $x$. You must type
Symbols $\sin x$.
Greek Letters
Integral Signs Another kind of operator is lim. This is called an operator with limits
Delimiters

Stretching Delimiters
because it is frequently used like this:
More on Stretching
Delimiters
Specifying Delimiter
lim f (x) \lim_{x \to 1} f(x)
x→1
Height
Operators

Tables of Operators
For this reason, operators like sin are called operators without
Large Operators limits.
Practice

Multiline Mathematics You need to be in display mode for the x → 1 to go under the
symbol; otherwise you’ll get limx→1 f (x).

You can fake display mode with \displaystyle.


Type: $\displaystyle \lim_{x \to 1} f(x)$
25
Tables of Operators

An Overview
Operators without limits:
Getting Started
Type Display Type Display
Working With Math

Symbols
$\sin$ sin $\cos$ cos
Greek Letters $\tan$ tan $\cot$ cot
Integral Signs
Delimiters
$\arcsin$ arcsin $\arctan$ arctan
Stretching Delimiters $\deg$ deg $\dim$ dim
More on Stretching
Delimiters
Specifying Delimiter
Height Operators with limits:
Operators

Tables of Operators
Type Display Type Display
Large Operators $\lim$ lim $\det$ det
Practice
$\max$ max $\min$ min
Multiline Mathematics

There are lots more of both of these; see resources linked from our
class web page if necessary.

26
Large Operators

An Overview
The symbols for sums and products are examples of symbols which
Getting Started
have different sizes depending on whether they are typeset inline or
Working With Math
in a displayed environment.
Symbols
Pn
Greek Letters
Here is the sum symbol i=i i typeset inline, and here it is
Integral Signs
Delimiters
displayed:
n
Stretching Delimiters X
More on Stretching i.
Delimiters
Specifying Delimiter i=1
Height
Operators \sum_{i=1}^n i
Tables of Operators
Large Operators
Practice Though there are lots of other symbols which have this property, the
Multiline Mathematics other most common one is the symbol for a product:
Y
i2 \prod_{i < 4} i^2
i<4

27
Practice

An Overview
Let’s practice!
Getting Started

Working With Math


Open up the second example PDF file from Sakai, and reproduce it.
Symbols

Greek Letters
Integral Signs
Delimiters

Stretching Delimiters
More on Stretching
Delimiters
Specifying Delimiter
Height
Operators

Tables of Operators
Large Operators
Practice

Multiline Mathematics

28
An Overview

Getting Started

Working With Math

Symbols

Multiline Mathematics

Aligned Formulas
Multiple Aligned
Columns
Multiline Mathematics
Matrices
More Matrices
Variant Matrix
Environments
Arrays

Cases
Practice

29
Aligned Formulas

An Overview
When you want to consider multiple formulas or equations at once,
Getting Started
you need a nice way to put math on multiple lines. The simplest
Working With Math
setup here is when you have a point to line up in the equations.
Symbols

Multiline Mathematics

Aligned Formulas
a2 + b2 = c2 (3)
Multiple Aligned
Columns
a+b=c+2 (4)
Matrices
More Matrices
Variant Matrix
\begin{align}
Environments a^2 + b^2 &= c^2 \\
Arrays

Cases
a+b &= c + 2
Practice \end{align}

Use & as your alignment point and \\ as the line separator.

The align* environment will align without equation numbers.

30
Multiple Aligned Columns

An Overview
The align environment aligned things in one column. The
Getting Started
alignat environment allows alignment of multiple columns and
Working With Math
control over the intercolumn space.
Symbols

Multiline Mathematics

Aligned Formulas
f (x) = x2 g(x) = 2x − 1 (5)
Multiple Aligned
Columns
f (2) = 4 g(2) = 3 (6)
Matrices
More Matrices
Variant Matrix
\begin{alignat}{2}
Environments f(x) &= x^2 \qquad & g(x) &= 2x-1 \\
Arrays

Cases
f(2) &= 4 & g(2) &= 3
Practice \end{alignat}
The mandatory argument is the number of aligned columns.
In this example, the first and third & give the alignment points, the
second & begins the second column. In general, even-numbered
&’s are column separators, and odd-numbered &’s are alignment
points.
31
Matrices

An Overview
Matrices function like tables, except everything is in math mode.
Getting Started
Consequently, you must enter math mode before entering a
Working With Math
matrix environment.
Symbols

Multiline Mathematics a−2 b x+y−z


Aligned Formulas
Multiple Aligned
4 e+f 0
Columns
Matrices
More Matrices
\[
Variant Matrix
Environments
\begin{matrix}
Arrays a-2 & b & x+y-z \\
Cases
4 & e+f & 0
Practice
\end{matrix}
\]

Within the matrix environment, all columns are centered. Also,


there are no delimiters on either side of the matrix.

32
More Matrices

An Overview
We can enclose a matrix in delimiters in the expected way:
Getting Started
 
Working With Math a b+c
Symbols d−e 2
Multiline Mathematics

Aligned Formulas
Multiple Aligned
\[
Columns
\left(
Matrices
More Matrices \begin{matrix}
Variant Matrix
Environments
a & b+c \\
Arrays d-e & 2
Cases
Practice
\end{matrix}
\right)
\]
 
a b+c
The delimiters do not have to match:
d−e 2

33
Variant Matrix Environments

An Overview
LATEX provides environments for matrices with the most common
Getting Started
delimiters:
Working With Math
 
Symbols a b
pmatrix
Multiline Mathematics c d
Aligned Formulas  
Multiple Aligned a b
Columns bmatrix
Matrices c d
More Matrices
Variant Matrix a b
Environments
c vmatrix
Arrays d
Cases
Practice a b

c
Vmatrix
d
 
a b
Bmatrix
c d

34
Arrays

An Overview
The major difference between the various matrix environments
Getting Started
and the array environment is that you have a lot more control
Working With Math
within array.
Symbols
a+b d
Multiline Mathematics

Aligned Formulas
e f +2
Multiple Aligned
Columns
Matrices \[
More Matrices
Variant Matrix
\begin{array}{|l|r|} \hline
Environments a+b & d \\ \hline
Arrays

Cases
e & f+2 \\ \hline
Practice \end{array}
\]

array is just like tabular except in math mode. If you want any
\multicolumns, you must use array instead of matrix.
You can put delimiters around array environments too.
35
Cases

An Overview
The cases environment is the way to denote a piecewise-defined
Getting Started
function. It is really a special type of matrix.
Working With Math
(
Symbols
−x x < 0
Multiline Mathematics |x| =
Aligned Formulas x x≥0
Multiple Aligned
Columns
Matrices \[
More Matrices
Variant Matrix
|x| =
Environments
Arrays
\begin{cases}
Cases -x & x<0 \\
Practice
x & x \ge 0
\end{cases}
\]

The cases environment can appear inline or displayed.

36
Practice

An Overview
Let’s practice!
Getting Started

Working With Math


Open up the third example PDF file from Sakai, and reproduce it.
Symbols

Multiline Mathematics

Aligned Formulas
Multiple Aligned
Columns
Matrices
More Matrices
Variant Matrix
Environments
Arrays

Cases
Practice

37

You might also like