[NTG-context] graphics

Mikael P. Sundqvist mickep at gmail.com
Wed Dec 12 21:13:36 CET 2018


On Wed, Dec 12, 2018 at 9:02 PM Henri Menke <henrimenke at gmail.com> wrote:
>
> On 13/12/18 8:56 AM, Alan Braslau wrote:
> > On Wed, 12 Dec 2018 20:42:56 +0100
> > "Mikael P. Sundqvist" <mickep at gmail.com> wrote:
> >>
> >> Thanks, Alan! That looks very promising. I could not make it work,
> >> though, and I guess that is because I use linux and do not know what
> >> to change for what. I installed libcerf but I assume something else is
> >> missing. In any case, this is one of the things it would be nice to
> >> have, at least as a module. I have no idea on how to realize that,
> >> though.
> >>
> >> /Mikael
> >
> > You likely also need to install libffi - I do not know what package
> > this is on your flavor of linux - Luigi is the ffi specialist!
>
> FFI is integrated in LuaTeX >= 1.03
>
> In you example you load libcerf but you are not using it.  What you are
> actually using are the Bessel function from the C Standard library.  GCC
> includes them as a GNU extension.
> https://www.gnu.org/software/libc/manual/html_node/Special-Functions.html#index-j0
> Your example also works if you remove libcerf (at least for me on Linux).
>

Thanks Henri! Indeed it worked now. The following example (just in
case someone else did not get what to change) compiles here, and shows
the expected graph. This is very good news!

\startluacode

ffi = require("ffi")
ffi.cdef[[
double j0(double x);
double j1(double x);
double jn(double x);
]]

\stopluacode

\startMPdefinitions{doublefun}
  vardef jzero primary x = scantokens(lua("mp.quoted( ffi.C.j0(" &
decimal x & "))")) enddef ;
  vardef jone  primary x = scantokens(lua("mp.quoted( ffi.C.j1(" &
decimal x & "))")) enddef ;
  vardef jn    primary x = scantokens(lua("mp.quoted( ffi.C.jn(" &
decimal x & "))")) enddef ;
\stopMPdefinitions


\starttext
\startMPpage[instance=doublefun]
draw function(1,"x","jone(x)",epsed(0),epsed(10),1/10) scaled 1cm;
\stopMPpage
\stoptext

/Mikael


More information about the ntg-context mailing list