L^{A}TEX for Beginners

John B. Little

February 3, 2016

Abstract

TEXand L^{A}TEX are typesetting programs for mathematical and other technical documents including in-line and “displayed” equations. This document shows some basic examples of formatting in the article document style in L^{A}TEX. To use them, you create an input source file (like this one!) containing text, specifications for the equations and formatting commands using a text editor. Then a TEX or L^{A}TEX translator is called to convert the source file to a “device-independent” or .dvi file containing an intermediate specification of the typeset document. Finally, a previewer or printer-driver program is used to display the type-set version of the file on the computer screen or send it to a printer. For more information, consult [1],

1 First Steps

A typeset L^{A}TEX document may consist of text, “in-line” equations, “displayed equations” (possibly occupying one or several lines) and other elements. It can also contain diagrams, Postscript graphics, etc. We’ll leave the “fancy stuff” for later! For now, let’s just look at how basic text and equations are entered and processed.

Ordinary text is inserted in the source file just as it will appear in the typeset document. (L^{A}TEX is quite “smart” about formatting of lines, paragraphs, pages etc. It right justifies output automatically, knows to indent paragraphs when a blank line occurs in the source file, breaks pages when they are “full” automatically, etc.) For now, I think you’ll generally be very satisfied with how things come out “by default.” But once you get to be a “master user”, you may (will probably) start to get very picky and find that you will want to override the way L^{A}TEX does things by default on occasion. For now, though, we will just let it do “its own thing” in almost all cases!

The overall structure of a L^{A}TEX source file is this: There is a “preamble” at the start indicating the “document style” and “page style” to be used. For now, we will use the article document style because it is the simplest and the plain page style. There are other predefined styles, and you can also create your own.

After the preamble comes a line that says

\begin{document}

