Defining new commands from LuaTeX

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite
1












Latex provides several commands relating to creating new commands such as newcommand. If I want to define new commands from a Lua script one way is use tex.print to write this directly into the document.



It this really the best way though? The whole point of LuaTeX is to avoid programming with Tex macros, yet this approaches involves doing exactly that. How can I directly access, edit and create commands directly from Lua?



script.lua



tex.print("\newcommand\helloHello world")


document.tex



documentclassarticle
begindocument
directlua require("script")
hello
enddocument









share|improve this question























  • LuaTeX is about combining Lua and TeX: if you look at ConTeXt, it is still a macro system using Lua _where it adds functionality
    – Joseph Wright♦
    6 mins ago














up vote
6
down vote

favorite
1












Latex provides several commands relating to creating new commands such as newcommand. If I want to define new commands from a Lua script one way is use tex.print to write this directly into the document.



It this really the best way though? The whole point of LuaTeX is to avoid programming with Tex macros, yet this approaches involves doing exactly that. How can I directly access, edit and create commands directly from Lua?



script.lua



tex.print("\newcommand\helloHello world")


document.tex



documentclassarticle
begindocument
directlua require("script")
hello
enddocument









share|improve this question























  • LuaTeX is about combining Lua and TeX: if you look at ConTeXt, it is still a macro system using Lua _where it adds functionality
    – Joseph Wright♦
    6 mins ago












up vote
6
down vote

favorite
1









up vote
6
down vote

favorite
1






1





Latex provides several commands relating to creating new commands such as newcommand. If I want to define new commands from a Lua script one way is use tex.print to write this directly into the document.



It this really the best way though? The whole point of LuaTeX is to avoid programming with Tex macros, yet this approaches involves doing exactly that. How can I directly access, edit and create commands directly from Lua?



script.lua



tex.print("\newcommand\helloHello world")


document.tex



documentclassarticle
begindocument
directlua require("script")
hello
enddocument









share|improve this question















Latex provides several commands relating to creating new commands such as newcommand. If I want to define new commands from a Lua script one way is use tex.print to write this directly into the document.



It this really the best way though? The whole point of LuaTeX is to avoid programming with Tex macros, yet this approaches involves doing exactly that. How can I directly access, edit and create commands directly from Lua?



script.lua



tex.print("\newcommand\helloHello world")


document.tex



documentclassarticle
begindocument
directlua require("script")
hello
enddocument






luatex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 mins ago









Mico

263k30355730




263k30355730










asked 1 hour ago









raiksey

364




364











  • LuaTeX is about combining Lua and TeX: if you look at ConTeXt, it is still a macro system using Lua _where it adds functionality
    – Joseph Wright♦
    6 mins ago
















  • LuaTeX is about combining Lua and TeX: if you look at ConTeXt, it is still a macro system using Lua _where it adds functionality
    – Joseph Wright♦
    6 mins ago















LuaTeX is about combining Lua and TeX: if you look at ConTeXt, it is still a macro system using Lua _where it adds functionality
– Joseph Wright♦
6 mins ago




LuaTeX is about combining Lua and TeX: if you look at ConTeXt, it is still a macro system using Lua _where it adds functionality
– Joseph Wright♦
6 mins ago










1 Answer
1






active

oldest

votes

















up vote
9
down vote



accepted










documentclassarticle
begindocument
directluatoken.set_macro("hello","goodbye")
hello
enddocument


enter image description here






share|improve this answer




















  • Accepted, thank you. Do you know of any good packages/classes on CTAN I could look at that are implemented in Lua and do this sort of thing? (To try to understand the common patterns a bit better. I'm looking at building a document class)
    – raiksey
    1 hour ago











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: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
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%2f450891%2fdefining-new-commands-from-luatex%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
9
down vote



accepted










documentclassarticle
begindocument
directluatoken.set_macro("hello","goodbye")
hello
enddocument


enter image description here






share|improve this answer




















  • Accepted, thank you. Do you know of any good packages/classes on CTAN I could look at that are implemented in Lua and do this sort of thing? (To try to understand the common patterns a bit better. I'm looking at building a document class)
    – raiksey
    1 hour ago















up vote
9
down vote



accepted










documentclassarticle
begindocument
directluatoken.set_macro("hello","goodbye")
hello
enddocument


enter image description here






share|improve this answer




















  • Accepted, thank you. Do you know of any good packages/classes on CTAN I could look at that are implemented in Lua and do this sort of thing? (To try to understand the common patterns a bit better. I'm looking at building a document class)
    – raiksey
    1 hour ago













up vote
9
down vote



accepted







up vote
9
down vote



accepted






documentclassarticle
begindocument
directluatoken.set_macro("hello","goodbye")
hello
enddocument


enter image description here






share|improve this answer












documentclassarticle
begindocument
directluatoken.set_macro("hello","goodbye")
hello
enddocument


enter image description here







share|improve this answer












share|improve this answer



share|improve this answer










answered 1 hour ago









David Carlisle

467k3810941817




467k3810941817











  • Accepted, thank you. Do you know of any good packages/classes on CTAN I could look at that are implemented in Lua and do this sort of thing? (To try to understand the common patterns a bit better. I'm looking at building a document class)
    – raiksey
    1 hour ago

















  • Accepted, thank you. Do you know of any good packages/classes on CTAN I could look at that are implemented in Lua and do this sort of thing? (To try to understand the common patterns a bit better. I'm looking at building a document class)
    – raiksey
    1 hour ago
















Accepted, thank you. Do you know of any good packages/classes on CTAN I could look at that are implemented in Lua and do this sort of thing? (To try to understand the common patterns a bit better. I'm looking at building a document class)
– raiksey
1 hour ago





Accepted, thank you. Do you know of any good packages/classes on CTAN I could look at that are implemented in Lua and do this sort of thing? (To try to understand the common patterns a bit better. I'm looking at building a document class)
– raiksey
1 hour ago


















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f450891%2fdefining-new-commands-from-luatex%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

Installing NextGIS Connect into QGIS 3?

One-line joke