I'd like to add 'Sweave.sty' to my search-path, so that I don't need to copy 'Sweave.sty' to every Sweave-Document I create.

I've located 'Sweave.sty' in '/usr/share/R/share/texmf/tex/latex'. I tried to create a symlink to this folder in my package-folder, however, this didn't really work.

Anyway, I think adding this folder to TeXLive's search path would be the most elegant solution. I also found instructions on how to expand the search path in TexLive (here). Well, I seem to be too stupid to understand that :-( Could somebody explain in clear words how I can add the path mentioned above to my search path?

Thank you!

  • Did you run sudo texhash after creating the symlink?
    – Caramdir
    Dec 8, 2010 at 21:01
  • @Joseph: Is there a reason you removed the sweave tag? Even though this is a more general problem, this might be of special interest to other sweave users.
    – Caramdir
    Dec 8, 2010 at 21:03
  • Thank you Caramdir! Didn't try that yet (however it was obvious I needed to update the database somehow). Anyway I would prefer expanding the search path instead of creating a symlink...
    – Marcel
    Dec 8, 2010 at 21:05
  • @Caramdir: Perhaps I'm wrong, but as I see it the underlying question here has nothing to do with sweave: it is about adding an additional path to TeX Live.
    – Joseph Wright
    Dec 8, 2010 at 21:16
  • 1
    @Joseph Wright: Technically you are right, however I can't think of any situation apart from using Sweave where this could be useful...
    – Marcel
    Dec 8, 2010 at 21:24

2 Answers 2


There are (at least) two parameters you may want to set, and two ways to set them (env var vs conf file) and finally you might want the setting to be system-wide or user specific. Since all this is more or less orthogonal, it makes like 8 possibilities.

First, you may change either TEXINPUTS or TEXMF. The former acts only of TeX's input search path, the later is also used by other tools (imagine the tree contains fonts, bibtex or makeindex styles, etc.) With TEXINPUTS, you should append (or preppend, if files from the new tree should override other versions) /usr/share/R/share/texmf/tex//, separated with a :. For TEXMF, should need to insert the same path where you want inside the braces in the current definition.

Second, environment vs configuration file. For the environment, adding something to TEXINPUTS is easy, but for TEXMF you need to copy the full definition, so that it may look like TEXMF='{$TEXMFCONFIG,$TEXMFVAR,$TEXMFHOME,$TEXMFR,...,$TEXMFDIST}' (with an appropriate definition of a TEXMFR environment variable). Editing the configuration file goes the same for TEXMF, but it's less convenient if you want to change TEXINPUTS since you also need to edit the various TEXINPUTS.format for each format you intend to use. With and envvar, it is easier, since setting TEXINPUTS=:$TEXMFR/tex// in the environment will insert the appropriate TEXINPUTS.format from the conffile before the leading colon.

Finally, user vs system. If you chose to use envvars, I refer you to your favourite shell's (and desktop environment) documentation. For configuration files, it should be noted that, system-wide, there are usually two texmf.cnf files which are both read. You should edit the first one returned by kpsewhich texmf.cnf (in case of doubt, look at the comments in the file). Include only your definitions, eg:

TEXMFR = /usr/share/R/share/texmf

(this is my preferred option btw). Note that if you use a packaged (by Debian or other) version of TeX Live, this may change, see Sylvain's answer. If you want to proceed for a single user, it's harder, because you should place a full (edited) copy of the original texmf.cnf file in some place (~/.texlive2010/texmf-config/web2c would be a ratonal choice) and defined an environment variable TEXMFCNF pointing to that directory.

I hope I didn't got you confused with too much choices, but I thought it might be interesting to explore the different options. If you have admin rights, I'd recommend editing the system-wide additional texmf.cnf to define a TEXMFR and adding it to the definition of TEXMF, as explained above.

  • There is a missing comma in your TEXMF code, it should be TEXMF = {$TEXMFCONFIG,$TEXMFVAR,$TEXMFHOME,!!$TEXMFSYSCONFIG,!!$TEXMFSYSVAR,!!$TEXMFMAIN,!!$TEXMFLOCAL,$TEXMFR,!!$TEXMFDIST} (It took me 20min to figure this out ...)
    – Sebastian
    Apr 6, 2020 at 11:43
  • (Apart from that, a great answers, and the clean way of doing it! Thanks!)
    – Sebastian
    Apr 6, 2020 at 11:43

Not sure I understood the question, but let's try...

  • If you simply want to add that path for yourself, add the path you provided to the TEXINPUTS variable.

    For instance, if you use sh or bash or ksh as shell


    export TEXINPUTS

    (something like setenv TEXINPUTS ${TEXINPUTS}:/usr/share/R/share/texmf/tex/latexunder csh and tcsh).

    If that does the trick, add the corresponding command to your .bash_profile (or the variant for your shell).

  • If you want that change to be applied to all users you might want to create a file in /etc/texmf/texmf.d/ (or the equivalent in your Linux distribution) for instance named 99R.cnf or to modify the existing 45TeXinputs.cnf and add what was given in the link you provided, i.e.

    TEXINPUTS.<command> = <existing path>;/usr/share/R/share/texmf/tex/latex

    However it is probably simpler to add the commands of the first solution to a global /etc/profile (or /etc/profile.d/whatever.sh)

  • 1
    In the first solution, you should add a trailing // so that subdirectories are searched, too. In the second one, don't forget to run update-texmf (as root) so that you new snippet is taken into consideration. Also, according to this document, "earlier entries override any later entries" so I guess you need to name your snippet 00R.cnf instead. Finally, note that this whole /etc/texmf/texmf.d/ stuff is completely specific to Debian (and derived or similar).
    – mpg
    Dec 9, 2010 at 3:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .