Defining new commands from Lua

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











up vote
3
down vote

favorite












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



























    up vote
    3
    down vote

    favorite












    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

























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      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 36 mins ago

























      asked 59 mins ago









      raiksey

      214




      214




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          5
          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
            30 mins 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-lua%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
          5
          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
            30 mins ago















          up vote
          5
          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
            30 mins ago













          up vote
          5
          down vote



          accepted







          up vote
          5
          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 55 mins 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
            30 mins 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
            30 mins 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
          30 mins 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
          30 mins 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-lua%23new-answer', 'question_page');

          );

          Post as a guest













































































          Comments

          Popular posts from this blog

          Long meetings (6-7 hours a day): Being “babysat” by supervisor

          Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

          Confectionery