2

I am working on a macro which will build revision history table in my document using Git tags. Each published version of my document has a tag with short description. I want to use them to automatically build revision table while compiling with XeLaTeX in Windows.

Using Git command below i get all information I need to create the revision history table. Output is formatted in CSV-like format.

git for-each-ref --format='%(refname:short); %(taggerdate:short); %(subject); %(*authorname); %(*authoremail)' refs/tags

I modified a macro for parsing CSV file so that I can read the output of the Git command and build my revision history table (not formatted yet as table in the script).

\documentclass{article}

\newcommand{\printrow}[5]{tag: #1 (#3) at #2 by #4 #5 + \}

\begin{document}

\def\readrow #1;#2;#3;#4;#5;{\ifx^#5^\else \printrow{#1}{#2}{#3}{#4}{#5}% \expandafter\readrow\fi} \def\startread {\readrow} % skip first row \begingroup \endlinechar=; \everyeof={;;;;;} \catcode@=11 \expandafter \startread @@input |"git revhist" % \endgroup %

\end{document}

It works with pre-saved output of the command, but when I paste the full command string into \@@input and try to compile (xelatex -shell-escape .\read-git-history-test.tex), XeLaTeX complains:

{|"git for-each-ref --format='
! Paragraph ended before \@iinput was complete.
<to be read again>
                   \par

I did a workaround by defining Git alias (git revhist -see below) but if one of my colleagues will try to compile it without defining the alias, it will fail. No, they do not read REDAME's...

git config --global alias.revhist "for-each-ref --format='%(refname:short); %(taggerdate:short); %(subject); %(*authorname); %(*authoremail);' refs/tags"

Is it possible to call the full Git command in *.tex file not to corrupt it by the % signs?

MaciekS
  • 277

1 Answers1

1

I used \@percentchar as suggested by @DavidCarlisle, and it works as expected.

\def\readrow #1;#2;#3;#4;#5;{\ifx^#5^\else
   \addrevision{#1}{#2}{#4}{#3}%
   \expandafter\readrow\fi}
\def\startread {\readrow} % skip first row
\begingroup
   \endlinechar=`; \everyeof={;;;;;} \catcode`\@=11
   \expandafter \startread \@@input |"git for-each-ref --format='\@percentchar(refname:short); \@percentchar(taggerdate:short); \@percentchar(subject); \@percentchar(*authorname); \@percentchar(*authoremail)' refs/tags" %
\endgroup %
MaciekS
  • 277