I'm an avid TeX user for quite some time now. I use LaTeX for most of my lecture notes and my assignments. That's why I'm usually working on about half a dozen LaTeX projects at a time. Over the time I have accumulated quite a lot of my own commands and environments which I store in a file makros.tex. I also have one large .bib File to store literature.

Since I only want to have a central copy of this file I used the following method for the last months:

  • Store the centralized files, makros.tex, lit.bib etc in a central folder called includes
  • Create a sym-link to this folder and put this link into my project folder
  • use \include{includes/makros.tex} etc in my project.

Now here is my problem: I started using git a few weeks ago for my C++ projects and became a really big fan of it. Hence I now want to use git for my TeX Projects as well. The Problem is however, that git doesn't really play well with symbolic links. Hence the folder includes is not actually uploaded.

How do you guys treat files you use for every project? I would really be interested in a file structure / workflow that accomplishes the following:

  • The files makros.tex and lit.bib are stored at only one location, in a folder includes/ on my computer.
  • I can include them in every project.
  • When I push my project to GitHub or Bitbucket the folder includes/ also gets pushed, that way, when a friend downloads my repo, he can compile my notes without me having to send him the includes/ folder.

In case this matters: I'm using Mac OS X as my primary and Ubuntu as my secondary OS.

  • 12
    How about creating a git repository for the shared code and include it as a submodule? – Marco Jan 28 '14 at 12:13
  • Tried it out right now, works perfectly. Exactly what I was looking for! – Florian W Jan 28 '14 at 12:45
  • 3
    Note that from the point of view of just including the stuff in TeX, putting your files in a suitable subdirectory of ${TEXMFHOME} is a good solution. Then you do not need the symbolic link although you might want that for use with your version control system, of course. For example ${TEXMFHOME}/tex/latex/makros/makros.tex, ${TEXMFHOME}/bibtex/bib/lit.bib etc. – cfr Jan 29 '14 at 0:49

You can use git submodules. Place the shared code in a directory and create a git repository as usual. Then you can add this repository to other projects as a submodule:

git submodule add <URL> <name>

When you clone the repository you can use the the --recursive switch to automatically pull in the submodules:

git clone --recursive <URL>

Using submodules ensures that the code is not duplicated and it is easy to include the code in other projects. Furthermore, submodules are a git feature and pose no problems for GitHub or Bitbucket.

git submodule - man page

|improve this answer|||||
  • Assuming that I publish the main project on Bitbucket, do I have to publish the "include" repository as well? Or is the data stored inside the main projects repo? – Florian W Jan 28 '14 at 19:15
  • 1
    @FlorianW The data itself is not stored in the main repo, only pointers in .gitmodules, .git/config and the submodule git repo in .git/modules/. If you want to make your repository usable you have to publish the submodules as well, otherwise no one can clone the repositories using --recursive. A non-recursive clone will still succeed but the TeX compilation will fail because of missing files. – Marco Jan 28 '14 at 19:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.