I have many TeX files for to get their PDFs versions and I put a date in each of them like as last updated data.

updated \today

But this is tricky, because every time that I compile them, this date would change in function of the day that I do it. So, because I track my changes with Git I want to change the \today command with the last date when the file was commited; and a file could be commited or not in the last change.

I use TeXLive distribution on Windows and I have a make.bat file for an automatic compilation of the files:

@echo off
for %%G in ("*.tex") DO (call :singlefile "%%G")
goto :eof

echo compiling %1
latexmk -xelatex -bibtex- -silent -auxdir=output -outdir=output %1
goto :eof

My Git version: 1.9.4.msysgit.0

  • 4
    Welcome to TeX.SX! Have you heard of the gitinfo package and its recent successor, gitinfo2? I don't know the specifics, but I'd say they're your best chance.
    – jub0bs
    Aug 8, 2014 at 18:02
  • Let me check it.
    – Fernando
    Aug 8, 2014 at 18:55
  • I believe gitinfo2 will do what you want, and more. However, it gives you access to commit dates, rather than individual file dates. [Full disclosure: I am the author and current maintainer] Aug 8, 2014 at 21:51
  • BTW, gitinfo is now deprecated for new work, and is kept on CTAN and in the distributions so that existing documents don't break. If you decide to use this, please use gitinfo2. Aug 8, 2014 at 21:53

2 Answers 2


After checking documentation of gitinfo2 package, I got this file/directory structure:

  • main directory
    • file.tex
    • other.tex
    • gitexinfo.sty (copied from gitinfo2)
    • gitinfo2.sty (copied from gitinfo2)
    • make.bat

Then I updated my make.bat file for to get the gitHeadInfo.gin file. With this change I avoid to use git hooks; I had just to reformat it for batch-Windows style:

@echo off

set GitInfoFormat=\usepackage[%%^

git --no-pager log -1 --date=short --pretty=format:"%GitInfoFormat%" HEAD > .git/gitHeadInfo.gin

for %%G in ("*.tex") DO (call :singlefile "%%G")
goto :eof

echo compiling %1
latexmk -xelatex -bibtex- -silent -auxdir=output -outdir=output %1
goto :eof

At this point, $FIRSTTAG and $RELTAG does not work with this, but I do not need them currently. And I think I can survive using the commit dates.

With this environment, the workflow would be:

  1. Do changes.
  2. Testing results with make.bat.
  3. Commit changes.
  4. Compile with make.bat.


  • Looks reasonable, though it may be a bit brittle. I'm sure you've already thought over the cases where the working copy has uncommitted changes, and also what happens when you start adding folder structure. That's why I think I'd recommend using the hooks. Aug 10, 2014 at 13:46
  • Currently, my workflow is 1) Do changes, 2) Testing results with make.bat, 3) Commit changes, 4) Compile with make.bat.
    – Fernando
    Aug 10, 2014 at 19:57

Here is an alternative solution that runs with gitinfo2. Hence I really like gitinfo2; the hooks mechanism proposed never satisfied me.

Lie Phersho, I ended up doing Makefile and shell scripts, but they weren't properly handled by my LaTeX editor and were not working on all platforms.

Finally, I ended up writing a kind of plugin for latexmk. latexmk is a nice tool that handles nicely the multiple compilations runs of LaTeX as well as the bibliographies. And last but not least, latexmk is working with most LaTeX editors.

This plugin is named gitinfo2-latexmk and is available on GitHub

Disclaimer: I'm the author of that plugin.

The setup is pretty easy :

  • download the plugin gitinfo2.pm (Perl module)
  • add one line in your .latexmkrc file

Once these two small steps are done, no more boilerplate is needed. Each time you, or your LaTeX editor, run latexmk, the git information is ready for the package gitinfo2.

  • I'll try it later. It looks like it'll be successful
    – Fernando
    Feb 16, 2018 at 23:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .