LaTeX

From LQWiki
Jump to navigation Jump to search

LaTeX is a front-end macro package for TeX.

TeX (capitalized that way on purpose) is text formatting software originally written by Donald Knuth that creates beautifully formatted documents, especially when they contain mathematics. TeX is very difficult to use. LaTeX is a package of macros written originally by a guy named Leslie Lamport that wraps TeX commands and makes TeX usuable by a much wider audience.

To create a document with LaTeX, you write your document as a plain text file, but mark it up with extra little notations (similar to writing html). When you're done, you save the file, then typically run a program (usually called pdflatex) to convert your text file to a nice pretty pdf file.

Example Document

Basic Code

There are some structures that need to appear in any latex doc. The following is an example of a very simple latex article:

\documentclass{article}

\begin{document}

hello world

\end{document}

The first line tells latex what kind of document you wish to create. There are a few different kinds; article is the most common. The space between the first line and \begin{document} is called the preamble and is where header-type things go. Naturally, the body of the document goes between \begin{document} and \end{document}.

Compiling

The following commands will compile a basic LaTeX document called sample.tex.

$ latex sample.tex
$ dvips sample -o sample.ps
$ ps2pdf sample.ps

The first command, latex, compiles the .tex file containing the latex code into a .dvi file. The second command, dvips, creates a postscript file from the dvi file. Note that the .dvi extension is not given when calling dvips.

The final command, ps2pdf, transforms the postscript file into a pdf, though this is not necessary if you like reading postscript files. To take a quick look at the resulting document, type:

$ xpdf sample.pdf

Comments

Comments start with a %, and work similar to // in C/C++.

See also

External Links