Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I know how to define a package - but how do I make it available (to myself) at all times?

Say I have the package file commonstuff.sty, that I want to be able to include in any .tex file I create on my computer. Where do I put it? Do I need to run some installer on it, or is it enough to keep it in a certain folder?

Note: I know I can just place it in the same folder as the .tex file, but that's not what I'm after here. I'm looking for a way to "install" the package centrally on my computer.

share|improve this question
    
Is there a way to place it in an arbitrary directory and point to it? (for portability) –  troyaner Mar 2 at 11:41
3  
@troyaner: If you want portability of your documents, you could ship your own packages with the file - *tex will find them if they're in the same folder as the document. If you want to be able to actually install to a custom directory, you can just run mktexlsr and point to that directory, e.g. sudo mktexlsr /path/to/your/texmf. –  Tomas Lycken Mar 2 at 17:17
    
the first solution is the one I was asking for. In case of beamer environment \usetheme{ABC} tries to expand to beamerthemeABC.sty and does not accept paths. This is my usage case for pointing to a directory... not sure if it's a completely different case compared to the OP's, but other posts redirect here –  troyaner Mar 2 at 19:18
    
@troyaner: Have you tried putting beamerthemeABC.sty in the same folder as your document? –  Tomas Lycken Mar 2 at 21:02
1  
@troyaner: An alternative approach would be to use some kind of build system in which you can specify a source directory and a build directory. That way, you could have your *.tex and *.sty files in different places, and let the build system handle the finding of them for you. –  Tomas Lycken Mar 4 at 7:59

11 Answers 11

up vote 110 down vote accepted

You could create a folder below your TeX home directory and put your .sty file therein. Use this command at the command prompt to find out where:

kpsewhich -var-value=TEXMFHOME

On my computer it shows

C:/Users/stefan/texmf

but it might also be ~/texmf/ on a Linux or Unix computer.

Following the TeX directory structure, you should place your file in a subdirectory like ~/texmf/tex/latex/commonstuff/, according to Arthur's comment below.

Afterwards it might be necessary to update the package database. Use a package manager like mpm or tlmgr or run at the command prompt texhash or mktexlsr. On some Linux systems it could be necessary to use sudo, like sudo mktexlsr.

Regarding MiKTeX, have a look at the section "Installing sty or cls files" in the answer to the question How can I manually install a package on MikTex (Windows).

You can then verify what file will be used with:

kpsewhich filename.sty

This will show the path to the file picked up by the TeX implementation.

share|improve this answer
12  
If he puts his .sty file directly in ~/texmf it just won't work! He needs to respect the TDS structure. –  Arthur Reutenauer Aug 5 '10 at 14:11
7  
On Linux, so long as you've put the file within the TEXMFHOME tree (in a suitable place) then you simply run texhash on that directory. For example, if TEXMFHOME points to /home/astacey/texmf then texhash /home/astacey/texmf will do, no need for sudo. –  Loop Space Aug 5 '10 at 14:30
13  
@Andrew: Actually, in recent releases of TeX Live, you don't even need to run mktexlsr on TEXMFHOME; kpathsea searches the directory by default (the TEXMFHOME hierarchy is assumed to be small, in general, so that a recursive search won't affect performances too much). It's been so since 2007, I think. –  Arthur Reutenauer Aug 5 '10 at 15:08
2  
It is not necessary to run texhash or mktexlsr in the TEXMFHOME tree when the default configuration of TeX Live is used. –  Philipp Aug 5 '10 at 15:11
7  
Just for completeness: The default location of the home TEXMF tree on Mac OS X is ~/Library/texmf. –  Philipp Aug 5 '10 at 15:14

It depends a bit on your OS and on your LaTeX distribution.

The standard answer for Unix-like OSes is either in your local texmf tree or your home texmf tree. For some guidance as to which to choose, see this entry on the UK TUG FAQ.

share|improve this answer

