8

How to specify path for additional packages in the LaTeX file itself?

For graphics, you use \graphicspath{{a}{b}}, and then \includegraphics{file} finds b/file.pdf. EDIT: it should be \graphicspath{{a/}{b/}}, with slashes at the end.

For \input, you use \def\input@path{{a}{b}}, and then \input{file} finds b/file.tex. EDIT: \def\input@path{{a/}{b/}} is the answer, with slashes at the end.

Can I use a similar construction for \usepackage, so that \usepackage{mystuff} would find b/mystuff.sty?

I know I can mess up with system configuration or environment variables, but I prefer to specify this in the file itself, so that my files could be compiled on another computer.

I know that I can simply use \usepackage{b/mystuff}, but it generates a warning You have requested b/mystaff but the package provides mystuff, and it is less portable -- for example, it requires knowing in which specific folder mystuff.sty is.

2
  • 1
    If the packages have been properly installed on a given computer then the {\usepackage} command will find them without any path information in the LaTeX file. Essentially the File Name Data Base must properly be refreshed after the package file have been saved in the proper locations. If you are using a package not normally installed by a user (non-CTAN) for a LaTeX distribution, then the package files can be placed in the same folder as the *.tex file. Because the LaTeX compiler always looks in the current folder before it uses the FNDB. Commented May 2, 2015 at 21:41
  • 1
    @R.Schumacher Thank you! Obviously in my case the packages are not properly installed, otherwise I would not ask. I do not want to properly install them because I want to be able to send the whole tree to a colleague who would not "properly install" my stuff on his computer. I do not want to copy the packages to the current folder because I want them to be used from different folders without copying and do not want each my folder to be full of packages. Commented May 2, 2015 at 21:47

1 Answer 1

6

\usepackage is a wrapper around \input so \input@path applies to that just as well, but it is better not to set \input@path and just set TEXINPUTS appropriately

8
  • Yes, it works! My problem was that I specified \def\input@path{{a}{b}}, and it should be \def\input@path{{a/}{b/}}. Apparently with \graphicspath it's different. Commented May 2, 2015 at 21:52
  • @AlexanderGelbukh, no it's same with \graphicspath (in fact \graphicspath is just a local setting of \input@path) Commented May 2, 2015 at 21:59
  • Oops, sorry, you are right! Commented May 2, 2015 at 22:18
  • 5
    @AlexanderGelbukh I did write that code:-) Commented May 2, 2015 at 22:19
  • The trouble with TEXINPUTS is that you can't easily use it with arara and you can't easily otherwise set it in the .tex file itself. At least, that's how I've understood it. I want to set it in the file and then know I can compile it without needing to remember a specific command line required for that specific case. Is there a disadvantage to this method? I know TEXINPUTS is meant to be better, but I'm not clear how so which makes it hard not to be impressed by the many disadvantages of the method.
    – cfr
    Commented Feb 5, 2016 at 0:40

You must log in to answer this question.

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