LaTeX -- A Typesetting Program

Contents

  1. Introduction
  2. Information and Software
  3. LaTeX Files
  4. Writing Ordinary Text in the Input File
  5. The Divisions of a Document
  6. List Environments
  7. Paragraph Alignment
  8. Tables
  9. Figures
  10. Mathematics
  11. Cross References
  12. References and Bibliography

Introduction

LaTeX is a program for typesetting documents on a computer. It may be pronounced "La-Tech" with "La" as in last and "Tech" as in technology. Note the special arrangement of capital letters in LaTeX.

In the production of a document with a WYSIWYG word processor (What You See Is What You Get) two kinds of work must be done:

  1. The work of writing the content.
  2. The work of typesetting and page layout.

LaTeX allows you to focus on the content of a document without wasting time on typesetting and page layout. LaTeX is not a WYSIWYG program---the input to LaTeX is plain text with commands showing the structure of the document and the special symbols needed. You may think at first that LaTeX is mysterious and complicated. However, after a little practice, you are likely to find it easier than WYSIWYG systems.

Information and Software

The standard references on LaTeX are:

You will need two software programs. They are available free on the Internet:

MiKTeX.  Download Small MiKTeX (24MB) from www.miktex.org
TeXnicCenter.  This is a LaTeX shell for Windows. It can be downloaded from www.texniccenter.org

The LaTeX Help e-Book included with the TeXnicCenter software gives full information on the LaTeX program.

LaTeX Files

The Input File

The input to LaTeX is an ASCII text file. It may be typed with any plain text processor, but it is more convenient to use TeXnicCenter. The file name must have the file extension .tex.

We shall consider two of the document classes in LaTeX:

article
Use this for seminar papers and short progress reports.
report
Use this for your research proposal and your thesis.

Most of the commands in LaTeX begin with a backslash, but some of the commands are simple typewriter characters. The input file begins with a document class command such as:

\documentclass[a4paper,12pt]{article}

This states that the document will be formatted automatically as an article on A4 paper with font size 12 points.

Next comes the body of the document with the command

\begin{document}

at the beginning and

\end{document}

at the end.

An example of a very simple document is shown in the box below.

\documentclass[a4paper,12pt]{article}
\begin{document}
This is an example of a very simple
document containing only one sentence.
\end{document}

Output Files

After making an input file (*.tex) you must build an output file for viewing and printing the document. The output file may be a device independent file (*.dvi), or a portable document file (*.pdf), or a postscript file (*.ps). You can use TeXnicCenter to build these files.

Writing Ordinary Text in the Input File

Paragraphs

Type ordinary text in the usual way. An empty line, obtained by pressing the [Enter] key twice, marks the end of a paragraph.

To break a line without marking the end of the paragraph use a double backslash \\.

Special Characters

Special characters that cannot be typed in the usual way are as follows:

$ & % # { } _ ^ ~ \

However, some of them can be made to appear in your text with the help of the backslash as follows:

\$ \& \% \# \{ \} \_

Quote Marks

Do not use the double quote " for quotations. Instead use one or two ` marks (` or ``) for opening a quotation and one or two ' marks (' or '') for closing the quotation.

Hyphens and Dashes

Use - for hyphens in words, -- for short dashes in number ranges, and --- for long dashes in sentence punctuation.

Emphasis

Use \emph{text} to emphasize text. This prints the text between the brackets in italics.

Spacing

LaTeX manages the spacing of words automatically. However, in some cases we must control the spacing with special commands.

Use \, to produce a small space, for example between a number and a unit symbol: 64\,km.

LaTeX assumes that a full stop after a small letter marks the end of a sentence and inserts a long space before the next word. To prevent this use \ followed by a single space. Use ~ to make a hard space as in Fig.~5.

When a full stop comes after a capital letter LaTeX assumes the full stop marks an abbreviation and not the end of a sentence. Use \@. to mark a full stop at the end of a sentence ending with a capital letter:

The program was written in BASIC\@.

Line Breaking

LaTeX makes line breaks when typesetting a page; this sometimes includes breaking words with a hyphen at the end of a line. A "hyphenation" command may be placed at the beginning of the input file to control how LaTeX is allowed to break words. For example

