How to conditionally load a package only if shell-escape (write18) is passedConditionally execute a command if a specific package is loadedwrite18 pass % through to shellhow to escape special chars in write18?“Shell escape not enabled” error, even though write18 is enabledHow to do shell-escape in TeXWorks?How to do shell escape in Texniccenter?How to run shell command with write18?newcommand with argument and shell-escape/write18

Do I need to use capacitors when using an L7805CV voltage regulator?

Average number of random permutations of a sequence, before seeing a sorted sequence

Why are compartments in western European day trains falling out of fashion?

Mindslavering a Mindslavered player?

Pawns pushes in the center

In academic writing why do some recommend to avoid "announcing" the topic?

Why the highlighted outline in animated cartoons?

Risk Neutral and Real World Valuations using Monte Carlo

Does this code demonstrate the central limit theorem?

What stops one country from issuing another country's passports?

Apollo CM heat shield burnt pattern around RCS thrusters

How can an AI train itself if no one is telling it if its answer is correct or wrong?

My passport's Machine Readable Zone is damaged. How do I deal with it?

What are the possible punishments for an impeached USA president?

Is there any conceivable way to "turn off" a star?

4 Attempts to Guess a Number Between 1-15

How many cows would you need to drop on Mars to successfully terraform it?

Should this unsafe code work also in .NET Core 3?

How many flight hours do the first retiring A380s have?

United States Towns/States Traversing by Name Puzzle

Is "to go berserk" used by native speakers or is it obsolete?

Conveying the idea of « go figure »

How close are we, really?

Why aren't flights continued after losing a tire on rotation?



How to conditionally load a package only if shell-escape (write18) is passed


Conditionally execute a command if a specific package is loadedwrite18 pass % through to shellhow to escape special chars in write18?“Shell escape not enabled” error, even though write18 is enabledHow to do shell-escape in TeXWorks?How to do shell escape in Texniccenter?How to run shell command with write18?newcommand with argument and shell-escape/write18






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









6


















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:



documentclassarticle

%%% Somehow detect shell-escape here
usepackagegitver % <-- load only if compiled with shell-escape
%%% end of test

begindocument
Hello world!
enddocument









share|improve this question

























  • 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

















6


















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:



documentclassarticle

%%% Somehow detect shell-escape here
usepackagegitver % <-- load only if compiled with shell-escape
%%% end of test

begindocument
Hello world!
enddocument









share|improve this question

























  • 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













6













6









6








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:



documentclassarticle

%%% Somehow detect shell-escape here
usepackagegitver % <-- load only if compiled with shell-escape
%%% end of test

begindocument
Hello world!
enddocument









share|improve this question














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:



documentclassarticle

%%% Somehow detect shell-escape here
usepackagegitver % <-- load only if compiled with shell-escape
%%% end of test

begindocument
Hello world!
enddocument






conditionals shell-escape






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 19 at 12:23









KrishnaKrishna

2,3656 silver badges22 bronze badges




2,3656 silver badges22 bronze badges















  • 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

















  • 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
















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





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










2 Answers
2






active

oldest

votes


















7



















expl3 has a test:



documentclassarticle
usepackageexpl3
csname sys_if_shell_unrestricted:Tendcsnameusepackagegitver
begindocument
Hello world!
enddocument





share|improve this answer

























  • 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


















3



















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



usepackagepdftexcmds

makeatletter
newcommandShellEscapeURN[3]%
ifcasepdf@shellescape
expandafter@firstofthree % 0 = no shell escape
or
expandafter@secondofthree % 1 = unrestricted
or
expandafter@thirdofthree % 2 = restricted
else
expandafter@firstofthree
fi
#3#1#2%

providecommand@firstofthree[3]#1
providecommand@secondofthree[3]#2
providecommand@thirdofthree[3]#3
makeatother


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



In your case,



ShellEscapeURNusepackagegitver


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.



usepackageexpl3

ExplSyntaxOn
cs_new:Npn ShellEscapeURN #1 #2 #3

sys_if_shell_unrestricted:TF
#1 % unrestricted shell

sys_if_shell_restricted:TF
#2
#3


ExplSyntaxOff





