-
Notifications
You must be signed in to change notification settings - Fork 9
/
00.gitrevisionnumber.tex
27 lines (26 loc) · 1.22 KB
/
00.gitrevisionnumber.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
% below is some really useful code for automatically inserting the version
% number below the title of the paper. This way we know which version we
% have printed out and can see what has changed since then.
% (uncomment one level to activate -- probably will only work on your Mac)
%
%%================================================================================
%% CALL OUT TO SHELL to get current hg revision number
\newread\myinput
% We use '\jobname.temp' to create a uniquely-named temporary file
\immediate\write18{git log -l1 | grep "^commit" | cut -c-14 > '\jobname.temp'}
\immediate\openin\myinput=\jobname.temp
% The group localizes the change to \endlinechar
\bgroup
\endlinechar=-1
\immediate\read\myinput to \localline
% Since everything in the group is local, we have to explicitly make the
% assignment global
\global\let\gitrevisionnumber\localline
\egroup
\immediate\closein\myinput
% Clean up after ourselves
\immediate\write18{rm -f -- '\jobname.temp'}
%\hgrevisionnumber used to be \myresult
%\dosomething{\myresult}
% via http://stackoverflow.com/questions/2671079/how-can-i-save-shell-output-to-a-variable-in-latex
%%================================================================================