Google
 

Monday, December 18, 2006

Latex

What is TeX

TeX (pronounced "Tech") is mainly a low level programming language aimed to typesetting documents. It is very powerful but, since you have to take care of everything, it is difficult and time-consuming to use it for long documents.

What is LaTeX

LaTeX (pronounced either "Lah-tech" or "Lay-tech") is a macro package created by Leslie Lamport based on the TeX typesetting language of Donald Knuth. Its purpose is to produce professional looking and correctly typeset documents, in particular those with mathematical formulae. It is currently maintained by the LaTeX3 project. Numerous authors have contributed extensions, called packages or styles, to LaTeX. A number of these is usually bundled with a TeX/LaTeX software distribution or can be found in the Comprehensive TeX Archive Network (CTAN).

Since LaTeX comprises a group of TeX commands, LaTeX document processing follows a programming perspective. One creates a text file in LaTeX markup, which is then to be read by the LaTeX macro, which produces the final document.

Obviously, this has its disadvantages, compared with a WYSIWYG (What You See Is What You Get) program such as Openoffice.org Writer or Microsoft Word.

  • One can't see the final result straight away.
  • One needs to know the necessary commands for LaTeX markup.
  • It can sometimes be difficult to obtain a certain 'look'.

On the other hand, there are certain advantages to the markup language approach:

  • The layout, fonts, tables, etc. is consistent throughout.
  • Mathematical formulae can be easily typeset.
  • Indexes, footnotes, references, etc., are generated easily.
  • It encourages correctly structured documents.

The LaTeX-like approach can be called WYSIWYM, i.e. What You See Is What You Mean: you can't see how the final version will look like while typing, but you can see only the logical structure of the document, LaTeX will take care of the formatting for you.

The LaTeX document is a plain text file containing the content of the document, with additional markup. When the source file is processed by the macro package, it can produce documents in several formats such as DVI, PDF or PostScript.

Prerequisites

At a minimum, you'll need the following programs to edit LaTeX:

  • An editor (You can use a basic text editor like notepad, but a dedicated LaTeX editor will be more useful).
    • On Windows, TeXnicCenter([1]) is a popular free and open source LaTeX editor.
    • On *nix (including Mac OS X) systems, Emacsen and gvim provide powerful TeX enviroments for the tech-savvy, while Texmaker and Kile [2] provide more user-friendly development environments.
  • The LaTeX binaries and style sheets - e.g. MiKTeX [3] for Windows, teTeX [4] for Linux and teTeX for Mac OS X [5].
  • A DVI viewer to view and print the final result. Usually, a DVI viewer is included in the editor or is available with the binary distribution.

A distribution of LaTeX, with many packages, add-ins, editors and viewers for Unix, Linux, Mac and Windows can be obtained from the TeX users group at http://www.tug.org/texlive/.

Applications within a distribution

Here are the main programs you expect to find in any (La)TeX distribution:

  • tex: the simplest compiler, it gets a TeX file and creates DVI
  • pdftex: it gets a TeX file, but creates a PDF file
  • latex: the most used one: it gets a LaTeX file and creates a DVI
  • pdflatex: from a LaTeX creates a PDF
  • dvi2ps: converts the DVI file to PostScript
  • dvipdfm: converts the DVI file to PDF

When LaTeX was created, the only format it could create was DVI; then the PDF support was added by pdflatex, even if several people still don't use it. As it is clear from this short list, PDF files can be created with both pdflatex and dvipdfm; anyway, the output of pdflatex is much better than the other. DVI is an old format, and it does not support hyperlinks for example, while PDF does, so passing through DVI you will bring all the bad points of that format to PDF. Moreover the general output will be better using only pdflatex.

Strictly speaking, the document you are writing should be sightly different according to the compiler you are using (latex or pdflatex), but as we will see later, it is possible to add a sort of abstraction layer so to ignore what you are using, the applications will do everything by themselves.

Note that, since LaTeX is just a collection of macros for TeX, if you compile a plain TeX document with a LaTeX compiler (such as pdflatex) it will work, while the opposite is not true: if you try to compile a LaTeX source with a TeX compiler you will get only a lot of errors.

The following diagram shows the relationships between the (La)TeX source code and all the formats you can create from it:

The boxed red text represents the file formats, the blue text on the arrows represents the commands you have to use, the small dark green text under the boxes represents the image formats that are supported. Anytime you pass through an arrow you lose some information, that might decrease the quality of your document. Therefore, in order to achieve the highest quality in your output file, you should choose the shortest route to reach your target format. This is probably the most convenient way to obtain an output in your desired format anyway. Starting from a LaTeX source, the best way is to use only latex for a DVI output or pdflatex for a PDF output, converting to PostScript only when it is necessary to do it to print the document.

Most of the programs should be already within your LaTeX distribution, the others come with Ghostscript, that is a free and multi-platform software as well.

Reference: http://en.wikibooks.org/wiki/LaTeX/Introduction

Script use for compilation, and dvi to PDF file conversion

run.pl:

#!/usr/bin/perl
my $text1 = shift @ARGV or die print "No tex file is given as input\n";
#print "Inputed argument is $text1\n";
chop;
my @fname = split(/\./,$text1);
#print "Input array is @fname \n";
#print "Input text is $fname[0] . $fname[1] \n";

system("latex $text1");
system("dvips -Ppdf $fname[0].dvi");
system("ps2pdf $fname[0].ps $fname[0].pdf");
system("xpdf $fname[0].pdf");

Usage: ./run.pl filename.tex - Gives you PDF file as output directly

Keywords: Latex, Tex, PDF writer, dvi to pdf conversion

No comments: