[luatex] Problem with luacode in sty file

Matthieu Berret m.berret at gmail.com
Thu Jul 3 13:42:59 CEST 2014


Hello, I'm trying to include a gcd function using lua in a sty file.
Here is the code of euclide.sty :

    \RequirePackage{ifluatex,luacode,luatextra}
    \ifluatex
         \begin{luacode}
             function euclide(a,b)
                 if a < b then a,b = b,a end
                 r = a-math.floor(a/b)*b
                 if r == 0 then tex.print(b)    else euclide(b,r) end
             end
         \end{luacode}
         \newcommand{\euclide}[2]{\luaexec{euclide(#1,#2)}}
    \fi

Here is the texfile code :

    \documentclass[10pt,oneside]{article}
    \usepackage{euclide}

    \begin{document}
    \euclide{435}{630}
    \end{document}

The lualatex compilation give me errors :

    Runaway argument?
    ! File ended while scanning use of \luacode at grab@lines.
    <inserted text>
    \par
    l.4

    I suspect you have forgotten a `}', causing me
    to read past where you wanted me to stop.
    I'll try to recover; but if the error is serious,
    you'd better type `E' or `X' now and fix your file.


    ! LaTeX Error: Missing \begin{document}.

Can somebody tell me what's wrong in my code ?
Thanks, MB.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/luatex/attachments/20140703/1d33fb4c/attachment.html>


More information about the luatex mailing list