1

The gitinfo2 package provides the command \gitAuthorDate which returns the date of the current commit in ISO format, e.g., 2018-02-22.

I would like to use this date with a different format within in my document, so I tried to use the datetime2 package to save the output of \gitAuthorDate and reformat it.

Here is a minimal example (to be used in a git-versioned directory with the appropriate hooks installed as per the documentation of gitinfo2:

\documentclass{article}

\usepackage[grumpy,mark]{gitinfo2}

\usepackage[calc]{datetime2}
\DTMsavedate{commitdate}{\gitAuthorDate}

\begin{document}

Hello world!

\end{document}

Unfortunately, this gives me

Runaway argument?
\gitInf@authsdate \@dtm@endparsedate \cslet {@dtm@commitdate@year}{\@dtm@year \
ETC.
! Paragraph ended before \@dtm@parsedate was complete.
<to be read again> 
                   \par 
l.9 

How can I fix this error, or is there another way to reformat the date provided by \gitAuthorDate?

Edit

As requested by Nicola, here is an excerpt of an interactive session to see how \gitAuthorDate expands

*\show\gitAuthorDate
...
> \gitAuthorDate=\long macro:
->\gitInf@authsdate .
*\makeatletter
*\show\gitInf@authsdate
> \gitInf@authsdate=macro:
->2018-02-22.
2
  • 1
    It's likely an expansion problem. \DTMsavedate performs a one-level expansion on the first token in the second argument, so it would work if, say, \gitAuthorDate is define as 2018-02-22 but not if it's defined in a more complicated manner. For those who don't have git, it would help to know exactly how \gitAuthorDate expands. Can you add \show\gitAuthorDate before \DTMsavedate and add the result. – Nicola Talbot Feb 22 '18 at 16:52
  • @NicolaTalbot I have added the information you requested. If I replace the offending command by \makeatletter\DTMsavedate{commitdate}{\gitInf@authsdate}\makeatother, it works as expected. Are there any side-effects or is there a better solution? Otherwise, I am happy to keep this solution. – Alexander Körschgen Feb 23 '18 at 20:22
2

(Turning comments into an answer.) \DTMsavedate performs a one-level expansion on the first token in the second argument, so it would work if, say, \gitAuthorDate is directly define as 2018-02-22 but not if it's defined in a more complicated manner. Given the expansion of \gitAuthorDate that you provided, you could use your proposed solution:

\makeatletter\DTMsavedate{commitdate}{\gitInf@authsdate}\makeatother

However, it's best not to use internal commands in case the package changes them in later versions. Instead, a more general solution is to ensure that the argument is fully expanded before being passed to \DTMsavedate:

\newcommand{\esavedate}[2]{%
  \begingroup
  \edef\x{\noexpand\endgroup\noexpand\DTMsavedate{#1}{#2}}\x
}

\esavedate{commitdate}{\gitAuthorDate}

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.