Perform and show arithmetic with LuaLaTeXHow to do a 'printline' in LuaTeXLuaTeX: How to handle a Lua function that prints TeX macrosLuaLatex: Difference between `dofile` and `require` when loading lua filesArithmetic overflow with fontspec and LuaTeXHow to perform arithmetic within siunitx?Perform simple calculations on user-defined variablesPerform spreadsheet-like calculations and display formula and resultPrecompiled header with lualatex and unicode-mathLuaLatex, includespread and libreoffice table with %Automated Creation of Questions and Solutions for a Worksheet/ExamPerform math operation with values of labelsArithmetic/calculations with lengthsConTeXt passing current counter value to lua

Character reincarnated...as a snail

Why are electrically insulating heatsinks so rare? Is it just cost?

Has there ever been an airliner design involving reducing generator load by installing solar panels?

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

How old can references or sources in a thesis be?

Do infinite dimensional systems make sense?

Maximum likelihood parameters deviate from posterior distributions

Can a vampire attack twice with their claws using Multiattack?

What would happen to a modern skyscraper if it rains micro blackholes?

How much RAM could one put in a typical 80386 setup?

Does an object always see its latest internal state irrespective of thread?

How to efficiently unroll a matrix by value with numpy?

Is it possible to do 50 km distance without any previous training?

Why is 150k or 200k jobs considered good when there's 300k+ births a month?

LaTeX: Why are digits allowed in environments, but forbidden in commands?

Does detail obscure or enhance action?

Replacing matching entries in one column of a file by another column from a different file

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

What does "Puller Prush Person" mean?

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

Convert two switches to a dual stack, and add outlet - possible here?

I'm flying to France today and my passport expires in less than 2 months

Revoked SSL certificate

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?



Perform and show arithmetic with LuaLaTeX


How to do a 'printline' in LuaTeXLuaTeX: How to handle a Lua function that prints TeX macrosLuaLatex: Difference between `dofile` and `require` when loading lua filesArithmetic overflow with fontspec and LuaTeXHow to perform arithmetic within siunitx?Perform simple calculations on user-defined variablesPerform spreadsheet-like calculations and display formula and resultPrecompiled header with lualatex and unicode-mathLuaLatex, includespread and libreoffice table with %Automated Creation of Questions and Solutions for a Worksheet/ExamPerform math operation with values of labelsArithmetic/calculations with lengthsConTeXt passing current counter value to lua













3















The function I'm trying to create is one that takes two numbers and prints the result with some math. The following is my code:



documentclass[12pt,a4paper]article

begindocument
directlua
function prod(a,b)
tex.print(a "$times$" b "$=$" a*c)
end


The product of 2 and 3: directluaprod(2,3).
enddocument


I can't make it print the whole statement correctly. How to solve it?










