TeX - LaTeX Asked by Andrew Stacey on October 2, 2021
I need to install a new TeX/LaTeX/ConTeXt package on my computer. I’m running Ubuntu/Fedora/Slackware/Some-Version-Of Linux. What are the possible ways to do this?
Note: We get a number of questions that essentially reduce to this one; it was felt a good idea to have one question-and-answer that can cover all the standard methods. See Should 'how to install package X on Ubuntu' questions be consolidated? for the discussion. The question-and-answer are CW so that more information can be easily added. If you have information to add, please do so. If you are unsure, leave a comment here or (preferably) in chat. Comments on the question and answer will be periodically removed to ensure that the information is clear.
Install the latest TeX Live
This is for if the package is in TeX Live and you want to or are using 'vanilla' TeXLive.
If you haven't yet installed TeX Live, follow the instructions at How to install "vanilla" TeXLive on Debian or Ubuntu? (these instructions apply to Linux systems in general, not just Debian-based ones).
How you install a package via TeX Live depends on whether you installed TeX Live as a single user or you installed it system-wide. If the first, try:
tlmgr install <package>
If the second, you will have a small problem in that tlmgr
might not be in the path that sudo
automatically searches. So you need to locate it first and use sudo
to call it with the full path. If your shell has the which
builtin, you can find tlmgr
using the command which tlmgr
. Thus:
which tlmgr
sudo /path/to/tlmgr install <package>
If your shell allows you to use the output of a command as a sort of variable, you can use the following command to condense the above (where we exploit the fact that which
returns a single instance of the command regardless of how many times it appears on the path):
sudo $(which tlmgr) install <package>
(You can test your shell with the less risky echo $(which tlmgr)
: this should produce the same as which tlmgr
.)
Find and install the package through your package manager.
This is for if you are using the version of TeX that came with your distribution and you don't mind particularly which version of the package you install.
Linux distributions tend to include TeX as a collection of packages, but it isn't usually on as fine a level as one TeX package equals one Linux package. You therefore need to find the right distribution package containing the TeX package that you want and install it. Different package managers have different methods of searching, if all else fails there is often a website where you can search for a specific file:
Install manually
In this situation, you have two options: to install system-wide (all users on your system) or to install just for you. System-wide means that any user on your system will be able to use it, just for you means just that: it will only be installed for your account. The difference between the two is the base location:
kpsewhich -var-value TEXMFLOCAL
in the Terminal to find the right directorykpsewhich -var-value TEXMFHOME
in the Terminal to find the right directoryOne thing to note here is that in the case of a 'package clash', i.e., the same file is found in multiple places (such as the 'system' location, the 'local' location, and/or the 'individual user' location), only the first instance of the file will be used. In this case, the order of precedence is usually: individual user (TEXMFHOME
) > local (TEXMFLOCAL
) > system. The full list (in the right order) can be determined by running kpsewhich --var-value TEXINPUTS
.
What happens now depends a bit on the package. If it is distributed in TDS then you are in luck. Go to the directory reported by kpsewhich
, and into the tex
subdirectory (or create it if it does not exist). Then extract the TDS file (remember to use sudo
if globally, and check that your umask
is set to 022
). Note check the TDS file first to ensure that it will extract into the right place: you may need to move up or down a directory to get it to match.
If it is not distributed in TDS, then there are two options: If the package is available from TeX Live, you can get the TDS packaged version from http://mirror.ctan.org/systems/texlive/tlnet/archive/.tar.xz, and unpack it into a temporary directory. In most cases it will contain subdirectories like tex, fonts, etc. Copy these to the TEXMF tree as decided above. In case it contains a directory texmf-dist or similar, it is a package that also ships some scripts or different things outside the texmf hierarchy, in this case it is the best to contact an expert. Finally, you can also download the package from CTAN or the original distribution channel, unpack it and then there might be instructions - in which case follow them - but the general pattern is pretty similar. If it is a LaTeX package, create a directory in <base dir>/tex/latex/<package name>
for it and extract the files (.sty
plus perhaps .cls
, etc.) there. Documentation files go in <base dir>/doc/latex/<package name>
.
If you installed it globally, you will now need to run mktexlsr
(or equivalently texhash
) via sudo
. If mktexlsr
is not in the path that sudo
searches, you will need to locate it. You can do:
which mktexlsr
sudo /path/to/mktexlsr
Or if your shell allows it:
sudo $(which mktexlsr)
This isn't necessary for local installations.
Point to it
This is for the case where you have a .sty
or .cls
file which you don't want to install centrally, for one reason or another. For example, it may be specific to a particular project (for example an unusual journal style file), or it may be known to clash with other packages, or you may wish to keep it alongside the source files in a repository.
As described above, the TeX family of programs consult a path when looking for input files, including .sty
and .cls
files. You can override this with the TEXINPUTS
environment variable, which (on unix) consists of a sequence of directories separated by colons; TeX searches each of these directories in turn. Thus, if you had a .sty
file in a subdirectory styles
, then
TEXINPUTS=styles:
would cause TeX to search for the file in that directory first.
Note the trailing colon: this is followed by an empty path element, which causes TeX to insert the standard search path in that position. Thus TEXINPUTS=:styles
would cause TeX to search the standard path before the subdirectory styles
.
As above, you can use kpsewhich
to check things are configured correctly.
% ls styles
myfancypackage.sty
% kpsewhich myfancypackage.sty # doesn't find anything
% export TEXINPUTS=styles:
% kpsewhich myfancypackage.sty
styles/myfancypackage.sty # found it!
%
sudo
When you add TeX Live to your path, it will not normally be added to the path for the root user, so will not be visible using sudo
. The methods above use which
to find tlmgr
, etc., from the 'normal user' path and pass the correct instruction to sudo
. This works with the bash
and zsh
shells: if you use another shell you may need to provide the full path to tlmgr
instead.
When running sudo
, the environment used is a mixture of the superuser's and the local user's. As well as the path mentioned above, it is important to ensure that the umask
setting is sufficiently lax: a user should have a umask
of 077
but root of 022
. The umask
controls the default permissions of newly created files: with 077
only root would be able to read (and thus use) them. With 022
, everyone can read (and possibly execute) them.
If your system does not have sudo
installed by default, it probably has it in its package repository. If not, see How universal is sudo? for alternatives.
mktexlsr
and texhash
To speed up its searching, the kpathsea
library uses caches in the form of files called ls-R
in various directories. These contain all the files that kpathsea
would find if it searched properly in that directory (obeying any recursive search directives). The files are recreated by the mktexlsr
command (which is short for "Make TeX's ls-R files") which has to be run manually (by someone with write access to the directory, usually root - see the note on sudo) if it is needed. This command used to be called texhash
and that is still an alias for this command (technically, a symlink).
kpsewhich
TeX uses the kpathsea
library for finding its files. Where this looks depends on various variable which can be set in configuration files or by the user's shell. The list of directories that kpathsea
searches in can be displayed by typing kpsewhich --var-value TEXINPUTS
. The output is a little condensed. The following attempts to clarify it a little:
$PATH
)!!
it means that the ls-R
file will be consulted instead of the filesystem.//
it will be searched recursively.Thus
{!!/usr/local/texlive/2012/texmf-dist,!!/usr/local/texlive/2012/texmf-var}}//
means that /usr/local/texlive/2012/texmf-dist
and /usr/local/texlive/2012/texmf-var
will both be searched, in that order. Both will actually use the cache which is stored in ls-R
in the base of the search (thus /usr/local/texlive/2012/texmf-dist/ls-R
, for example). And both searches will be recursive.
The simplest way to check that the installed file is being found is to run
kpsewhich <package_name>
(where <package_name>
includes the extension). If this lists the newly installed file, all should be fine. If it doesn't but does display something then it may be that there is another version of this package installed which is being found first. If that is the case, then
kpsewhich --all <package_name>
will list all of the matching names so you can test to see if it is finding it at all.
If it did find it but isn't using it, you will either have to choose a location which is searched earlier than the version that is being found or remove the version(s) that are being found first.
If it did not find it at all, there are some possible reasons.
If you did a full installation of TeX Live, is the kpsewhich
command from the new installation? Try which kpsewhich
to find out. If not, adjust your $PATH
and try again. (If your path is correct, it might be that your shell hasn't noticed it: try rehash
to correct this (Bourne-Again Shells)).
If you only installed a package, did you put it somewhere that TeX can find it? The full list of directories in which TeX searches can be found by running
kpsewhich --var-value TEXMF
These are searched recursively.
If it is in a directory that TeX searches, and that directory is prepended in the list by !!
then it is one where TeX consults the cache, not the actual files on the disc. To recreate the cache, run mktexlsr
or texhash
as super-user.
If you do not use the package manager to install TeX or one of its packages (i.e., you didn't use Method 1), then the package manager will not know that what you have just installed is installed. This means that installing system packages that depend on these manually installed packages will try to install them again. The simplest solution is to let them do so as it is usually the case that your manually installed things are found before the system ones. If space is tight, many distributions have "dummy" packages that can be installed to trick the package manager. See How to install "vanilla" TeXLive on Debian or Ubuntu? for more details.
Answered by Andrew Stacey on October 2, 2021
As I use Ubuntu I have installed TeX Live and of course I use apt-get
to install packages.
I found that I was missing some files needed to compile my document. Using apt-cache
as recommended in Method 1 above I found that texlive-latex-extra
was the package I needed. However the download size was huge (327 MB).
The essential package only, was easily installed by
sudo apt-get install texlive-latex-extra --no-install-recommends
Including the --no-install-recommends
avoids the huge (320 MB) of extras.
Answered by Justin Solms on October 2, 2021
On Fedora 19 (and probably later distributions as well) you can install the (e.g.) multirow.sty package with the following command:
yum install texlive-multirow
You have to log in as root first
Answered by Stephan Korsholm on October 2, 2021
If You can't install the package (why ever) You can also put the .sty file next to Your .tex file which uses it. The LaTeX compiler will search in the current directory as well.
Answered by jovobe on October 2, 2021
Under OpenSUSE, you can use this command:
sudo zypper install 'tex(<package_name>.sty)
Note that the OpenSUSE distribution can be installed under Windows 10 easily, through the Windows Subsystem for Linux (WSL).
Answered by jciloa on October 2, 2021
If you are getting an error message about missing files, there is a step even before this: finding which package you need to install.
If you are installing a TeX Live (or MikTeX) package, this will be a file search on CTAN.org. It might return a CTAN package that is not available for installation with your version, but that you still need to install anyway. In that case, you would follow the “Method 3: Install Manually” instructions from the community-wiki answer.
On Debian or Ubuntu, you can search for the .deb
package containing a file with apt-file search
. The web search will work as well.
If you’re looking for a document class, the file extension will be .cls
. A package loaded with usepackage
or RequirePackage
will end with .sty
. A legacy Type 1 font will consist of multiple files, but you can search for the family name plus .tfm
. An old-fashioned METAFONT file will end in .mf
.
If fontspec
cannot locate a modern font, it is not always possible to guess what the filename will be. For example, CMU Typewriter Text Oblique is cmunst.ttf
. The document might also be looking for a system font, rather than one in your TeX Live tree specifically, and it might even be one that you have to download from the Web. On Linux, LuaLaTeX or XeLaTeX can search your user font directory, ~/.fonts
, or you can put downloaded fonts in a subdirectory of /usr/local/share/fonts
. On Windows or (I believe) Mac, there is a trap option! A font must be installed for all users for fontspec
to find it. Therefore, if you installed a font only for one user, you might need to reinstall it for all users, or it will display as available but give you a file-not-found error in LaTeX.
Answered by Davislor on October 2, 2021
For anyone using Arch Linux, Arch wiki says:
The
tllocalmgr
utility, provided bytllocalmgr-git
, lets you install (and update) packages from CTAN as pacman packages, see its usage (-h
) for details.
To install tllocalmgr-git
one can use an AUR helper such as yay
:
yay -S tllocalmgr-git
Then simply run:
tllocalmgr
and the TexLive Local Manager Shell will be available. To install a package just run:
> install threeparttable # could be anyother package
> texhash # refresh the TeX file database
Answered by Marcelo Villa-Piñeros on October 2, 2021
Debian/Ubuntu specific answer:
If you know that you want e.g. outlines.sty
, you could just do
apt-file search outlines.sty
and get the result:
texlive-latex-extra: /usr/share/texlive/texmf-dist/tex/latex/outlines/outlines.sty
Then you can just proceed with sudo apt install texlive-latex-extra
.
Note that apt-file
is usually not installed by default. To have this command, you have to do sudo apt install apt-file
and then sudo apt-file update
to fetch the latest info about all available files. Note that this is required so that apt-file
can find any file that can be provided by any package known by your package manager, already installed or otherwise. If you think package repositories have changed so much that the existing info about provided files is no longer up to date, you can just run sudo apt-file update
again.
Answered by Mikko Rantalainen on October 2, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP