The package gitver requires -shell-escape to fetch git metadata from the manuscript's git repository on the local filesystem.

However, it is needless to pass the shell-escape flag when compiling the source outside of a gitVCS repo (such as on my advisor's machine). It is tedious to comment-out and comment-in this line appropriately. It is also hard to change other collaborator's (good) habits of not compiling with -shell-escape enabled. However, gitver complains loudly and errors out/halts if shell-escape is not detected.

Hence, can I change my preamble in such a way that a generic source line (not just to loading gitver package, but the same argument applies to minted and other generic latex commands) is executed only when compiled with shell-escape?

Minimal conceptual example:


%%% Somehow detect shell-escape here
  \usepackage{gitver} % <-- load only if compiled with shell-escape 
%%% end of test

Hello world!
  • For the given problem you may want to have a look at gitinfo2 instead of gitver since gitinfo2 doesn’t require shell-escape (I think). – Jendrik Stelzner Sep 20 at 1:55

expl3 has a test:

\csname sys_if_shell_unrestricted:T\endcsname{\usepackage{gitver}} 
Hello world!
  • I thought I had added this to shellescape package (or at least a common name for a number to test) but apparently not:-) – David Carlisle Sep 19 at 12:37
  • @DavidCarlisle I checked shellesc first ;-) – Ulrike Fischer Sep 19 at 12:38
  • @UlrikeFischer perfect. Works like a charm. Upvoted & accepted. – Krishna Sep 19 at 13:51
  • 1
    Imho you should make a feature request for the package. It should have a "warn" mode and quit cleanly if shell-escape is not enabled. As you said: it is a pain if such packages then errors. – Ulrike Fischer Sep 19 at 13:56
  • @DavidCarlisle Maybe pdftexcmds? – egreg Sep 19 at 14:11

You can use pdftexcmds and define a three-branch test:


    \expandafter\@firstofthree  % 0 = no shell escape
    \expandafter\@secondofthree % 1 = unrestricted
    \expandafter\@thirdofthree  % 2 = restricted

The three arguments are “code for Unrestricted shell escape”, “code for Restricted shell escape” and “code for No shell escape” respectively.

In your case,


It might be more convenient to use expl3 so as not to expose the actual values of the integer variable denoting the status of shell escape.


\cs_new:Npn \ShellEscapeURN #1 #2 #3
   { #1 } % unrestricted shell
     { #2 }
     { #3 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.