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

I am using a Makefile for generating a document from its tex source. The whole project consisting of own input files (.tex,.bib,.eps, ...) and non-pre-installed static input files (cls, sty, bst) is kept under version control (svn) for colloborative writing. I try to avoid messing up the main folder and use subdirectories for output and different kinds of input files. All files which are not available within standard texlive should be in the repository to allow everyone a simple svn checkout and make to create the document. My question is: is there any convenient way which allows me to place all .cls,.sty,.bst into a ./texmf folder with in the document tree:


The Makefile looks like this

LATEX    := pdflatex
ODIR     := ./output
LATEXOPTS:= --output-dir=$(ODIR)

    $(TEXFILE).pdf: $(TEXFILE).tex $(TEXFILE).bib
         $(LATEX) $(LATEXOPTS) $(TEXFILE).tex

Following solution works but as colloborators have to adjust environment variables every time or their .bashrc for this project, I am not really happy about it:

$ export TEXINPUTS=".:./texmf:~/texmf:$TEXINPUTS"
$ make

Changing environment variables within a Makefile is not possible as far as I know.

share|improve this question
up vote 8 down vote accepted

You can in fact that environment variables inside a Makefile (tested with GNU make only). You need to do the following:

export VAR=value without quotes

If you reference the previous value of the same variable you need to use the := assignment instead which expands the value immediately. The normal = is expanding the value at every use and will lead to an recursive assignment, which make detects and reports as an error. There are no quotes required around the value and using them might cause trouble. Also variables must be written as ${VAR} on the right-hand side, not $VAR.

So you can add the following line to your Makefile, at best at the beginning:

export TEXINPUTS:=.:./texmf:~/texmf:${TEXINPUTS}
share|improve this answer

I use latexmk for some document building, and I've wanted something like this for a long time. Especially when I have document and class under version control.

I discovered that you can configure latexmk with a local latexmkrc file in the document's directory. latexmkrc files are just perl code.

So in this workflow, if the class files are in ./texmf you can add the following line to a local latexmkrc:

$ENV{'TEXINPUTS'}='./texmf//:' . $ENV{'TEXINPUTS'};
share|improve this answer
Thanks. This is good to know, too. However, at the moment I still use existing Makefiles and my colleagues are not aware of latexmk. I will give latexmk a try at the next occasion. The customization feature via a latexmkrc file sounds like a neat way to deal with user-dependent preferences. – Hotschke Apr 5 '12 at 17:11
Could you clarify that latexmkrc doesn't need a preceding dot in its name? – einpoklum Jun 20 at 21:04
@einpoklum According to the manual, it will work with or without the dot. – Matthew Leingang Jun 21 at 0:28

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.