The .sty files need to be put it some subdirectory of tex/latex in a texmf tree. Those trees have a rather fixed structure, but their location may vary according to your OS and TeX distribution. If you use Unix (including Mac OS) and TeX Live, there's by default a hierarchy

/usr/local/texlive/2009/texmf
/usr/local/texlive/2009/texmf-dist
/usr/local/texlive/texmf-local

as well as other directories. You want to put it in the texmf-local directory, not in the other directories that are managed by the TeX Live installer; when you upgrade TeX Live, your package may be overwritten. The texmf-local hierarchy, as the names hints, is for local packages managed by you; it won't be touched by updates (which is also why it's directly under the texlive directory, and not texlive/2009, for instance).

You may also choose to create a directory called texmf in your home directory, and the package will be visible only to you, not the other users on your computer.

On Windows with MiKTeX, I believe the directory for local installs is C:\Localtexmf by default.

In any case and whatever your distribution, you have to place the .sty file inside .../texmf-local/tex/latex and not directly in the root directory; it's just won't work otherwise.

Then, if you've installed the package in your home directory, you have nothing to do. If you've put in texmf-local, on the other hand, you need to run the utility mktexlsr (or texhash, it's an alias).

share|improve this answer
2  
I second Arthur's recommendation to use /usr/local/texlive/texmf-local/tex/latex/, if on a Unix system. –  András Salamon Aug 5 '10 at 16:30

On Linux, you can pick any directory you like, and then add a line like

export TEXINPUTS=".:~/latex:"

to your .bashrc file (you can add multiple directories, separated by colons. I think you do need the '.' in the beginning). There may be something similar in Windows. I find this easier, since it separates "my" stuff from the texmf tree. Probably not great if you're writing a big package, but handy for some small things you just want to share between all your projects.

share|improve this answer
3  
@Neil: No, you don't need the dot in the variable, it's there by default. You do need the trailing colon, though, or the system directories won't be searched at all. –  Arthur Reutenauer Aug 5 '10 at 15:10
4  
This is not the best solution. There is already a standard user-specific TEXMF tree (~/texmf on Linux), see Stefan Kottwitz's answer. –  Philipp Aug 5 '10 at 15:13
3  
@Philipp: On my Mac OS X system, the user-specific TEXMF tree is inside ~/Library, which contains random applications' preferences, and other stuff that I haven't put there. It doesn't feel like "my" directory, and I won't remember to look there when I'm (say) copying my preferences to another computer. I really do prefer having my own .sty files in a directory I remember and regularly backup, and using TEXINPUTS. So I will repeat my opinion from the comment I hastily deleted: this is the best solution as far as I can see. –  ShreevatsaR Aug 5 '10 at 20:36
    
Note that the question is about a .sty file with common preamble stuff and definitions you wrote yourself (and will frequently edit as you think of new useful definitions and macros, presumably), not a package you downloaded and were trying to install on the system. For the latter, I agree it's better to place in the texmf tree and forget about it. –  ShreevatsaR Aug 5 '10 at 20:49
6  
@Philipp: If you have a good memory or use only one computer, I'm sure ~/Library is fine. But I for instance have all my config files (bash, emacs, etc.) and some other stuff in one directory that I keep synced between several computers running Mac OS X, Linux, and Solaris. Obviously, having to update files at several different paths separately on the different computers each time is impractical—and as I said, when I reinstall OS or copy preferences, I'm very likely to forget ~/Library. Nothing I've seen here convinces me this answer is not the best solution… but whatever works for you. :-) –  ShreevatsaR Aug 10 '10 at 3:15

All of the other answers cover things quite well, but I thought a slightly different version might be helpful.

There are two parts to telling TeX about a new .sty file. First, you have to put it in the 'right' place and second you need to update the database TeX uses to find files. The place to put the file depends on your operating system. Assuming you have a standard installation, this will probably be

  • Windows XP C:\Documents and Settings\<user name>\texmf\tex\latex\local\
  • Windows Vista/7 C:\Users\<user name>\texmf\tex\latex\local\
  • Linux ~/texmf/tex/latex/local/
  • Mac OS X /Users/<user name>/Library/texmf/tex/latex/local/

A few of notes on that. First, on Windows the 'Users' part of the location is language dependent. Second, I've represented your home/user folder as '<user name>': this will obviously be dependent on your system. The folder I've indicated may well not exist: you may just have the texmf part, bits within that or nothing at all. The file location is important, and although you could just put your file inside texmf/tex/latex is is usual to keep things organised by package. The local folder is reserved for stuff installed on individual machines.

Letting TeX 'know' about the file means running a program that builds a database of file locations. There are graphical interfaces to do this, but the way that works on all operating systems is to use the Command Prompt/Terminal and type texhash. This will build the databases for your tree (the one that is in your home folder). Once the 'hash' is created TeX should be able to find your file. For recent TeXLive distributions, this step is not necessary for files in the local folder.

share|improve this answer
1  
@Juan. Depends on your TeX installation. For recent TeX Live's that is true, but as I understand it older ones do need texhash running. –  Joseph Wright Jan 26 '11 at 10:52

For me, using MAC OS X with standard MacTeX, the above answer were only partially helpful. I couldn't find the directory ~/Library/texmf.

I did the following. Assume that you want to add mystyle.sty to your TeX. Create the directory ~/Library/texmf/tex/latex and place mystyle.sty in it. Afterwards invoke texhash ~/Library/texmf/.

This worked for me.

share|improve this answer
1  
You don't need to run texhash for files added in ~/Library/texmf, they will be automatically found. –  Juan A. Navarro Jan 26 '11 at 10:28
    
@Juan: will they be found without any action from my side? –  Dror Jan 27 '11 at 12:31
    
yes, see the comments on the accepted answer about TeX Live (which is what MacTeX installs). –  Juan A. Navarro Jan 27 '11 at 12:39

As already mentioned by Arthur, .sty or .cls files must be in some subdirectory of tex\latex which can be in any directory of any drive.

See the following screenshot, it shows how the path to my packages and classes is.

enter image description here

I will explain two cases, registering to MikTeX and registering to TeX Live.

Registering to MikTeX

Open Settings (Admin), select Roots tab, and add my path E:\A\My LaTeX\MyLibrary.

Note that the trailing \tex\latex\misc must not be included !

enter image description here

Afterwards, select General tab and press Refresh FNDB button.

enter image description here

Registering to TeX Live

See How to register my own packages or classes in a separate drive to TeX Live installation?

share|improve this answer

The other answers provided to this question all suggest to put your .sty files in the folder /texmf/ in your user profile folder (although there doesn't seem to be any agreement on what exactly you need to do after that).

This will, however, not work if you (like me) are using a portable LaTeX program, because then there won't be any such /texmf/ folder on your computer.

An alternative solution is therefore to put your .sty files (e.g. foo.sty) in any folder you'd like (e.g. C:/foo/), and then simply specify the path where you keep your .sty file when you load it in the preamble:

\usepackage{C:/foo/foo}

To avoid errors or warning messages, be sure to give the path also in your .sty file:

\ProvidesPackage{C:/foo/foo}

To maintain full portability of your LaTeX program, you can put your .sty files in a LaTeX subfolder, e.g. C:/texlive/foo/.

This way you can keep all your .sty files in one single place on your computer, and include the same path with \usepackage in all your .tex documents.

share|improve this answer
1  
But this is not at all portable. Already another Windows user can have put the individual package in another folder, other operating systems do not even know paths starting with C:. –  Speravir Apr 30 '13 at 20:27
1  
The way you apparently understand and answer the question it had to be closed as “too localized”. Happily other users answered for general use. This said if you would add some strong warning in your answer it would be a lot better. –  Speravir Apr 30 '13 at 21:30
5  
The argument to \usepackage is a pagckage name not a file path. If the packages that you include this way have a\ProvidesPackage line (as packages should have) then the use described here will produce a warning that the name used is incorrect. Unfortunately (due to compatibility with LaTeX2.09) ProvidesPackage is not mandatory and supplying a path does not give an error or warning in that case, however that is a lack of error checking by the system, it does not mean that this is supported syntax. –  David Carlisle May 5 '13 at 9:28
3  
@Sverre oh yes exactly, but that means your package can not be installed in any other location, which makes it a rather odd package. the name in the ProvidesPackage and the name in the usepackage should be the same. any relationship to any path on the file system is an accident of the implementation. –  David Carlisle May 5 '13 at 10:46
2  
the standard way to do that is to put your local files in ~/texmf so they are in the standard search path or any other directory of your choice so long as you add it to the TEXINPUTS path. –  David Carlisle May 5 '13 at 10:51

I've just found this in the MiKTeX documentation. Just FYI:

6.2. Which is the best directory to keep .sty files where MiKTeX can find them? MiKTeX Package Manager takes care of the proper installation of well known LaTeX packages.

If (for some reason) you have to install a package by hand, then you should copy the input files into the directory tex\latex\misc relative to a registered root directory. For example:

Create the root directory C:\Local TeX Files.

Create the sub-directory tex\latex\misc and copy your input files (*.sty, *.cls) here.

Register the root directory (C:\Local TeX Files) in MiKTeX Options.

For more information, read the section Integrating Local Additions in the MiKTeX manual.

share|improve this answer
2  
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format –  texenthusiast Aug 9 '13 at 2:22

Using texlive on Ubuntu, the *.sty files are located at

/usr/share/texmf-texlive/tex/latex/

Adding a new style foo.sty usually means

  1. create folder foo

    sudo mkdir /usr/share/texmf-texlive/tex/latex/foo

  2. copy foo.sty there

    sudo cp foo.sty /usr/share/texmf-texlive/tex/latex/foo/

  3. run texhash

    sudo texhash

Forks for me with texlive 2009-15 on Xubuntu 12.04LTS

share|improve this answer
2  
Note that Stefan's answer (the one with the most upvotes) describes a much easier way to do this on Linux. For LaTeX: create a folder structure that mimics your TeX-tree: mkdir -p ~/texmf/tex/latex/foo; and for bibtex: mkdir -p ~/texmf/bib/{bib,bst}. Put foo.sty in foo, and put custom bst files in bst. Note that this is not a 'system-wide' location, but one personal to you; but it is easier to deal with (no su needed), and doesn't need texhash because it is always searched automatically. –  jon Nov 8 '13 at 14:09
1  
Note that user39700's answer is wrong even for system wide installation. The files should be installing into the local tree, not the system one managed by the package manager. That is not to say it will not work. It will. But it is not the way it should be done for a Linux distro. –  cfr Jan 21 at 3:08

To avoid tex distribution or operating system specific requirements on where to put stuff and what to run to get it to be found I use a GNUmakefile rule of the following form:

%.sty : ../%.sty
  cp $^ $@

Each subdirectory for which I build latex code references this rule, resulting in the .sty file to be copied locally to that directory before pdflatex is invoked (using suitable dependency rules). See for example, notes/make.rules and notes/phy452/GNUmakefile in my physicsplay github repo.

This works well for me on Linux (ubuntu + TexLive) and Windows (cygwin + MikTex).

share|improve this answer
    
And what if I compile TeX files all around my disk space, and not in any nicely organized structure? Like: papers in Dropbox, talks here, Copy-editor job there, etc. Am I supposed to create a makefile for all my >100 projects a year? –  tohecz May 1 at 20:39
    
Would you really be using personal .sty files in so many ad-hoc locations? Even so, there isn't anything that would prevent such a method from being used even from many locations (since the makefiles in each location can be trivial, including just an include of the make rules). –  Peeter Joot May 1 at 21:34
1  
For one, I use my own beamer style, and the class of the journal I work for. That already makes the process way to complicated. Especially since TEXINPUTS, ~/texmf and texmf-local exist... –  tohecz May 1 at 21:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.