What is the best practice to pass spaces to Lua from expl3?
up vote
12
down vote
favorite
In LuaTeX, using the directlua
primitive (within a standard LaTeX2e setup)
directlua{tex.print("Hello World!")}
will produce "Hello World!" to the output PDF.
On the other hand, in expl3 code
ExplSyntaxOn
lua_now:e { tex.print("Hello~World!") }
ExplSyntaxOff
left "HelloWorld!" (no space between Hello
and World!
) to the input stream.
What is the best practice to pass spaces to Lua interpreter from expl3 code?
luatex expl3
add a comment |
up vote
12
down vote
favorite
In LuaTeX, using the directlua
primitive (within a standard LaTeX2e setup)
directlua{tex.print("Hello World!")}
will produce "Hello World!" to the output PDF.
On the other hand, in expl3 code
ExplSyntaxOn
lua_now:e { tex.print("Hello~World!") }
ExplSyntaxOff
left "HelloWorld!" (no space between Hello
and World!
) to the input stream.
What is the best practice to pass spaces to Lua interpreter from expl3 code?
luatex expl3
add a comment |
up vote
12
down vote
favorite
up vote
12
down vote
favorite
In LuaTeX, using the directlua
primitive (within a standard LaTeX2e setup)
directlua{tex.print("Hello World!")}
will produce "Hello World!" to the output PDF.
On the other hand, in expl3 code
ExplSyntaxOn
lua_now:e { tex.print("Hello~World!") }
ExplSyntaxOff
left "HelloWorld!" (no space between Hello
and World!
) to the input stream.
What is the best practice to pass spaces to Lua interpreter from expl3 code?
luatex expl3
In LuaTeX, using the directlua
primitive (within a standard LaTeX2e setup)
directlua{tex.print("Hello World!")}
will produce "Hello World!" to the output PDF.
On the other hand, in expl3 code
ExplSyntaxOn
lua_now:e { tex.print("Hello~World!") }
ExplSyntaxOff
left "HelloWorld!" (no space between Hello
and World!
) to the input stream.
What is the best practice to pass spaces to Lua interpreter from expl3 code?
luatex expl3
luatex expl3
edited Dec 5 at 7:12
Raaja
2,0602628
2,0602628
asked Dec 5 at 5:26
wtsnjp
657
657
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
14
down vote
accepted
In general, we recommend that Lua chunks are defined separately from expl3
(or indeed standard LaTeX) code, so they can simply be loaded using require()
. Where you do want a short piece of Lua 'inside' expl3
, using ~
is the correct action. However, when you use tex.print
or similar to return tokens to TeX, LuaTeX tokenizes them using the current catcode regime. As such, your space gets ignored. However, there is an optional argument to tex.print()
which takes a category code table number: this can be used to apply any catcode setup one likes.
At present, we are finalising category code table support for expl3
. The 'Lua side' is perhaps not quite right just yet, but it is workable:
documentclass{article}
usepackage{expl3}
usepackage{l3cctab}
begin{document}
ExplSyntaxOn
lua_now:e { tex.print(int_use:N c_document_cctab, "Hello~World!") }
ExplSyntaxOn
end{document}
(Eventually, l3cctab
will be part of the expl3
core.)
Category code tables are supported by LaTeX nowadays via ltluatex
: you could avoid loading l3cctab
entirely:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
makeatletter
lua_now:e { tex.print(numbercatcodetable@latex, "Hello~World!") }
makeatother
ExplSyntaxOn
end{document}
we really should fix thatnumber
requirement
– David Carlisle
Dec 5 at 8:07
@DavidCarlisle Yeah, that did bother me too, hence the 'we are working on it' part: probably we should have a Lua name for the information, which we can create in parallel with thecount
(so we don't have to point to thetex.count
table)
– Joseph Wright♦
Dec 5 at 10:04
yes or allow e@allocate to use def rather than chardef to define the allocated integer so they are expandable
– David Carlisle
Dec 5 at 10:07
@DavidCarlisle That was my other thought too (also forexpl3
version). I see the point, but I suspect longer-term this should have a 'proper' Lua-side interface
– Joseph Wright♦
Dec 5 at 10:08
add a comment |
up vote
10
down vote
As Joseph said, the default tex.print
will tokenize by the catcode current at that point so rather than letting ~
making a space then printing with a normal catcode regime, you can print with the expl3
catcode regime which means that you nneed to print a ~
so need to avoid the ~
being tokenised as a space as it's passed to Lua:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
lua_now:e { tex.print("Hello c_tilde_str World!") }
ExplSyntaxOn
end{document}
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',
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%2f463276%2fwhat-is-the-best-practice-to-pass-spaces-to-lua-from-expl3%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
up vote
14
down vote
accepted
In general, we recommend that Lua chunks are defined separately from expl3
(or indeed standard LaTeX) code, so they can simply be loaded using require()
. Where you do want a short piece of Lua 'inside' expl3
, using ~
is the correct action. However, when you use tex.print
or similar to return tokens to TeX, LuaTeX tokenizes them using the current catcode regime. As such, your space gets ignored. However, there is an optional argument to tex.print()
which takes a category code table number: this can be used to apply any catcode setup one likes.
At present, we are finalising category code table support for expl3
. The 'Lua side' is perhaps not quite right just yet, but it is workable:
documentclass{article}
usepackage{expl3}
usepackage{l3cctab}
begin{document}
ExplSyntaxOn
lua_now:e { tex.print(int_use:N c_document_cctab, "Hello~World!") }
ExplSyntaxOn
end{document}
(Eventually, l3cctab
will be part of the expl3
core.)
Category code tables are supported by LaTeX nowadays via ltluatex
: you could avoid loading l3cctab
entirely:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
makeatletter
lua_now:e { tex.print(numbercatcodetable@latex, "Hello~World!") }
makeatother
ExplSyntaxOn
end{document}
we really should fix thatnumber
requirement
– David Carlisle
Dec 5 at 8:07
@DavidCarlisle Yeah, that did bother me too, hence the 'we are working on it' part: probably we should have a Lua name for the information, which we can create in parallel with thecount
(so we don't have to point to thetex.count
table)
– Joseph Wright♦
Dec 5 at 10:04
yes or allow e@allocate to use def rather than chardef to define the allocated integer so they are expandable
– David Carlisle
Dec 5 at 10:07
@DavidCarlisle That was my other thought too (also forexpl3
version). I see the point, but I suspect longer-term this should have a 'proper' Lua-side interface
– Joseph Wright♦
Dec 5 at 10:08
add a comment |
up vote
14
down vote
accepted
In general, we recommend that Lua chunks are defined separately from expl3
(or indeed standard LaTeX) code, so they can simply be loaded using require()
. Where you do want a short piece of Lua 'inside' expl3
, using ~
is the correct action. However, when you use tex.print
or similar to return tokens to TeX, LuaTeX tokenizes them using the current catcode regime. As such, your space gets ignored. However, there is an optional argument to tex.print()
which takes a category code table number: this can be used to apply any catcode setup one likes.
At present, we are finalising category code table support for expl3
. The 'Lua side' is perhaps not quite right just yet, but it is workable:
documentclass{article}
usepackage{expl3}
usepackage{l3cctab}
begin{document}
ExplSyntaxOn
lua_now:e { tex.print(int_use:N c_document_cctab, "Hello~World!") }
ExplSyntaxOn
end{document}
(Eventually, l3cctab
will be part of the expl3
core.)
Category code tables are supported by LaTeX nowadays via ltluatex
: you could avoid loading l3cctab
entirely:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
makeatletter
lua_now:e { tex.print(numbercatcodetable@latex, "Hello~World!") }
makeatother
ExplSyntaxOn
end{document}
we really should fix thatnumber
requirement
– David Carlisle
Dec 5 at 8:07
@DavidCarlisle Yeah, that did bother me too, hence the 'we are working on it' part: probably we should have a Lua name for the information, which we can create in parallel with thecount
(so we don't have to point to thetex.count
table)
– Joseph Wright♦
Dec 5 at 10:04
yes or allow e@allocate to use def rather than chardef to define the allocated integer so they are expandable
– David Carlisle
Dec 5 at 10:07
@DavidCarlisle That was my other thought too (also forexpl3
version). I see the point, but I suspect longer-term this should have a 'proper' Lua-side interface
– Joseph Wright♦
Dec 5 at 10:08
add a comment |
up vote
14
down vote
accepted
up vote
14
down vote
accepted
In general, we recommend that Lua chunks are defined separately from expl3
(or indeed standard LaTeX) code, so they can simply be loaded using require()
. Where you do want a short piece of Lua 'inside' expl3
, using ~
is the correct action. However, when you use tex.print
or similar to return tokens to TeX, LuaTeX tokenizes them using the current catcode regime. As such, your space gets ignored. However, there is an optional argument to tex.print()
which takes a category code table number: this can be used to apply any catcode setup one likes.
At present, we are finalising category code table support for expl3
. The 'Lua side' is perhaps not quite right just yet, but it is workable:
documentclass{article}
usepackage{expl3}
usepackage{l3cctab}
begin{document}
ExplSyntaxOn
lua_now:e { tex.print(int_use:N c_document_cctab, "Hello~World!") }
ExplSyntaxOn
end{document}
(Eventually, l3cctab
will be part of the expl3
core.)
Category code tables are supported by LaTeX nowadays via ltluatex
: you could avoid loading l3cctab
entirely:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
makeatletter
lua_now:e { tex.print(numbercatcodetable@latex, "Hello~World!") }
makeatother
ExplSyntaxOn
end{document}
In general, we recommend that Lua chunks are defined separately from expl3
(or indeed standard LaTeX) code, so they can simply be loaded using require()
. Where you do want a short piece of Lua 'inside' expl3
, using ~
is the correct action. However, when you use tex.print
or similar to return tokens to TeX, LuaTeX tokenizes them using the current catcode regime. As such, your space gets ignored. However, there is an optional argument to tex.print()
which takes a category code table number: this can be used to apply any catcode setup one likes.
At present, we are finalising category code table support for expl3
. The 'Lua side' is perhaps not quite right just yet, but it is workable:
documentclass{article}
usepackage{expl3}
usepackage{l3cctab}
begin{document}
ExplSyntaxOn
lua_now:e { tex.print(int_use:N c_document_cctab, "Hello~World!") }
ExplSyntaxOn
end{document}
(Eventually, l3cctab
will be part of the expl3
core.)
Category code tables are supported by LaTeX nowadays via ltluatex
: you could avoid loading l3cctab
entirely:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
makeatletter
lua_now:e { tex.print(numbercatcodetable@latex, "Hello~World!") }
makeatother
ExplSyntaxOn
end{document}
edited Dec 5 at 7:44
answered Dec 5 at 7:36
Joseph Wright♦
201k21554879
201k21554879
we really should fix thatnumber
requirement
– David Carlisle
Dec 5 at 8:07
@DavidCarlisle Yeah, that did bother me too, hence the 'we are working on it' part: probably we should have a Lua name for the information, which we can create in parallel with thecount
(so we don't have to point to thetex.count
table)
– Joseph Wright♦
Dec 5 at 10:04
yes or allow e@allocate to use def rather than chardef to define the allocated integer so they are expandable
– David Carlisle
Dec 5 at 10:07
@DavidCarlisle That was my other thought too (also forexpl3
version). I see the point, but I suspect longer-term this should have a 'proper' Lua-side interface
– Joseph Wright♦
Dec 5 at 10:08
add a comment |
we really should fix thatnumber
requirement
– David Carlisle
Dec 5 at 8:07
@DavidCarlisle Yeah, that did bother me too, hence the 'we are working on it' part: probably we should have a Lua name for the information, which we can create in parallel with thecount
(so we don't have to point to thetex.count
table)
– Joseph Wright♦
Dec 5 at 10:04
yes or allow e@allocate to use def rather than chardef to define the allocated integer so they are expandable
– David Carlisle
Dec 5 at 10:07
@DavidCarlisle That was my other thought too (also forexpl3
version). I see the point, but I suspect longer-term this should have a 'proper' Lua-side interface
– Joseph Wright♦
Dec 5 at 10:08
we really should fix that
number
requirement– David Carlisle
Dec 5 at 8:07
we really should fix that
number
requirement– David Carlisle
Dec 5 at 8:07
@DavidCarlisle Yeah, that did bother me too, hence the 'we are working on it' part: probably we should have a Lua name for the information, which we can create in parallel with the
count
(so we don't have to point to the tex.count
table)– Joseph Wright♦
Dec 5 at 10:04
@DavidCarlisle Yeah, that did bother me too, hence the 'we are working on it' part: probably we should have a Lua name for the information, which we can create in parallel with the
count
(so we don't have to point to the tex.count
table)– Joseph Wright♦
Dec 5 at 10:04
yes or allow e@allocate to use def rather than chardef to define the allocated integer so they are expandable
– David Carlisle
Dec 5 at 10:07
yes or allow e@allocate to use def rather than chardef to define the allocated integer so they are expandable
– David Carlisle
Dec 5 at 10:07
@DavidCarlisle That was my other thought too (also for
expl3
version). I see the point, but I suspect longer-term this should have a 'proper' Lua-side interface– Joseph Wright♦
Dec 5 at 10:08
@DavidCarlisle That was my other thought too (also for
expl3
version). I see the point, but I suspect longer-term this should have a 'proper' Lua-side interface– Joseph Wright♦
Dec 5 at 10:08
add a comment |
up vote
10
down vote
As Joseph said, the default tex.print
will tokenize by the catcode current at that point so rather than letting ~
making a space then printing with a normal catcode regime, you can print with the expl3
catcode regime which means that you nneed to print a ~
so need to avoid the ~
being tokenised as a space as it's passed to Lua:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
lua_now:e { tex.print("Hello c_tilde_str World!") }
ExplSyntaxOn
end{document}
add a comment |
up vote
10
down vote
As Joseph said, the default tex.print
will tokenize by the catcode current at that point so rather than letting ~
making a space then printing with a normal catcode regime, you can print with the expl3
catcode regime which means that you nneed to print a ~
so need to avoid the ~
being tokenised as a space as it's passed to Lua:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
lua_now:e { tex.print("Hello c_tilde_str World!") }
ExplSyntaxOn
end{document}
add a comment |
up vote
10
down vote
up vote
10
down vote
As Joseph said, the default tex.print
will tokenize by the catcode current at that point so rather than letting ~
making a space then printing with a normal catcode regime, you can print with the expl3
catcode regime which means that you nneed to print a ~
so need to avoid the ~
being tokenised as a space as it's passed to Lua:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
lua_now:e { tex.print("Hello c_tilde_str World!") }
ExplSyntaxOn
end{document}
As Joseph said, the default tex.print
will tokenize by the catcode current at that point so rather than letting ~
making a space then printing with a normal catcode regime, you can print with the expl3
catcode regime which means that you nneed to print a ~
so need to avoid the ~
being tokenised as a space as it's passed to Lua:
documentclass{article}
usepackage{expl3}
begin{document}
ExplSyntaxOn
lua_now:e { tex.print("Hello c_tilde_str World!") }
ExplSyntaxOn
end{document}
answered Dec 5 at 8:19
David Carlisle
480k3811121848
480k3811121848
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f463276%2fwhat-is-the-best-practice-to-pass-spaces-to-lua-from-expl3%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