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

\setdefaultlanguage[spelling=new, babelshorthands=true]{german}



  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
  p = 47
  q = 97
  d,x,y = EEA(p,q)
We have $\wert{d} = \wert{p} \cdot \wert{x} + \wert{p} \cdot \wert{y}$.

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)

works fine. How do I solve this?

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

  • 1
    Here, with TeXLive 2021, I get the correct result ("We have 1 = 47 · −33 + 47 · 16.")... Apr 26, 2021 at 23:26
  • TeXLive2021 currently features LuaTeX 1.13.2 as well as LuaHBTeX 1.13.2, which the latter employing the harfbuzz rendering engine. Both programs employ Lua 5.3.6, which features the integer division operator //, Versions of Lua prior to 5.3 do not feature this operator. TeXLive last featured a version of LuaTeX that was based on Lua 5.2.x in 2018. Is something stopping you from updating your TeX distribution by four generations (from TeXLive2017 to TeXLive2021)?
    – Mico
    Apr 27, 2021 at 3:33
  • Does it actually report "ngerman"? Are you sure it isn't "german"? What is the "n" for? Apr 27, 2021 at 15:14
  • @PeterMortensen as far as I know, it is the "new" german spelling, opposed to the one until early 90's
    – Hennich
    Apr 28, 2021 at 2:18

1 Answer 1


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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .