Upload
aosdfjodsaofodfcom
View
219
Download
0
Embed Size (px)
Citation preview
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 1/36
How to use LATEX
Christopher A. Wong
University of California, Berkeley
13 September 2012
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 1 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 2/36
Outline
1 General structure of LATEX
2 Writing mathematics - AMS LATEX
3 Environments
4 Bibliographies
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 2 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 3/36
What is TEX?
Pronunciation: ‘Tek’
Developed by Donald Knuth.
A low-level typesetting program.Provides precise formatting control over basic features such asspacing, justification, and fonts.
The availability of macros.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 3 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 4/36
What is LATEX?
Pronunciation: ‘Lay-tek’
A higher-level system running on top of TEX for end-users.
Advantages: Document styles, bibliographies, equation and figurereferencing, and more.
Platform-independent and can be edited through a text editor.
LATEX is the standard for professional academic paper writing.
An example:
(1)
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 4 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 5/36
Settings up LATEX
LATEX package: Look up TeX Live.
There are a variety of TeX editors out there, but we will not usethem today. Windows: TeXnicCenter. For Mac: TeX Shop.
The download can be large and possibly annoying. Pay attentionto the instructions.
For today we will use a web compiler:http://sciencesoft.at/latex/?lang=en
http://www.artofproblemsolving.com/Resources/texer.php
Please type everything in a text editor, then paste into the website.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 5 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 6/36
Obligatory First Document
We need to specify a document type, and then create the document.
\documentclass{article}
\begin{document}
Hello world!!!
\end{document}
One of the most important things to note is that LaTeX treats yoursymbols as commands, not directly typed text. So you can addarbitrary spaces between words.Try testing the text when you skip lines.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 6 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 7/36
Special charactersMany characters on the keyboard are now reserved for LaTeX codeinstead of being printed directly on the screen. This includes :
1 $ - mark the beginning and end of math.2 % - for comments (try this!)
3 & - mark separation between columns in a table
4 _ - denote subscript
5 - at the beginning of every LaTeX command6 { } - used to enclosed arguments of LaTeX commands.
To actually reproduce these symbols, we use
\$
\%\&
\_
$\backslash$
\{ \}
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 7 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 8/36
Some basic mathematics
We can now try doing some math. We must begin and end any math
symbols with $. Arithmetic:$ 1+1 = 2$ \\
$ 3-2 = 1$ \\
$ \sqrt{9} = 3, 9^{1/2} = 3$. \\
$ 4^2 = 16, 3^{2 + 1} = 27$.
If you are using any math variables, also use dollar signs:
Let $x$ be an unknown. If $x = 1$ then $x + 1 = 2$.
I can also do nested super and sub scripts:
A googol is equal to $10^{10^2}$.
A sequence $\{a_n\}$ has a subsequence $\{a_{n_k} \}$.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 8 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 9/36
AMS Packages - the preamble
The American Mathematical Society has provided several packages thatexpand on the math functionality of LaTeX. We have to place thefollowing commands before we begin our document, in the preamble :
\usepackage{amsmath}\usepackage{amssymb}
\usepackage{amsthm}
From now on, include these packages in your preamble.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 9 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 10/36
Basic mathematics, continued
Many of the most important symbols used in math mode can be found
here:http://www.artofproblemsolving.com/Wiki/index.php/LaTeX:
Symbols On that same website, you can find a tutorial similar to thisone. Binary relations:
$5 < 6, x \le y, 9 > 4, z \ge x, q = r, q \neq x$.
Set notation, blackboard font, the symbol:
Let $A = \{ f(x) \in C^{\infty}(\mathbb{R}): f(0) = \pm 1 \}$.
Fractions:
\frac{x^2 + x + 1}{2x + 5}
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 10 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 11/36
Exercise!
Try writing the quadratic formula:
If , then .
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 11 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 12/36
Exercise!
Try writing the quadratic formula:
If , then .
Notice that our fractions so far have been a little bit squished. If we use
\dfrac{}{}
we get
.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 11 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 13/36
Other valuable commands
$F(b) - F(a) = \int_a^b f(x) \, dx$. \\
$\lim_{n \rightarrow \infty} \sin(1/n) = 0$.\\$\sum_{n = 1}^{\infty} \dfrac{1}{n^2} = \dfrac{\pi^2}{6}$.
.
.
.
Notice that the summation and integral symbols are too small. We canuse
\displaystyle
beforehand (inside math mode) to improve their appearances. Basicallyevery command you can imagine is written very similarly to whatwould be natural.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 12 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 14/36
Greek letters
Very simple; it’s just plus the name of the greek letter. If you use acapital first letter then you get the upper-case version (warning: thisdoes not work if the upper-case letter is actually just a regular Romanletter).
$\alpha, \beta, \gamma, \delta, \pi$ \\
$\Gamma, \Delta, \Pi$.
.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 13 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 15/36
Exercise
Try writing the following:
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 14 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 16/36
Exercise
Try writing the following:
$\displaystyle \sum_{j=0}^{\infty} \epsilon \pi^{1 - j} =
\frac{\epsilon \pi}{1 - \frac{1}{\pi}} $
If I use displaystyle, I don’t have to use dfrac or dint.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 14 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 17/36
Displaymath Environment
Notice that in the previous frame, my series was centered and on a lineof its own, unlike your own recreation. This was done using thedisplaymath environment.
An example of display math:
\begin{displaymath}
A = \pi r^2
\end{displaymath}
Try recreating the previous series, but using the displaymath
environment. You will not need displaystyle or dollar signs.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 15 / 29
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 18/36
BoundariesIf we just write
\begin{displaymath} ( 1 + \frac{1}{n})^2 \end{displaymath}
I get
These parentheses are too small. The way to fix this is by using
LaTeX’s automatic boundary sizes. A boundary means things likebrackets, parentheses, curly braces, etc. The commands are:
\begin{displaymath}
\left( 1 + \frac{1}{n} \right)^2
\end{displaymath}
which produces
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 16 / 29
E
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 19/36
Exercise
Produce the following limit definition of :
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 17 / 29
E i
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 20/36
Exercise
Produce the following limit definition of :
\begin{displaymath}
e = \lim_{n \rightarrow \infty} \left(1+\frac{1}{n} \right)^n
\end{displaymath}
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 17 / 29
B d i ti d
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 21/36
Boundaries, continued
We can nest boundaries in one another; this will typically make theoutside boundary larger:
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 18 / 29
B d i ti d
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 22/36
Boundaries, continued
We can nest boundaries in one another; this will typically make theoutside boundary larger:
\[ e^x = \left[ \lim_{n \rightarrow \infty}
\left(1+\frac{1}{n} \right)^n \right]^x \]
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 18 / 29
B d i ti d
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 23/36
Boundaries, continued
We can nest boundaries in one another; this will typically make theoutside boundary larger:
\[ e^x = \left[ \lim_{n \rightarrow \infty}
\left(1+\frac{1}{n} \right)^n \right]^x \]
Notice that instead of using begin{displaymath}, etc, I was able to use[. This is a shortcut for displaymath.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 18 / 29
Try things out!
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 24/36
Try things out!
http://www.artofproblemsolving.com/Wiki/index.php/LaTeX:Symbols
Also, we can use lots of common functions like
\sin{x}, \cos{x}, \tan{x}, \dim{V}, \hom(G),
\max, \sup, \min, \inf, \det, \gcd, \exp, \binom{n}{k}
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 19 / 29
Try things out!
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 25/36
Try things out!
http://www.artofproblemsolving.com/Wiki/index.php/LaTeX:Symbols
Also, we can use lots of common functions like
\sin{x}, \cos{x}, \tan{x}, \dim{V}, \hom(G),
\max, \sup, \min, \inf, \det, \gcd, \exp, \binom{n}{k}
We can choose between
$\sin{x}$ and $\sin(x)$
depending on whether we want parentheses or not. To find moresymbols, use Detexify: http://detexify.kirelabs.org
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 19 / 29
Equation Environment
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 26/36
Equation Environment
Like displaymath, the equation environment centers and full-sizes the
math in its contents. However, the equation environment hasreferencing capabilities, thus making it valuable for papers.
\begin{equation}
i\hbar \frac{\partial}{\partial t} \Psi(x, t) =
- \frac{\hbar^2}{2m} \frac{\partial^2}{\partial x^2} \Psi(x,t)
+ V(x) \Psi(x,t)
\label{schrodinger}
\end{equation}
(2)
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 20 / 29
Equation Environment continued
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 27/36
Equation Environment, continued
Notice that my equation is labeled (2). I wrote the above sentence bydoing:
Notice that my equation is labeled (\ref{schrodinger}).
The number indicated will update for all references if you decide to addan equation before that one.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 21 / 29
Align Environment
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 28/36
Align Environment
For a series of equations, we can do the following
\begin{align}
x + 2y + z & = 0 \\
2x + y - z & = 2 \\
- 3 x - y - z & = 1
\end{align}
(3)
(4)
(5)
The & symbol makes all the equations line up according to thepositions of that symbol.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 22 / 29
Align Environment continued
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 29/36
Align Environment, continued
To label each equation in the align environment, I use the labelcommand before the line break:
\begin{align}
x + 2y + z & = 0 \label{eqn1} \\
2x + y - z & = 2 \label{eqn2} \\
-3x - y - z & = 1 \label{eqn3}
\end{align}
If we want some of the equations in our align to be unlabeled (nonumber on the right side), use nonumber where you would normallyput
label. If we want to suppress labels altogether, use
\begin{align*} \end{align*}
\begin{equation*} \end{equation*}
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 23 / 29
Macros
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 30/36
MacrosOften, we use the same things over and over. Or worse, somecommands just simply take a lot of typing.
irrationals \[ \text{irrationals} = \mathbb{R} \setminus \mathbb{Q} \]
Instead, we can put in our preamble:
\newcommand{\RQ}{ \mathbb{R} \setminus \mathbb{Q} }
Then I can write
\[ \text{irrationals} = \RQ \]
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 24 / 29
Macros
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 31/36
MacrosOften, we use the same things over and over. Or worse, somecommands just simply take a lot of typing.
irrationals \[ \text{irrationals} = \mathbb{R} \setminus \mathbb{Q} \]
Instead, we can put in our preamble:
\newcommand{\RQ}{ \mathbb{R} \setminus \mathbb{Q} }
Then I can write
\[ \text{irrationals} = \RQ \]
Similarly, if I was writing about the University of California, Berkeley,a lot, I could define
\newcommand{\UCB}{\text{University of California, Berkeley}}
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 24 / 29
The Theorem Environment
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 32/36
The Theorem Environment
The AMS package provides us with a standard template to state a
theorem.Theorem (Dov Jarden)
There exist irrational numbers such that is rational.
\begin{theorem}[Dov Jarden]There exist irrational numbers $\alpha, \beta$ such
that $\alpha^\beta$ is rational.
\label{thm1}
\end{theorem}
Notice that I can label this theorem just like I can label anything else. Ihave turned off theorem numbering in my document, however.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 25 / 29
The Proof Environment
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 33/36
e oo v o e t
Proof.
Pick
. If is rational, then we are done. Otherwise, isirrational. But then
is rational.
\begin{proof}
Pick $\alpha = \beta = \sqrt{2}$. If $\alpha^\beta$
is rational, then we are done. Otherwise, $\alpha^\beta$
is irrational. But then $(\alpha^{\beta})^{\sqrt{2}} =
(2^{\sqrt{2}/2})^{\sqrt{2}} = 2$ is rational.
\end{proof}
The proof environment even makes the little QED tombstone for you!
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 26 / 29
Setting up a bibliography
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 34/36
g p g p y
First we have to create a bibliography file, which is just a plain textdocument with the extension .bib. Let’s say that the file is called “ref.bib”. Make sure it is in the same folder as our .tex file. Then,before the end of our LaTeX document, do the following:
\bibliography{ref}
This will generate a bibliography with entries that are given in the .bibfile.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 27 / 29
Creating the .bib file
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 35/36
g
We simply go to our online article, find the exported citation in bibtex,
and then copy it into our .bib file.
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 28 / 29
The End!
8/13/2019 Latex Pres 2012
http://slidepdf.com/reader/full/latex-pres-2012 36/36
LATEX is an incredibly powerful tool for developing high-qualitydocuments.
There are still many features I have not even touched upon, suchas graphics, more advanced macros, and more powerful formattingfeatures.
There are also many templates online that you can look at tofamiliarize yourself with other features.
Don’t forget Detexify!
C. Wong (UC Berkeley) How to use LATEX 13 September 2012 29 / 29