-
-
Save Kraymer/4045011 to your computer and use it in GitHub Desktop.
Make LaTeX git-aware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% 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