Skip to content

Commit d2a2783

Browse files
committed
Update documentation
1 parent f77bc26 commit d2a2783

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

doc/gitinfo-lua-init.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
-- Global texconfig should already be available when executed with lualtex
1+
-- Global texconfig should already be available when executed with lualatex
22
local texconfig = texconfig or require('texconfig')
33

4-
-- Use restricted shell_escape with git as only command
4+
-- Use restricted shell_escape with git as only command.
5+
-- Add others where needed, separated with a comma (no spaces in between)
56
texconfig.shell_escape = 'p'
67
texconfig.shell_escape_commands = 'git'

doc/gitinfo-lua.tex

+45-20
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,16 @@
2121

2222
\usepackage{listings}
2323
\lstset{
24-
basicstyle=\ttfamily,
2524
columns=fullflexible,
25+
basicstyle=\ttfamily\lst@ifdisplaystyle\small\fi,
26+
commentstyle={\slshape},
27+
showspaces=false,
28+
showstringspaces=false,
2629
breaklines=true,
27-
breakatwhitespace=false
30+
breakatwhitespace=true,
31+
breakindent=1em,
32+
prebreak=\raisebox{0ex}[0ex][0ex]
33+
{ \ensuremath{_{\kern-2.2pt\hookleftarrow}}}
2834
}
2935
\usepackage{calc}
3036
\usepackage{multicol}
@@ -59,7 +65,7 @@
5965

6066
\begin{abstract}
6167
This project aims to display git project information in PDF documents.
62-
It's mostly written in Lua for executing the \texttt{git} commands, therefore making this package only applicable for \texttt{lualatex} with \texttt{shell escape} enabled.
68+
It's mostly written in Lua for executing the \texttt{git} commands, therefore making this package only applicable for \texttt{lualatex}.
6369
If \texttt{lualatex} isn't working for you, you could try \href{https://ctan.org/pkg/gitinfo2}{gitinfo2} instead.
6470
For \LaTeX{} it provides a set of standard macros for displaying basic information or setting the project directory, and a set of advanced macros for formatting commits and tags.
6571
\end{abstract}
@@ -102,7 +108,22 @@
102108
\end{lstlisting}
103109
Note that in both cases option \texttt{--shell-escape} is required.
104110
This is required for issuing \texttt{git} via the commandline.
105-
If using \texttt{--shell-restricted} mode, make sure to add \texttt{git} to the CSV variable \texttt{shell\_escape\_commands} in i.e.\ \texttt{texmf.cnf}.
111+
If using \texttt{--shell-restricted} mode, which is the default, make sure to add \texttt{git} to the CSV variable \texttt{shell\_escape\_commands} in either your \texttt{texmf.cnf} or using a Lua initialization script, like:
112+
\lstinputlisting[language={[5.3]Lua},caption={Lua initialization script},frame=single]{gitinfo-lua-init.lua}
113+
114+
\noindent
115+
The Lua initialization script can be used as follows:
116+
\begin{lstlisting}[language=bash,frame=single,caption={With Lua initialization script},morekeywords=lualatex]
117+
lualatex --lua=gitinfo-lua-init.lua main
118+
\end{lstlisting}
119+
For using the script with \texttt{latexmk}, this can be achieved with the \texttt{-lualatex="COMMAND"} option or specifying the \texttt{\$lualatex} command using a \texttt{latexmkrc} configuration file:
120+
\begin{lstlisting}[language=bash,frame=single,caption={Overriding Lua\LaTeX\ on commandline},morekeywords=latexmk]
121+
latexmk --lualatex --lualatex="lualatex --lua=gitinfo-lua-init.lua %O %S" main
122+
\end{lstlisting}
123+
\begin{lstlisting}[language=perl,frame=single,caption={Overriding Lua\LaTeX\ in \texttt{latexmkrc}}]
124+
$lualatex = "lualatex --lua=gitinfo-lua-init.lua %O %S";
125+
\end{lstlisting}
126+
Keep in mind that both the Lua initialization script and \texttt{latexmkrc} need to be placed within the same directory as the main file.\\
106127

107128
When utilizing the continuous compilation option \texttt{-pvc} with \texttt{latexmk}, it's important to note that only committed changes will be detected, while tag changes, unfortunately, won't be recognized.
108129

