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

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

What does the "remote control" for a QF-4 look like?

infared filters v nd

Can a vampire attack twice with their claws using Multiattack?

High voltage LED indicator 40-1000 VDC without additional power supply

Rock identification in KY

Today is the Center

"You are your self first supporter", a more proper way to say it

Arrow those variables!

Horror movie about a virus at the prom; beginning and end are stylized as a cartoon

Can a Cauchy sequence converge for one metric while not converging for another?

Why can't we play rap on piano?

What are the disadvantages of having a left skewed distribution?

Unable to deploy metadata from Partner Developer scratch org because of extra fields

Can I ask the recruiters in my resume to put the reason why I am rejected?

Java Casting: Java 11 throws LambdaConversionException while 1.8 does not

What doth I be?

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

Modeling an IP Address

How does one intimidate enemies without having the capacity for violence?

Revoked SSL certificate

Are the number of citations and number of published articles the most important criteria for a tenure promotion?

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

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



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
    5 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
    5 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
    5 hours ago











  • @ShreevatsaR Thanks for that option!

    – Levy
    4 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
    5 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
    5 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
    5 hours ago











  • @ShreevatsaR Thanks for that option!

    – Levy
    4 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 4 hours ago









Mico

285k31388778




285k31388778










asked 5 hours ago









LevyLevy

437312




437312







  • 3





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

    – moewe
    5 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
    5 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
    5 hours ago











  • @ShreevatsaR Thanks for that option!

    – Levy
    4 hours ago












  • 3





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

    – moewe
    5 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
    5 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
    5 hours ago











  • @ShreevatsaR Thanks for that option!

    – Levy
    4 hours ago







3




3





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

– moewe
5 hours ago





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

– moewe
5 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
5 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
5 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
5 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
5 hours ago













@ShreevatsaR Thanks for that option!

– Levy
4 hours ago





@ShreevatsaR Thanks for that option!

– Levy
4 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
    5 hours ago











  • And the explanation was really helpful!

    – Levy
    5 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






























    4














    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
        5 hours ago











      • And the explanation was really helpful!

        – Levy
        5 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
        5 hours ago











      • And the explanation was really helpful!

        – Levy
        5 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 4 hours ago

























      answered 5 hours ago









      moewemoewe

      96.2k10117360




      96.2k10117360












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

        – Levy
        5 hours ago











      • And the explanation was really helpful!

        – Levy
        5 hours ago

















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

        – Levy
        5 hours ago











      • And the explanation was really helpful!

        – Levy
        5 hours ago
















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

      – Levy
      5 hours ago





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

      – Levy
      5 hours ago













      And the explanation was really helpful!

      – Levy
      5 hours ago





      And the explanation was really helpful!

      – Levy
      5 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 5 hours ago









          Ulrike FischerUlrike Fischer

          198k9305692




          198k9305692





















              4














              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



























                4














                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

























                  4












                  4








                  4







                  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 4 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

                      How to create a command for the “strange m” symbol in latex? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How do you make your own symbol when Detexify fails?Writing bold small caps with mathpazo packageplus-minus symbol with parenthesis around the minus signGreek character in Beamer document titleHow to create dashed right arrow over symbol?Currency symbol: Turkish LiraDouble prec as a single symbol?Plus Sign Too Big; How to Call adfbullet?Is there a TeX macro for three-legged pi?How do I get my integral-like symbol to align like the integral?How to selectively substitute a letter with another symbol representing the same letterHow do I generate a less than symbol and vertical bar that are the same height?

                      Българска екзархия Съдържание История | Български екзарси | Вижте също | Външни препратки | Литература | Бележки | НавигацияУстав за управлението на българската екзархия. Цариград, 1870Слово на Ловешкия митрополит Иларион при откриването на Българския народен събор в Цариград на 23. II. 1870 г.Българската правда и гръцката кривда. От С. М. (= Софийски Мелетий). Цариград, 1872Предстоятели на Българската екзархияПодмененият ВеликденИнформационна агенция „Фокус“Димитър Ризов. Българите в техните исторически, етнографически и политически граници (Атлас съдържащ 40 карти). Berlin, Königliche Hoflithographie, Hof-Buch- und -Steindruckerei Wilhelm Greve, 1917Report of the International Commission to Inquire into the Causes and Conduct of the Balkan Wars

                      Category:Tremithousa Media in category "Tremithousa"Navigation menuUpload media34° 49′ 02.7″ N, 32° 26′ 37.32″ EOpenStreetMapGoogle EarthProximityramaReasonatorScholiaStatisticsWikiShootMe