diff options
author | Karl Berry <karl@freefriends.org> | 2022-07-17 19:58:04 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-07-17 19:58:04 +0000 |
commit | e0553ff4e53f7d6417fc5f90bb661f38826d2395 (patch) | |
tree | 4a7247d4ad726984fc525b370990eb950f18bc10 /Master/texmf-dist/tex/latex | |
parent | e247fd87d43c1d36e8f7a4fcb861a293279e1756 (diff) |
gitver (17jul22)
git-svn-id: svn://tug.org/texlive/trunk@63920 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r-- | Master/texmf-dist/tex/latex/gitver/gitver.sty | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/Master/texmf-dist/tex/latex/gitver/gitver.sty b/Master/texmf-dist/tex/latex/gitver/gitver.sty index 4a06cd05a39..c2649c3d976 100644 --- a/Master/texmf-dist/tex/latex/gitver/gitver.sty +++ b/Master/texmf-dist/tex/latex/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 |