# Where do I place my own .sty or .cls files, to make them available to all my .tex files?

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

Say I have the package file commonstuff.sty (or myprettyclass.cls), 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.

• Is there a way to place it in an arbitrary directory and point to it? (for portability) – IljaBek Mar 2 '14 at 11:41
• @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 Aschan Mar 2 '14 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 – IljaBek Mar 2 '14 at 19:18
• @troyaner: Have you tried putting beamerthemeABC.sty in the same folder as your document? – Tomas Aschan Mar 2 '14 at 21:02
• @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 Aschan Mar 4 '14 at 7:59

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. This has the advantage that it is not necessary to update the package database as TeX searches your personal texmf tree directly. If there is an ls-R file in your home texmf tree you can safely delete it as TeX will not use it anyway. (Note: this assumes your personal tree is on a local file system: users with remotely-mounted home folders may still need to hash.)

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.

• 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
• 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. – Andrew Stacey Aug 5 '10 at 14:30
• 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
• @Philip: Not if you use TeX Live. For TeX Live it's always ~/texmf. – Arthur Reutenauer Aug 5 '10 at 15:17
• @Arthur: No. I have TeX Live 2009 on OS X 10.5 and the default location is, as Philipp has said, ~/Library/texmf. – Konrad Rudolph Aug 5 '10 at 18:30

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 10 (and miktex)
C:\Users\<user name>\Appdata\Local\MikTex\<number>\tex\latex\local\
• Windows Vista/7 C:\Users\<user name>\texmf\tex\latex\local\
• Windows XP C:\Documents and Settings\<user name>\texmf\tex\latex\local\
• Linux ~/texmf/tex/latex/local/
• Mac OS X /Users/<user name>/Library/texmf/tex/latex/local/

Note: the local/ folder might not exist; in this case, go ahead and create it.

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.

• @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
• I don't think you've ever needed a database for TeX Live with TEXMFHOME. I've never needed it on Mac, starting around 2002. Admittedly, that was before TL was available for Mac, so gwtex etc. I've never seen the point of using ~/texmf/tex/latex/local/ rather than ~/texmf/tex/latex/<package name>. – cfr Sep 10 '17 at 21:35
• @cfr If you have ii on a network share under some circumstances it is, or at least was, necessary. – Joseph Wright Sep 11 '17 at 5:58
• Ah. Thank you for the explanation. Is/was that true on Linux, too? – cfr Sep 11 '17 at 12:52
• @cfr I got the information from some Linux users on an older 'big' system, where their ~ directories were an NFS mount :) – Joseph Wright Sep 11 '17 at 12:57

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.

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 !

Afterwards, select General tab and press Refresh FNDB button.

If you cant find MiKTeX Options (Admin) you may have a newer installation that instead uses MiKTex Console. For this version, simply go to the Packages tab and click the database icon.

## Registering to TeX Live

• I would like to inform that in the versions of MikTeX that includes the "MikTeX Console" (after 2018-02-26) the refresh has been replaced to Menu Tasks -> Refresh file name database. – FHZ Feb 6 '20 at 2:15

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).

• 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
• For me it was /usr/share/texmf/ on ubuntu 20.04 – Exceptional NullPointer Feb 1 at 2:50

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.

• @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
• 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
• @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
• @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
• +1 on this answer for project-specific sty directories export TEXINPUTS=".:./sty:. So, in /home/me/my_thesis folder, it will search for custom stys in /home/me/my_thesis/sty. (Put that TEXINPUTS binding just inside your per-project makefile). – Rudy Matela Feb 25 '14 at 13:13

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

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


or

/usr/share/texmf-dist/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 the file foo.sty there

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

3. run texhash

sudo texhash

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

• 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
• 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 '14 at 3:08
• Note that for bibtex, you need to have the following: mkdir -p ~/texmf/bibtex/{bib,bst} and NOT mkdir -p ~/texmf/bib/{bib,bst} as mentioned by jon. – aatishk Nov 23 '15 at 11:36
• Using Ubuntu 20.04 I had to sudo mkdir /usr/share/texmf/tex/latex/foo/ and the rest was the same (with the said directory, obviously) – Yair Daon Jul 20 '20 at 6:21

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 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.

• 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
• Your suggestions were not working until I changed my class name from something-else.cls to somethingelse.cls. Apparently the hyphen was causing a problem. No such problem with my style file with or without a hyphen... Having fixed the name, your suggestions work. – PatrickT May 22 '17 at 15:47

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.

• 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
• 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
• 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
• @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
• 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 am using a quick fix to this issue since I work mainly on a USB stick and don't want to touch to the tex folders the computers I am using.

Indeed, you can specify backward directories to \usepackage, then you don't have to know the exact full path but only the relative path from your .tex to your .sty file.

An example: given a portable hard disk D, I have in D:/latex/files/ my .tex files and in D:/latex/packages/ some packages I want to use, then you can write \usepackage{../packages/mypack.sty}

Not sure if this works on windows however

• Hi and welcome, i did some additional code markup. You can have a look at our starter guide to familiarize yourself further with our format. – Johannes_B Nov 26 '14 at 13:35
• This (using ../) will most likely not work because of security restrictions. And it's much better to move these files in a separate texmf tree. – Martin Schröder Nov 26 '14 at 13:39
• Welcome to TeX.SX! Sure, this approach works to some extent, but I don't see any addition with respect to Sverre's answer. – Claudio Fiandrino Nov 26 '14 at 13:39
• @ClaudioFiandrino the main point was that you don't need the full path, meaning you can copy and paste your folder everywhere and it still works – ClementWalter Nov 26 '14 at 14:53
• How do you handle .cls files? – PatrickT May 22 '17 at 15:28

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).

• 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? – yo' May 1 '14 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 '14 at 21:34
• 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... – yo' May 1 '14 at 21:37

This worked for me (Makefile):

KEY := myrepo
TEX := $(shell kpsewhich -var-value=TEXMFHOME) PWD :=$(shell pwd)

ln -s "$(PWD)" "$(TEX)/\$(KEY)"

make link