Perform and show arithmetic with LuaLaTeX The 2019 Stack Overflow Developer Survey Results Are InHow 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

Can the Protection from Evil and Good spell be used on the caster?

CiviEvent: Public link for events of a specific type

How to reverse every other sublist of a list?

"To split hairs" vs "To be pedantic"

If the Wish spell is used to duplicate the effect of Simulacrum, are existing duplicates destroyed?

Should I write numbers in words or as numerals when there are multiple next to each other?

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

Why is Grand Jury testimony secret?

Could JWST stay at L2 "forever"?

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Does light intensity oscillate really fast since it is a wave?

Where to refill my bottle in India?

How to change the limits of integration

Lethal sonic weapons

On the insanity of kings as an argument against monarchy

Limit the amount of RAM Mathematica may access?

Understanding the implication of what "well-defined" means for the operation in quotient group

How is radar separation assured between primary and secondary targets?

Landlord wants to switch my lease to a "Land contract" to "get back at the city"

Is flight data recorder erased after every flight?

Does it makes sense to buy a new cycle to learn riding?

Pristine Bit Checking

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

Is an up-to-date browser secure on an out-of-date OS?



Perform and show arithmetic with LuaLaTeX



The 2019 Stack Overflow Developer Survey Results Are InHow 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










5















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
    Apr 5 at 19:32






  • 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
    Apr 5 at 19:39






  • 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
    Apr 5 at 19:46











  • @ShreevatsaR Thanks for that option!

    – Levy
    Apr 5 at 20:10















5















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
    Apr 5 at 19:32






  • 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
    Apr 5 at 19:39






  • 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
    Apr 5 at 19:46











  • @ShreevatsaR Thanks for that option!

    – Levy
    Apr 5 at 20:10













5












5








5








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 Apr 5 at 20:18









Mico

286k32390779




286k32390779










asked Apr 5 at 19:23









LevyLevy

447312




447312







  • 3





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

    – moewe
    Apr 5 at 19:32






  • 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
    Apr 5 at 19:39






  • 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
    Apr 5 at 19:46











  • @ShreevatsaR Thanks for that option!

    – Levy
    Apr 5 at 20:10












  • 3





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

    – moewe
    Apr 5 at 19:32






  • 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
    Apr 5 at 19:39






  • 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
    Apr 5 at 19:46











  • @ShreevatsaR Thanks for that option!

    – Levy
    Apr 5 at 20:10







3




3





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

– moewe
Apr 5 at 19:32





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

– moewe
Apr 5 at 19:32




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
Apr 5 at 19:39





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
Apr 5 at 19:39




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
Apr 5 at 19:46





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
Apr 5 at 19:46













@ShreevatsaR Thanks for that option!

– Levy
Apr 5 at 20:10





@ShreevatsaR Thanks for that option!

– Levy
Apr 5 at 20:10










3 Answers
3






active

oldest

votes


















7














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
    Apr 5 at 19:40











  • And the explanation was really helpful!

    – Levy
    Apr 5 at 19:40


















6














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






























    6














    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









      7














      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
        Apr 5 at 19:40











      • And the explanation was really helpful!

        – Levy
        Apr 5 at 19:40















      7














      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
        Apr 5 at 19:40











      • And the explanation was really helpful!

        – Levy
        Apr 5 at 19:40













      7












      7








      7







      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 Apr 5 at 20:04

























      answered Apr 5 at 19:34









      moewemoewe

      96.5k10118362




      96.5k10118362












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

        – Levy
        Apr 5 at 19:40











      • And the explanation was really helpful!

        – Levy
        Apr 5 at 19:40

















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

        – Levy
        Apr 5 at 19:40











      • And the explanation was really helpful!

        – Levy
        Apr 5 at 19:40
















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

      – Levy
      Apr 5 at 19:40





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

      – Levy
      Apr 5 at 19:40













      And the explanation was really helpful!

      – Levy
      Apr 5 at 19:40





      And the explanation was really helpful!

      – Levy
      Apr 5 at 19:40











      6














      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



























        6














        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

























          6












          6








          6







          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 Apr 5 at 19:34









          Ulrike FischerUlrike Fischer

          198k9306692




          198k9306692





















              6














              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



























                6














                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

























                  6












                  6








                  6







                  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 Apr 5 at 20:14









                  MicoMico

                  286k32390779




                  286k32390779



























                      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

                      Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

                      Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

                      Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020