Finding Greatest Common Divisor using LuaLatexAccessing to .log messages from LuaTeX. Is it possible?LuaLaTeX for dummies: basic directlua useHelp integrating some LUA code into a Luatex document?LuaLaTeX: compilation fails when sorting text using luacodeLuaLaTeX — Attempt to index global 'luatexbase'LuaLaTeX: Calculate length in LuaMy first luaLaTeX exampleLoad fields from JSON file using LuaLatexHow to use lua code from external file in lualatex?Arithmetics in LuaLaTeX

Does switching on an old games console without a cartridge damage it?

Why are Oscar, India, and X-Ray (O, I, and X) not used as taxiway identifiers?

Substitute dried pig's blood for fresh

When will the last unambiguous evidence of mankind disappear?

Longest to Shortest tractates of Yerushalmi by daf

Can "Taking algebraic closure" be made into a functor?

How to pass array of values in lualatex?

What do Unicorns want?

Oriented vector bundle with odd-dimensional fibers

Pass USB 3.0 connection through D-SUB connector

MITM on HTTPS traffic in Kazakhstan 2019

Why does the salt in the oceans not sink to the bottom?

Why do we need an estimator to be consistent?

Considerations when providing money to only one child out of two

What kind of vegetable has pink and white concentric rings?

Langton's Ant Periodic Behavior

Acoustic guitar chords' positions vs those of a Bass guitar

Would using carbon dioxide as fuel work to reduce the greenhouse effect?

Found more old paper shares from broken up companies

Calculating Fibonacci sequence in several different ways

Quickest way to move a line in a text file before another line in a text file?

Why is there an extra "t" in Lemmatization?

You have no, but can try for yes

How can I show that the speed of light in vacuum is the same in all reference frames?



Finding Greatest Common Divisor using LuaLatex


Accessing to .log messages from LuaTeX. Is it possible?LuaLaTeX for dummies: basic directlua useHelp integrating some LUA code into a Luatex document?LuaLaTeX: compilation fails when sorting text using luacodeLuaLaTeX — Attempt to index global 'luatexbase'LuaLaTeX: Calculate length in LuaMy first luaLaTeX exampleLoad fields from JSON file using LuaLatexHow to use lua code from external file in lualatex?Arithmetics in LuaLaTeX






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








7















Here is my code to find Greatest Common Divisor of two positive integers.



documentclassarticle
usepackageluacode

