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.
//, 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)?