|
21 | 21 |
|
22 | 22 | \usepackage{listings}
|
23 | 23 | \lstset{
|
24 |
| - basicstyle=\ttfamily, |
25 | 24 | columns=fullflexible,
|
| 25 | + basicstyle=\ttfamily\lst@ifdisplaystyle\small\fi, |
| 26 | + commentstyle={\slshape}, |
| 27 | + showspaces=false, |
| 28 | + showstringspaces=false, |
26 | 29 | breaklines=true,
|
27 |
| - breakatwhitespace=false |
| 30 | + breakatwhitespace=true, |
| 31 | + breakindent=1em, |
| 32 | + prebreak=\raisebox{0ex}[0ex][0ex] |
| 33 | + { \ensuremath{_{\kern-2.2pt\hookleftarrow}}} |
28 | 34 | }
|
29 | 35 | \usepackage{calc}
|
30 | 36 | \usepackage{multicol}
|
|
59 | 65 |
|
60 | 66 | \begin{abstract}
|
61 | 67 | 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}. |
63 | 69 | If \texttt{lualatex} isn't working for you, you could try \href{https://ctan.org/pkg/gitinfo2}{gitinfo2} instead.
|
64 | 70 | 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.
|
65 | 71 | \end{abstract}
|
|
102 | 108 | \end{lstlisting}
|
103 | 109 | Note that in both cases option \texttt{--shell-escape} is required.
|
104 | 110 | 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.\\ |
106 | 127 |
|
107 | 128 | 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.
|
108 | 129 |
|
|
131 | 152 | The main reason for this macro to exist is its usage in the project example in section~\ref{sec:project}.
|
132 | 153 | \DescribeMacro{\gitunsetdirectory} To undo an operation done with \cmd{\gitdirectory} and switch back to the main file's directory, use \cmd{\gitunsetdirectory}.\\
|
133 | 154 |
|
134 |
| - \noindent |
135 | 155 | \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.
|
136 | 156 | For this project \cmd{\gitversion} results in \gitversion.
|
137 | 157 | When the version is dirty it will be post fixed with \texttt{-<commit count>-<short ref>}.
|
|
146 | 166 | These values are based on \texttt{git config user.name} and \texttt{git config user.email}.
|
147 | 167 |
|
148 | 168 | \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. |
151 | 171 | 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}}. |
153 | 173 |
|
154 | 174 | \gitdirectory{../../git-test-project}%
|
155 | 175 | \setlength\xample{4.6cm-5pt}%
|
|
181 | 201 | For this section the git project of this document is used due to the fact that there are references to revisions.
|
182 | 202 | 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}).\\
|
183 | 203 |
|
| 204 | + \clearpage |
184 | 205 | \noindent
|
185 | 206 | \DescribeMacro{\gitcommit}\oarg{format}\marg{csname}\marg{revision}\\
|
186 | 207 | For displaying commit data \cmd{\gitcommit} can be used.
|
187 | 208 | The optional \texttt{format} takes variables separated by a comma.
|
188 | 209 | 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.\\ |
190 | 211 | \setlength\xample{3.5cm}%
|
191 | 212 | \setlength\xamplesep{0pt}%
|
192 | 213 | \noindent%
|
|
251 | 272 | \end{minipage}\\
|
252 | 273 | \gitdirectory{../../git-test-project}
|
253 | 274 |
|
254 |
| - \clearpage |
| 275 | +% \clearpage |
255 | 276 | \subsection{Tags}
|
256 | 277 | In this section the \texttt{git-test-project} is used.
|
257 | 278 |
|
|
286 | 307 | {formattags}
|
287 | 308 | \end{itemize}
|
288 | 309 | }}
|
289 |
| - \end{minipage}\\ |
| 310 | + \end{minipage}\\[1em] |
290 | 311 | This example shows that the versions used are mixed.
|
291 | 312 | This is, of course, a horrible way to manage a project's version, though, we'll continue on with this hard objective.
|
292 | 313 | 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.
|
293 | 314 | The format would be: \texttt{(taggername)(taggername)(authorname)}.
|
294 | 315 | Here the \texttt{taggername} will show up, or if not present, the \texttt{authorname} will be shown instead.
|
295 | 316 |
|
296 | 317 | 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.\\ |
299 | 323 |
|
300 | 324 | For displaying commits in between tags, there's a \DescribeMacro{\forgittagseq}\cmd{\forgittagseq}\marg{csname}.
|
301 | 325 | 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}.\\ |
303 | 327 |
|
304 | 328 | Afterward tag info can be fetched using the \DescribeMacro{\gittag} \cmd{\gittag}\oarg{format}\marg{csname}\marg{tag}.
|
305 | 329 | This macro takes the same formatting specification as \cmd{\fotgittag}.
|
306 | 330 | Beware of using \cmd{\gittag} for the \meta{next tag} parameter in \cmd{\forgittagseq}.
|
307 | 331 |
|
308 | 332 | All these macros put together are demonstrated in listing~\ref{lst:changelog} (see next page).
|
309 |
| - \clearpage |
| 333 | +% \clearpage |
310 | 334 | \subsection{Changelog}
|
311 | 335 | This example demonstrates the generation of a changelog.
|
312 | 336 | 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.
|
313 | 337 | \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} |
315 | 339 | \newcommand{\commitline}[1]{\item #1}
|
316 | 340 | \newcommand{\formatversion}[3]{%
|
317 | 341 | \item[#1]
|
@@ -340,23 +364,24 @@ \section*{Changelog}
|
340 | 364 | \noindent
|
341 | 365 | \fbox{
|
342 | 366 | \parbox{\linewidth-8pt-2\fboxsep}{
|
343 |
| - {\bfseries\Large Changelog} |
| 367 | + {\bfseries\Large Change History} |
344 | 368 | \begin{description}
|
345 | 369 | \forgittagseq{formatversion}%
|
346 | 370 | \end{description}
|
347 | 371 | }
|
348 |
| - }\\ |
| 372 | + }\\[1em] |
349 | 373 |
|
| 374 | + \noindent |
350 | 375 | For displaying the tagline (see line 5) we use the existing \cmd{\printdate} macro of package \texttt{isodate}, which also takes exactly one argument
|
351 | 376 | 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.
|
352 | 377 |
|
353 |
| - \clearpage |
354 | 378 | \section{Project Example}\label{sec:project}
|
355 | 379 | This documentation uses an example \texttt{project} which gets created by the \texttt{git-scenario.sh} script (see listing~\ref{lst:scenario}).
|
356 | 380 | It creates some commits having dates in the past and different authors set.
|
357 | 381 | Lastly it creates a `lightweight-' and `annotated' tag.
|
358 | 382 |
|
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. |
360 | 385 |
|
361 | 386 | \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}
|
362 | 387 | \end{document}
|
0 commit comments