Sunteți pe pagina 1din 9

LATEX

Shahed Sharif
March 5, 2010

What LATEX is

LATEX is a typesetting language ideally suited to creating professional-looking


documents with mathematical content. As a typesetting language, it should
be contrasted to WYSIWYG applicationsthat is, What You See Is
What You Get applications like MS Word. In these latter applications,
writers interactively create the layout as they type, so what appears on the
screen is exactly what gets printed out. Typesetting languages, on the other
hand, are written in a kind of code. Then the LATEX engine interprets the
code and outputs a nicely layed-out document. In essence, you the writer
specify only the structure and content of the document; LATEX does the work
of figuring out how it looks.
On the other hand, because you dont immediately see what a document
looks like, using LATEX can seem needlessly complicated, at least initially.

Getting Started

To get started, you need to download the appropriate software. First you
need the LATEX engine. This is a program that interprets LATEX code and
turns it into a nice pdf or postscript document. Youll also need a front-end ;
that is, an application where you type in the code, and a viewer for the resulting pdf or postscript. On Windows, you can use MikTeX for the LATEX
engine, available at www.miktex.org. Alternatively, you can use TeXLive
(www.tug.org/texlive/windows.html). Both come with the TeXWorks
front-end.

If youre on a Mac, the easiest method is to use TeXShop; see www.


uoregon.edu/~koch/texshop/obtaining.html. (In fact, this link leads to
the TeXLive distribution.) On a Linux machine, use your package manager
to install TeXLive. One user-friendly front-end is Kile (kile.sourceforge.
net).
In all of the above, the front-end is optional. One can use whatever
simple text-editor comes with your system (e.g. NotePad, TextEdit, gEdit).
Front-ends usually make the process easier, especially for beginners.

3
3.1

How LATEX works


The .tex file

Once you have set up whatever software you need to run LATEX, the first step
is to create a .tex file. A .tex file is just a text file with the extension .tex
(e.g. filename.tex), that contains your instructions as to what should appear in your document. It has two parts: a preamble, which contains all the
global settings, like type-size, margins, and spacing; and the body, which contains the document text itself. The document text includes any instructions
youve specified for special features, such as mathematical equations. These
instructions are written in a code. In order to distinguish this code from
text you want to appear in your document, certain characters are reserved
for coding purposes. These are:
\

&

} ~

As an example, the way I get the following text:


The discriminant of a quadratic polynomial is

b2 4ac.

is by typing the following into my .tex file:


The \emph{discriminant} of a quadratic polynomial
is $\sqrt{b^2-4ac}$.
If you must use one of these reserved characters, typically just putting
a backslash in front of it will do the trick. So if the .tex file had the text
Cookies \& Cream, it would come out looking like Cookies & Cream. The
only exception is the backslash; for that, you need to use $\backslash$.
2

Notice the importance of the backslash. The backslash signals that what
follows is a command of some sort. For example, the \emph tells LATEX to
put the next thing in italics, while \sqrt says to put the next thing under a
square root. This holds in general: whenever you use a typesetting command,
that command begins with a backslash.
A couple warnings about the .tex file: because the compiler takes care of
layout, extra spaces and extra line returns have no effect on the final output.

3.2

Compiling

Once you have finished typing up your .tex file, you then compile it. If you
are using a front-end like TeXShop, there should be a button or menu-item
that does this for you. If you made any mistakes in your typing, the program
will tell you so. If you are using a simple text editor, open up a console,
cd to the appropriate directory, and enter either latex filename.tex or
pdflatex filename.tex; the output will tell you if there are errors. You
should correct your errors, then once youve compiled without a hitch, you
can view the output.

4
4.1

How to type
The preamble

As mentioned earlier, the first thing you need in a document is to specify the
global settings. You do this in the first section of the document, known as
the preamble. In practice, one never actually types up the preamble. Instead,
it is easier just to cut and paste the preamble from a similar document, and
then make any necessary changes.

4.2

Types of text

