8

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.

\usepackage[yyyymmdd]{datetime}
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

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

My Git version: 1.9.4.msysgit.0

jub0bs
  • 58,916
Fernando
  • 131

2 Answers2

5

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[%%^
        shash^={%%h},^
        lhash^={%%H},^
        authname^={%%an},^
        authemail^={%%ae},^
        authsdate^={%%ad},^
        authidate^={%%ai},^
        authudate^={%%at},^
        commname^={%%an},^
        commemail^={%%ae},^
        commsdate^={%%ad},^
        commidate^={%%ai},^
        commudate^={%%at},^
        refnames^={%%d},^
        firsttagdescribe^={$FIRSTTAG},^
        reltag^={$RELTAG}^
    ]{gitexinfo}

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

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

:singlefile
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.

Thanks.

Fernando
  • 131
  • 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. – Brent.Longborough Aug 10 '14 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 '14 at 19:57
0

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.

Raphael
  • 61
  • 1
  • 2