Tx · LaTeX & TikZ

How to Change TeX Live’s Package Search Path on Linux

Published By the 9to5Science editorial team

At a glance

  1. 1. Choose a TeX tree

    Use TEXMFHOME for your personal packages; it is usually safer than changing TeX Live’s system-wide configuration.

  2. 2. Arrange the files

    Put package files beneath the tree in the usual structure, such as tex/latex/package-name/package-name.sty.

  3. 3. Set and verify the path

    Set TEXMFHOME in your environment, then check it and locate a package with kpsewhich.

  4. 4. Refresh if needed

    If the tree uses a filename database, rebuild it with mktexlsr and test the lookup again.

TeX Live does not normally search arbitrary folders for installed LaTeX packages. It searches a set of TeX directory trees, whose locations are controlled by the Kpathsea filename-search system. For personal packages, the simplest approach is usually to set TEXMFHOME to the root of a TeX tree in your chosen location.

Use TEXMFHOME for personal packages

A TeX tree has a conventional directory structure. For example, if your package is called samplepkg, put its style file here:

/path/to/my-texmf/tex/latex/samplepkg/samplepkg.sty

Set TEXMFHOME to the tree’s root, not to the tex/latex directory itself. For the example above, the value is /path/to/my-texmf.

In a shell, you can set it temporarily and test the result:

export TEXMFHOME="$HOME/texmf-custom"
kpsewhich -var-value=TEXMFHOME
kpsewhich samplepkg.sty

The first command sets the variable for that shell and programs launched from it. The second prints the value TeX Live is using. The third should print the full path to samplepkg.sty if TeX Live can find it.

To make the setting persistent, add the export line to a shell startup file that applies to the way you launch your TeX editor. For example, a terminal-launched editor inherits the terminal’s environment. A desktop-launched editor may not read the same startup files, so check its environment if the command-line test works but the editor still cannot find the package.

Check TeX Live’s search paths

Use kpsewhich to inspect what TeX Live is searching:

kpsewhich -var-value=TEXMFHOME
kpsewhich -show-path=tex
kpsewhich samplepkg.sty

-show-path=tex displays the search path for TeX source files. It can be long, because it includes multiple TeX trees. If the last command prints nothing, first check that the file exists in the expected directory and that TEXMFHOME points to the tree root. Also confirm that the variable is set in the environment of the program that needs the package.

For a normal personal tree, TeX Live often finds new files without rebuilding a filename database. If a tree has an ls-R database, or the new file is not found, refresh the database and test again:

mktexlsr "$TEXMFHOME"
kpsewhich samplepkg.sty

Other ways to extend the search path

If you want packages available to every user, use TeX Live’s local system tree, TEXMFLOCAL, rather than changing each user’s TEXMFHOME. The default location depends on how TeX Live was installed. Check it with:

kpsewhich -var-value=TEXMFLOCAL

Writing to this tree may require administrator privileges. After adding files, run mktexlsr on that tree so its filename database is current. Avoid editing files inside TeX Live’s managed distribution trees: package updates can replace them.

For a single extra folder that does not follow a full TeX tree layout, you can extend TEXINPUTS. For example:

export TEXINPUTS="/path/to/extra-tex-files//:"

On Linux, : separates search-path entries. The // asks Kpathsea to search recursively, and the final : tells it to retain the default search path. This can be useful for a one-off collection of input files, but TEXMFHOME is generally clearer for installing packages in a reusable TeX tree.

Changing these search paths is separate from configuring tlmgr’s package repository. A custom tree makes files available to TeX, but it does not make tlmgr manage or update those files.

Common mistakes

  • Setting the tree root too deep. Set TEXMFHOME to the directory containing tex, not to tex/latex or the package’s own folder.
  • Using an irregular folder layout. Put package files under a path such as tex/latex/package-name/ so TeX Live can find and organize them as expected.
  • Replacing defaults accidentally. When extending TEXINPUTS, keep the final colon so the normal TeX search path remains available.
  • Testing in the wrong environment. A variable set in one terminal may not be inherited by a graphical editor launched from the desktop.
  • Assuming tlmgr installs custom files. tlmgr manages packages in its configured TeX Live installation, not arbitrary files placed in a personal tree.

References

  1. TeX Live Guide
  2. Kpathsea: The GNU TeX directory structure and search library

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.