I use Mercurial. Imagine the following scenario. Suppose I have a document which is in a state of ongoing revision. I print out a version and file it. Some time later, I want to check whether the version I have on disk has changed compared to the version I have printed out. For simplicity assume that the version I have on disk has no local changes; i.e. the current version in version control is also the most recent version.

It would be handy to have some identifier as part of the file, say for example the revision when the file was last changed. Then I could look at that and see that there has been no change since I last printed the file.

Now, Mercurial actually has an extension that does something similar, namely the keyword extension. However, this has problems, and is officially disapproved of by the Mercurial founder and project leader, Matt Mackall.

After looking at this, it occurred to me that though using this extension could be problematic, there was no real problem using LaTeX to embed version control information in a LaTeX file. And nearly all text documents I write are LaTeX documents.

I see there is prior art by Martin Scharrer. Any tips on how to do similar things in Mercurial?

EDIT: To be clear, my intention was not to use the keywords extension, but rather call hg directly from TeX as part of the typesetting.

  • 2
    You could adopt a similar approach to the vc bundle but with a script that write the info from hg to some file that tex reads... – Seamus Jun 13 '14 at 9:06
  • I have used mecurial but don't have a live access now, but there have been packages to do this for rcs. cvs svn etc so hg should be no different. It would help (as always) if you posted a complete document with a mecurial keywords comment that showed the format. althought looking at that documentation pag eit looks like you wouldn't have to do anything, just put $HGdate$ in the document header and it'll get changed to teh checkout date – David Carlisle Jun 13 '14 at 9:17
  • @DavidCarlisle Were you suggesting using the keywords extension itself? I was hoping to bypass that. Maybe call hg directly from TeX? – Faheem Mitha Jun 13 '14 at 9:19
  • @Seamus Thanks for the suggestion. vc does indeed look suitable. However, it also does not appear to be in TeX Live, unfortunately, nor does it support Mercurial currently. – Faheem Mitha Jun 13 '14 at 9:25
  • @FaheemMitha : is it something like an equivalent of git2info for mercurial you are looking for ? – Clément Jun 13 '14 at 9:27

The following one-liner, if placed in a LaTeX file, gives the Mercurial changeset identification hash. Substitute rev for node to get the local revision number.

\input{"| hg log -v -l 1 \jobname.tex --template '{node}'"}

For this to work, running LaTeX with the -shell-escape option is required. Thanks to @egreg and @DavidCarlisle for providing most of the information for this answer in chat.

  • Any idea why this does not work with LuaLaTeX? – Bordaigorl Jun 13 '14 at 18:23
  • @Bordaigorl none at all, sorry. Better ask the experts. – Faheem Mitha Jun 13 '14 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.