share|improve this answer




























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "85"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f508919%2fhow-to-conditionally-load-a-package-only-if-shell-escape-write18-is-passed%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown


























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7



















    expl3 has a test:



    documentclassarticle
    usepackageexpl3
    csname sys_if_shell_unrestricted:Tendcsnameusepackagegitver
    begindocument
    Hello world!
    enddocument





    share|improve this answer

























    • 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















    7



















    expl3 has a test:



    documentclassarticle
    usepackageexpl3
    csname sys_if_shell_unrestricted:Tendcsnameusepackagegitver
    begindocument
    Hello world!
    enddocument





    share|improve this answer

























    • 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













    7















    7











    7









    expl3 has a test:



    documentclassarticle
    usepackageexpl3
    csname sys_if_shell_unrestricted:Tendcsnameusepackagegitver
    begindocument
    Hello world!
    enddocument





    share|improve this answer














    expl3 has a test:



    documentclassarticle
    usepackageexpl3
    csname sys_if_shell_unrestricted:Tendcsnameusepackagegitver
    begindocument
    Hello world!
    enddocument






    share|improve this answer













    share|improve this answer




    share|improve this answer










    answered Sep 19 at 12:31









    Ulrike FischerUlrike Fischer

    227k9 gold badges337 silver badges744 bronze badges




    227k9 gold badges337 silver badges744 bronze badges















    • 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

















    • 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
















    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






    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





    @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






    @UlrikeFischer perfect. Works like a charm. Upvoted & accepted.

    – Krishna
    Sep 19 at 13:51





    1




    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





    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





    @DavidCarlisle Maybe pdftexcmds?

    – egreg
    Sep 19 at 14:11













    3



















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



    usepackagepdftexcmds

    makeatletter
    newcommandShellEscapeURN[3]%
    ifcasepdf@shellescape
    expandafter@firstofthree % 0 = no shell escape
    or
    expandafter@secondofthree % 1 = unrestricted
    or
    expandafter@thirdofthree % 2 = restricted
    else
    expandafter@firstofthree
    fi
    #3#1#2%

    providecommand@firstofthree[3]#1
    providecommand@secondofthree[3]#2
    providecommand@thirdofthree[3]#3
    makeatother


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



    In your case,



    ShellEscapeURNusepackagegitver


    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.



    usepackageexpl3

    ExplSyntaxOn
    cs_new:Npn ShellEscapeURN #1 #2 #3

    sys_if_shell_unrestricted:TF
    #1 % unrestricted shell

    sys_if_shell_restricted:TF
    #2
    #3


    ExplSyntaxOff





    share|improve this answer































      3



















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



      usepackagepdftexcmds

      makeatletter
      newcommandShellEscapeURN[3]%
      ifcasepdf@shellescape
      expandafter@firstofthree % 0 = no shell escape
      or
      expandafter@secondofthree % 1 = unrestricted
      or
      expandafter@thirdofthree % 2 = restricted
      else
      expandafter@firstofthree
      fi
      #3#1#2%

      providecommand@firstofthree[3]#1
      providecommand@secondofthree[3]#2
      providecommand@thirdofthree[3]#3
      makeatother


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



      In your case,



      ShellEscapeURNusepackagegitver


      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.



      usepackageexpl3

      ExplSyntaxOn
      cs_new:Npn ShellEscapeURN #1 #2 #3

      sys_if_shell_unrestricted:TF
      #1 % unrestricted shell

      sys_if_shell_restricted:TF
      #2
      #3


      ExplSyntaxOff





      share|improve this answer





























        3















        3











        3









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



        usepackagepdftexcmds

        makeatletter
        newcommandShellEscapeURN[3]%
        ifcasepdf@shellescape
        expandafter@firstofthree % 0 = no shell escape
        or
        expandafter@secondofthree % 1 = unrestricted
        or
        expandafter@thirdofthree % 2 = restricted
        else
        expandafter@firstofthree
        fi
        #3#1#2%

        providecommand@firstofthree[3]#1
        providecommand@secondofthree[3]#2
        providecommand@thirdofthree[3]#3
        makeatother


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



        In your case,



        ShellEscapeURNusepackagegitver


        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.



        usepackageexpl3

        ExplSyntaxOn
        cs_new:Npn ShellEscapeURN #1 #2 #3

        sys_if_shell_unrestricted:TF
        #1 % unrestricted shell

        sys_if_shell_restricted:TF
        #2
        #3


        ExplSyntaxOff





        share|improve this answer
















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



        usepackagepdftexcmds

        makeatletter
        newcommandShellEscapeURN[3]%
        ifcasepdf@shellescape
        expandafter@firstofthree % 0 = no shell escape
        or
        expandafter@secondofthree % 1 = unrestricted
        or
        expandafter@thirdofthree % 2 = restricted
        else
        expandafter@firstofthree
        fi
        #3#1#2%

        providecommand@firstofthree[3]#1
        providecommand@secondofthree[3]#2
        providecommand@thirdofthree[3]#3
        makeatother


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



        In your case,



        ShellEscapeURNusepackagegitver


        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.



        usepackageexpl3

        ExplSyntaxOn
        cs_new:Npn ShellEscapeURN #1 #2 #3

        sys_if_shell_unrestricted:TF
        #1 % unrestricted shell

        sys_if_shell_restricted:TF
        #2
        #3


        ExplSyntaxOff






        share|improve this answer















        share|improve this answer




        share|improve this answer








        edited Sep 19 at 14:10

























        answered Sep 19 at 14:00









        egregegreg

        785k93 gold badges2046 silver badges3416 bronze badges




        785k93 gold badges2046 silver badges3416 bronze badges































            draft saved

            draft discarded















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f508919%2fhow-to-conditionally-load-a-package-only-if-shell-escape-write18-is-passed%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown









            Popular posts from this blog

            Tamil (spriik) Luke uk diar | Nawigatjuun

            Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

            Training a classifier when some of the features are unknownWhy does Gradient Boosting regression predict negative values when there are no negative y-values in my training set?How to improve an existing (trained) classifier?What is effect when I set up some self defined predisctor variables?Why Matlab neural network classification returns decimal values on prediction dataset?Fitting and transforming text data in training, testing, and validation setsHow to quantify the performance of the classifier (multi-class SVM) using the test data?How do I control for some patients providing multiple samples in my training data?Training and Test setTraining a convolutional neural network for image denoising in MatlabShouldn't an autoencoder with #(neurons in hidden layer) = #(neurons in input layer) be “perfect”?