Include *.sty file from a super/subdirectory of main *.tex file
This probably isn't relevant to you any more, but here is another way to do what you want. Set up your git repository like this:
mystyle.sty
project/
makefile
project.tex
and put \usepackage{mystyle}
in the preamble of project.tex
.
Compiling project.tex
manually won't work, of course, because mystyle.sty
is not in the same directory as project.tex
.
However, if makefile
contains something along the lines of:
project.pdf: mystyle.sty project.tex
pdflatex project
mystyle.sty: ../mystyle.sty
cp ../$@ $@
then running make
from within the project
directory will cause mystyle.sty
to be copied to the correct place before project.tex
is (this time successfully) compiled.
This way might seem a little bit over the top, but it does combine the best features of other methods.
- If several projects in the same repository require
mystyle.sty
then having a commonmystyle.sty
sitting above them all makes more sense than having a copy in each project directory; all these copies would have to be maintained. - The compilation is portable, in the sense that if you gave me your copies of
mystyle.sty
andproject.tex
then I would (in theory at least) be able to compile manually without needing to modify the files you gave me. For example, I would not have to replace\usepackage{/your/path/mystyle}
with\usepackage{/my/path/mystyle}
.
You can import a style file (mystyle.sty
) into your document in two ways:
- If you have it in your path or in the same folder as the
.tex
file, simply include this line in your preamble:\usepackage{mystyle}
- If you have it in a different folder, you can access using its full path as
\usepackage{/path/to/folder/mystyle}
That said, if you're not sure if the style file is in everyone's installation, simply include it in the same directory and make sure you do git add mystyle.sty
and track it along with the rest of your files (although most likely there won't be any changes to it). There is no need for a parent directory. But if you insist on a different directory, see option 2 above.
It would be better if it were in a subdirectory than in a parent directory, as you can still call the file as \usepackage{subdir/mystyle}
and be certain that you are invoking your style file. However, if you escape out to the parent directory, you never know if the other users have a similarly named folder that is not part of your package, which can result in errors.