3

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.

4
  • 1
    Here, with TeXLive 2021, I get the correct result ("We have 1 = 47 · −33 + 47 · 16.")... Commented 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)? Commented Apr 27, 2021 at 3:33
  • Does it actually report "ngerman"? Are you sure it isn't "german"? What is the "n" for? Commented 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 Commented Apr 28, 2021 at 2:18

1 Answer 1

4

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.