@@ -131,7 +152,6 @@
131152
The main reason for this macro to exist is its usage in the project example in section~\ref{sec:project}.
132153
\DescribeMacro{\gitunsetdirectory} To undo an operation done with \cmd{\gitdirectory} and switch back to the main file's directory, use \cmd{\gitunsetdirectory}.\\
133154

134-
\noindent
135155
\DescribeMacro{\gitversion} The current version can be display by using \cmd{\gitversion} and is equivalent to \texttt{git describe --tags --always}, working for both lightweight and annotated tags.
136156
For this project \cmd{\gitversion} results in \gitversion.
137157
When the version is dirty it will be post fixed with \texttt{-<commit count>-<short ref>}.
@@ -146,10 +166,10 @@
146166
These values are based on \texttt{git config user.name} and \texttt{git config user.email}.
147167

148168
\subsection{Multiple Authors}
149-
When projects having multiple authors this package can help with the \DescribeMacro{\dogitauthors}\break\cmd{\dogitauthors}\oarg{conj} and \DescribeMacro{\forgitauthors}\cmd{\forgitauthors}\oarg{conj}\marg{csname} macro.
150-
Where \cmd{\dogitauthors} executes a default formatting implementation of \break\cmd{\git@format@author} and \cmd{\forgitauthors} executes the given \meta{csname} for every author available.
169+
When projects having multiple authors, this package can help with the \DescribeMacro{\dogitauthors}\cmd{\dogitauthors}\oarg{conj} and \DescribeMacro{\forgitauthors}\cmd{\forgitauthors}\oarg{conj}\marg{csname} macro.
170+
Where \cmd{\dogitauthors} executes a default formatting implementation of \cmd{\git@format@author} and \cmd{\forgitauthors} executes the given \meta{csname} for every author available.
151171
The optional \meta{conj} conjunction makes it possible to even integrate it further.
152-
For example, when setting the authors in pdfx, the conjunction would be \texttt{[\textbackslash\textbackslash sep\textasciitilde]}, so that the authors are properly separated in the document properties\footnote{See package documentation of \texttt{pdfx}: \url{https://ctan.org/pkg/pdfx}}.
172+
For example, when setting the authors in pdfx, the conjunction would be \texttt{[\textbackslash\textbackslash sep ]}, so that the authors are properly separated in the document properties\footnote{See package documentation of \texttt{pdfx}: \url{https://ctan.org/pkg/pdfx}}.
153173

154174
\gitdirectory{../../git-test-project}%
155175
\setlength\xample{4.6cm-5pt}%
@@ -181,12 +201,13 @@
181201
For this section the git project of this document is used due to the fact that there are references to revisions.
182202
The test project's revisions change for every user, since they get recreated every time \texttt{test-scenario.sh} is executed (see section~\ref{sec:project}).\\
183203

204+
\clearpage
184205
\noindent
185206
\DescribeMacro{\gitcommit}\oarg{format}\marg{csname}\marg{revision}\\
186207
For displaying commit data \cmd{\gitcommit} can be used.
187208
The optional \texttt{format} takes variables separated by a comma.
188209
The default \texttt{format} is \texttt{h,an,ae,as,s,b}.
189-
The \texttt{csname} is a user defined command accepting every variable as argument.
210+
The \texttt{csname} is a user defined command accepting every variable as argument.\\
190211
\setlength\xample{3.5cm}%
191212
\setlength\xamplesep{0pt}%
192213
\noindent%
@@ -251,7 +272,7 @@
251272
\end{minipage}\\
252273
\gitdirectory{../../git-test-project}
253274

254-
\clearpage
275+
% \clearpage
255276
\subsection{Tags}
256277
In this section the \texttt{git-test-project} is used.
257278

@@ -286,32 +307,35 @@
286307
{formattags}
287308
\end{itemize}
288309
}}
289-
\end{minipage}\\
310+
\end{minipage}\\[1em]
290311
This example shows that the versions used are mixed.
291312
This is, of course, a horrible way to manage a project's version, though, we'll continue on with this hard objective.
292313
For example, if we wish to display the author of the lightweight and annotated tag, we can do so by specifying a format using the if-then-else feature of the format specification.
293314
The format would be: \texttt{(taggername)(taggername)(authorname)}.
294315
Here the \texttt{taggername} will show up, or if not present, the \texttt{authorname} will be shown instead.
295316

296317
The default format specification is like the \cmd{\forgitcommit} format, but then again, some bit more complex:\\
297-
\texttt{refname:short,(taggername)(taggername,taggeremail,taggerdate:short)\\(authorname,authoremail,authordate:short),subject,body}.
298-
This is a robust example of getting all information, being it a lightweight- or annotated tag.\\
318+
319+
\hfill\parbox{\linewidth-\parindent}{\texttt{refname:short,(taggername)(taggername,taggeremail,taggerdate:short)\\(authorname,authoremail,authordate:short),subject,body}}\\
320+
321+
\noindent
322+
This is a robust example of getting all information, being it either a lightweight- or annotated tag.\\
299323

300324
For displaying commits in between tags, there's a \DescribeMacro{\forgittagseq}\cmd{\forgittagseq}\marg{csname}.
301325
The \meta{csname} takes exactly three arguments, namely, the \meta{current}, \meta{next tag} and \meta{rev spec}.
302-
The last iteration gives an empty value for \meta{next tag} and the \meta{rev spec} is identical to \meta{current}.
326+
The last iteration gives an empty value for \meta{next tag} and the \meta{rev spec} is identical to \meta{current}.\\
303327

304328
Afterward tag info can be fetched using the \DescribeMacro{\gittag} \cmd{\gittag}\oarg{format}\marg{csname}\marg{tag}.
305329
This macro takes the same formatting specification as \cmd{\fotgittag}.
306330
Beware of using \cmd{\gittag} for the \meta{next tag} parameter in \cmd{\forgittagseq}.
307331

308332
All these macros put together are demonstrated in listing~\ref{lst:changelog} (see next page).
309-
\clearpage
333+
% \clearpage
310334
\subsection{Changelog}
311335
This example demonstrates the generation of a changelog.
312336
For simplicity’s sake, every tag is displayed in a \texttt{description} environment's item and within an \texttt{enumerate} environment displaying commits in between.
313337
\begin{lstlisting}[language={[LaTeX]TeX},numbers=left,captionpos=t,caption={Formatting a changelog},label={lst:changelog},morekeywords={commitline,formatversion,gittag,forgitcommit,forgittagseq,printdate}]
314-
\section*{Changelog}
338+
\section*{Change History}
315339
\newcommand{\commitline}[1]{\item #1}
316340
\newcommand{\formatversion}[3]{%
317341
\item[#1]
@@ -340,23 +364,24 @@ \section*{Changelog}
340364
\noindent
341365
\fbox{
342366
\parbox{\linewidth-8pt-2\fboxsep}{
343-
{\bfseries\Large Changelog}
367+
{\bfseries\Large Change History}
344368
\begin{description}
345369
\forgittagseq{formatversion}%
346370
\end{description}
347371
}
348-
}\\
372+
}\\[1em]
349373

374+
\noindent
350375
For displaying the tagline (see line 5) we use the existing \cmd{\printdate} macro of package \texttt{isodate}, which also takes exactly one argument
351376
For every version sequence the commits in between are displayed (see line 7), where the last sequence having the initial commit as second argument plays well with the \cmd{\forgitcommit} macro and makes it possible to show the whole sequence of history.
352377

353-
\clearpage
354378
\section{Project Example}\label{sec:project}
355379
This documentation uses an example \texttt{project} which gets created by the \texttt{git-scenario.sh} script (see listing~\ref{lst:scenario}).
356380
It creates some commits having dates in the past and different authors set.
357381
Lastly it creates a `lightweight-' and `annotated' tag.
358382

359-
To set up this scenario either do \texttt{make scenario} or \texttt{bash scenario.sh}.
383+
To set up this scenario either do \texttt{make scenario} or execute \texttt{bash git-scenario.sh} in an initialized \texttt{git} repository.
384+
Keep in mind that when executing with Bash directly, you may need to specify the path to the Bash file.
360385

361386
\lstinputlisting[language=bash,numbers=left,frame=single,label={lst:scenario},caption={git-scenario.sh},captionpos=t,morekeywords={git,alice,bob,charlie,mkdir,rm,curl,set\_author}]{git-scenario.sh}
362387
\end{document}

0 commit comments

Comments
 (0)