\hyphenation{FORTRAN hy-phen-a-tion}

prevents FORTRAN being broken, and allows hyphenation to be broken in three ways. Only ordinary letters should be used in this command. Capitalization is ignored.

An mbox command causes the characters between brackets to be treated as a single character. For example

\mbox{0 2872 9014-5}

is a telephone number that cannot be broken at the end of a line.

Comments

The percent sign % causes LaTeX to ignore everything that follows it on the line. You can use a line beginning with % to write non-printing comments in your input file.

The Divisions of a Document

The Title

Documents normally begin with a title, the author's name and affiliation, and the date. Several authors may be given, separated by the command \and. These items of information are entered as follows:

\title{Title of the Document}
\author{Name of First Author,\\Address of First Author
\and Name of Second Author\\Address of Second Author}
\date{dd Month 2004}
\maketitle

The double backslash causes the address of the author to be placed under the author's name. The last command \maketitle causes the title, author and date to be placed at the top of the page in the article document class and on a separate title page in the report document class.

Abstract

An abstract may be written as follows:

\begin{abstract}
Insert the text of the abstract here.
\end{abstract}

The abstract is placed below the title, author and date in articles, and on a separate page after the title page in reports.

Chapters and Sections

Reports are divided into chapters. LaTeX gives serial numbers to the chapters automatically. Chapters are made by the command

\chapter[Short Title]{Title of Chapter}

The optional short title is used when LaTeX makes a table of contents for the document (explained later). The contents of each chapter follow the title command. Chapters are not used in articles.

Articles and the chapters in a report are divided into automatically numbered sections and subsections by the commands

\section[Short Title]{Title of Section}
\subsection[Short Title]{Title of Subsection}

Subsections can be further divided into subsubsections. To simplify the document, the numbering of the subsubsections should be stopped by using * in the the command. Then the subsubsection does not have a short title and does not appear in the table of contents. The command is written as follows:

\subsubsection*{Title of Subsubsection}

The Appendix

To make an appendix the command

\appendix

may be placed at the end of a document. In the article class the sections following this command are labeled "A", "B", etc., instead of being numbered. In the report class the chapters following this command are called "Appendix A", "Appendix B", etc.

Tables of Contents

A table of contents (including chapters, sections and subsections) may be inserted into a report by the command

\tableofcontents

Lists of tables and figures can also be inserted:

\listoftables
\listoffigures

These tables should be inserted after the abstract and before the first chapter.

Splitting the Input

When the document is long you can divide the LaTeX input into separate files, for example a separate file for each chapter. The command

\input{filename}

inserts the contents of the file with the specified filename into the input file at the point where the command occurs.

List Environments

Formatted lists are created by the following commands.

Itemized (Bulleted) Lists

\begin{itemize}
\item First item in the bulleted list.
\item Second item in the bulleted list.
\end{itemize}

Enumerated (Numbered) Lists

\begin{enumerate}
\item First item in the numbered list.
\item Second item in the numbered list.
\end{enumerate}

Description Lists

\begin{description}
\item[label] Description of the term or symbol in the label.
\end{description}

Description lists may be used in glossaries for defining acronyms, technical terms and mathematical symbols.

Paragraph Alignment

The following environment commands control how the contents of paragraphs are aligned on the printed page.

Center

This is used for centering text, tables, pictures, etc., as follows:

\begin{center}
Text, table, picture, etc., to be centered.
\end{center}

Quote

This is used for indenting a block of text.

\begin{quote}
Text to be indented.
\end{quote}

Verbatim

This causes text to be printed exactly as it is typed in typewriter font without any reformatting:

\begin{verbatim}
Text to be printed as typed.
\end{verbatim}

Use typewriter font on your computer when typing the contents of a verbatim environment to ensure that your screen shows the layout correctly.

Tables

Tables are created in the table and tabular environments:

\begin{table}
\caption[Short Caption]{Caption Above the Table}
\begin{center}
\begin{tabular}{tabular specification}
Insert the rows of the table here.
\end{tabular}
\end{center}
\end{table}

