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;
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 git
VCS 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
add a comment
|
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 git
VCS 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
For the given problem you may want to have a look atgitinfo2
instead ofgitver
sincegitinfo2
doesn’t require shell-escape (I think).
– Jendrik Stelzner
Sep 20 at 1:55
add a comment
|
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 git
VCS 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
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 git
VCS 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
conditionals shell-escape
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 atgitinfo2
instead ofgitver
sincegitinfo2
doesn’t require shell-escape (I think).
– Jendrik Stelzner
Sep 20 at 1:55
add a comment
|
For the given problem you may want to have a look atgitinfo2
instead ofgitver
sincegitinfo2
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
add a comment
|
2 Answers
2
active
oldest
votes
expl3 has a test:
documentclassarticle
usepackageexpl3
csname sys_if_shell_unrestricted:Tendcsnameusepackagegitver
begindocument
Hello world!
enddocument
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 Maybepdftexcmds
?
– egreg
Sep 19 at 14:11
add a comment
|
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
add a comment
|
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
expl3 has a test:
documentclassarticle
usepackageexpl3
csname sys_if_shell_unrestricted:Tendcsnameusepackagegitver
begindocument
Hello world!
enddocument
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 Maybepdftexcmds
?
– egreg
Sep 19 at 14:11
add a comment
|
expl3 has a test:
documentclassarticle
usepackageexpl3
csname sys_if_shell_unrestricted:Tendcsnameusepackagegitver
begindocument
Hello world!
enddocument
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 Maybepdftexcmds
?
– egreg
Sep 19 at 14:11
add a comment
|
expl3 has a test:
documentclassarticle
usepackageexpl3
csname sys_if_shell_unrestricted:Tendcsnameusepackagegitver
begindocument
Hello world!
enddocument
expl3 has a test:
documentclassarticle
usepackageexpl3
csname sys_if_shell_unrestricted:Tendcsnameusepackagegitver
begindocument
Hello world!
enddocument
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 Maybepdftexcmds
?
– egreg
Sep 19 at 14:11
add a comment
|
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 Maybepdftexcmds
?
– 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
add a comment
|
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
add a comment
|
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
add a comment
|
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
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
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
add a comment
|
add a comment
|
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
For the given problem you may want to have a look at
gitinfo2
instead ofgitver
sincegitinfo2
doesn’t require shell-escape (I think).– Jendrik Stelzner
Sep 20 at 1:55