Include *.sty file from a super/subdirectory of main *.tex file

后端 未结 5 1922
滥情空心
滥情空心 2021-01-31 15:58

I want to share a latex document via git with many other people. Therefore we decided to put all the special sty files, that are not present in everyones latex-installation, in

5条回答
  •  长情又很酷
    2021-01-31 16:26

    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.

    1. If several projects in the same repository require mystyle.sty then having a common mystyle.sty sitting above them all makes more sense than having a copy in each project directory; all these copies would have to be maintained.
    2. The compilation is portable, in the sense that if you gave me your copies of mystyle.sty and project.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}.

提交回复
热议问题