share|improve this question



















  • 3





    Try tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")

    – moewe
    9 hours ago






  • 1





    Unlike TeX, to which everything is (by default) a token to be typeset so you can simply write "hello world" and have those words appear in the typeset output, Lua is a general-purpose programming language in which something like a b is a syntax error (assuming a and b are variables). Here, tex.print is a Lua function that takes a single string as input, so you need to give it a single string. (There are other forms of tex.print too, that you can read in the LuaTeX manual, but those are probably not what you want.) Lua uses .. to concatenate strings.

    – ShreevatsaR
    9 hours ago






  • 2





    BTW instead of concatenating different strings with .., you can also use string.format to build a string, e.g. in a file test.lua put function prod(a,b) tex.print(string.format([[$%d times %d = %d$]], a, b, a*b)) end and in your file do directluadofile('test.lua') -- here the [[ instead of " is to avoid needing to escape the backslash in times.

    – ShreevatsaR
    9 hours ago











  • @ShreevatsaR Thanks for that option!

    – Levy
    8 hours ago















3















The function I'm trying to create is one that takes two numbers and prints the result with some math. The following is my code:



documentclass[12pt,a4paper]article

begindocument
directlua
function prod(a,b)
tex.print(a "$times$" b "$=$" a*c)
end


The product of 2 and 3: directluaprod(2,3).
enddocument


I can't make it print the whole statement correctly. How to solve it?










share|improve this question



















  • 3





    Try tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")

    – moewe
    9 hours ago






  • 1





    Unlike TeX, to which everything is (by default) a token to be typeset so you can simply write "hello world" and have those words appear in the typeset output, Lua is a general-purpose programming language in which something like a b is a syntax error (assuming a and b are variables). Here, tex.print is a Lua function that takes a single string as input, so you need to give it a single string. (There are other forms of tex.print too, that you can read in the LuaTeX manual, but those are probably not what you want.) Lua uses .. to concatenate strings.

    – ShreevatsaR
    9 hours ago






  • 2





    BTW instead of concatenating different strings with .., you can also use string.format to build a string, e.g. in a file test.lua put function prod(a,b) tex.print(string.format([[$%d times %d = %d$]], a, b, a*b)) end and in your file do directluadofile('test.lua') -- here the [[ instead of " is to avoid needing to escape the backslash in times.

    – ShreevatsaR
    9 hours ago











  • @ShreevatsaR Thanks for that option!

    – Levy
    8 hours ago













3












3








3








The function I'm trying to create is one that takes two numbers and prints the result with some math. The following is my code:



documentclass[12pt,a4paper]article

begindocument
directlua
function prod(a,b)
tex.print(a "$times$" b "$=$" a*c)
end


The product of 2 and 3: directluaprod(2,3).
enddocument


I can't make it print the whole statement correctly. How to solve it?










share|improve this question
















The function I'm trying to create is one that takes two numbers and prints the result with some math. The following is my code:



documentclass[12pt,a4paper]article

begindocument
directlua
function prod(a,b)
tex.print(a "$times$" b "$=$" a*c)
end


The product of 2 and 3: directluaprod(2,3).
enddocument


I can't make it print the whole statement correctly. How to solve it?







luatex calculations






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago









Mico

285k31388778




285k31388778










asked 9 hours ago









LevyLevy

437312




437312







  • 3





    Try tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")

    – moewe
    9 hours ago






  • 1





    Unlike TeX, to which everything is (by default) a token to be typeset so you can simply write "hello world" and have those words appear in the typeset output, Lua is a general-purpose programming language in which something like a b is a syntax error (assuming a and b are variables). Here, tex.print is a Lua function that takes a single string as input, so you need to give it a single string. (There are other forms of tex.print too, that you can read in the LuaTeX manual, but those are probably not what you want.) Lua uses .. to concatenate strings.

    – ShreevatsaR
    9 hours ago






  • 2





    BTW instead of concatenating different strings with .., you can also use string.format to build a string, e.g. in a file test.lua put function prod(a,b) tex.print(string.format([[$%d times %d = %d$]], a, b, a*b)) end and in your file do directluadofile('test.lua') -- here the [[ instead of " is to avoid needing to escape the backslash in times.

    – ShreevatsaR
    9 hours ago











  • @ShreevatsaR Thanks for that option!

    – Levy
    8 hours ago












  • 3





    Try tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")

    – moewe
    9 hours ago






  • 1





    Unlike TeX, to which everything is (by default) a token to be typeset so you can simply write "hello world" and have those words appear in the typeset output, Lua is a general-purpose programming language in which something like a b is a syntax error (assuming a and b are variables). Here, tex.print is a Lua function that takes a single string as input, so you need to give it a single string. (There are other forms of tex.print too, that you can read in the LuaTeX manual, but those are probably not what you want.) Lua uses .. to concatenate strings.

    – ShreevatsaR
    9 hours ago






  • 2





    BTW instead of concatenating different strings with .., you can also use string.format to build a string, e.g. in a file test.lua put function prod(a,b) tex.print(string.format([[$%d times %d = %d$]], a, b, a*b)) end and in your file do directluadofile('test.lua') -- here the [[ instead of " is to avoid needing to escape the backslash in times.

    – ShreevatsaR
    9 hours ago











  • @ShreevatsaR Thanks for that option!

    – Levy
    8 hours ago







3




3





Try tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")

– moewe
9 hours ago





Try tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")

– moewe
9 hours ago




1




1





Unlike TeX, to which everything is (by default) a token to be typeset so you can simply write "hello world" and have those words appear in the typeset output, Lua is a general-purpose programming language in which something like a b is a syntax error (assuming a and b are variables). Here, tex.print is a Lua function that takes a single string as input, so you need to give it a single string. (There are other forms of tex.print too, that you can read in the LuaTeX manual, but those are probably not what you want.) Lua uses .. to concatenate strings.

– ShreevatsaR
9 hours ago





Unlike TeX, to which everything is (by default) a token to be typeset so you can simply write "hello world" and have those words appear in the typeset output, Lua is a general-purpose programming language in which something like a b is a syntax error (assuming a and b are variables). Here, tex.print is a Lua function that takes a single string as input, so you need to give it a single string. (There are other forms of tex.print too, that you can read in the LuaTeX manual, but those are probably not what you want.) Lua uses .. to concatenate strings.

– ShreevatsaR
9 hours ago




2




2





BTW instead of concatenating different strings with .., you can also use string.format to build a string, e.g. in a file test.lua put function prod(a,b) tex.print(string.format([[$%d times %d = %d$]], a, b, a*b)) end and in your file do directluadofile('test.lua') -- here the [[ instead of " is to avoid needing to escape the backslash in times.

– ShreevatsaR
9 hours ago





BTW instead of concatenating different strings with .., you can also use string.format to build a string, e.g. in a file test.lua put function prod(a,b) tex.print(string.format([[$%d times %d = %d$]], a, b, a*b)) end and in your file do directluadofile('test.lua') -- here the [[ instead of " is to avoid needing to escape the backslash in times.

– ShreevatsaR
9 hours ago













@ShreevatsaR Thanks for that option!

– Levy
8 hours ago





@ShreevatsaR Thanks for that option!

– Levy
8 hours ago










3 Answers
3






active

oldest

votes


















6














documentclass[12pt,a4paper]article

directlua
function prod(a,b)
tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")
end


begindocument
The product of 2 and 3: directluaprod(2,3).
enddocument


The product of 2 and 3: 2 × 3 = 6.



One tricky thing is getting the backslash escaping game right: LuaTeX: How to handle a Lua function that prints TeX macros. directlua expands macros before passing them on to Lua, so times gets messed up. But something like stringtimes, which should stop that expansion does not quite work as intended because t is a special escape for the tab in Lua. Hence we need to escape the backslash there. In Lua you would have to type \times, but in TeX we need to stop the \ from being expanded, so we need string\times. That is one of the reasons why it is often recommended to use the luacode package or externalise Lua functions into their own .lua files and then load them with dofile or require (see for example How to do a 'printline' in LuaTeX, a bit on dofile and require can be found at LuaLatex: Difference between `dofile` and `require` when loading lua files).



Another thing is that you need .. to concatenate strings.



Finally, you probably want the entire expression in math mode and not just certain bits.



Also moved the directlua function definition into the preamble. (Thanks to Mico for the suggestion.)






share|improve this answer

























  • That's what I was looking for. It worked here. Thank you!

    – Levy
    9 hours ago











  • And the explanation was really helpful!

    – Levy
    9 hours ago


















5














documentclass[12pt,a4paper]article

begindocument
directlua
function prod(a,b)
tex.print(a.. "$string\times$".. b.. "$=$".. a*b)
end


The product of 2 and 3: directluaprod(2,3).
enddocument


enter image description here






share|improve this answer






























    5














    Just for completeness, here's a solution that shows how to (a) write the Lua code to an external file, (b) load the Luacode via a directluadofile("...") directive, and (c) set up a LaTeX "wrapper" macro (called showprod in the example below) whose function (pun intended) is to invoke the Lua function.



    Note that with this setup, one can write \ rather than string\ to denote a single backslash character. (This is also the case for the luacode and luacode* environments that are provided by the luacode package.)



    enter image description here



    RequirePackagefilecontents
    beginfilecontents*show_prod.lua


    function show_prod ( a , b )
    tex.sprint ( "$"..a.."\times"..b.."="..a*b.."$" )
    end


    endfilecontents*

    documentclassarticle
    %% Load Lua code from external file and define a LaTeX "wrapper" macro
    directluadofile("show_prod.lua")
    newcommandshowprod[2]directluashow_prod(#1,#2)

    begindocument
    The product of 2 and 3: showprod23.
    enddocument





    share|improve this answer























      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
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483416%2fperform-and-show-arithmetic-with-lualatex%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      6














      documentclass[12pt,a4paper]article

      directlua
      function prod(a,b)
      tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")
      end


      begindocument
      The product of 2 and 3: directluaprod(2,3).
      enddocument


      The product of 2 and 3: 2 × 3 = 6.



      One tricky thing is getting the backslash escaping game right: LuaTeX: How to handle a Lua function that prints TeX macros. directlua expands macros before passing them on to Lua, so times gets messed up. But something like stringtimes, which should stop that expansion does not quite work as intended because t is a special escape for the tab in Lua. Hence we need to escape the backslash there. In Lua you would have to type \times, but in TeX we need to stop the \ from being expanded, so we need string\times. That is one of the reasons why it is often recommended to use the luacode package or externalise Lua functions into their own .lua files and then load them with dofile or require (see for example How to do a 'printline' in LuaTeX, a bit on dofile and require can be found at LuaLatex: Difference between `dofile` and `require` when loading lua files).



      Another thing is that you need .. to concatenate strings.



      Finally, you probably want the entire expression in math mode and not just certain bits.



      Also moved the directlua function definition into the preamble. (Thanks to Mico for the suggestion.)






      share|improve this answer

























      • That's what I was looking for. It worked here. Thank you!

        – Levy
        9 hours ago











      • And the explanation was really helpful!

        – Levy
        9 hours ago















      6














      documentclass[12pt,a4paper]article

      directlua
      function prod(a,b)
      tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")
      end


      begindocument
      The product of 2 and 3: directluaprod(2,3).
      enddocument


      The product of 2 and 3: 2 × 3 = 6.



      One tricky thing is getting the backslash escaping game right: LuaTeX: How to handle a Lua function that prints TeX macros. directlua expands macros before passing them on to Lua, so times gets messed up. But something like stringtimes, which should stop that expansion does not quite work as intended because t is a special escape for the tab in Lua. Hence we need to escape the backslash there. In Lua you would have to type \times, but in TeX we need to stop the \ from being expanded, so we need string\times. That is one of the reasons why it is often recommended to use the luacode package or externalise Lua functions into their own .lua files and then load them with dofile or require (see for example How to do a 'printline' in LuaTeX, a bit on dofile and require can be found at LuaLatex: Difference between `dofile` and `require` when loading lua files).



      Another thing is that you need .. to concatenate strings.



      Finally, you probably want the entire expression in math mode and not just certain bits.



      Also moved the directlua function definition into the preamble. (Thanks to Mico for the suggestion.)






      share|improve this answer

























      • That's what I was looking for. It worked here. Thank you!

        – Levy
        9 hours ago











      • And the explanation was really helpful!

        – Levy
        9 hours ago













      6












      6








      6







      documentclass[12pt,a4paper]article

      directlua
      function prod(a,b)
      tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")
      end


      begindocument
      The product of 2 and 3: directluaprod(2,3).
      enddocument


      The product of 2 and 3: 2 × 3 = 6.



      One tricky thing is getting the backslash escaping game right: LuaTeX: How to handle a Lua function that prints TeX macros. directlua expands macros before passing them on to Lua, so times gets messed up. But something like stringtimes, which should stop that expansion does not quite work as intended because t is a special escape for the tab in Lua. Hence we need to escape the backslash there. In Lua you would have to type \times, but in TeX we need to stop the \ from being expanded, so we need string\times. That is one of the reasons why it is often recommended to use the luacode package or externalise Lua functions into their own .lua files and then load them with dofile or require (see for example How to do a 'printline' in LuaTeX, a bit on dofile and require can be found at LuaLatex: Difference between `dofile` and `require` when loading lua files).



      Another thing is that you need .. to concatenate strings.



      Finally, you probably want the entire expression in math mode and not just certain bits.



      Also moved the directlua function definition into the preamble. (Thanks to Mico for the suggestion.)






      share|improve this answer















      documentclass[12pt,a4paper]article

      directlua
      function prod(a,b)
      tex.print("$" .. a .. "string\times" .. b .. "=" .. a*b .. "$")
      end


      begindocument
      The product of 2 and 3: directluaprod(2,3).
      enddocument


      The product of 2 and 3: 2 × 3 = 6.



      One tricky thing is getting the backslash escaping game right: LuaTeX: How to handle a Lua function that prints TeX macros. directlua expands macros before passing them on to Lua, so times gets messed up. But something like stringtimes, which should stop that expansion does not quite work as intended because t is a special escape for the tab in Lua. Hence we need to escape the backslash there. In Lua you would have to type \times, but in TeX we need to stop the \ from being expanded, so we need string\times. That is one of the reasons why it is often recommended to use the luacode package or externalise Lua functions into their own .lua files and then load them with dofile or require (see for example How to do a 'printline' in LuaTeX, a bit on dofile and require can be found at LuaLatex: Difference between `dofile` and `require` when loading lua files).



      Another thing is that you need .. to concatenate strings.



      Finally, you probably want the entire expression in math mode and not just certain bits.



      Also moved the directlua function definition into the preamble. (Thanks to Mico for the suggestion.)







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited 8 hours ago

























      answered 9 hours ago









      moewemoewe

      96.2k10117360




      96.2k10117360












      • That's what I was looking for. It worked here. Thank you!

        – Levy
        9 hours ago











      • And the explanation was really helpful!

        – Levy
        9 hours ago

















      • That's what I was looking for. It worked here. Thank you!

        – Levy
        9 hours ago











      • And the explanation was really helpful!

        – Levy
        9 hours ago
















      That's what I was looking for. It worked here. Thank you!

      – Levy
      9 hours ago





      That's what I was looking for. It worked here. Thank you!

      – Levy
      9 hours ago













      And the explanation was really helpful!

      – Levy
      9 hours ago





      And the explanation was really helpful!

      – Levy
      9 hours ago











      5














      documentclass[12pt,a4paper]article

      begindocument
      directlua
      function prod(a,b)
      tex.print(a.. "$string\times$".. b.. "$=$".. a*b)
      end


      The product of 2 and 3: directluaprod(2,3).
      enddocument


      enter image description here






      share|improve this answer



























        5














        documentclass[12pt,a4paper]article

        begindocument
        directlua
        function prod(a,b)
        tex.print(a.. "$string\times$".. b.. "$=$".. a*b)
        end


        The product of 2 and 3: directluaprod(2,3).
        enddocument


        enter image description here






        share|improve this answer

























          5












          5








          5







          documentclass[12pt,a4paper]article

          begindocument
          directlua
          function prod(a,b)
          tex.print(a.. "$string\times$".. b.. "$=$".. a*b)
          end


          The product of 2 and 3: directluaprod(2,3).
          enddocument


          enter image description here






          share|improve this answer













          documentclass[12pt,a4paper]article

          begindocument
          directlua
          function prod(a,b)
          tex.print(a.. "$string\times$".. b.. "$=$".. a*b)
          end


          The product of 2 and 3: directluaprod(2,3).
          enddocument


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 9 hours ago









          Ulrike FischerUlrike Fischer

          198k9305692




          198k9305692





















              5














              Just for completeness, here's a solution that shows how to (a) write the Lua code to an external file, (b) load the Luacode via a directluadofile("...") directive, and (c) set up a LaTeX "wrapper" macro (called showprod in the example below) whose function (pun intended) is to invoke the Lua function.



              Note that with this setup, one can write \ rather than string\ to denote a single backslash character. (This is also the case for the luacode and luacode* environments that are provided by the luacode package.)



              enter image description here



              RequirePackagefilecontents
              beginfilecontents*show_prod.lua


              function show_prod ( a , b )
              tex.sprint ( "$"..a.."\times"..b.."="..a*b.."$" )
              end


              endfilecontents*

              documentclassarticle
              %% Load Lua code from external file and define a LaTeX "wrapper" macro
              directluadofile("show_prod.lua")
              newcommandshowprod[2]directluashow_prod(#1,#2)

              begindocument
              The product of 2 and 3: showprod23.
              enddocument





              share|improve this answer



























                5














                Just for completeness, here's a solution that shows how to (a) write the Lua code to an external file, (b) load the Luacode via a directluadofile("...") directive, and (c) set up a LaTeX "wrapper" macro (called showprod in the example below) whose function (pun intended) is to invoke the Lua function.



                Note that with this setup, one can write \ rather than string\ to denote a single backslash character. (This is also the case for the luacode and luacode* environments that are provided by the luacode package.)



                enter image description here



                RequirePackagefilecontents
                beginfilecontents*show_prod.lua


                function show_prod ( a , b )
                tex.sprint ( "$"..a.."\times"..b.."="..a*b.."$" )
                end


                endfilecontents*

                documentclassarticle
                %% Load Lua code from external file and define a LaTeX "wrapper" macro
                directluadofile("show_prod.lua")
                newcommandshowprod[2]directluashow_prod(#1,#2)

                begindocument
                The product of 2 and 3: showprod23.
                enddocument





                share|improve this answer

























                  5












                  5








                  5







                  Just for completeness, here's a solution that shows how to (a) write the Lua code to an external file, (b) load the Luacode via a directluadofile("...") directive, and (c) set up a LaTeX "wrapper" macro (called showprod in the example below) whose function (pun intended) is to invoke the Lua function.



                  Note that with this setup, one can write \ rather than string\ to denote a single backslash character. (This is also the case for the luacode and luacode* environments that are provided by the luacode package.)



                  enter image description here



                  RequirePackagefilecontents
                  beginfilecontents*show_prod.lua


                  function show_prod ( a , b )
                  tex.sprint ( "$"..a.."\times"..b.."="..a*b.."$" )
                  end


                  endfilecontents*

                  documentclassarticle
                  %% Load Lua code from external file and define a LaTeX "wrapper" macro
                  directluadofile("show_prod.lua")
                  newcommandshowprod[2]directluashow_prod(#1,#2)

                  begindocument
                  The product of 2 and 3: showprod23.
                  enddocument





                  share|improve this answer













                  Just for completeness, here's a solution that shows how to (a) write the Lua code to an external file, (b) load the Luacode via a directluadofile("...") directive, and (c) set up a LaTeX "wrapper" macro (called showprod in the example below) whose function (pun intended) is to invoke the Lua function.



                  Note that with this setup, one can write \ rather than string\ to denote a single backslash character. (This is also the case for the luacode and luacode* environments that are provided by the luacode package.)



                  enter image description here



                  RequirePackagefilecontents
                  beginfilecontents*show_prod.lua


                  function show_prod ( a , b )
                  tex.sprint ( "$"..a.."\times"..b.."="..a*b.."$" )
                  end


                  endfilecontents*

                  documentclassarticle
                  %% Load Lua code from external file and define a LaTeX "wrapper" macro
                  directluadofile("show_prod.lua")
                  newcommandshowprod[2]directluashow_prod(#1,#2)

                  begindocument
                  The product of 2 and 3: showprod23.
                  enddocument






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 8 hours ago









                  MicoMico

                  285k31388778




                  285k31388778



























                      draft saved

                      draft discarded
















































                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f483416%2fperform-and-show-arithmetic-with-lualatex%23new-answer', 'question_page');

                      );

                      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







                      Popular posts from this blog

                      Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                      Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                      Tom Holland Mục lục Đầu đời và giáo dục | Sự nghiệp | Cuộc sống cá nhân | Phim tham gia | Giải thưởng và đề cử | Chú thích | Liên kết ngoài | Trình đơn chuyển hướngProfile“Person Details for Thomas Stanley Holland, "England and Wales Birth Registration Index, 1837-2008" — FamilySearch.org”"Meet Tom Holland... the 16-year-old star of The Impossible""Schoolboy actor Tom Holland finds himself in Oscar contention for role in tsunami drama"“Naomi Watts on the Prince William and Harry's reaction to her film about the late Princess Diana”lưu trữ"Holland and Pflueger Are West End's Two New 'Billy Elliots'""I'm so envious of my son, the movie star! British writer Dominic Holland's spent 20 years trying to crack Hollywood - but he's been beaten to it by a very unlikely rival"“Richard and Margaret Povey of Jersey, Channel Islands, UK: Information about Thomas Stanley Holland”"Tom Holland to play Billy Elliot""New Billy Elliot leaving the garage"Billy Elliot the Musical - Tom Holland - Billy"A Tale of four Billys: Tom Holland""The Feel Good Factor""Thames Christian College schoolboys join Myleene Klass for The Feelgood Factor""Government launches £600,000 arts bursaries pilot""BILLY's Chapman, Holland, Gardner & Jackson-Keen Visit Prime Minister""Elton John 'blown away' by Billy Elliot fifth birthday" (video with John's interview and fragments of Holland's performance)"First News interviews Arrietty's Tom Holland"“33rd Critics' Circle Film Awards winners”“National Board of Review Current Awards”Bản gốc"Ron Howard Whaling Tale 'In The Heart Of The Sea' Casts Tom Holland"“'Spider-Man' Finds Tom Holland to Star as New Web-Slinger”lưu trữ“Captain America: Civil War (2016)”“Film Review: ‘Captain America: Civil War’”lưu trữ“‘Captain America: Civil War’ review: Choose your own avenger”lưu trữ“The Lost City of Z reviews”“Sony Pictures and Marvel Studios Find Their 'Spider-Man' Star and Director”“‘Mary Magdalene’, ‘Current War’ & ‘Wind River’ Get 2017 Release Dates From Weinstein”“Lionsgate Unleashing Daisy Ridley & Tom Holland Starrer ‘Chaos Walking’ In Cannes”“PTA's 'Master' Leads Chicago Film Critics Nominations, UPDATED: Houston and Indiana Critics Nominations”“Nominaciones Goya 2013 Telecinco Cinema – ENG”“Jameson Empire Film Awards: Martin Freeman wins best actor for performance in The Hobbit”“34th Annual Young Artist Awards”Bản gốc“Teen Choice Awards 2016—Captain America: Civil War Leads Second Wave of Nominations”“BAFTA Film Award Nominations: ‘La La Land’ Leads Race”“Saturn Awards Nominations 2017: 'Rogue One,' 'Walking Dead' Lead”Tom HollandTom HollandTom HollandTom Hollandmedia.gettyimages.comWorldCat Identities300279794no20130442900000 0004 0355 42791085670554170004732cb16706349t(data)XX5557367