I am working on a LaTeX document with LuaLaTeX and try to include git information in the document to make it easier to find the correct version once I stumble over a printed copy.
With the help of some posts here, I was already able to get most of the git information in the document: commit hash and the timestamp. This is following the \input|"git log -1 --format=\@percentchar ci ./"
approach.
But now I would like to use the timestamp also as the date for e.g. \maketitle
. So I came across this post: Is it possible to parse a date string in LaTeX to convert it to a different date format? The solution provided there works great for me, as long as I use a test date created with \newcommand{\testDate}{2021-05-27 ...}
. But as soon as I want to use the date retrieved from git, it stops working.
Down below you find a MWE, which produces various kinds of errors, depending on which line you comment out
\documentclass{article}
\usepackage[ngerman]{babel}
% define a parser
\def\parsegitdate#1-#2-#3 #4\endparse{#3.#2.#1}
\begin{document}
\makeatletter
% first definiton
\newcommand{\gitdatex}{\input|"git log -1 --format=\@percentchar ci"}
% second definition
\def\gitdatey{\@@input|"git log -1 --format=\@percentchar ci"}
% third definition
\edef\gitdatez{\@@input|"git log -1 --format=\@percentchar ci"}
\makeatother
% print date for reference
\gitdatex
% version 1
\expandafter\parsegitdate\gitdatex\endparse
% version 2
\expandafter\parsegitdate\gitdatey\endparse
% version 3
\expandafter\parsegitdate\gitdatez\endparse
\end{document}
First and second definition with version 1 and 2 give me the same error: ! Paragraph ended before \parsegitdate was complete.
Apparently the definition is not properly expanded and the actual git command is handed to the parser rather than its result. Thus, I tried \edef
.
The third definition with \edef
and version 3 produce the desired result, as long as I do not include \usepackage[ngerman]{babel}
. Once I include that package (with the option ngerman
), I get an ! Argument of \language@active@arg" has an extra }.
How can I get this to work in combination?
I am also aware of the following answers, which are kind of similar. But I actually do not want to use external scripts. Thus, gitinfo2 or vsc bundle are not my desired solution.
- What are \immediate & \write18 and how does one use them?
- Put the last date of the file versioned with Git
- Inserting git commit date without hooks
By the way: Can someone explain the \endparse
to me as well? I was not able to find any information what this is actually meaning and doing.