LaTeX/Packages
From Wikibooks, the open-content textbooks collection
Add-on features for LaTeX are known as packages. Dozens of these are pre-installed with LaTeX and can be used in your documents immediately. They should all be stored in subdirectories of texmf/tex/latex named after each package. To find out what other packages are available and what they do, you should use the CTAN search page which includes a link to Graham Williams' comprehensive package catalogue. A package is a file or collection of files containing extra LaTeX commands and programming which add new styling features or modify those already existing. Installed package files all end with .sty (there may be ancillary files as well). When you try to typeset a document which requires a package which is not installed on your system, LaTeX will warn you with an error message that it is missing, and you can then download the package and install it using the instructions in the installing extra packages section. You can also download updates to packages you already have (both the ones that were installed along with your version of LaTeX as well as ones you added). There is no limit to the number of packages you can have installed on your computer (apart from disk space!), but there is probably a physical limit to the number that can be used inside any one LaTeX document at the same time, although it depends on how big each package is. In practice there is no problem in having even a couple of dozen packages active.
Contents |
[edit] Using an existing package
To use a package already installed on your system, insert a \usepackage command in your document preamble with the package name in curly braces:
\usepackage{package_name}
For example, to use the color package, which lets you typeset in colors, you would type:
\documentclass[11pt,a4paper,oneside]{report} \usepackage{color} \begin{document} ... \end{document}
You can include several package names in one \usepackage command by separating the names with commas, like this:
\usepackage{package1,package2,package3}
and you can have more than one \usepackage command. Some packages allow optional settings in square brackets. If you use these, you must give the package its own separate \usepackage command, like geometry shown below:
\documentclass[11pt,a4paper,oneside]{report} \usepackage{pslatex,palatino,avant,graphicx,color} \usepackage[margin=2cm]{geometry} \begin{document} \title{\color{red}Practical Typesetting} \author{\color{blue}Peter Flynn\\ Silmaril Consultants} \date{\color{green}December 2005} \maketitle \end{document}
Many packages can have additional formatting specifications in optional arguments in square brackets, in the same way as geometry does. Read the documentation for the package concerned to find out what can be done. You can pass several options together separated by a comma:
\usepackage[option1,option2,option3]{''package_name''}
[edit] Package documentation
To find out what commands a package provides (and thus how to use it), you need to read the documentation. In the texmf/doc subdirectory of your installation there should be directories full of .dvi files, one for every package installed. This location is distribution-specific, but is typically found in:
| Distribution | Path |
|---|---|
| MiKTeX | C:\Program Files\MiKTeX 2.7\doc\latex |
| teTeX | /usr/share/texmf-tetex/doc/latex |
Generally, most of the packages are in the latex subdirectory, although other packages (such as BibTeX and font packages) are found in other subdirectories in doc. The documentation directories have the same name of the package (e.g. amsmath), which generally have one or more relevant documents in a variety of formats (dvi, txt, pdf, etc.). The documents generally have the same name as the package, but there are exceptions (for example, the documentation for amsmath is found at latex/amsmath/amsdoc.dvi). If your installation procedure has not installed the documentation, the DVI files can all be downloaded from CTAN. Before using a package, you should read the documentation carefully, especially the subsection usually called "User Interface", which describes the commands the package makes available. You cannot just guess and hope it will work: you have to read it and find out.
[edit] Packages list
Here is a (not complete) list of useful packages that can be used for a wide range of different kind of documents. Each package has a short description next to it and, when available, there is a link to a section describing such package in detail. All of them (unless stated) should be included in your LaTeX distribution as package_name.sty. For more information, refer to the documentation of the single packages, as described in the previous section. The list is in alphabetical order.
| amsmath | it contains the advanced math extensions for LaTeX. The complete documentation should be in your LaTeX distribution; the file is called amsdoc, and can be dvi or pdf. For more information, see the chapter about Mathematics |
| amssymb | it adds new symbols in to be used in math mode. |
| amsthm | it introduces the proof environment and the theoremstyle command. For more information see the Theorems section. |
| array | it extends the possibility of LaTeX to handle tables, fixing some bugs and adding new features. Using it, you can create very complicated and customized tables. For more information, see the Tables section. |
| babel | it provides the internationalization of LaTeX. It has to be loaded in any document, and you have to give as an option the main language you are going to use in the document. |
| bm | allows use of bold greek letters in math mode using the \bm{...} command. This supersedes the amsbsy package. |
| boxedminipage | it introduces the boxedminipage environment, that works exactly like minipage but adds a frame around it |
| changepage | to easily change the margins of pages. The syntax is
\changepage{textheight}{textwidth}% {evensidemargin}{oddsidemargin}% {columnsep}{topmargin}% {headheight}{headsep}% {footskip} All the arguments can be both positive and negative numbers; they will be added (keeping the sign) to the relative variable. |
| cite | assists in citation management |
| color | it adds support for colored text. For more information, see the relevant section |
| eucal | other mathematical symbols |
| fancyhdr | to change header and footer of any page of the document. It is described in the Page Layout section |
| fontenc | to choose the font encoding of the output text. You might need it if you are writing documents in a language other than English. Check in the Internationalization section. |
| geometry | for easy management of document margins |
| graphicx | to manage external pictures |
| hyperref | it gives LaTeX the possibility to manage links within the document or to any URL when you compile in PDF. For more information, see the relevant section |
| indentfirst | once loaded, the beginning of any chapter/section is indented by the usual paragraph indentation. |
| inputenc | to choose the encoding of the input text. You might need it if you are writing documents in a language other than English. Check in the Internationalization section. |
| latexsym | other mathematical symbols |
| listings | to insert programming code within the document. Many languages are supported and the output can be customized. For more information, see the relevant section |
| mathrsfs | other mathematical symbols |
| natbib | gives additional citation options and styles |
| pdfpages | This package simplifies the insertion of external multi-page PDF or PS documents. |
| rotating | It lets you rotate any kind of object. It is particularly useful for rotating tables. For more information, see the relevant section |
| setspace | Lets you change line spacing, e.g. provides the \doublespacing command for making double spaced documents. For more information, see the relevant section |
| showkeys | it is very useful while writing any document. If you want to reference an image or a formula, you have to give it a name using \label{...} and then you can recall it using \ref{...}. When you compile the document these will be replaced only with numbers, and you can't know which label you had used unless you take a look at the source. If you have loaded the showkeys package, you will see the label just next or above the relevant number in the compiled version. An example of a reference to a section is |
| showidx | it prints out all index entries in the left margin of the text. This is quite useful for proofreading a document and verifying the index. For more information, see the Indexing section. |
| subfig | it allows to define multiple floats (figures, tables) within one environment giving individual captions and labels in the form 1a, 1b. |
| syntonly | if you add the following code in your preamble:
\usepackage{syntonly} \syntaxonly LaTeX skims through your document only checking for proper syntax and usage of the commands, but doesn’t produce any (DVI or PDF) output. As LaTeX runs faster in this mode you may save yourself valuable time. If you want to get the output, you can simply comment out the second line. |
| textcomp | provides extra symbols, for example for different currencies (\texteuro,...), things like \textcelsius and many other |
| theorem | you can change the style of newly defined theorems. For more information see the Theorems section. |
| siunitx | helps you typeset of SI-units correctly. For example \SI{12}{\mega\herz}. Automatically handles the correct spacing between the number and the unit. Note that even non-SI-units are set, like dB, rad, ... |
| url | it defines the \url{...} command. URLs often contain special character such as _ and &, in order to write them you should escape them inserting a backslash, but if you write them as an argument of \url{...}, you don't need to escape any special character and it will take care of proper formatting for you. If you are using the hyperref, you don't need to load url because it already provides the \url{...} command. |
| verbatim | it improves the verbatim environment, fixing some bugs. Moreover, it provides the comment environment, that lets you add multiple-line comments or comment out easily big parts of the code. |
| wrapfig | to insert images surrounded by text. It was discussed in section Floats, Figures and Captions |
[edit] Creating packages
See