Installing a LaTeX package

Let’s say you want to create a A0 poster with LaTeX. You find an example on the internet that starts like this:

\documentclass[final]{beamer}
\usepackage[orientation=landscape,size=a0,scale=1]{beamerposter}
\usepackage{lipsum} % lorem ipsum

You download the example ‘example.tex’, run pdflatex on it and it fails like this:

me@mycomputer: pdflatex example.tex
This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011)
 restricted \write18 enabled.
entering extended mode
(./example.tex
LaTeX2e <2011/06/27>
Babel  and hyphenation patterns for english, dumylang, nohyphenation, lo
aded.
(/usr/share/texlive/texmf-dist/tex/latex/beamer/beamer.cls

[...]

! LaTeX Error: File `beamerposter.sty' not found.

Type X to quit or  to proceed,
or enter new name. (Default extension: sty)

Enter file name: 

This means, that this particular LaTeX package ‘beamerposter’ is not installed on your machine. Bad luck.

What to do if you have admin permissions

On linux, open your favourite package manager (e.g., Synaptic), type the name of the LaTeX package (in this case ‘beamerposter’). If the result shows a linux package like ‘texlive-latex-extra’ install it and be happy.

What to do if you do not have admin permissions

1. Download the package

Go to CTAN. Search for the missing package name and click on the best result. In the beamerposter case, you will end up here. To get to a page where you can actually download the package, you need to follow the link listed under CTAN path in the box at the bottom of the page. Click on ‘Download’ and save the ‘beamerposter.zip’ somewhere on your computer.

We will also assume that the second package, ‘lipsum’, is also missing, you would find it on CTAN here.

2. Extract the package to the correct location

The READMEs of LaTeX package usually contain "Put it in your tex folder" or "Put it somewhere where LaTeX can find it" (if they contain anything on installation at all). What this actually means is, that there are several possibilities. LaTeX searches for sources in a few directories, depending on your system and LaTeX distribution. Some examples for linux and texlive are:

/usr/share/texmf/
/usr/share/texlive/texmf/
/usr/local/share/texmf/tex/latex/
~/texmf/

If you don’t have admin permissions, the easiest is to create a folder ‘texmf’ in your home directory (~). You will need in this folder a subfolder ‘tex’, and then ‘latex’. So in total you should have:

~
   |- texmf/
      |- tex
         |- latex

In this folder, i.e., ~/texmf/tex/latex/, you can put any style files and latex will find them. It is advisable to create separate folders for separate packages, so we will extract the ‘beamerposter.zip’ that we downloaded into the folder ~/texmf/tex/latex/beamerposter/ and ‘lipsum.zip’ into the folder ~/texmf/tex/latex/lipsum/. This is what the folder looks like now:

~
   |- texmf/
      |- tex
         |- latex
            |- beamerposter
               |- beamerposter.pdf
               |- beamerposter.sty
               |- beamerposter.tex
               |- example.tex
               |- README
            |- lipsum
               |- lipsum.dtx
               |- lipsum.ins
               |- lipsum.pdf
               |- README

As you can see, we now have a ‘beamerposter.sty’. So if this were the only package we needed, we could skip step 3. Unfortunately we are still missing ‘lipsum.sty’, so this is what step 3 is about.

3. Create a style file

As we see, there is no style file ‘lipsum.sty’. There is only a ‘lipsum.ins’ and a ‘lipsum.dtx’ file. The .dtx file is only to create the documentation and we can ignore it here. To create the style file, run latex (latex, not pdflatex!) on ‘lipsum.ins’:

me@mycomputer: latex lipsum.ins 

The result should look like this:

~
   |- texmf/
      |- tex
         |- latex
            |- beamerposter
               |- ...
            |- lipsum
               |- lipsum.dtx
               |- lipsum.ins
               |- lipsum.log
               |- lipsum.pdf
               |- lipsum.sty
               |- README

4. Try pdflatex again

And it should work (unless of course a different package is missing…).

Updating the Database

If you install fonts and in some other cases you need to update the LaTeX package database. On linux/texlive this is done with ‘texhash’:

me@mycomputer: texhash

More

This works for regular LaTeX packages. Bibtex packages go to texmf/bibtex. If there are fonts involved, you will need to put them in texmf/fonts and it might get tricky.

LaTeX at Wikibooks

This entry was posted in LaTeX and tagged , , by swk. Bookmark the permalink.

About swk

I am a computational linguist, teacher of computer science and above all a huge fan of LaTeX. I use LaTeX for everything, including things you never wanted to do with LaTeX. My latest love is lilypond, aka LaTeX for music. I'll post at irregular intervals about cool stuff, stupid hacks and annoying settings I want to remember for the future.