TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


Is there a way to distribute a LaTeX package with a document and to use it during compilation?


At our university, we're writing a lot of lecture summaries with LaTeX. Sometimes those summaries need non-standard packages, or sometimes there are version incompatibilities between packages between different LaTeX distributions / operating systems.

As an example, https://github.com/HSR-Stud/CN1 uses the siunitx package, which changed the name of an option between Texlive 2009 and 2011. Therefore, the document compiles on either Texlive 2009 or 2011 depending on the option name used, but not on both.

There are also cases of packages that are distributed with MikTeX, but not with Texlive (an example would be Picins).


Is it possible to distribute LaTeX packages along with a document and use them during compilation?

As a sidenote, in all our documents Makefiles are used to build the PDF using latexmk, which is included both in Texlive and MikTeX, so custom compile/build options could be passed to the used tools and environment variables could be set. That could be of help.

share|improve this question
perhaps using \begin{filecontents}{nameofpackage.sty}<lines of package>\end{filecontents} before the documentclass? This would create the package in the working directory... Is that the kind of thing? – cmhughes Jan 12 '13 at 20:29
In the specific case of siunitx, provided you set at least one version 1 option in the preamble the updated package will pick this up and use settings and options which are appropriate. – Joseph Wright Jan 12 '13 at 20:29
The search path for packages is: current directory->$LOCALTEXMF->$TEXMF. Create a loacal texmf with your packages and they will be used instead of the ones in $TEXMF – Herbert Jan 12 '13 at 20:47
@Herbert that sounds like the perfect solution, but it doesn't seem to work. I added a "texmf" folder to the project folder that looks like this: hastebin.com/xeciramafe.txt Any clue about why it isn't working? (It works if I place that folder in my homedir) – Danilo Bargen Jan 12 '13 at 20:56
In some cases this can be done, but big packages such as siunitx depend on many others being at a certain version. Only packages that have no dependencies (\RequirePackage) are safe to be distributed along with a document; those with dependencies may or may not work. – egreg Jan 12 '13 at 21:17
up vote 1 down vote accepted

For Linux the search path for TeX is

doc directory -> $TEXMFLOCAL->$TEXMFHOME->$TEXMF

$TEXMFLOCAL is /usr/local/texlive/texmf-local/

$TEXMFHOME is ~/texmf

For $TEXMF and $TEXMFLOCAL you need a texhash when adding files. $TEXMFHOME is searched recursively.

All directories must have a structure compatible to TDS (http://tug.org/tds)

share|improve this answer

Your Answer


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.