[Tex/LaTex] How to find out which Linux package contains which (La)TeX package

big-listinstallinglinuxpackages

I'm using (La)TeX as installed by my Linux/Unix distribution. I've come across a package that I don't have installed. How do I find out which Linux/Unix package contains that (La)TeX package?

Notes:

  1. This is a public service question, please take that into account when answering. More than ever, good answers should be detailed.
  2. If the distribution has an "install everything" package, that's worth mentioning. But some people want to only install what they need so please still answer the question as asked.
  3. Please specify the flavour of Linux/Unix in your answer.

I don't think we have a question that covers this, but obviously if someone finds it then we'll delete this one.

Best Answer

Most Linux distributions provide a tool to find out which distribution package contains which file. Some distributions provide a website as well.

Which file do I want?

  • For \usepackage{foo} (LaTeX package), you need foo.sty.
  • For \documentclass{foo} (LaTeX class), you need foo.cls.
  • For \input foo (TeX macro file), you need foo.tex.
  • For \bibligraphystyle{foo} (BibTeX style), you need foo.bst.
  • For a font, it depends on the font's encoding. The easiest thing would be to look for the LaTeX package that makes the requisite declarations (foo.sty).

If you know which CTAN package you want, on CTAN, follow the “Sources” link and look at the file names there. Note that .dtx files are used to generate other files; often one of the generated file has the same name and the extension .sty (for LaTeX) or .tex (for other formats), but this is a habit, not a rule.

If you use a graphical package manager, check if it has an option to search a package by file name. If not, see below for command line methods.

Debian, Ubuntu, Linux Mint, elementary OS...

On Debian-based distributions, the tool apt-file lets you search the package database by file name. First, install it if it is not installed already. You only need to do this once, and to run apt-file update after upgrading to a new release of the distribution.

sudo apt-get install apt-file
sudo apt-file update

Here's an example of looking for a given file and installing the package containing it. $ represents a shell prompt.

$ apt-file search /foils.sty
foiltex: /usr/share/texmf/tex/latex/foiltex/foils.sty
$ sudo apt-get install foiltex

Some Debian derivatives may include the apt-file program but not the databases that it needs to function. If so you'll need to find another way. Chances are that the derivative hasn't changed the way the TeX packages are organized, so you can use the web to find out where it is in Debian or Ubuntu:

Red Hat, CentOS, Fedora

Modern releases use dnf, which offers the following command:

dnf provides '*/foils.sty'

Older releases use yum, which has a similar command with a slightly different name:

yum whatprovides '*/foils.sty'

Note that both commands need a full path, not just the base name of the file. But you can use * to replace a part of the path that you don't know, thus */foils.sty looks for a file called foils.sty located anywhere.

Once you've identified the package name, install it with sudo dnf install … or sudo yum install ….

SuSE

See Schweinebacke's answer. In a nutshell:

zypper search --provides --match-exact 'tex(foo.sty)'
sudo zypper install …

Arch Linux

You can search for packages by contents with pacman. First update the local database:

sudo pacman -Fy

(or su -c 'pacman -Fy' or using whatever method you prefer to run commands as root). Then, to search for a specific file name:

pacman -F /foo.sty

or pkgfile foo.sty.

Once you've identified the package name, install it with pacman -S.

Gentoo

You can search for the package providing a given file name with equery.

equery belongs /foo.sty

FreeBSD

Try searching for a port on Porgle. Tick the “packing list” checkbox to search by file name.

Where else can I look for help?