Now lets talk about the body text. Within the body text, there are various
environments. An environment is a type of text with certain rules. If you
want a piece of text to look differentsay if you wanted to insert an equation between paragraphs, or a few lines of poetryyoud introduce a new
environment for that piece of text.

The most trivial environment is the document environment. This tells


the LATEX engine what part of your document is the body text, as opposed to the preamble. Basically, at the end of the preamble one types
\begin{document}. Then you type the stuff in your document, and when
youre done, you type \end{document}.
Some environments work exactly like this: you type \begin{environment },
then the text that you want in that environment, then \end{environment }.
You have to remember to end each environment, or else youll get an error
message when you compile your .tex file.
Here are some examples of environments that use the begin/end format:
center Not surprisingly, this centers the text.
enumerate This creates a numbered list. Each entry in the list is specified with the \item command. Numbers are generated automatically.
itemize Creates a bulleted list, just like this one. Each entry is
specified with \item for this environment as well.
equation This creates an equation set off from the surrounding text
and centered.
There are other ways of making text look different. Two useful examples
for paragraph text:
\textbf{ } puts the stuff in braces in bold face. So \textbf{hooray}
comes out looking like hooray.
\emph{ } puts the stuff in braces in italics: hooray!
One last thing about paragraph text. To start a new paragraph, you just
need to skip a line by hitting return twice. If you hit return more than twice,
even though youd be skipping several lines in the .tex file, it wont show
up in the output document.

4.3

What about math?

So, how does one typeset mathematics? To do this, one needs to enter a
math environment. There are several of these. The simplest is math set off
by single dollar signs, $, for math that appears in the middle of a sentence
(in-line). Then one enters the stuff you want to appear, and LATEX takes
care of the rest. Heres an example. Say we typed
4

Therefore $\frac{\alpha}{2}=\int_{-1}^{\infty} f(x)^2 dx$.


Then wed get
Therefore

R
1

f (x)2 dx.

One important stylistic point to keep in mind: if you are using a mathematical object in a paragraph, it should always be typeset as math. For
example, if we are using the variable n, then if you refer to it in a sentence,
it should always be set off by $:
So then we list the factors of $n$.
instead of
So then we list the factors of n.
Compare the way it looks in the first instance:
So then we list the factors of n.
with the way it looks in the incorrect second instance:
So then we list the factors of n.
In the next section, well talk about math in more detail.

5
5.1

How to typeset mathematics


Math environments

There are two main ways to typeset mathematics: in-line and display-style.
In-line means that you have some mathematical stuff in the middle of a
sentencesee the examples earlier in this document. Display-style mathematics is set off in its own line and centered, for example
Z

=
f (x)2 dx.
2
1
There are several ways to get display-style math, the simplest being to set off
formulas is by putting them between the symbols \[ and \]. So for example,
the way I got the above formula was by typing
5

\[
\frac{\alpha}{2}=\int_{-1}^{\infty} f(x)^2 dx.
\]
Notice that the code is exactly the same as the in-line version from the
previous section, but that the display-style formula looks different. The
fraction and integral are bigger, and the placement of the bounds on the
integral looks nicer on the display-style version.
If you want to do multiple lines, the align environment is probably the
way to go. So if you want
ax + by = dq
=n

(1)
(2)

then youd type


\begin{align}
ax+by & = dq \\
& = n
\end{align}
.
The double backslash \\ tells where to end each line, and the ampersand &
on the first line gets aligned with the ampersand on the second line.

5.2

Math code

So that leaves one last topic: what exactly do we type inside the $?
R Weve
already seen some commands, such as \alpha for and \int for . What
are the rest?
There are probably hundreds of commands for all sorts of weird mathematical notation. In general, youre probably best off Googling for LATEX
documents written by other people; theyre bound to have tons of tables for
you to refer to.
There are a few things you should know. First, many commands are
known as math operator commands. These are commands
that represent
R
well-known functions or operators, such as the integral . Other examples
are sin, given by \sin, cos, given by \cos, tan, log, ln, and lim, given by

