4

I am working with multiple LaTeX projects at any given point in time, each of which is stored in a separate git repository. I have also accumulated a set of commands and environments which I am familiar with which help me to save time when writing LaTeX code. My question is how to merge the style file contained in each git repository into a single style file that can be shared across git repositories.


Currently, in each git repository I have a single style file which I put in a localtexmf tree inside the git repository. The file tree hierarchy might look like the following:

project-a/doc1/main.tex
project-a/doc2/main.tex
project-a/localtexmf/tex/latex/mymacros/mymacros.sty

This approach has the following advantanges:

  1. All the documents in the git repository can share the same style file.
  2. The style file is also under version control.

The disadvantage of this approach is that I have multiple style files which share a lot of similar code, e.g.

project-a/localtexmf/tex/latex/mymacros/mymacros.sty
project-b/localtexmf/tex/latex/mymacros/mymacros.sty
project-c/localtexmf/tex/latex/mymacros/mymacros.sty

This results in unnecessary code duplication. Often when I fix a bug or change a command definition, I want the change to occur in all the mymacros.sty files.


What I want to do is to somehow have a single style file that is under version control, but is shared by multiple git repositories. How do I do this?

My operating system of choice is Ubuntu Linux or OS X.

Based on How do you perform version control on TeX-related files that are used in multiple projects?, I suspect that git submodule is part of the answer.

  • Are you on a system which supports symlinks (Unix or admin privileges on Windows)? – Joseph Wright Nov 21 '14 at 18:51
  • @JosephWright See my edit to the question – I Like to Code Nov 21 '14 at 18:53
  • I have a directory, ~/TeX, where I put any personal style files that I use in many places. This directory is in its' own git repository and I have the environment variable TEXINPUTS set to .:~/TeX//: so that it is automatically searched by latex and friends. – Andrew Nov 21 '14 at 19:59
  • @Andrew A problem with the approach you suggest is that if I want to recompile say the 2013-01-01 version of a particular project, this version was compiled with a particular version of the style file which I will have to find by hand because the two versions are not tied together. – I Like to Code Nov 21 '14 at 20:47
  • Yes, this is a potential issue. Typically I find that this is not a problem as most of my changes to these files are backwardly compatible "improvements". Of course, what you can do is also wind back the ~/TeX repository to the date of the 2013-01-01 version and then compile - it is easy enough to find the dates in the git logs. If I needed to do this often then I'd write a hook for simultaneously winding back both repositories. As this is rarely a problem for me I haven't worried about it. – Andrew Nov 21 '14 at 21:08
2

I have a directory, ~/TeX, where I put any personal style files that I use in many places. This directory is in its' own git repository and I have the environment variable TEXINPUTS set to .:~/TeX//: so that it is automatically searched by latex and friends.

As the OP says in the comments, there is an issue in that repositories for the tex files and for the style will not always be in sync, which means that it can happen that an old commit will not compile because it requires a different version of the style files than those appearing in the current version of this. Typically I find that this is not a problem as most of my changes to these files are backwardly compatible "improvements". In any case, if an old commit does not compile then you can wind back the ~/TeX repository to the date of the source file commit version and then compile - it is easy enough to find the dates in the git logs. If I needed to do this often then I'd write a hook/script for simultaneously winding back both repositories. As this is rarely a problem for me I haven't worried about doing this.

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.