The optional "Short Caption" is used when a list of tables is made. The full text of the caption appears above the table.

The tabular specification defines the format of the columns in the table using the following symbols:

l   for a column of left-justified text (words).
r   for a column of right-justified text (numbers).
c   for centered text (column headings).
p{width}   for a column of text (with line breaks) having a specified width, e.g., 40 mm.

The rows of the table are typed one after the other with & between column entries.

\\ starts a new row of the table; this is not needed before the first row, nor after the last row.
\hline draws a horizontal line.
\cline{i-j} draws a horizontal line through columns i to j inclusive.

To span a number of columns with centered text use:

\multicolumn{n}{c}{Text}

Here n is the number of columns to be spanned, and c indicates that the text is to be centered over these columns.

Example of a Simple Table

The following commands give the table below.

\begin{table}
\caption{Longwave Emittance of Clouds}
\begin{center}
\begin{tabular}{lr}
\hline\\
Cloud Type & Emittance\\
\hline\\
High & 0.5\\
Middle & 0.8\\
Low & 1.0\\
\hline
\end{tabular}
\end{center}
\end{table}
     Table #. Longwave Emittance of Clouds
           -------------------------
           Cloud Type      Emittance
           -------------------------
           High                  0.5
           Middle                0.8
           Low                   1.0
           -------------------------

Figures

The Figure Environment

Figures are created in the figure and picture environments. The figure environment controls the position of the figure in the document. The picture environment contains the drawing commands. Before the picture environment is opened the unit length for measurements should be defined with the setlength and unitlength commands, as shown below. The picture is centered using the center environment.

\begin{figure}
\setlength{\unitlength}{1mm}
\begin{center}
\begin{picture}(width,height)
Insert the commands for drawing the figure here
\end{picture}
\end{center}
\caption[Short Caption]{Full text of the caption.}
\end{figure}

The optional "Short Caption" is used when a list of figures is made. The full text of the caption appears below the figure.

Picture Commands

If the unit length is 1 mm the commands

\begin{picture}(50,40) ... \end{picture}

make a picture of width 50 mm and height 40 mm. The lower left corner has coordinates (0,0) and the upper right corner has coordinates (50,40).

Text is written on the picture, starting at the point (x, y), by the command

\put(x,y){Written text}

Lines drawn are thin (the default) or thick. They are specified by the commands \thinlines and \thicklines declared at any time.

Straight lines are drawn with a command

\put(x,y){\line(m,n){l}}

where (x,y) is the starting point, (m,n) defines the slope, and l is the horizontal component of the length, or the vertical component if the horizontal component is zero. The value of l must be positive; m and n must be relatively prime integers with magnitude not greater than 6; they can be positive or negative. The length of a slanting line must be at least 4 mm.

Arrows are drawn like straight lines, but m and n must have magnitude not greater than 4. The command for drawing an arrow of length l starting at (x, y) and pointing in the direction (m, n) is as follows:

\put(x,y){\vector(m,n){l}}

A small circle with center (x, y) and diameter d is drawn by the command

\put(x,y){\circle{d}}

A filled circle or disk is drawn by the command

\put(x,y){\circle*{d}}

The diameter of a circle or disk cannot be greater than 14 mm.

Boxes of width w and height h containing centered text are drawn by the commands

\put(x,y){\makebox(w,h){Text in the box}}
\put(x,y){\framebox(w,h){Text in the box}}
\put(x,y){\dashbox{d}(w,h){Text in the box}}

Here (x, y) is the position of the bottom left corner of the box. The \makebox command draws an invisible box. The \framebox command draws a box surrounded by a frame. The \dashbox{d} command draws a box with a frame broken into dashes of length d; the dashed box looks best when w and h are integral multiples of d. A box can have zero size; then (x, y) is the position of the center of the text:

\put(x,y){\makebox(0,0){Text in the box}}

A quadratic Bezier curve with control points P1 = (x1, y1), P2 = (x2, y2) and P3 = (x3, y3) begins at the point P1 with tangent pointing in the direction of P2, and ends at the point P3 with tangent in the direction from P2 to P3. The curve is drawn by the command