P
the obvious commands, and , given by \sum. These commands are distinguished by the fact that when they appear in mathematical formulas, they
appear in roman type, not italic type, as is usual for mathematical variables.
The carat ^ (above the 6) and underscore _ are used for superscripts
and subscripts, respectively. If more than one symbol is in a superscript or
subscript, use braces {}. For example, $a^x+y$ yields ax +y, while $a^{x+y}$
yields ax+y .
Two common commands are the fraction command, \frac, and the root
command, \sqrt. The way these work is best shown by the following examples:
\frac{x^2}{1+\tan \theta},\sqrt{3x+2},\sqrt[3]{\frac{1+x}{1-x}}
r

x2
3 1 + x
3x + 2
1 + tan
1x
There are various math fonts. For our purposes, only one will be of use:
the mathbb font. In this font, the capital letter Q looks like Q. Notice
this is how we write the set of rational numbers. Similarly, we use N, Z, R
and C from the mathbb font. In order to use them in the text, wed type
$\mathbb{Q}$, say. But if we refer to Q frequently, this can be a lot to type.
One thing we can do to decrease our work is to define a new command, \Q,
which stands for \mathbb{Q}. In order to do this, we add the following line
to our preamble:
\newcommand{\Q}{\mathbb{Q}}
Similarly, if theres some other long command that we use frequently, we can
define a shortened version in the preamble to stand in for the long command.

Other tools

Here are some miscellaneous items that might be useful.


Cross-references When referencing a theorem, section, or other heading,
use the \label and \ref constructions. That is, if you would like to reference
a proposition (say), do
\begin{proposition} \label{prop:important-proposition}
If the sky is blue, then this statement is important.
\end{proposition}
7

in the statement of the proposition. To refer to the proposition later, use


something like
By Proposition~\ref{prop:important-proposition}, we conclude
that the sky is not blue.
Propositions are automatically assigned a number1 . The \ref command
refers to the number that was generated. The ~ is optionalit is there
to ensure that line breaks dont separate the word Proposition from the
number.
The text inside of \label is fairly arbitraryany alphanumeric character
and most punctuation are allowed. Note that spaces are not allowed.
See the comments in the source code (around the bibliography) for details
on citations.
Presentations To prepare a mathematics presentation in the style of Powerpoint, use the beamer package. In most TexLive distributions, beamer is
included by default. Otherwise, youll have to find and install it yourself.
The documentation included with the beamer package is quite extensive, so
I refer you to that document. Though the beamer package produces a pdf,
it is surprisingly powerful; one can even include movies.
Whatever you do, do not use Powerpoint! Unless your mathematical
content is minimal, beamer is both easier and less time-consuming even in
the short run, not to mention free. (Ive learned this from painful personal
experience.) Of course, for most purposes, a presentation at the chalkboard
is totally fine.

Numbering is subject to rules defined in the preamble; see the preamble of the source
code of this document for details.

Exercises

Try typesetting the following in your own document.


Exercise 1 :
My first LaTeX document

This is my first LaTeX document. It is the greatest. However, it


doesnt have any math in it.
Exercise 2 : How does one prove that ax + by = 1? Does it have to do with the
greatest common divisor ?
Exercise 3 : Let n = ab. Then since a | n, we know that there exists m such that
Z 1
mn
a + i =
sin xdx.
1

Exercise 4 : Weve shown that n Z, n 6= 1, there exists a prime p such that


p | n. Actually, this holds if n 2. There are also primes p such that
p - n.
Exercise 5 : By computing the Euler function evaluated at 12, we get
(12) = (4) (3)
= 2(2) (3)
=22
= 4.
The four elements in Z/12Z which are invertible are 1, 5, 7, and 11.
Exercise 6 : My favorite matrix is the block matrix


A 3 1
.
C 0 2

References
[Sharif2010] S. Sharif, This paper needs no title. The Journal of SelfReferential Articles, 5 no. 1 (2010).
9

S-ar putea să vă placă și