TransWikia.com

Compilation error in LuaTeX, but in runs in Lua

TeX - LaTeX Asked by Hennich on May 5, 2021

I want to create an example for the extended Euclidean algorithm in LuaTeX.

documentclass[a4paper]{scrartcl}
usepackage{luacode}
usepackage{polyglossia}
setdefaultlanguage[spelling=new, babelshorthands=true]{german}

newcommand{wert}[1]{directlua{tex.sprint(#1)}}

begin{document}

begin{luacode*}
  function EEA(a,b)
    if b == 0 then return a, 1, 0 end
    d,s,t = EEA(b, a % b)
    x = s - (a//b) * t
    return d, t, x
  end
  p = 47
  q = 97
  d,x,y = EEA(p,q)
end{luacode*}
We have $wert{d} = wert{p} cdot wert{x} + wert{p} cdot wert{y}$.
end{document}

Running the code on https://www.lua.org/cgi-bin/demo works, but when I try LuaTeX, I get the error:

Language ngerman already loaded; id is 8[directlua]:4: unexpected symbol near
‘/’.
luacode@dbg@exec …code@maybe@printdbg {#1} #1 }

l.20 end{luacode*}

I thought i is connected with the percent sign, but

  function gcd(a,b)
    if b == 0 then return a end
    return gcd(b, a % b)
  end

works fine. How do I solve this?

I have LuaTeX version 1.0.4 and I just run lualatex lua_test.tex.

One Answer

It seems you're with an older LuaTeX version: in TeX Live, TL2017 matches LuaTeX 1.0.4 and Lua 5.2. As you can see in the documentation, integer division (//) isn't supported and has been added from Lua 5.3. Thus, either use math.floor(a/b) or update your current distribution so that Lua 5.3 and therefore // are available.

Correct answer by Jairo A. del Rio on May 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP