diff options
Diffstat (limited to 'macros/latex/contrib/gitver')
-rw-r--r-- | macros/latex/contrib/gitver/ChangeLog | 4 | ||||
-rw-r--r-- | macros/latex/contrib/gitver/README.md | 2 | ||||
-rw-r--r-- | macros/latex/contrib/gitver/gitver.pdf | bin | 128530 -> 134559 bytes | |||
-rw-r--r-- | macros/latex/contrib/gitver/gitver.sty | 44 | ||||
-rw-r--r-- | macros/latex/contrib/gitver/gitver.tex | 7 | ||||
-rw-r--r-- | macros/latex/contrib/gitver/latexmkrc | 8 |
6 files changed, 57 insertions, 8 deletions
diff --git a/macros/latex/contrib/gitver/ChangeLog b/macros/latex/contrib/gitver/ChangeLog index 4b3da3083c..d49c9a0ced 100644 --- a/macros/latex/contrib/gitver/ChangeLog +++ b/macros/latex/contrib/gitver/ChangeLog @@ -6,4 +6,6 @@ * Use datetime2 instead of datetime to reduce dependancy burden and display dates in ISO format 2020-10-30 - v1.3 - * Support lualatex
\ No newline at end of file + * Support lualatex +2022-07-16 - v1.4 + * Detect running in online builders via "CLSI" environmental variable
\ No newline at end of file diff --git a/macros/latex/contrib/gitver/README.md b/macros/latex/contrib/gitver/README.md index 6edb662f9f..b4eb37e836 100644 --- a/macros/latex/contrib/gitver/README.md +++ b/macros/latex/contrib/gitver/README.md @@ -2,7 +2,7 @@ Git Version (version 1.3) ========================= URL: https://github.com/charlesbaynham/gitver -(c) Charles Baynham 2020 +(c) Charles Baynham 2022 License: LaTeX Project Public License 1.3c diff --git a/macros/latex/contrib/gitver/gitver.pdf b/macros/latex/contrib/gitver/gitver.pdf Binary files differindex e73e6bcfc4..a2ee4b8e2b 100644 --- a/macros/latex/contrib/gitver/gitver.pdf +++ b/macros/latex/contrib/gitver/gitver.pdf diff --git a/macros/latex/contrib/gitver/gitver.sty b/macros/latex/contrib/gitver/gitver.sty index 4a06cd05a3..c2649c3d97 100644 --- a/macros/latex/contrib/gitver/gitver.sty +++ b/macros/latex/contrib/gitver/gitver.sty @@ -1,6 +1,6 @@ % gitVer % -% (c) Charles Baynham 2020 +% (c) Charles Baynham 2022 % % License: LaTeX Project Public License 1.3c % @@ -19,12 +19,31 @@ \NeedsTeXFormat{LaTeX2e} \def\@gitVerPkgName{gitver} \ProvidesPackage{\@gitVerPkgName} - [2020/10/30 v1.3 Access current git version and optionally add it to document headers] + [2022/07/16 v1.4 Access current git version and optionally add it to document headers] \RequirePackage{hyperref} \RequirePackage{catchfile} \RequirePackage{pdftexcmds} \RequirePackage{datetime2} +\RequirePackage{ifthen} +\RequirePackage{xparse} + +% Define a command to get environmental variables +% Thanks to egreg at https://tex.stackexchange.com/questions/62010/can-i-access-system-environment-variables-from-latex-for-instance-home +\ExplSyntaxOn +\NewDocumentCommand{\getenv}{om} + { + \sys_get_shell:nnN { kpsewhich ~ --var-value ~ #2 } { } \l_tmpa_tl % + \tl_trim_spaces:N \l_tmpa_tl % + \IfNoValueTF { #1 } % + {% + \tl_use:N \l_tmpa_tl% + }% + {% + \tl_set_eq:NN #1 \l_tmpa_tl% + }% + } +\ExplSyntaxOff % Support lualatex by reinstating the \write18 command \RequirePackage{ifluatex} @@ -85,7 +104,7 @@ \def\@gitver@emptyfile{} \ifx\gitVer\@gitver@emptyfile% - \PackageError{\@gitVerPkgName}{Git output is empty: is this folder a git repo?}{Make sure that this directory has had "git init" called in it, and has at least one commit.} + \PackageWarning{\@gitVerPkgName}{Git output is empty: is this folder a git repo? Make sure that this directory has had "git init" called in it, has at least one commit, and that git is installed.} \else \@gitver@successtrue \fi @@ -93,8 +112,23 @@ \if@gitver@success \else - \PackageWarning{\@gitVerPkgName}{Git command failed: writing as "unknown"}% - \def\gitVer{unknown} + % Look for "CLSI" environmental variable: this stands for Common Latex Service + % Interface, and is set to "1" in web builders like Overleaf.com + \getenv[\CLSI]{CLSI} + % Check if CLSI == 1 (see https://tex.stackexchange.com/a/306500) + \ifnum1=0\CLSI\relax + \PackageWarning{\@gitVerPkgName}{Running on a Common Latex Service % + Interface without Git: writing version as "CLSI"}% + \def\gitVer{CLSI} + \else + \PackageError{\@gitVerPkgName}{Git command failed: writing as "unknown"}{% + Calling git failed, and your system did not identify itself as a + Common Latex Service Interface (e.g. overleaf.com). Make sure that git + is installed and that this file is in a repository which has at least + one commit. + }% + \def\gitVer{unknown} + \fi \fi % % Make a box containing the date and version diff --git a/macros/latex/contrib/gitver/gitver.tex b/macros/latex/contrib/gitver/gitver.tex index f6ecf2654c..a5b68af99e 100644 --- a/macros/latex/contrib/gitver/gitver.tex +++ b/macros/latex/contrib/gitver/gitver.tex @@ -18,7 +18,7 @@ \title{\textsf{gitver} -- Git version tags \\ for \LaTeX{} projects} \author{Charles Baynham} -\date{2020/10/30 (v\,1.3)} +\date{2022/07/16 (v\,1.4)} \MaintainedBy{% This file is maintained by Charles Baynham.\\% Bug reports can be opened at\\% @@ -43,6 +43,10 @@ running in ``shell escape'' mode. This can be enabled by passing \textsf{--shell on the command line when compiling your document, or will be available in the options of whatever GUI you're using (try Googling). +Note that online Latex editors like Overleaf.com often do not have git installed. +Gitver will detect these by the precense of the environmental variable "CLSI" +and will display the version as "CLSI" instead. + Note that it's a good idea to tell git to ignore all the latex auxilary files, otherwise your version will always be ``dirty''. Try the \textsf{.gitignore} file from \url{https://www.gitignore.io/api/latex} if you don't already have @@ -117,6 +121,7 @@ the option |nopdfinfo|. \item v1.2 - Use datetime2 instead of datetime to reduce dependancy burden and display dates in ISO format \item v1.3 - Support LuaLatex + \item v1.4 - Detect running in online builders via "CLSI" environmental variable \end{itemize} \end{document} diff --git a/macros/latex/contrib/gitver/latexmkrc b/macros/latex/contrib/gitver/latexmkrc new file mode 100644 index 0000000000..a22b23ddad --- /dev/null +++ b/macros/latex/contrib/gitver/latexmkrc @@ -0,0 +1,8 @@ +# .latexmkrc +# This file will be read by latexmk when building the documentation + +# Run pdflatex with shell escape (for git tagging) and ignore errors +$pdflatex = 'pdflatex %O -interaction=nonstopmode --shell-escape %S'; + +# Default to pdf output +$pdf_mode = 1;
\ No newline at end of file |