(There is a matching

\end{document}

at the end. All the text, etc. are placed between these. (The stuff between a begin and end like this is called an “environment” in L^{A}TEX. The document as a whole can be thought of as the “top-level” environment. The preamble also includes several definitions of “environments” for statements of theorems, propositions, and corollaries. Another example of an environment is the “verbatim” environment used to produce the lines above. Articles will have titles at the top of the first page and may have abstracts – look at the way the title and abstract are specified above.

Equations come in two forms as mentioned above, “in-line” and displayed. “In-line” equations are set off from plain text in the source file by single $’s (dollar signs). For example, here is a simple in-line equation: a = bβ + cγ. Note that the typeset version uses italics for the letters and includes the actual Greek letters specified by their names in the input. If you look at the point in the source file corresponding to second sentence of this paragraph, you will also see that the dollar sign there was entered with a preceeding “backslash character”. Specifications for special symbols (such as Greek letters and mathematical symbols) and L^{A}TEX formatting commands begin with this character. (That’s how L^{A}TEX knew we wanted an actual dollar sign above rather than the start or end of an in-line equation.)

Within equations, subscripts are indicated by the underscore character, and superscripts (exponents) by the carat. If you want a subscript with several characters, they need to be grouped together using curly brackets. For example: f′(x) = nx^{n−1}+g(x). (Question: Suppose you want to actually include a curly bracket in an equation – for instance in a definition of a set. How do you think that is done? Right: using backslashes! {}.)

Within text or equations, you can also control the fonts used to display things. For instance in text you can use italic (or italic), bold, ... . In equations, you can use ℝ (”blackboard bold” – this is part of the amssymb package loaded in the preamble), C (“calligraphic” letters), 𝔞 (old-style German “fraktur” letters) and many others.

In general the specifications for special symbols in L^{A}TEX are usually (close to) their actual names. For instance the integral sign is “backslash - int”: ∫_{0}^{1} sin(t^{2}) dt. The L^{A}TEX book and numerous online L^{A}TEX “reference cards” that you will find easily via Google have tables showing all of the standard ones and their specifications.

Displayed equations can be specified in several ways, either using double dollar signs, or using backslash-square brackets. Here is a displayed equation giving one definition of what’s called the Fourier transform:

F[f](ω) = \frac{1}{2π} ∫_{−∞}^{∞} f(t)e^{−iωt} dt.

Displayed equations extending over several lines can be created with the eqnarray or eqnarray* environments. This one is an eqnarray*:

a_{0}(x, 0)/b_{0}(x, 0) = −3 − 2x − 9x^{2},
b_{0}(0, y) = −3 + y,

This one is an eqnarray:

a_{0}(x, 0)/b_{0}(x, 0) = −3 − 2x − 9x^{2},  (1)
b_{0}(0, y) = −3 + y,  (2)

See the difference? Some people number every displayed equation in a paper, but I think that ends up looking “busy” on the page – I’d recommend only numbering equations that you want to refer back to later. Here’s how to do that: In the equation, put in a

 \label

definition like this:

\begin{equation}
\label{newformula}
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}.
\end{equation}

The typeset version of the equation looks like this:

x = \frac{−b ± \sqrt{b^{2} − 4ac}}{2a}.  (3)

To create the statement of a Theorem, Proposition, etc. use environments like this:

\begin{theorem}
\label{MVT}
(Mean Value Theorem) Let $f(x)$ be continuous
on $[a,b]$ and differentiable on $(a,b)$.  Then there exists
a $c\in (a,b)$ such that
$$f'(c) = \frac{f(b) - f(a)}{b-a}.$$
\end{theorem}

And the typeset version looks like this:

Theorem 1 (Mean Value Theorem) Let f(x) be continuous on [a, b] and differentiable on (a, b). Then there exists a c ∈ (a, b) such that

f′(c) = \frac{f(b) − f(a)}{b − a}.

Note that the convention is to typeset the text of theorems, propositions, etc. in an italic font to make them stand out. The “labels” lines here are used if you want to make cross-references to this theorem within the text by number. Then if you want to refer to a theorem or an equation later, you use a reference, like one of these: The quadratic formula gives (3) for the roots of the equation

ax^{2} + bx + c = 0.

L^{A}TEX keeps track of the equation numbers automatically. If you say Theorem 1, the number is filled in automatically by L^{A}TEX. This is especially useful for when you make changes, insert new items in a source file, and so forth. L^{A}TEX will automatically generate the correct new numbers when you recompile the source file.

Proposition 1 If the infinite series ∑_{n=1}^{∞} a_{n} converges, then

lim_{n→∞} a_{n} = 0.

To typeset matrices:

A = ( \begin{matrix}a & b & c \\ d & e & f \\ g & h & i \end{matrix} ) .

A = ( \begin{matrix}a & b & c \\ d & e & f \\ g & h & i \end{matrix} ) .

Note that the default is to number Theorems, Propositions, etc. in separate sequences. You can override that if you want, though.

Note that summations, integrals, etc. are typeset differently in inline formulas and in displayed formulas. If you want to use the display style in an inline formula, though, (for instance to improve readability) you can do

it like this: ∑_{n=1}^{∞} a_{n}. This was produced by the following commands in the

source file:

$\displaystyle{\sum_{n=1}^\infty a_n}$.

2 Graphics in L^{A}TEX documents

L^{A}TEX has several features for incorporating graphics of various sorts into documents. For basic pictures (say things with straight lines, circles, ...) you can use the built-in picture environment. The idea here is based on specifying parts of an image through Cartesian coordinates. Here is an example, showing the source file lines:

\begin{center}
\begin{picture}(100,120)
\put(60,10){\line(0,1){100}}
\put(-10,50){\line(1,0){140}}
\put(120,40){$x$}
\put(63,110){$y$}

\put(90,70){\circle*{4}}
\put(95,70){$P = (a,b)$}
\put(75,40){$a$}
\put(53,57){$b$}
\put(90,70){\line(0,-1){20}}
\put(90,70){\line(-1,0){30}}
\put(90,53){\line(1,0){3}}
\put(93,53){\line(0,-1){3}}
\put(63,70){\line(0,-1){3}}
\put(63,67){\line(-1,0){3}}
\end{picture}
\end{center}

and the picture they produce:

x y ^{}P = (a, b) a b

Can you guess what each command does?

For more complicated graphs (such as plots produced by Maple^{1} or other software, you can use the epsfig package to include Postscript graphics files – note this was included in the usepackage in the preamble. Once you have generated the Postscript, you put in a line like this:

\begin{center}
\includegraphics[width=3.0truein,height=3.0truein]{II.ps}
\end{center}

and the graphics are inserted (close to) the point where you placed this in the file. (Note: L^{A}TEX will sometimes move a graph to the top of the next page if there is not enough space for it on the current page, or do other things to try to compose good-looking pages). Note: I had to “fiddle” with the placement

1This is a commercial computer algebra package.

Figure 1: A Maple Graph

of this graph, though, to keep L^{A}TEX from leaving a massive hole at the end of one page(!)

3 Installations of L^{A}TEX

There are implementations of L^{A}TEX on almost all computer systems now. The simplest way to use L^{A}TEX and work on a thesis is probably to use one of the machines on the Mathematics/CS departmental network, which has full installations of TEX and L^{A}TEX available for all users. You would create the source file using any text editor.

Then from a terminal window:

• latex filename – (with the name of your source file substituted in, of course!) compiles the source file.

• dvips -t letter filename -o – creates a PostScript version of the file (suitable for printing on some printers)

• ps2pdf filename.ps – converts to a .pdf file • acroread filename.pdf – open the file in Acrobat reader (Adobe’s

previewer for .pdf files). You can print from this on paper if you want. Do that sparingly though(!)

The L^{A}TEX system is also available as freeware from several sources if you want to install it on a personal PC or Mac. I recommend the MiKTeX version, in conjunction with the WinEdt “front end,” if you are using a Windows PC. WinEdt offers a good text editor and toolbar buttons for compiling, previewing, and printing documents. It is easy to use and it works very well. These are both downloadable from corresponding web sites.

References

[1] Lamport, L. The L^{A}TEX Book. Addison-Wesley.