LaTeX/Basics

From Wikibooks, the open-content textbooks collection

< LaTeX
Jump to: navigation, search

Contents

[edit] Document Classes

The first information LaTeX needs to know when processing an input file is the type of document the author wants to create. This is specified with the \documentclass command.

\documentclass[options]{class}

Here class specifies the type of document to be created. The LaTeX distribution provides additional classes for other documents, including letters and slides. The options parameter customizes the behavior of the document class. The options have to be separated by commas.

Example: an input file for a LaTeX document could start with the line

\documentclass[11pt,twoside,a4paper]{article}

which instructs LaTeX to typeset the document as an article with a base font size of eleven points, and to produce a layout suitable for double sided printing on A4 paper.

Here are some document classes that can be used with LaTeX:

Document Classes
article for articles in scientific journals, presentations, short reports, program documentation, invitations, ...
proc a class for proceedings based on the article class.
minimal is as small as it can get. It only sets a page size and a base font. It is mainly used for debugging purposes.
report for longer reports containing several chapters, small books, thesis, ...
book for real books
slides for slides. The class uses big sans serif letters.
memoir for changing sensibly the output of the document. It is based on the book class, but you can create any kind of document with it [1]
letter for writing letters.
beamer for writing presentations (see LaTeX/Presentations).

The most common options for the standard document classes are listed in the following table:

Document Class Options
10pt, 11pt, 12pt Sets the size of the main font in the document. If no option is specified, 10pt is assumed.
a4paper, letterpaper,... Defines the paper size. The default size is letterpaper; However, many European distributions of TeX now come pre-set for A4, not Letter, and this is also true of all distributions of pdfLaTeX. Besides that, a5paper, b5paper, executivepaper, and legalpaper can be specified.
fleqn Typesets displayed formulas left-aligned instead of centered.
leqno Places the numbering of formulae on the left hand side instead of the right.
titlepage, notitlepage Specifies whether a new page should be started after the document title or not. The article class does not start a new page by default, while report and book do.
onecolumn, twocolumn Instructs LaTeX to typeset the document in one column or two columns.
twoside, oneside Specifies whether double or single sided output should be generated. The classes article and report are single sided and the book class is double sided by default. Note that this option concerns the style of the document only. The option twoside does not tell the printer you use that it should actually make a two-sided printout.
landscape Changes the layout of the document to print in landscape mode.
openright, openany Makes chapters begin either only on right hand pages or on the next page available. This does not work with the article class, as it does not know about chapters. The report class by default starts chapters on the next page available and the book class starts them on right hand pages.
draft makes LaTeX indicate hyphenation and justification problems with a small square in the right-hand margin of the problem line so they can be located quickly by a human.

For example, if you want a report to be in 12pt type on A4, but printed one-sided in draft mode, you would use:

\documentclass[12pt,a4paper,oneside,draft]{report}

[edit] Packages

While writing your document, you will probably find that there are some areas where basic LaTeX cannot solve your problem. If you want to include graphics, colored text or source code from a file into your document, you need to enhance the capabilities of LaTeX. Such enhancements are called packages. Packages are activated with the

\usepackage[options]{package}

command, where package is the name of the package and options is a list of keywords that trigger special features in the package. Some packages come with the LaTeX base distribution. Others are provided separately.

Modern TeX distributions come with a large number of packages pre-installed. If you are working on a Unix system, use the command texdoc for accessing package documentation. For more information, see the Packages section.

[edit] Files you might Encounter

When you work with LaTeX you will soon find yourself in a maze of files with various extensions and probably no clue. The following list explains the most common file types you might encounter when working with TeX:


Common file extensions in LaTeX
.aux A file that transports information from one compiler run to the next. Among other things, the .aux file is used to store information associated with cross-references.
.bbl Bibliography file output by BiBTeX and used by LaTeX
.bib Bibliography database file
.blg BiBTeX log file.
.bst BiBTeX style file.
.cls Class files define what your document looks like. They are selected with the \documentclass command.
.dtx Documented TeX. This is the main distribution format for LaTeX style files. If you process a .dtx file you get documented macro code of the LaTeX package contained in the .dtx file.
.ins The installer for the files contained in the matching .dtx file. If you download a LaTeX package from the net, you will normally get a .dtx and a .ins file. Run LaTeX on the .ins file to unpack the .dtx file.
.fd Font description file telling LaTeX about new fonts.
.dvi Device Independent File. This is the main result of a LaTeX compile run with latex. You can look at its content with a DVI previewer program or you can send it to a printer with dvips or a similar application.
.pdf Portable Document Format. This is the main result of a LaTeX compile run with pdflatex. You can look at its content or print it with any PDF viewer.
.log Gives a detailed account of what happened during the last compiler run.
.toc Stores all your section headers. It gets read in for the next compiler run and is used to produce the table of contents.
.lof This is like .toc but for the list of figures.
.lot And again the same for the list of tables.
.idx If your document contains an index. LaTeX stores all the words that go into the index in this file. Process this file with makeindex.
.ind The processed .idx file, ready for inclusion into your document on the next compile cycle.
.ilg Logfile telling what makeindex did.
.sty LaTeX Macro package. This is a file you can load into your LaTeX document using the \usepackage command.
.tex LaTeX or TeX input file. It can be compiled with latex.

[edit] Big Projects

When working on big documents, you might want to split the input file into several parts. LaTeX has three commands to insert a file into another when building the document.

The simplest is the \input command:

\input{filename}

\input inserts the contents of another file, named filename.tex; note that the .tex extension is omitted. For all practical purposes, \input is no more than a simple, automated cut-and-paste of the source code in filename.tex.

The other main inclusion command is \include:

\include{filename}

The \include command is different from \input in that it's the output that is added instead of the commands from the other files. Therefore a new page will be created at every \include command, which makes it appropriate to use it for large entities such as book chapters.

Very large documents (that usually include many files) take a very long time to compile, and most users find it convenient to test their last changes by including only the files they have been working on. One option is to hunt down all \include commands in the inclusion hierarchy and to comment them out:

%\include{filename1}
\include{filename2}
\include{filename3}
%\include{filename4}

In this case, the user wants to include only filename2.tex and filename3.tex. If the inclusion hierarchy is intricate, commenting can become error-prone: page numbering will change, and any cross references won't work. A better alternative is to retain the include calls and use the \includeonly command in the preamble:

\includeonly{filename2,filename3}

This way, only \include commands for the specified files will be executed, and inclusion will be handled in only one place. Note that there must be no spaces between the filenames and the commas.

[edit] Picking suitable filenames

Never, ever use directories (folders) or file names that contain spaces. Although your operating system probably supports them, some don't, and they will only cause grief and tears with TeX. Make filenames as short or as long as you wish, but strictly avoid spaces. Stick to lower-case letters without accents (a-z), the digits 0-9, the hyphen (-), and the full point or period (.), (similar to the conventions for a Web URL): it will let you refer to TeX files over the Web more easily and make your files more portable. Some operating systems do not distinguish between upper-case and lower-case letters, others do. Therefore it's best not to mix them.

[edit] Working in a team

See chapter Collaborative Writing of LaTeX Documents.


Previous: Absolute Beginners Index Next: Document Structure