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.

  • 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. – R. Schumacher May 02 '15 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. – Alexander Gelbukh May 02 '15 at 21:47

1 Answers1

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

David Carlisle
  • 757,742
  • 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. – Alexander Gelbukh May 02 '15 at 21:52
  • @AlexanderGelbukh, no it's same with \graphicspath (in fact \graphicspath is just a local setting of \input@path) – David Carlisle May 02 '15 at 21:59
  • Oops, sorry, you are right! – Alexander Gelbukh May 02 '15 at 22:18
  • 5
    @AlexanderGelbukh I did write that code:-) – David Carlisle May 02 '15 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 Feb 05 '16 at 00:40
  • @cfr well mostly $TEXINPUTS uses kpathsearch which is implemented in C and \graphicspath implements the search in TeX macros. With the speed of things today possibly that doesn't make so much difference if you don't put thousands of directories in \graphicspath (which kpathsea has to handle in the TEXINPUTS) but I wrote those macros and I feel TeX's pain as it looks in each directory in turn:-) If you have .// in your texinputs and all documents have graphics in or below the current directory (the most common case I would guess) then you don't need any setting in the document or arara – David Carlisle Feb 05 '16 at 01:12
  • Sadly, I appear to do things in uncommon ways.... (An IT person once told me I should get a job as a beta tester I was so good at doing weird bug-revealing things within minutes of sitting down with new-to-me software.) And it doesn't work for non-graphics, right? – cfr Feb 05 '16 at 03:11
  • @cfr actually the underlying mechanism was written for \input and is part of the format, not any package (for mainframe and other systems which didn't have path searching) (\input@path) but no top level settings (there are some answers on site about that) adding \graphicspath to locally set \input@path for includegraphics was a throw-away afterthought just added at the time in case anyone should want it:-) – David Carlisle Feb 05 '16 at 07:59