Documente Academic
Documente Profesional
Documente Cultură
Shahed Sharif
March 5, 2010
What LATEX is
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.
3
3.1
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:
\
&
} ~
b2 4ac.
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.
4.3
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
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
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)
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
Numbering is subject to rules defined in the preamble; see the preamble of the source
code of this document for details.
Exercises
References
[Sharif2010] S. Sharif, This paper needs no title. The Journal of SelfReferential Articles, 5 no. 1 (2010).
9