A Simple Example Using L^{A}TEX

R. J. LeVeque and T. P. Chartier

October 29, 2001

Abstract

This short paper illustrates basic techniques in the use of the L^{A}TEX text formatting language, which is useful in typesetting scientific and mathematical papers. This paper can serve as a short tutorial and as a useful template for a beginning L^{A}TEX programmer.

1 Introduction

This paper illustrates how various typesetting is accomplished in L^{A}TEX. You are encouraged to view both the source code (sample.tex) and the typeset paper (sample.dvi).

First, notice that components of your paper such as sections, subsections, and equations are numbered automatically.

1.1 Lists

Making an itemized list is easy:

• If the L^{A}TEX file is called sample.tex then output is created by executing

     latex sample

This creates a file sample.dvi. To view or print, see documentation for your system.

• Note that leaving one or more blank lines in the input gives the start of a new paragraph. Otherwise blanks do not matter. To force a line to end, use double backslash as in the previous item as seen

     in sample.tex.

• Anything after a % is a comment that won’t appear in the output.

2 Mathematical formulas

This paper supplies only a taste of how mathematical formulas are created in L^{A}TEX. For more information, see a L^{A}TEX manual such as [1]. As a short introduction, a few pointers are contained in this section.

Dollar signs places L^{A}TEX into its math mode, which is where mathematical formulas and equations are created. To include an equation in a current line of text, place one dollar sign ($) before and after the equation, for example we might define f(x) = 3e^{x}. If an equation should be displayed, place two dollar signs ($$) before and after the equation. For example, we might define:

∑_{j=1}^{N} j = \frac{N(N + 1)}{2} .

If the equation should be numbered, use the following notation (see the L^{A}TEX file):

e^{iπ} = cos(π) = −1.  (1)

This equation was given a label (which is optional). Hence, the equation can be referred to later as (1) rather than hardcoding such numbers into the L^{A}TEX file. Therefore, adding new equations does not facilitate a need for the programmer to manually renumber the equations. (Note that you will have to run L^{A}TEX twice on your .tex file for numbering to appear properly. The first run stores the labels in the file sample.aux and the second time run reads these labels at the beginning of processing.)

Figure 1: Histogram of 1000 normally distributed random numbers.

3 Matrices

Matrices can be made using an “array”. Here’s a useful definition that makes it easier to define matrices: (see the L^{A}TEX source file)

Here’s a simple matrix equation using this definition:

[ \begin{matrix}a_{11} & a_{12} \\ a_{21} & a_{22} \end{matrix} ] [ \begin{matrix}x_{1} \\ x_{2} \end{matrix} ] = [ \begin{matrix}b_{1} \\ b_{2} \end{matrix} ]  (2)

4 Figures

Many plotting packages (e.g. matlab) allow you to produce an encapsulated postscript file (ending in .eps). Then the graphic can be incorporated into a paper with the following command (see the L^{A}TEX file)

Note that the caption command gives the figure a number that can be referred to later as Figure 1. The file fig.eps was created in matlab with the commands:

     >> r = randn(1000,1);
     >> hist(r)
     >> colormap([.7 .7 .7])    % to change the color and make it print better
     >> print fig.eps

5 Bibliography and citations

See a L^{A}TEX manual such as [1] for complete information on the use of a bibliography and citations. The main idea is the use of a bibliographic database such as the one in samplebib.bib, which lists a large set of papers and books, each with a distinct label. Then the cite command references one of the entries in the database by its label. Hence, the citation is included in the paper; the corresponding reference is automatically included in the bibliography of the paper. To do this, you must:

  1. First run latex sample
  2. Then run bibtex sample
  3. Then run latex sample

  4. Then run latex sample

The first run of L^{A}TEX creates a file sample.aux that contains information on the literature references. Running bibtex then creates another file sample.bbl, which is read into the next L^{A}TEX run producing the list of literature references. Running L^{A}TEX twice more is needed to read in the citations with proper numbering.

References

[1] M. Goossens, F. Mittelbach, and A. Samarin. The LATEX Companion. Addison-Wesley, 1994.