Expand def in write18What are immediate & write18 and how does one use them?how to escape special chars in write18?How do you detect restricted write18 supportHow to invoke write18pdflatex “defparam…inputfilename”?write18 encodingGet return value of `write18`Postprocess pdf with write18How to force-expand a def for in@?Get write18 to accept / expand command
Meaning of words заштырить and отштырить
When does The Truman Show take place?
Polar contour plot in Mathematica?
Earliest evidence of objects intended for future archaeologists?
How best to join tables, which have different lengths on the same column values which exist in both tables?
Can 'in-' mean both 'in' and 'no'?
My father gets angry everytime I pass Salam, that means I should stop saying Salam when he's around?
Are unaudited server logs admissible in a court of law?
Rotate List by K places
Is there a commercial liquid with refractive index greater than n=2?
Do predators tend to have vertical slit pupils versus horizontal for prey animals?
Unsolved Problems due to Lack of Computational Power
Why do balloons get cold when they deflate?
Why don't politicians push for fossil fuel reduction by pointing out their scarcity?
How do we test and determine if a USB cable+connector is version 2, 3.0 or 3.1?
Installing the original OS X version onto a Mac?
Best model for precedence constraints within scheduling problem
Why is su world executable?
Number of matrices with bounded products of rows and columns
How to translate 脑袋短路 into English?
Eric Andre had a dream
Is there a way to make the "o" keypress of other-window <C-x><C-o> repeatable?
Adding things to bunches of things vs multiplication
Repurpose telephone line to ethernet
Expand def in write18
What are immediate & write18 and how does one use them?how to escape special chars in write18?How do you detect restricted write18 supportHow to invoke write18pdflatex “defparam…inputfilename”?write18 encodingGet return value of `write18`Postprocess pdf with write18How to force-expand a def for in@?Get write18 to accept / expand command
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have defined the following command:
newcommandformatcommand[1]
deftemp#1
defsifxtempempty emptyelse not emptyfi
echo "s"
This works correctly:
formatcommand
formatcommand
However, when using the above command inside write18
,
immediatewrite18formatcommand
the def
s seem to not be expanding, since I'm getting def is not an executable...
, meaning that write18
sent the body of formatcommand
without expanding it to the command line. How can this be fixed?
MWE
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
deftemp#1
defsifxtempempty emptyelse not emptyfi
echo "s"
formatcommand
formatcommand
immediatewrite18formatcommand
enddocument
expansion shell-escape definition
add a comment |
I have defined the following command:
newcommandformatcommand[1]
deftemp#1
defsifxtempempty emptyelse not emptyfi
echo "s"
This works correctly:
formatcommand
formatcommand
However, when using the above command inside write18
,
immediatewrite18formatcommand
the def
s seem to not be expanding, since I'm getting def is not an executable...
, meaning that write18
sent the body of formatcommand
without expanding it to the command line. How can this be fixed?
MWE
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
deftemp#1
defsifxtempempty emptyelse not emptyfi
echo "s"
formatcommand
formatcommand
immediatewrite18formatcommand
enddocument
expansion shell-escape definition
add a comment |
I have defined the following command:
newcommandformatcommand[1]
deftemp#1
defsifxtempempty emptyelse not emptyfi
echo "s"
This works correctly:
formatcommand
formatcommand
However, when using the above command inside write18
,
immediatewrite18formatcommand
the def
s seem to not be expanding, since I'm getting def is not an executable...
, meaning that write18
sent the body of formatcommand
without expanding it to the command line. How can this be fixed?
MWE
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
deftemp#1
defsifxtempempty emptyelse not emptyfi
echo "s"
formatcommand
formatcommand
immediatewrite18formatcommand
enddocument
expansion shell-escape definition
I have defined the following command:
newcommandformatcommand[1]
deftemp#1
defsifxtempempty emptyelse not emptyfi
echo "s"
This works correctly:
formatcommand
formatcommand
However, when using the above command inside write18
,
immediatewrite18formatcommand
the def
s seem to not be expanding, since I'm getting def is not an executable...
, meaning that write18
sent the body of formatcommand
without expanding it to the command line. How can this be fixed?
MWE
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
deftemp#1
defsifxtempempty emptyelse not emptyfi
echo "s"
formatcommand
formatcommand
immediatewrite18formatcommand
enddocument
expansion shell-escape definition
expansion shell-escape definition
asked 11 hours ago
AnakhandAnakhand
2351 silver badge11 bronze badges
2351 silver badge11 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
When TeX writes the contents of a write
command, it expands all material similarly to what happens on an edef
defintion, i.e. all expandable commands are expanded but no execution happens. Macro definitions (or other assignments) are not expandable, so the def
s remain in the input stream when they are written as shell commands.
The solution is to use a fully-expandable test for an empty token list, like the following ifempty
macro:
makeatletter
newcommandifempty[1]%
ifrelaxdetokenize#1relax
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
newcommandformatcommand[1]
echo "ifempty#1emptynot empty"
add a comment |
Generally I recommend siracusa'a solution, but if you LuaTeX there is another trick which you can use if your problem can't be written in an expandable manner:
LuaTeX has primitives immediateassignment
and immediateassigned
which allow expandable def
s:
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
immediateassignmentdeftemp#1
immediateassignmentdefsifxtempempty emptyelse not emptyfi
echo "s"
formatcommand
formatcommand
immediatewrite255formatcommand
enddocument
(I replaced write18
with write255
to show the command on the terminal because shell-escape works differently in LuaTeX, so executing the command would have needed bigger changes.)
Using immediateassigned
, you can make all assignments in a block expandable:
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
immediateassigned%
deftemp#1
defsifxtempempty emptyelse not emptyfi
%
echo "s"
formatcommand
formatcommand
immediatewrite255formatcommand
enddocument
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/3.0/"u003ecc by-sa 3.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%2f504697%2fexpand-def-in-write18%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
When TeX writes the contents of a write
command, it expands all material similarly to what happens on an edef
defintion, i.e. all expandable commands are expanded but no execution happens. Macro definitions (or other assignments) are not expandable, so the def
s remain in the input stream when they are written as shell commands.
The solution is to use a fully-expandable test for an empty token list, like the following ifempty
macro:
makeatletter
newcommandifempty[1]%
ifrelaxdetokenize#1relax
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
newcommandformatcommand[1]
echo "ifempty#1emptynot empty"
add a comment |
When TeX writes the contents of a write
command, it expands all material similarly to what happens on an edef
defintion, i.e. all expandable commands are expanded but no execution happens. Macro definitions (or other assignments) are not expandable, so the def
s remain in the input stream when they are written as shell commands.
The solution is to use a fully-expandable test for an empty token list, like the following ifempty
macro:
makeatletter
newcommandifempty[1]%
ifrelaxdetokenize#1relax
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
newcommandformatcommand[1]
echo "ifempty#1emptynot empty"
add a comment |
When TeX writes the contents of a write
command, it expands all material similarly to what happens on an edef
defintion, i.e. all expandable commands are expanded but no execution happens. Macro definitions (or other assignments) are not expandable, so the def
s remain in the input stream when they are written as shell commands.
The solution is to use a fully-expandable test for an empty token list, like the following ifempty
macro:
makeatletter
newcommandifempty[1]%
ifrelaxdetokenize#1relax
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
newcommandformatcommand[1]
echo "ifempty#1emptynot empty"
When TeX writes the contents of a write
command, it expands all material similarly to what happens on an edef
defintion, i.e. all expandable commands are expanded but no execution happens. Macro definitions (or other assignments) are not expandable, so the def
s remain in the input stream when they are written as shell commands.
The solution is to use a fully-expandable test for an empty token list, like the following ifempty
macro:
makeatletter
newcommandifempty[1]%
ifrelaxdetokenize#1relax
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
makeatother
newcommandformatcommand[1]
echo "ifempty#1emptynot empty"
edited 11 hours ago
answered 11 hours ago
siracusasiracusa
7,9812 gold badges18 silver badges35 bronze badges
7,9812 gold badges18 silver badges35 bronze badges
add a comment |
add a comment |
Generally I recommend siracusa'a solution, but if you LuaTeX there is another trick which you can use if your problem can't be written in an expandable manner:
LuaTeX has primitives immediateassignment
and immediateassigned
which allow expandable def
s:
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
immediateassignmentdeftemp#1
immediateassignmentdefsifxtempempty emptyelse not emptyfi
echo "s"
formatcommand
formatcommand
immediatewrite255formatcommand
enddocument
(I replaced write18
with write255
to show the command on the terminal because shell-escape works differently in LuaTeX, so executing the command would have needed bigger changes.)
Using immediateassigned
, you can make all assignments in a block expandable:
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
immediateassigned%
deftemp#1
defsifxtempempty emptyelse not emptyfi
%
echo "s"
formatcommand
formatcommand
immediatewrite255formatcommand
enddocument
add a comment |
Generally I recommend siracusa'a solution, but if you LuaTeX there is another trick which you can use if your problem can't be written in an expandable manner:
LuaTeX has primitives immediateassignment
and immediateassigned
which allow expandable def
s:
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
immediateassignmentdeftemp#1
immediateassignmentdefsifxtempempty emptyelse not emptyfi
echo "s"
formatcommand
formatcommand
immediatewrite255formatcommand
enddocument
(I replaced write18
with write255
to show the command on the terminal because shell-escape works differently in LuaTeX, so executing the command would have needed bigger changes.)
Using immediateassigned
, you can make all assignments in a block expandable:
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
immediateassigned%
deftemp#1
defsifxtempempty emptyelse not emptyfi
%
echo "s"
formatcommand
formatcommand
immediatewrite255formatcommand
enddocument
add a comment |
Generally I recommend siracusa'a solution, but if you LuaTeX there is another trick which you can use if your problem can't be written in an expandable manner:
LuaTeX has primitives immediateassignment
and immediateassigned
which allow expandable def
s:
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
immediateassignmentdeftemp#1
immediateassignmentdefsifxtempempty emptyelse not emptyfi
echo "s"
formatcommand
formatcommand
immediatewrite255formatcommand
enddocument
(I replaced write18
with write255
to show the command on the terminal because shell-escape works differently in LuaTeX, so executing the command would have needed bigger changes.)
Using immediateassigned
, you can make all assignments in a block expandable:
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
immediateassigned%
deftemp#1
defsifxtempempty emptyelse not emptyfi
%
echo "s"
formatcommand
formatcommand
immediatewrite255formatcommand
enddocument
Generally I recommend siracusa'a solution, but if you LuaTeX there is another trick which you can use if your problem can't be written in an expandable manner:
LuaTeX has primitives immediateassignment
and immediateassigned
which allow expandable def
s:
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
immediateassignmentdeftemp#1
immediateassignmentdefsifxtempempty emptyelse not emptyfi
echo "s"
formatcommand
formatcommand
immediatewrite255formatcommand
enddocument
(I replaced write18
with write255
to show the command on the terminal because shell-escape works differently in LuaTeX, so executing the command would have needed bigger changes.)
Using immediateassigned
, you can make all assignments in a block expandable:
documentclass[border=1cm]standalone
begindocument
newcommandformatcommand[1]
immediateassigned%
deftemp#1
defsifxtempempty emptyelse not emptyfi
%
echo "s"
formatcommand
formatcommand
immediatewrite255formatcommand
enddocument
answered 10 hours ago
Marcel KrügerMarcel Krüger
15.2k1 gold badge18 silver badges38 bronze badges
15.2k1 gold badge18 silver badges38 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%2f504697%2fexpand-def-in-write18%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