Skip to content

Instantly share code, notes, and snippets.

@Kraymer
Forked from SamWhited/gitparse.tex
Created November 9, 2012 10:21
Show Gist options
  • Save Kraymer/4045011 to your computer and use it in GitHub Desktop.
Save Kraymer/4045011 to your computer and use it in GitHub Desktop.
Make LaTeX git-aware
% A few example commands for a more git-aware LaTeX.
% Note that this requires you to run pdflatex/xelatex/etc. with the
% `--shell-escape' option which is extremely unsafe. Use with care
% and *never* use with plain TeX.
% Print the short-hash of the current commit
\newcommand*{\gitrev}{%
\immediate\write18{%
rm gitrev.tex 2> /dev/null; git rev-parse --short HEAD > gitrev.tex
}%
\InputIfFileExists{gitrev.tex}{}{}\unskip%
\immediate\write18{%
rm gitrev.tex 2> /dev/null
}%
}
% Print `*' if the index is dirty
\newcommand*{\gitdirty}{%
\immediate\write18{%
rm gitdirty.tex 2> /dev/null; git diff-files --quiet || echo "*" > gitdirty.tex
}%
\InputIfFileExists{gitdirty.tex}{\endlinechar=-1\relax}{}\unskip%
\immediate\write18{%
rm gitdirty.tex 2> /dev/null
}%
}
% Print `+' if there are uncommitted files in the index
\newcommand*{\gituncommitted}{%
\immediate\write18{%
rm gituncommitted.tex 2> /dev/null; git diff-index --quiet --cached HEAD || echo "+" > gituncommitted.tex
}%
\InputIfFileExists{gituncommitted.tex}{\endlinechar=-1\relax}{}\unskip%
\immediate\write18{%
rm gituncommitted.tex 2> /dev/null
}%
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment