57

I use some .sty-files that are not part of texlive and want to have them in a subdirectory of the folder with my main.tex. I used the following line to load the package:

\usepackage{sty/prettythesis}

This works, but compiling the main.tex with xelatex and using rubber gives me a warning:

sty/prettythesis.sty: You have requested package `sty/prettythesis',
but the package provides `prettythesis'. (page 1)

Is there a way to prevent this warning or handle this case without having to include "sty\" in all .sty-files' \ProvidesPackage command or set the TEXINPUTS environment variable (which seems not to be possible from the main.tex itself)?

Bruno
  • 708
  • 1
  • 5
  • 7

4 Answers4

25

I believe this thread here:

talks about precisely the same thing: so it seems, the only alternatives are either using TEXINPUTS environment variable; or using the import package. (note, there is a variant on the import package on ...Including tex files pg 3.)

A bit more about TEXINPUTS:

Hope this helps;
Cheers!

 

EDIT: I hoped that one could set the TEXINPUTS path directly in the tex file (by using \write18 -- and note, some versions of LaTeX use --enable-write18, mine uses -shell-escape to enable \write18; see also this) - but it seems it is not possible:

"... This isn't possible. ... The environment variable of the child process is set, but this hasn't an effect to its parent process (TeX)." (Re: Setting the environmental variable TEXINPUTS within latex - comp.text.tex).

... so, now I just call pdflatex in my Linux bash like this:

TEXINPUTS=.//:$TEXINPUTS pdflatex ./myfile.tex

and then it will resolve directly \usepackage{mypackage} in the myfile.tex file - even if mypackage.sty is in a subdirectory, say ./subdir/mypackage.sty.

user778174
  • 27
  • 6
sdaau
  • 36,975
  • 46
  • 198
  • 278
  • The most portable solution would be to use a `latexmkrc` file with a subdirectory added to TEXINPUTS. See the answer here: https://tex.stackexchange.com/a/474915 – egormkn Apr 27 '21 at 16:22
8

As you discovered, putting the package in a subdirectory (say, ./sty/prettythesis.sty with respect to your main .tex file at ./), and calling the package via

\usepackage{sty/prettythesis}

will successfully load the package, but it will produce the warning

sty/prettythesis.sty: You have requested package `sty/prettythesis',
but the package provides `prettythesis'. (page 1)

If all you want is to get rid of this warning, and you're OK with minor modifications in the .sty file, then you can simply change the package name that it reports, by changing the \ProvidesPackage command to

\ProvidesPackage{sty/prettythesis}

This can be inconvenient if you're going to be moving it around loads, but the modifications load isn't too bad either.

Even better, if what you have in there is a specific, modified version of a standard TeX package (like, say, this patch of natbib), then the change in the package name clearly indicates what package it's providing, and if you reuse the file then it will (most likely) re-raise a warning to prompt you into making sure that you know what you're doing.

Community
  • 1
  • 1
E.P.
  • 342
  • 4
  • 13
6

You can do it in your TeX file without changing your system's environment (do not forget the trailing slash / with each directory):

\makeatletter
\def\input@path{{../one-directory/}{../another-directory/}}
\makeatother

\documentclass{myclass} 
\usepackage{mypackage}

This way, though, may be not recommended for portability. As other answers mention, the "correct" way is to set the TEXINPUTS variable in your system environment before you call latex; in Windows it is (you can place it in a batch file):

set TEXINPUTS=../one-directory/;../another-directory/;%TEXINPUTS%
pdflatex myfile.tex
Alexander Gelbukh
  • 2,104
  • 17
  • 29
  • this presumably also works in overleaf, which is why it is better than the modification of the path on the unix shell. – ivo Welch Nov 06 '21 at 03:53
5

Simply put line below before the call to pdflatex (or latex) in your makefile or build script:

export TEXINPUTS=".:./sty:"

Then reference your package as:

\usepackage{prettythesis}
Rudy Matela
  • 6,310
  • 2
  • 32
  • 37
  • 2
    Doing this make it unable to find other packages, in my case. How to know which default directories to also add to the environment variable? – gigabytes Nov 24 '16 at 08:57
  • 2
    According to the official documentation, it _should_ find system packages. ("man pdftex" in my system says so). Aren't you missing the final colon (":")? – Rudy Matela Dec 20 '16 at 19:51