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.
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) [1].
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.
[1] https://tex.stackexchange.com/questions/2063/how-can-i-manually-install-a-package-on-miktex-windows.sty
file directly in ~/texmf
it just won't work! He needs to respect the TDS structure. - Arthur Reutenauer
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
~/Library/texmf
. - Philipp
~/texmf
. - Arthur Reutenauer
sudo
in the answer: that certainly shouldn't be there. - Andrew Stacey
TEXMF
was already defined as ...,$TEXMFHOME,...
without the leading !!
in texmf.cnf; thus you didn't need mktexlsr
at that time. I seem to remember from a recent discussion on the TeX Live list that they changed the behaviour around that time. - Arthur Reutenauer
~/Library/texmf
. - Konrad Rudolph
~/texmf
- KeithB
textmf
catalogue anywhere... =( - Tomas Aschan
C:\Documents and Settings\<username>\Application Data\MiKTeX\2.8
or type at the command prompt: kpsewhich -var-value=TEXMFHOME
. - Stefan Kottwitz
ls-R
file. Please elaborate. What does it have to do with the question the OP is asking? Why is this recommended? What goes wrong if you don't delete it? Etc. - Sverre
dnf
but it didn't have tabularray
but I'm thinking if there's a way to update those packages rather than manually - Eduardo Jiménez
tlgmr
throws me this warning instead *** WARNING ***: Performing this action will likely destroy the Fedora TeXLive install on your system.
But it's because it conflicts with dnf install; it's all about your needs - Eduardo Jiménez
All of the other answers cover things quite well, but I thought a slightly different version might be helpful.
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:
C:\Users\<user name>\Appdata\Local\MikTex\<number>\tex\latex\local\
C:\Users\<user name>\texmf\tex\latex\local\
C:\Documents and Settings\<user name>\texmf\tex\latex\local\
~/texmf/tex/latex/local/
/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.
texhash
running. - Joseph Wright
~/texmf/tex/latex/local/
rather than ~/texmf/tex/latex/<package name>
. - cfr
~
directories were an NFS mount :) - Joseph Wright
C:\Users\<user name>\AppData\Local\Programs\MiKTeX 2.9\tex\latex\
- iago
kpsewhich -var-value=TEXMFHOME
not give the trailing tex/latex/local/
part? - zyy
.log
if you are likely dealing with a one-off file or simply a personal install of a standard package (e.g. when one needs to force a particular version of a standard package). The creation of a local
dir is something I saw in I think TLC2, and have used ever since. - Joseph Wright
tex/latex/<whatever>
parts of the log :) - Joseph Wright
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.
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.
See How to register my own packages or classes in a separate drive to TeX Live installation? [1]
[1] https://tex.stackexchange.com/q/20160/2099Tasks -> Refresh file name database
. - FHZ
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).
/usr/local/texlive/texmf-local/tex/latex/
, if on a Unix system. - András Salamon
/usr/share/texmf/
on ubuntu 20.04 - Exceptional NullPointer
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.
~/texmf
on Linux), see Stefan Kottwitz's answer. - Philipp
~/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
Library
resides in your home directory and is not hidden (doesn't start with a dot), so its a perfectly valid place to put user-created files. Plus, on OS X, environment changes in the shell initialization files aren't read by graphical applications. - Philipp
~/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
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
Library
does not start with a dot, it is partly hidden on MacOS
since you need to press the option key to find it under the 'Go' menu, and doesn't show at all in the Finder. I agree that putting personal things in the Library does not feel right. - PatrickT
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
create folder foo
sudo mkdir /usr/share/texmf-texlive/tex/latex/foo
copy the file foo.sty
there
sudo cp foo.sty /usr/share/texmf-texlive/tex/latex/foo/
run texhash
sudo texhash
Works for me with texlive 2009-15 on Xubuntu 12.04LTS
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
mkdir -p ~/texmf/bibtex/{bib,bst}
and NOT mkdir -p ~/texmf/bib/{bib,bst}
as mentioned by jon. - aatishk
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.
C:
. - Speravir
C:
is a Windows thing, I didn't mean it that literally when asking if "this" would work on MacOS and Linux - I only meant specifying a path in \usepackage
). - Sverre
\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
\usepackage
, and my packages have a line \ProvidesPackage
. I get no error or warning messages, and everything works the way it should. - Sverre
/c/tmp/longtable', but the package provides
longtable'. - David Carlisle
\ProvidesPackage
? - Sverre
.sty
files in the same folder as your .tex
file always bugged me, so it's precisely to avoid moving them around that I put a path in \usepackage
, so that I can keep them in the same folder all the time. - Sverre
~/texmf
). I merely suggested an alternative solution that doesn't require you to add, remove, or change anything in your TeX program files. - Sverre
not portable
. My LaTeX is fully portable, so I need an alternative solution. I've updated my answer accordingly. - Sverre
C:\Users\<user name>\texmf\
mentioned by others here, and I believed this was the result of using portable LaTeX. You might be right that I am wrong about that, so I would love to see how I should do it. - Sverre
I've just found this in the MiKTeX documentation [1]. Just FYI:
[1] http://mirrors.ctan.org/systems/win32/miktex/doc/2.9/miktex.pdf6.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 registeredroot
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.
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.
~/Library/texmf
, they will be automatically found. - Juan A. Navarro
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
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 [1].
This works well for me on Linux (ubuntu + TexLive) and Windows (cygwin + MikTex).
[1] https://github.com/peeterjoot/physicsplay/tree/master/TEXINPUTS
, ~/texmf
and texmf-local
exist... - yo'
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
../
) 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
.cls
files? - PatrickT
For Windows (10) users on Miktex (Console 4.2):
Open Miktex Console (4.2) > Settings > Directories and observe the informational links FAQ: Which is the best directory to keep my .sty files? [1] and KB: TEXMF root directories [2]. We'll follow the advice in those links.
Anywhere you like: create a TEXMF root directory, with a structure suitable for your custom latex packages (.sty files). Add your package. E.g. C:\Users\John\Documents\Sda\Code\WritingReadingTech\Markup\Latex\Libraries\texmf\tex\latex\MyPackage\MyPackage.sty
Miktex Console (4.2) > Settings > Directories > [+]. Select the TEXMF root directory. E.g. C:\Users\John\Documents\Sda\Code\WritingReadingTech\Markup\Latex\Libraries\texmf
. Click [Select Folder]. Observe this folder as in the picture above with "Purposes: Generic", "Attributes: User"
In your latex (.tex) source files, existing anywhere on your computer, add a reference to your custom package with \usepackage{MyPackage}
. Build/compile your latex source file. Everything should be as desired.
I found it unnecessary to run Miktex Console (4.2) > Tasks > Refresh File Name Database.
[1] https://miktex.org/faq/local-additionsThis worked for me (Makefile):
KEY := myrepo
TEX := $(shell kpsewhich -var-value=TEXMFHOME)
PWD := $(shell pwd)
link:
ln -s "$(PWD)" "$(TEX)/$(KEY)"
.PHONY: link
Then:
make link
mktexlsr
and point to that directory, e.g.sudo mktexlsr /path/to/your/texmf
. - Tomas Aschan\usetheme{ABC}
tries to expand tobeamerthemeABC.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 - IljaBekbeamerthemeABC.sty
in the same folder as your document? - Tomas Aschan*.tex
and*.sty
files in different places, and let the build system handle the finding of them for you. - Tomas Aschan