beginluacode
function gcd(a,b)
if b ~= 0 then
return gcd(b, a % b)
else
return math.abs(a)
end
end
endluacode
newcommandfindgcd[2]directluatex.sprint(gcd(#1,#2))

begindocument
findgcd5,10
enddocument


It throws error. The expected output is simply gcd of 5 and 10. Is % sign in lua code causing the error?










share|improve this question




























    7















    Here is my code to find Greatest Common Divisor of two positive integers.



    documentclassarticle
    usepackageluacode

    beginluacode
    function gcd(a,b)
    if b ~= 0 then
    return gcd(b, a % b)
    else
    return math.abs(a)
    end
    end
    endluacode
    newcommandfindgcd[2]directluatex.sprint(gcd(#1,#2))

    begindocument
    findgcd5,10
    enddocument


    It throws error. The expected output is simply gcd of 5 and 10. Is % sign in lua code causing the error?










    share|improve this question
























      7












      7








      7


      1






      Here is my code to find Greatest Common Divisor of two positive integers.



      documentclassarticle
      usepackageluacode

      beginluacode
      function gcd(a,b)
      if b ~= 0 then
      return gcd(b, a % b)
      else
      return math.abs(a)
      end
      end
      endluacode
      newcommandfindgcd[2]directluatex.sprint(gcd(#1,#2))

      begindocument
      findgcd5,10
      enddocument


      It throws error. The expected output is simply gcd of 5 and 10. Is % sign in lua code causing the error?










      share|improve this question














      Here is my code to find Greatest Common Divisor of two positive integers.



      documentclassarticle
      usepackageluacode

      beginluacode
      function gcd(a,b)
      if b ~= 0 then
      return gcd(b, a % b)
      else
      return math.abs(a)
      end
      end
      endluacode
      newcommandfindgcd[2]directluatex.sprint(gcd(#1,#2))

      begindocument
      findgcd5,10
      enddocument


      It throws error. The expected output is simply gcd of 5 and 10. Is % sign in lua code causing the error?







      luatex lua luacode directlua






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 11 hours ago









      user61681user61681

      3891 silver badge9 bronze badges




      3891 silver badge9 bronze badges




















          1 Answer
          1






          active

          oldest

          votes


















          9














          You have defined findgcd with two arguments, but you only supply one:



          findgcd510


          will work.



          If you want the syntax findgcd5,10, then declare it:



          documentclassarticle
          usepackageluacode

          beginluacode
          function gcd(a,b)
          if b ~= 0 then
          return gcd(b, a % b)
          else
          return math.abs(a)
          end
          end
          endluacode

          newcommandfindgcd[1]directluatex.sprint(gcd(#1))

          begindocument
          findgcd5,10
          enddocument


          Here's a simple package code, save as gcd.sty:



          ProvidesPackagegcd[2019/07/22]
          RequirePackageluacode

          beginluacode
          function gcd(a,b)
          if b ~= 0 then
          return gcd(b, a % b)
          else
          return math.abs(a)
          end
          end
          endluacode

          newcommandfindgcd[2]directluatex.sprint(gcd(#1,#2))

          endinput


          Now your document, as soon as gcd.sty is in a directory read by the TeX engines, can be



          documentclassarticle
          usepackagegcd

          begindocument
          findgcd510
          enddocument





          share|improve this answer

























          • Is it possible to store this function as a package? I mean something like this. usepackagegcd and with this package findgcd command will be available to use it anywhere in document.

            – user61681
            10 hours ago












          • @user61681 Yes, write a package and upload it to CTAN.

            – egreg
            10 hours ago











          • Could you share some resources? How to write package for this type of lua functions?

            – user61681
            10 hours ago






          • 1





            Thanks for your detailed help. You are great...! Just one last query, though it is out of scope here. I am trying to learn how to write latex macros (own commands, environments etc.). I couldn't find any resources for that. I have programming background but still find it difficult to learn latex programming. Could you share some resources if you know? Thanks again.

            – user61681
            9 hours ago












          • @user61681 It's best if they're documented.

            – egreg
            9 hours ago













          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "85"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          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%2f500932%2ffinding-greatest-common-divisor-using-lualatex%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          9














          You have defined findgcd with two arguments, but you only supply one:



          findgcd510


          will work.



          If you want the syntax findgcd5,10, then declare it:



          documentclassarticle
          usepackageluacode

          beginluacode
          function gcd(a,b)
          if b ~= 0 then
          return gcd(b, a % b)
          else
          return math.abs(a)
          end
          end
          endluacode

          newcommandfindgcd[1]directluatex.sprint(gcd(#1))

          begindocument
          findgcd5,10
          enddocument


          Here's a simple package code, save as gcd.sty:



          ProvidesPackagegcd[2019/07/22]
          RequirePackageluacode

          beginluacode
          function gcd(a,b)
          if b ~= 0 then
          return gcd(b, a % b)
          else
          return math.abs(a)
          end
          end
          endluacode

          newcommandfindgcd[2]directluatex.sprint(gcd(#1,#2))

          endinput


          Now your document, as soon as gcd.sty is in a directory read by the TeX engines, can be



          documentclassarticle
          usepackagegcd

          begindocument
          findgcd510
          enddocument





          share|improve this answer

























          • Is it possible to store this function as a package? I mean something like this. usepackagegcd and with this package findgcd command will be available to use it anywhere in document.

            – user61681
            10 hours ago












          • @user61681 Yes, write a package and upload it to CTAN.

            – egreg
            10 hours ago











          • Could you share some resources? How to write package for this type of lua functions?

            – user61681
            10 hours ago






          • 1





            Thanks for your detailed help. You are great...! Just one last query, though it is out of scope here. I am trying to learn how to write latex macros (own commands, environments etc.). I couldn't find any resources for that. I have programming background but still find it difficult to learn latex programming. Could you share some resources if you know? Thanks again.

            – user61681
            9 hours ago












          • @user61681 It's best if they're documented.

            – egreg
            9 hours ago















          9














          You have defined findgcd with two arguments, but you only supply one:



          findgcd510


          will work.



          If you want the syntax findgcd5,10, then declare it:



          documentclassarticle
          usepackageluacode

          beginluacode
          function gcd(a,b)
          if b ~= 0 then
          return gcd(b, a % b)
          else
          return math.abs(a)
          end
          end
          endluacode

          newcommandfindgcd[1]directluatex.sprint(gcd(#1))

          begindocument
          findgcd5,10
          enddocument


          Here's a simple package code, save as gcd.sty:



          ProvidesPackagegcd[2019/07/22]
          RequirePackageluacode

          beginluacode
          function gcd(a,b)
          if b ~= 0 then
          return gcd(b, a % b)
          else
          return math.abs(a)
          end
          end
          endluacode

          newcommandfindgcd[2]directluatex.sprint(gcd(#1,#2))

          endinput


          Now your document, as soon as gcd.sty is in a directory read by the TeX engines, can be



          documentclassarticle
          usepackagegcd

          begindocument
          findgcd510
          enddocument





          share|improve this answer

























          • Is it possible to store this function as a package? I mean something like this. usepackagegcd and with this package findgcd command will be available to use it anywhere in document.

            – user61681
            10 hours ago












          • @user61681 Yes, write a package and upload it to CTAN.

            – egreg
            10 hours ago











          • Could you share some resources? How to write package for this type of lua functions?

            – user61681
            10 hours ago






          • 1





            Thanks for your detailed help. You are great...! Just one last query, though it is out of scope here. I am trying to learn how to write latex macros (own commands, environments etc.). I couldn't find any resources for that. I have programming background but still find it difficult to learn latex programming. Could you share some resources if you know? Thanks again.

            – user61681
            9 hours ago












          • @user61681 It's best if they're documented.

            – egreg
            9 hours ago













          9












          9








          9







          You have defined findgcd with two arguments, but you only supply one:



          findgcd510


          will work.



          If you want the syntax findgcd5,10, then declare it:



          documentclassarticle
          usepackageluacode

          beginluacode
          function gcd(a,b)
          if b ~= 0 then
          return gcd(b, a % b)
          else
          return math.abs(a)
          end
          end
          endluacode

          newcommandfindgcd[1]directluatex.sprint(gcd(#1))

          begindocument
          findgcd5,10
          enddocument


          Here's a simple package code, save as gcd.sty:



          ProvidesPackagegcd[2019/07/22]
          RequirePackageluacode

          beginluacode
          function gcd(a,b)
          if b ~= 0 then
          return gcd(b, a % b)
          else
          return math.abs(a)
          end
          end
          endluacode

          newcommandfindgcd[2]directluatex.sprint(gcd(#1,#2))

          endinput


          Now your document, as soon as gcd.sty is in a directory read by the TeX engines, can be



          documentclassarticle
          usepackagegcd

          begindocument
          findgcd510
          enddocument





          share|improve this answer















          You have defined findgcd with two arguments, but you only supply one:



          findgcd510


          will work.



          If you want the syntax findgcd5,10, then declare it:



          documentclassarticle
          usepackageluacode

          beginluacode
          function gcd(a,b)
          if b ~= 0 then
          return gcd(b, a % b)
          else
          return math.abs(a)
          end
          end
          endluacode

          newcommandfindgcd[1]directluatex.sprint(gcd(#1))

          begindocument
          findgcd5,10
          enddocument


          Here's a simple package code, save as gcd.sty:



          ProvidesPackagegcd[2019/07/22]
          RequirePackageluacode

          beginluacode
          function gcd(a,b)
          if b ~= 0 then
          return gcd(b, a % b)
          else
          return math.abs(a)
          end
          end
          endluacode

          newcommandfindgcd[2]directluatex.sprint(gcd(#1,#2))

          endinput


          Now your document, as soon as gcd.sty is in a directory read by the TeX engines, can be



          documentclassarticle
          usepackagegcd

          begindocument
          findgcd510
          enddocument






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 10 hours ago

























          answered 10 hours ago









          egregegreg

          756k90 gold badges1979 silver badges3325 bronze badges




          756k90 gold badges1979 silver badges3325 bronze badges












          • Is it possible to store this function as a package? I mean something like this. usepackagegcd and with this package findgcd command will be available to use it anywhere in document.

            – user61681
            10 hours ago












          • @user61681 Yes, write a package and upload it to CTAN.

            – egreg
            10 hours ago











          • Could you share some resources? How to write package for this type of lua functions?

            – user61681
            10 hours ago






          • 1





            Thanks for your detailed help. You are great...! Just one last query, though it is out of scope here. I am trying to learn how to write latex macros (own commands, environments etc.). I couldn't find any resources for that. I have programming background but still find it difficult to learn latex programming. Could you share some resources if you know? Thanks again.

            – user61681
            9 hours ago












          • @user61681 It's best if they're documented.

            – egreg
            9 hours ago

















          • Is it possible to store this function as a package? I mean something like this. usepackagegcd and with this package findgcd command will be available to use it anywhere in document.

            – user61681
            10 hours ago












          • @user61681 Yes, write a package and upload it to CTAN.

            – egreg
            10 hours ago











          • Could you share some resources? How to write package for this type of lua functions?

            – user61681
            10 hours ago






          • 1





            Thanks for your detailed help. You are great...! Just one last query, though it is out of scope here. I am trying to learn how to write latex macros (own commands, environments etc.). I couldn't find any resources for that. I have programming background but still find it difficult to learn latex programming. Could you share some resources if you know? Thanks again.

            – user61681
            9 hours ago












          • @user61681 It's best if they're documented.

            – egreg
            9 hours ago
















          Is it possible to store this function as a package? I mean something like this. usepackagegcd and with this package findgcd command will be available to use it anywhere in document.

          – user61681
          10 hours ago






          Is it possible to store this function as a package? I mean something like this. usepackagegcd and with this package findgcd command will be available to use it anywhere in document.

          – user61681
          10 hours ago














          @user61681 Yes, write a package and upload it to CTAN.

          – egreg
          10 hours ago





          @user61681 Yes, write a package and upload it to CTAN.

          – egreg
          10 hours ago













          Could you share some resources? How to write package for this type of lua functions?

          – user61681
          10 hours ago





          Could you share some resources? How to write package for this type of lua functions?

          – user61681
          10 hours ago




          1




          1





          Thanks for your detailed help. You are great...! Just one last query, though it is out of scope here. I am trying to learn how to write latex macros (own commands, environments etc.). I couldn't find any resources for that. I have programming background but still find it difficult to learn latex programming. Could you share some resources if you know? Thanks again.

          – user61681
          9 hours ago






          Thanks for your detailed help. You are great...! Just one last query, though it is out of scope here. I am trying to learn how to write latex macros (own commands, environments etc.). I couldn't find any resources for that. I have programming background but still find it difficult to learn latex programming. Could you share some resources if you know? Thanks again.

          – user61681
          9 hours ago














          @user61681 It's best if they're documented.

          – egreg
          9 hours ago





          @user61681 It's best if they're documented.

          – egreg
          9 hours ago

















          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%2f500932%2ffinding-greatest-common-divisor-using-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

          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

          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

          François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480