Latex: A Text-processing System

Typesetting Technical Documents With LaTeX

MagicPoint

Build your ‘wysiwyg’ HTML Editor

Build your ‘wysiwyg’ HTML Editor

One of the most useful utilities of personal computers is the facility it provides for preparing attractive documents with a variety of fonts and other features like tables and graphics. Word processors like Wordstar, MS Word, and Corel Wordperfect provide a WYSIWYG (What-You-See-Is-What-You-Get) environment, where you can format documents as you want. The flip side is that you may get lost in making documents look appealing rather than concentrate on the content. Also, managing large documents using word-processing systems can be tedious.

Text processing or typesetting is an alternative approach towards producing flattering documents. Here, text that forms a document is entered in a normal ASCII text file using an editor like Notepad, Edit or vi. Along with the text, some special control codes or typesetting commands are inserted at appropriate places to tell the logical structure of the document. For example, a command may tell that a new section has started or that certain text needs to be emphasized. This is very similar to HTML tags but here the control codes convey some different information.

Describing the logical structure of a document rather than the formatting has many advantages. It makes your documents much more coherent and enables you to write more effectively. And changing the formatting of the document becomes easy. For example, if you want all headings to be displayed in a manner different than the default, you need to change the definition of the heading style, rather than make changes at all places in the document. This input file is now processed by the text-processing system to produce a document in printable form.

Many text-processing systems are available under various platforms, like troff, Tex, and Latex. Latex is the most widely used.

Where it’s used

Latex is being widely used in typesetting books, papers in scientific journals, newsletters and articles. Latex is based on a typesetting system called Tex (pronounces tech), which was developed by Donald Knuth of the Stanford University. Tex, though powerful, by itself is difficult to use. So Leslie Lamport created a macro package for Tex to ease the creation of documents by providing a higher level of abstraction.

This package, called Latex (pronounced latech) provides a number of document styles that determine exactly how your document will be formatted. Furthermore, there are a number of commands for describing the various constituents of the 
document like sections, subsections, tables, and figures.

Installation

To start with Latex, you first need to install the Latex system and the associated programs. If you are using Linux, then the Latex system is available on the RedHat Linux CD-ROM. The Latex implementation on Linux is called tetex, so you can install all the tetex RPM packages to get started with Latex. You will also need to install the GhostScript and GhostView (gv) packages. These are required to view the PostScript file that Latex will produce.

For Windows users, many Latex implementations are available. The one that I tried out is MikTeX, which can be downloaded from www.miktex.org. When you run the MikTeX setup program, it will first present you a list of FTP sites and ask you from where to download the required installation files. Once the installation files are downloaded, you need to run
the setup program again, this time for the actual installation. You will also need to install GhostScript for Windows, which you can easily search for on the Internet.

Getting started

To get you started with Latex, let us write a very simple document. Using Notepad or vi, create a simple text file with the contents as follows.

%
% This is a simple LaTeX document

\\documentclass[12pt]{article} 
% This document is an article
% typeset using 12pt font
\\begin{document} % Start the document
\\section{This is the first section}
\\subsection{This is a subsection}
In \\LaTeX{}, consecutive words are separated by spaces or
newlines. Two or more spaces between words are
equivalent to one space.

Paragraphs are separated by one or more blank lines.

‘‘Double quotes are produced by this synis boldfaced text. }
{it This is italicized text. }
\\begin{itemize} % this is an unordered list
\\item This is the first item in the list
\\item This is the second item in the list
\\end{itemize}
\\end{document}

Save the above file as say first.tex and then run the following command from the shell prompt (on Linux) or on the Windows DOS command prompt:

latex first.tex

If everything goes smooth, a file containing the typeset document called first.dvi will be created. You can now view this file using the xdvi program on Linux or using the YAP program on Windows that is installed along with MikTeX.

Alternatively, you can convert this document to PostScript format and print it using a PostScript printer. The command for doing this is:

dvips -f latex.dvi > latex.ps

You can now view this PostScript file using the GhostView program, on either Linux or Windows. This is just a simple demonstration of Latex. Latex supports many features like automatic generation of table of contents, a variety of fonts based on the METAFONT system invented by Knuth and also the TrueType fonts that come with Windows, lists, footnotes, multiple column documents like the one found in magazines, tables, etc.

Some other programs included with Latex enable you to automate other routine tasks that are required for creating any large document. For example, the program MakeIndex can create an index at the end of the document and BIBTEX helps us create and maintain a list of bibliographic references. The advantage of these programs is that if you change something (like adding a new reference), then re-running Latex will resolve all the reference like page numbers and reference numbers correctly.

Any good document-preparation system of its worth must provide the ability to include diagrams and figures in the document. In Latex, graphics can be included using a graphic-description package like picture. Here we include the commands for creating the diagrams, like draw a circle and then a line, in the document.

However, an easier way is to draw the diagrams using some drawing tool and then include the file into the document. The graphics package allows you to import Encapsulated PostScript files (.eps) into the document. The commands to do this are:

...
\\usepackage{graphics} % Include the graphics package
...
\\begin{figure}
\\includegraphics{mydiagram.eps} % insert the diagram
\\caption{A sample diagram} % its caption
\\label{fig:mydiagram} % label to refer to it
\\end{figure}

Such diagrams in Encapsulated ProtScript form can be created using the drawing package called xfig that is included on the RedHat Linux CD-ROM. Alternatively, you can convert your figures in GIF, JPEG, TIFF, etc formats into EPS format using the xpaint program on Linux. For Windows users, an equivalent of xfig called WinFig is availabe.

One of the advantages of Latex is that the size of documents with figures is not enormously large as in case of some word-processing systems.

One of the reasons for the popularity of Latex is its ability to typeset complex mathematical formulae easily and effectively.

Any math formula is to be enclosed in $ signs. An underscore is used for subscripts and a circumflex is used for superscripts. Control codes are provided for many mathematical symbols. For example,

$\\sum_{i=1}ˆ{n}iˆ2 = \\frac{n(n+1)(2n+1)}{6}$

results in the expression :

Indeed, the facilities Latex provides for typesetting math formulae are very large to discuss here. It provides many mathematical symbols and other commonly used functions. This capability of Latex is not available in many of the modern word processors and explains the reason behind the popularity of Latex among researchers and mathematicians.

Indeed, Tex and Latex provide far more features than those discussed in this article. The Latex software comes with a number of packages that let you do such things as customize the header and footers, insert special symbols likeª, set spacing between lines, and typeset algorithms nicely.

Also, various software packages are available to convert Latex files into other formats. For example, latex2HTML is a program to convert Latex documents in HTML format so that they can be easily uploaded on your website.

An extension of the original Latex software called pdflatex allows you to create PDF files from the Latex source, and then these files can be viewed using Adobe Acrobat Reader available under various platforms. Also, pfdlatex allows direct inclusion of figures in JPEG, PNG and TIFF formats; you don’t need to convert them in EPS format.

For those who want to reap the benefits of these features but don’t want to learn the syntax of Latex, a WYSIWYG Latex editor called LyX is also available. However, learning the syntax is the most efficient way to make use of all the Latex features.

Happy Latexing.

Rahul U Joshi Associate Software Engineer, Veritas Software India

  • Follow PCQuest on
  • become a fan on
  • Stay updated via
  • RSS

LEAVE A REPLY

Notify me of follow-up comments via e-mail address

Post Comment

Survey Box

Now that Microsoft has finally discontinued support for Windows XP, which OS are you likely to upgrade to?

Send this article by email

X