\qbezier(x1,y1)(x2,y2)(x3,y3)

Smooth curves through a sequence of points can be drawn by aligning their tangents at the end points.

Regularly spaced copies of the same object can be drawn by the following command:

\multiput(x,y)(dx,dy){n}{ ... }

This draws n copies of the object defined in the brackets { ... }; the first object is at (x, y) and the remaining n - 1 copies are in a line with steps (dx, dy) between them.

Mathematics

Math Mode Environments

To insert mathematical expressions into a line of text use $ at the beginning and end of the expression.

Example: The solution of the equation $3x - 2 = 7$ is $x = 3$.

An unnumbered centered equation is displayed using the commands \[ and \] as follows:

The distributive law of multiplication over addition is:
\[ a(b + c) = ab + ac \]

A numbered centered equation is displayed as follows:

\begin{equation}
a(b + c) = ab + ac
\end{equation}

There many commands for typesetting mathematics in math mode environments. A few of the simple commands are given below. For more details consult the references mentioned above in the section Information and Software. The TeXnicCenter software gives shortcut buttons for the specialized math commands.

In the examples below the brackets { and } are used to group symbols into expressions treated as single units in the mathematical structures.

Common Structures

a', a'', ...
Primes: a', a", ...
x_i, x_{i+1}
Subscripts: xi, xi+1
x^2, x^{m+n}
Superscripts: x2, xm+n
\sqrt{expression}
The square root of the expression in brackets.
\frac{numerator}{denominator}
A double line fraction.
\int_a^b f(x)\,dx
The integral from a to b of f(x) with respect to x. Note the small space between f(x) and dx.

Common Mathematical Symbols

\ldots, \cdots
Three dots (...) at the bottom of the line, and three dots in the center of the line (···).
\pm, \times, \leq, \geq, \approx
Plus or minus +, times ×, less than or equal <, greater than or equal >, approximately equal.
\circ
A small circle useful as a superscript indicating degrees.
\alpha, \beta, \gamma, \delta, ...
Lower case Greek letters.
\Gamma, \Delta, ...
Upper case Greek letters. Note that they start with a capital letter.
\exp x, \ln(1+x), \sin \theta, \cos(A+B)
Examples of standard functions.

Cross References

Cross references from one part of the document to another chapter, section, or subsection, or to a table, figure or numbered equation, are made with the help of the following commands:

\label{keyword}
Put this immediately after the chapter heading, section heading, subsection heading, table caption, figure caption, or numbered equation which will be cited elsewhere in the document. The keyword is chosen to uniquely define the reference point in the document.
\ref{keyword}
This command is used in the citation. LaTeX replaces the command by the number of the chapter, section, subsection, table, figure, or equation that has been labeled with the same keyword.

Example: Suppose we have an equation labeled as follows:

\begin{equation}
a(b + c) = ab + ac
\label{distrib}
\end{equation}

We may refer to this equation in the main text as follows:

Equation \ref{distrib} is the distributive law.

References and Bibliography

References to the literature are placed at the end of articles and reports in an environment called thebibliography. This environment is headed "References" in articles, and "Bibliography" in reports. The entries in this environment are your literature references created by a bibitem command. These references are labeled automatically with numbers in square brackets: [1], [2], ...

\begin{thebibliography}{[00]}
\bibitem{keyword}Details of the reference.
\bibitem{ExChDu1989}R. H. B. Exell, Chumnong Sorapipatana and Dusadee Sukawat, (1989). The relation between wind speeds at the surface and above the boundary layer in Thailand and India. \emph{Solar Energy}, Vol.~35, pp.~3--13.
\end{thebibliography}

The expression [00] in the first command indicates the size of the widest label in the bibliography, which is a two-digit number enclosed in square brackets.

The keyword in the \bibitem command is used to uniquely identify the reference. Letters and numbers representing the authors and the year are recommended as keywords, as shown in the second reference.

The items in the bibliography are cited in the main text of the document by the command

\cite{keyword}

The \cite command prints the numerical label of the reference in the main text.


By R. H. B. Exell, 2004. Joint Graduate School of Energy and Environment, King Mongkut's University of Technology Thonburi.   Home Page