1 Special Characters and Other Commands 2 Spacing 3 Sections

LATEX Workshop
Brown Science Center
1
Lecture 1
Intoduction to LATEX
Special Characters and Other Commands
Command
2
1
23 February 2014
Result
\{
{
\}
}
\%
%
\$
$
\&
&
\_
_
\^{}
ˆ
\#
#
\textbackslash
\
\~{}
˜
\ldots
...
Maxwell-Boltzmann
Maxwell-Boltzmann
12:00--5:30
12:00–5:30
yes---or no
yes—or no
“This is a quote.”
“This is a quote.”
You will see this % but not this
You will see this
Spacing
General Spacing
Spacing is generally ignored in LATEX, as well as line breaks; you need an empty line to make a difference:
Code
Here are
some big
spaces between
words that do nothing!
One empty line does it! We’ve got a new paragraph.
However one line does naught.
Output
3
Here are some big spaces between words that do nothing!
One empty line does it! We’ve got a new paragraph. However one line does naught.
Sections
Notice the autonumbering so you don’t have to worry about that stuff when adding or deleting sections.
2
23 February 2014
Lecture 1
Intoduction to LATEX
LATEX Workshop
Brown Science Center
Code
• \section{ . . . }
• \subsection{ . . . }
• \subsubsection{ . . . }
Output
1 I’m a big bad section!
2 I’m also a big section!
2.1 and I’m a subsection!
2.1.1 and I’m a subsubsection!
4
List Structures
• For enumerated lists:
\ b e g i n { enumerate }
\ item Put item h e r e t o a c t u a l l y g e t t h e number
\ end { enumerate }
• For bulleted lists:
\ begin { itemize }
\ item Put item h e r e t o a c t u a l l y g e t a b u l l e t p o i n t
\ end { i t e m i z e }
Here’s an example of what you can do with some nesting:
1. This is the first.
2. (a) The second ...
i. But wait, there’s more!
ii. me too!
(b) and even more! Anyway, here are some bullets:
(c)
• α
• β
• γ
3. This is the third item.
LATEX Workshop
Brown Science Center
5
Lecture 1
Intoduction to LATEX
3
23 February 2014
Basic fonts
Command
Result
\texttt{typewriter}
typewriter
\textsl{slanted}
slanted
\textsc{small caps}
small caps
\textit{italic}
italic
\textbf{bold}
bold
\textbf{\textit{bold-italic}}
bold-italic
Lastly, remember if in doubt, Prof. Google is your best friend!
6
Writing Mathematics in LATEX
LATEX is designed to make writing math easy and elegant. There is a command do virtually anything you
can write. However, there are also considerations of style; just because we can write something a certain
way doesn’t mean that we should. Let’s take a second to look at what constitutes good style when you’re
writing mathematics.
Notice there are three different types of equations that show up:
1. Inline equation: equations inside a sentence. Usually short and do not contain any “tall symbols”, such
as sums or integral.
2. Displayed equation: equations on their own line with spacing before any afterwards. Used for long or
tall equations.
3. Aligned equation: several equations, each on their own line, with a certain symbol (usually =) in the
same place in each line. Used for equations that are too long for a single line, or computations with
multiple steps.
Additionally, the last two types of equations sometimes have equation numbers next to them. If a sentence
ends with a displayed or aligned equation, it still needs a period.
The most important consideration when writing math is what equation type to use.
If you choose badly, your document will quickly become almost unreadable.
6.1
Inline Mode
Now that we know what we want to produce, we can focus on how to do it in LATEX. Let’s look at inline
equations first. Here’s an example.
What’s going on here? To enter inline math mode, you enclose your equation in dollar signs ($).
Anything between the dollar signs is interpretted as math, not regular text. In math mode, TeX acts slightly
differently. Here are some of the ways:
• All letters are automatically displayed as italics. This gives the reader a visual cue that they’re looking
at a variable instead of a normal letter.
• Math-only commands are available to make mathematical symbols, such as fractions, greek letters, etc.
• Extra spaces are automatically removed.
There are zillions of math commands in LATEX, enough to make any symbol you could possibly use, and
then some. But dont worry!
Commands have obvious names so that you can guess them.
4
23 February 2014
Lecture 1
Intoduction to LATEX
LATEX Workshop
Brown Science Center
Code
I f our f a t h e r s brought f o r t h on t h i s c o n t i n e n t a new n a t i o n ,
c o n c e i v e d i n l i b e r t y , and d e d i c a t e d t o t h e p r o p o s i t i o n t h a t a l l
men a r e c r e a t e d e q u a l $ s=4$ s c o r e and $y = 7 $ y e a r s ago , how o l d
i s t h e United S t a t e s ?
To go from p o l a r t o C a r t e s i a n c o o r d i n a t e s , l e t $x = r \ c o s \ t h e t a $ and
$y = r \ s i n \ t h e t a $ . To go t h e o t h e r way , one can i n v e r t t h e s e
e q u a t i o n s and f i n d $ r = \ s q r t {x^2 + y^2}$ and $ \ t h e t a = \ a r c t a n \
f r a c {y }{ x} $ .
Output
If our fathers brought forth on this continent a new nation, conceived in liberty, and dedicated
to the proposition that all men are created equal s = 4 score and y = 7 years ago, how old is the
United States?
To go from polar to Cartesian coordinates, let
! x = r cos θ and y = r sin θ. To go the other way,
one can invert these equations and find r = x2 + y 2 and θ = arctan (y/x).
As in the example, the command to make a fraction is \frac and the command for square root is \sqrt.
Here is a table of some common math commands.
Command
Input
Output
Superscript
$a^{ S u p e r s c r i p t } $
aSuperscript
Subscript
$a_{ S u b s c r i p t } $
aSubscript
Trigonometric Functions
$ f ( x )=\ s i n ( x ) $
f (x) = sin(x)
Lower Case Greek Letter
$\ alpha$
α
Upper Case Greek Letter
$ \ Pi$
Π
Sum and Powers
$y = x_{1}^{2} + x_{2}^{2} $
y = x21 + x22
There are lots of good lists of symbols on the internet. A list of basic symbols is available from
Brown’s CS department at http://cs.brown.edu/about/system/software/latex/doc/symbols.pdf. A fully
comprehensive list of symbols in LATEX — 164 pages long — is available at http://www.tex.ac.uk/texarchive/info/symbols/comprehensive/symbols-a4.pdf.
If you don’t even know what a symbol is called, then try Detexify. This is an app and website where you
can draw a symbol and it will give you the TeX command for it.
6.2
Display Mode
Often when you’re writing math, symbols such as sums or integrals are used. These are too large to fit into
"∞ 1
a single line, and look rather ugly. As an example, the equation n=0 2 doesn’t fit comfortably inside
n
the line and has to insert extra space in the lines below and above it to compensate. To avoid this, use
displayed math mode. This is also a math mode, so all commands from inline mode also work here. To
use displayed mode mode, use
Code
\[
∗math h e r e ∗
\]
LATEX Workshop
Brown Science Center
Lecture 1
Intoduction to LATEX
5
23 February 2014
The only difference is how the equation as a whole is displayed. So that you can read what have written,
always put the actual equation on a different line from the \[ and \[ symbols. Let’s look at an example
involving tall symbols that is best suited for display mode.
Code
\[
\ int_a^b f ( x ) \ , dx = \lim_{n\ t o \ i n f t y } \sum_{ i =0}^{n−1} \ f r a c {b−a }{
n} f \ l e f t ( a+ i \ f r a c {b−a }{n} \ r i g h t )
\]
Output
#
b
f (x) dx = lim
a
n→∞
n−1
$
i=0
b−a
f
n
%
b−a
a+i
n
&
It is also possible to nest commands in LATEX. For instance, the caret sign is used for powers and fractions
can be nested within those, as is done in the following example:
Code
\[
x^{\ f r a c {1}{1+\ f r a c {1}{ x }}}
\]
Output
1
1
x 1+ x
Many equations involve combinatorial notation and sequences where you need to omit some terms.
LATEXprovides special commands for both these things. The commands for the dots is \cdots and the
command for the binomial coefficients is: {n \choose r}. For instance, here’s how the binomial theorem
can be written as follows:
Code
\[
( x+y ) ^n = {n \ c h o o s e 0} x^n y^0 + {n \ c h o o s e 1} x^{n−1}y^1 + {n \ c h o o s e
2} x^{n−2}y^2 + \ c d o t s + {n \ c h o o s e n−1}x^1 y^{n−1} + {n \ c h o o s e n
}x^0 y^n
\]
Output
% &
% &
% &
%
&
% &
n n 0
n n−1 1
n n−2 2
n
n 0 n
1 n−1
(x + y) =
x y +
x
y +
x
y + ··· +
x y
+
x y
0
1
2
n−1
n
n
The example so far have had “naked” equations. Now let’s see how display mode can be integrated inside
a paragraph of text.
6
23 February 2014
Lecture 1
Intoduction to LATEX
LATEX Workshop
Brown Science Center
Code
The fundamental theorem o f c a l c u l u s i s
\[
\ f r a c {d}{ dx} \ int_0^x f ( t ) \ , dt = f ( x ) .
\]
I t has a v e r y i m p o r t a n t c o r o l l a r y : i f $F ( x ) $ i s an a n t i −d e r i v a t i v e
o f $ f ( x ) $ , then
\[
\ int_a^b f ( x ) \ , dx = F( b ) − F( a ) .
\]
Output
The fundamental theorem of calculus is
d
dx
#
x
f (t) dt = f (x).
0
It has a very important corollary: if F (x) is an anti-derivative of f (x), then
#
6.3
b
a
f (x) dx = F (b) − F (a).
Aligned Mode
To do aligned mode, we need to make a modification to our document’s preamble. Add the line \usepackage{amsmath}
anywhere before the document environment begins. To enter align mode, go into the enviornment align*.
To use aligned mode, type equations as you would for inline or display mode and do the following
1. An ampersand (&) before each symbol you want to have vertically aligned.
2. A double backslash (\\) at the end of every line.
3. No extra blank lines inside the align environment (you will get an error if you do this).
LATEX Workshop
Brown Science Center
Lecture 1
Intoduction to LATEX
7
23 February 2014
Code
\ documentclass { a r t i c l e }
\ u s e p a c k a g e {amsmath}
\ b e g i n { document }
. . .
We then need t o n o r m a l i z e .
\ b e g i n { a l i g n ∗}
1
&= \ int_0 ^\ i n f t y R^2( r ) r ^2 \ , dr \\
&= \ int_0 ^\ i n f t y ( 2 a_0 ) ^3 R^2(\ rho ) \ rho ^2 \ , d\ rho \\
&= 8a_0^3 D^2 \ int_0 ^\ i n f t y \ rho ^4 e^{−2\ rho } \ , d\ rho \\
&= 8a_0^3 D^2 \ f r a c {1}{16} \ int_0 ^\ i n f t y x^4 e^{−x} \ , dx \\
&= \ f r a c {1}{4} a_0^3 D^2 ( 2 4 ) \\
&= 6D^2 a_0 ^ 3 .
\ end { a l i g n ∗}
. . .
\ end { document }
Output
We then need to normalize.
1=
#
#
∞
0
∞
R2 (r)r2 dr
(2a0 )3 R2 (ρ)ρ2 dρ
# ∞
3 2
= 8a0 D
ρ4 e−2ρ dρ
0
# ∞
1
= 8a30 D2
x4 e−x dx
16 0
1
= a30 D2 (24)
4
= 6D2 a30 .
=
0