This is my first time asking a question on a site like this. Please tell me if I should do something differently, thanks!
I want to include a short version of the latest commit hash from git as a text string in a (Xe)LaTeX document. How do I do that?
I am able to include the full hash simply with:
\input{.git/ORIG_HEAD}
But I am not able to figure out how to shorten down the hash with the xstring
package when I am getting the string from a macro. What I currently have is this:
\usepackage{xstring}
\expandarg %% Not at all sure about this command
\StrLeft{\input{.git/ORIG_HEAD}}{8}[\gitrevision]
I would prefer \gitrevision\ to be a short hash.
A fix for the above code would be most appreciated, as the code is constructed from my way of thinking. Yes, I have RTFM, but it is in my opinion lacking in the department of plain down-to-earth usage examples.
Of course, a completely different (working) solution is also welcome!
A final note, I would easily be able to do all this with an external bash
script and/or with the \write18
macro, but I have put an arbitrary limit on myself to only rely on TeX in this case. Otherwise I will never learn more. Many thanks for taking the time to read this question!
gitinfo
package?gitinfo
I can get the desired result. But I would like to set up a workflow where scripts (git hooks included) aren’t needed. And it seems to me that thexstring
solution should work, just that I am missing some crucial understanding of TeX’s grammar or inner workings.