macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

LaTeX: It's Not Just for Academia, Part 2
Pages: 1, 2, 3

Generating an Index

If you are writing a reference document, a book, or a report, it's sometimes useful to include an index section at the end of the document. An index is a list of key words in the document and the page, or pages, where they occur. You add an index to your document with the makeinx package.



To create an index, you first include and enable the makeinx package in the document preamble. Next, add the index command to each word you wish to include in the index.

...
\usepackage{makeidx}
\makeindex
...
\begin{document}
As you learned in the first article, in LaTeX\index{LaTeX}, 
you can manage your bibliographic citations using 
BibTeX\index{BibTeX}.
...
\end{document}

Finally, you generate the index by running the following programs (do not add the extension, just the file name):

% latex latex-file    
% makeindex latex-file
% latex latex-file

or

% pdflatex latex-file    
% makeindex latex-file
% pdflatex latex-file

Here's how it works. First, LaTeX processes the file and writes each index entry to a file, with a .idx extension. Next, makeindex creates the sorted index, which it stores in a file with a .ind extension. Finally, you run LaTeX again to place the index into the document.

You can create many different index formats by changing the syntax of the index command. See a LaTeX reference for more information.

BibTeX

As you learned in the first article, you manage your bibliographic citations using BibTeX. BibTeX is a separate program you use to manage your bibliographic citations and merge selected citation information onto your LaTeX documents.

BibTeX solves some very common problems that arise when constructing a bibliography. For example, imagine you are writing a paper that includes many references and citations. Further imagine that the publication you are submitting to requires citation information to be formatted in a certain format, such as ACM or IEEE. Without BibTeX, you would need to maintain a list of your references and format each entry by hand in the required format. If you need to submit the paper to another publication, with a different citation format, you have to reformat each citation by hand.

BibTeX solves this problem quite easily. Here's what you need to do. First, maintain your citations in a format that BibTeX understands. You do this by formatting each citation in a defined format and placing it into a file, with a .bib extension. You can place all citations in a single file, or break them up as you wish.

Here's an example of the format:

@misc{ wilson-ltxx,
  author = "Peter R. Wilson",
  title = "LTX2X: A LATEX to X Auto-tagger",
  url = "citeseer.nj.nec.com/wilson97ltxx.html" }

BibTeX identifies each record by its key. In the above example, the key is wilson-ltxx. This is the value you use to reference the citation within your LaTeX document.

As you can imagine, the format has many options and parameters. See the Resource section for more information. In fact, you can get many citations already formatted in BibTeX format at sites such as CiteSeer .

To create a citation in your text, use the cite command (\cite), with the parameter specifying the citation key. This command places a citation mark into the final text, pointing to the reference and includes the reference in the bibliography. You can add a reference to the bibliography, without adding a reference mark to the main text with the no cite command (\nocite).

To create a bibliography, add the following commands just before the end document command.

...
\bibliographystyle{plain}
\bibliography{sources}
...
\end{document}

The bibliography style command specifies the bibliographic style used to format each citation. The bibliography command instructs LaTeX to insert the appropriate citations into the document. BibTeX supports many bibliographic styles. See its documentation for more information.

To generate your bibliography, perform the following steps:

  • Run LaTeX on the LaTeX file
  • Run BibTeX on the LaTeX file
  • Run LaTeX again on the LaTeX file
  • Run LaTeX yet again on the LaTeX file
% latex latexfile
% bibtex latex-file
% latex latex-file
% latex latex-file

Footnotes

LaTeX supports the inclusion of footnotes in your text with the footnote command. The footnote command takes an optional argument, num, that you can use to change the default footnote number.

\footnote{Text for the footnote.}

In addition to the footnote command, you can also include footnotes with the footnote mark and footnote test commands (\footnotemark, \footnotetext). The footnote mark and footnote test commands are used in concert to place footnotes at the botton of a page.

Tables

Table are something that we all use in our documents. LaTeX enables you to create high-quality tables through the table and tabular environments. Using these environments, you can easily produce very well-structured and readable tables of information. The basic syntax for creating a table is as follows:

\begin{table}[where]
\caption{Table caption}
\centering
\begin{tabular}[pos]{cols}
 column 1 & column 2 ... & column k \\
 ...
\end{tabular}
\end{table}

Where LaTeX places a table is very important. For example, if you have a large table in your document, you would rather see it on a single page, rather than broken up across pages. In the LaTeX literature, you will see the term "float'" or "floating object" to refer to this idea. This describes the situation where a table or figure can not fit on its current page, and is placed on a separate so-called floating page.

LaTeX enables control over the placement of tables through the where parameter. The where parameter defines where the table is displayed on the page. A value of b places the table at the bottom of the page, h places the table here, t at the top of the page, and p on a separate float page containing no text, only floats.

The concept of floating objects also applied to figures and footnotes.

You use the tabular environment to construct the table. The pos and cols parameters control how the table is formatted. The pos parameter controls the vertical position of the whole tabular environment. The values are either t (align with top row) or b (align with bottom row). The cols parameter controls the column formatting: l = format text left, r = format text right, c = format text center. The p{wd} parameter controls the size of a column and makes columns with multiple lines.

Figures

You add figures to a document with the figure command. Like tables, this places a figure at the location of the command, conditioned by the where parameter. Figures can also float over pages so make sure you read the description of floating objects in the Tables section.

You insert a figure as follows:

\begin{figure}[where]
\caption{Figure caption}
...
\end{figure}

Graphics

Most documents are composed of not only text, but also graphics. You insert graphics into a LaTeX file with the insert graphic command (\includegraphics). However, you cannot insert a JPG or PDF file into a LaTeX document, only EPS files. To insert other file formats like JPG, you have a few choices. One way is to convert your graphic file to EPS and then insert it into the document. Another way is to use PDFLaTeX, which is described below.

To convert the graphics file you can use a Mac OS X Aqua-based programs, such as Graphics Converter, or install ImageMagick from Fink, and use the following command:

% convert [jpeg-file] [eps-file]

You insert a graphics file into a document by first using the graphicx package and then using the insert graphics command.

\usepackage{graphicx}
..
\begin{document}
...
\includegraphics{mjh.eps}
...

To insert a JPG file directly, use the PDFLaTeX program to process your LaTeX document.

\usepackage{graphicx}
..
\begin{document}
...
\includegraphics{mjh.jpg}
...

This explanation is quite basic and there are far more issues to working with graphics in LaTeX. In addition to inserting graphics, LaTeX supports commands that enable you to draw picture elements such as boxes, trees, and curves in your document. Consult the Resource sections for more information.

Math

One of the major reasons for using LaTeX is its strong handling of mathematical equations and formulas. This is a complex subject, so I'm just going to touch on the basics to give you a feel for how it works and looks.

You insert mathematical symbols into your document by either surrounding the expressions with the $ symbol, or using the begin/end math commands.

The time-points $x_{i}$ to $x_{j}$ are embedded in the main text.

\begin{math}
(l_{1} \leq x_{j} - x_{i} \leq u_{i}) \vee ... 
\vee (l_{n} \leq x_{j} - x_{i} \leq u_{n})
\end{math}

Lists

There are many times when you need to include a list of information in a document. To create lists, LaTeX provides the itemize, enumerate, and description environments. Each of these environments lets you easily add different types of lists to your documents. All of these lists can be nested, so you can produce various kinds of lists with different sub-list levels.

\begin{list-environment}
\item item 1 text
\item item 2 text
\end{list-environment}

Pages: 1, 2, 3

Next Pagearrow