Hi, As most mechanism are reasonable okay now we can look into what future versions of ConteXt should provide in terms of functionality. The (luatex) engine is also more of less finished or at least stable in terms of functionality. One possible area of further development is graphics so I'd like to know if there are (reasonable) demands for more graphics support using metapost. Alan and I are on-and-off working on some extensions and one of the things we discuss is visualization of data. The question is of course what should be done in the lua/mp/tex combination and what externally but the combination has some advantages. There has been presentations and discussions at the last meeting and graphics is always a nice topic, and also kind of rewarding in terms of development. Of course other demands can be formulated too, but these then need to come with well defined descriptions (or mockup examples). Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On Tue, 4 Dec 2018 18:03:14 +0100
Hans Hagen
Hi,
As most mechanism are reasonable okay now we can look into what future versions of ConteXt should provide in terms of functionality. The (luatex) engine is also more of less finished or at least stable in terms of functionality.
One possible area of further development is graphics so I'd like to know if there are (reasonable) demands for more graphics support using metapost. Alan and I are on-and-off working on some extensions and one of the things we discuss is visualization of data. The question is of course what should be done in the lua/mp/tex combination and what externally but the combination has some advantages. There has been presentations and discussions at the last meeting and graphics is always a nice topic, and also kind of rewarding in terms of development.
Of course other demands can be formulated too, but these then need to come with well defined descriptions (or mockup examples).
Hans is alluding to work that we are doing to explore the possibilities of lua + MetaPost in the treatment and visualization of data, efficiently, with the possibility of handling large quantities of data. Lua does this particularly well. My first exercise has been a complete rewrite of the John Hobby graph macros. It was/is an exercise in recreating the functionality "from scratch", trying to use lua effectively when needed. The code and approach is entirely new. My use case was the analysis of a large set of data - entirely ridiculous for graphical display but containing "outliers" or instances that are significant, and it works! I am trying to generalize, and am doing this in my "free time". So the aim is two-fold: 1) to efficiently handle large datasets through the use of lua 2) to generalize the notion of user data space from the two-dimensional drawing space of MetaPost (and the represented page), and affine transformations of this 2D space to other coordinate systems and dimensions. We are not thinking about 3D rendering or raytracing, but rather simple projections and other transformations such as polar coordinates. (Of course, log scales, for example are a "simple" non-linear transformation.) I guess that Hans would like to expand the discussion to the future of graphics in general, inviting input from everybody. Alan
On 4 Dec 2018, at 19:54, Alan Braslau
wrote: 2) to generalize the notion of user data space from the two-dimensional drawing space of MetaPost (and the represented page), and affine transformations of this 2D space to other coordinate systems and dimensions. We are not thinking about 3D rendering or raytracing, but rather simple projections and other transformations such as polar coordinates. (Of course, log scales, for example are a "simple" non-linear transformation.)
On this note: I would like to have an ‘official’ way to map 3D coordinates to 2D coordinates with for a camera position with an orthogonal window. Not the most complicated thing in the world, but it would be nice if metafun had an ‘official’ way of setting up a scene. Best wishes, Taco
On 12/5/2018 10:02 AM, Taco Hoekwater wrote:
On 4 Dec 2018, at 19:54, Alan Braslau
wrote: 2) to generalize the notion of user data space from the two-dimensional drawing space of MetaPost (and the represented page), and affine transformations of this 2D space to other coordinate systems and dimensions. We are not thinking about 3D rendering or raytracing, but rather simple projections and other transformations such as polar coordinates. (Of course, log scales, for example are a "simple" non-linear transformation.)
On this note: I would like to have an ‘official’ way to map 3D coordinates to 2D coordinates with for a camera position with an orthogonal window.
Not the most complicated thing in the world, but it would be nice if metafun had an ‘official’ way of setting up a scene.
sounds like a challenge for our meta-math-magician Alan Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On Wed, 5 Dec 2018 13:59:35 +0100
Hans Hagen
On this note: I would like to have an ‘official’ way to map 3D coordinates to 2D coordinates with for a camera position with an orthogonal window.
Not the most complicated thing in the world, but it would be nice if metafun had an ‘official’ way of setting up a scene. sounds like a challenge for our meta-math-magician Alan
Not a particularly hard problem (well known) but then one will want hidden line removal, (partial) transparency, shading, ... and whereas this is possible, it becomes complicated (and one will then want animation). For now, in my simple use of 3D to create diagrams, not any attempt to make phluffy* images, I am quite content with a simple "caviler" projection (infinite view position). Alan *Tufte's phluff!
Hello,
would it be possible to provide some samples finally?
That would be very handy especially for those who are used to create plots via "several clicks on Excel ribbon".
Personally, I am interested in 2D plots to be created loading (an) external data file(s) (text files formed into tables with some headers and comments marked by a letter in the beginning of the line), often altered by Lua somehow (e.g. trimming "bad" values).
I am used to use tickz/pgfplots for this purpose; use of pgfplots is (probably) very powerful but one has to study a lot of pages to create a simple plot followed by many try-and-see.
Also, support for showing extremal values (local extremes) in 2d plots is something handy.
"My" typical 2d plot looks:
A
|
30 | 24.1 <- local extreme
| +
20 | --- --- 15.6 <- local extreme
|/ \ +
10 | -- ---
|
+----------------------------------------->
10. 20. 30. 40.
Best regards,
Lukas
On Tue, 04 Dec 2018 19:54:54 +0100, Alan Braslau
On Tue, 4 Dec 2018 18:03:14 +0100 Hans Hagen
wrote: Hi,
As most mechanism are reasonable okay now we can look into what future versions of ConteXt should provide in terms of functionality. The (luatex) engine is also more of less finished or at least stable in terms of functionality.
One possible area of further development is graphics so I'd like to know if there are (reasonable) demands for more graphics support using metapost. Alan and I are on-and-off working on some extensions and one of the things we discuss is visualization of data. The question is of course what should be done in the lua/mp/tex combination and what externally but the combination has some advantages. There has been presentations and discussions at the last meeting and graphics is always a nice topic, and also kind of rewarding in terms of development.
Of course other demands can be formulated too, but these then need to come with well defined descriptions (or mockup examples).
Hans is alluding to work that we are doing to explore the possibilities of lua + MetaPost in the treatment and visualization of data, efficiently, with the possibility of handling large quantities of data. Lua does this particularly well.
My first exercise has been a complete rewrite of the John Hobby graph macros. It was/is an exercise in recreating the functionality "from scratch", trying to use lua effectively when needed. The code and approach is entirely new. My use case was the analysis of a large set of data - entirely ridiculous for graphical display but containing "outliers" or instances that are significant, and it works! I am trying to generalize, and am doing this in my "free time".
So the aim is two-fold:
1) to efficiently handle large datasets through the use of lua
2) to generalize the notion of user data space from the two-dimensional drawing space of MetaPost (and the represented page), and affine transformations of this 2D space to other coordinate systems and dimensions. We are not thinking about 3D rendering or raytracing, but rather simple projections and other transformations such as polar coordinates. (Of course, log scales, for example are a "simple" non-linear transformation.)
I guess that Hans would like to expand the discussion to the future of graphics in general, inviting input from everybody.
Alan
-- Ing. Lukáš Procházka | mailto:LPr@pontex.cz Pontex s. r. o. | mailto:pontex@pontex.cz | http://www.pontex.cz | IDDS: nrpt3sn | IČO: 40763439 Bezová 1658 147 14 Praha 4 Mob.: +420 702 033 396
ConTeXt already comes with a full XML parser. SVG is XML. It would be nice if it was possible to render some subset of SVG. On 12/5/18 6:03 AM, Hans Hagen wrote:
Hi,
As most mechanism are reasonable okay now we can look into what future versions of ConteXt should provide in terms of functionality. The (luatex) engine is also more of less finished or at least stable in terms of functionality.
One possible area of further development is graphics so I'd like to know if there are (reasonable) demands for more graphics support using metapost. Alan and I are on-and-off working on some extensions and one of the things we discuss is visualization of data. The question is of course what should be done in the lua/mp/tex combination and what externally but the combination has some advantages. There has been presentations and discussions at the last meeting and graphics is always a nice topic, and also kind of rewarding in terms of development.
Of course other demands can be formulated too, but these then need to come with well defined descriptions (or mockup examples).
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl ----------------------------------------------------------------- ___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
On Wed, Dec 5, 2018 at 10:15 AM Henri Menke
ConTeXt already comes with a full XML parser. SVG is XML. It would be nice if it was possible to render some subset of SVG.
In the mean time, I think we should also consider Headless Chromium for SVG -> PDF (with --print-to-pdf ) (together with inkscape) -- luigi
On 12/5/2018 10:14 AM, Henri Menke wrote:
ConTeXt already comes with a full XML parser. SVG is XML. It would be nice if it was possible to render some subset of SVG. So what subset? ... Doing some shapes etc is doable but doing all is over the top
Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On Wed, Dec 5, 2018 at 1:37 PM Hans Hagen
On 12/5/2018 10:14 AM, Henri Menke wrote:
ConTeXt already comes with a full XML parser. SVG is XML. It would be nice if it was possible to render some subset of SVG. So what subset? ... Doing some shapes etc is doable but doing all is over the top
and of course some <something> will never be enough... never ending story. The sad story with svg is that is an all-or-nothing thing . -- luigi
On Tue, Dec 4, 2018 at 6:03 PM Hans Hagen
Hi,
As most mechanism are reasonable okay now we can look into what future versions of ConteXt should provide in terms of functionality. The (luatex) engine is also more of less finished or at least stable in terms of functionality.
One possible area of further development is graphics so I'd like to know if there are (reasonable) demands for more graphics support using metapost. Alan and I are on-and-off working on some extensions and one of the things we discuss is visualization of data. The question is of course what should be done in the lua/mp/tex combination and what externally but the combination has some advantages. There has been presentations and discussions at the last meeting and graphics is always a nice topic, and also kind of rewarding in terms of development.
Of course other demands can be formulated too, but these then need to come with well defined descriptions (or mockup examples).
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl ----------------------------------------------------------------- ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
Hi, I don't know if what I describe below is along the lines you ask for, but here comes two wishes: 1) Full support for drawing implicit curve plots. For some curves, like a lemniscate (https://en.wikipedia.org/wiki/Lemniscate_of_Bernoulli) one can easily succeed by using a parametrisation, but sometimes one end up with equations and to find a parametrisation might be difficult (not to say impossible). I asked about this a while ago and got a simple solution working for that curve, but I think a general working solution would be neat. I think the bernoulli lemniscate could be a good test curve, since it intersect itself. 2) Support for transforming images in a more general way. With the zscaled, slanted, ... we are able to transform any object in an affine way. It would be nice to be able to transform any object in a more general way (i.e. by a mapping defined by the user). The example code below shows what happens in the complex plane with a grid and a curve when the mapping z to z^2 is applied. Perhaps I am missing something, but I'm not able to apply this to a piece of text for example, or to apply it directly to a picture. Instead, I have to loop over all separate paths. I think the ideal would be to have a "ftransformed" (or with some other name), and then just define a function (as fun in the example below), and then be able to do "draw X ftransformed fun;", where X is some(any?) general object. Is that doable? /Mikael %%% Example code \starttext \startMPpage[offset=3bp] u:=3cm; def fun(expr x,y) = (x**2-y**2,2*x*y) enddef; def sq(expr kv,s) = fun(xpart point 0 along kv,ypart point 0 along kv) for i=s step s until 1: -- fun(xpart point i along kv,ypart point i along kv) endfor enddef; path rp; rp = (0,-0.8)..(0.7,-0.2)..(0.7,0.6){dir 150}..(-0.7,0.4)..(-0.4,-0.5){dir 0}..cycle; % Draw the original grid and the path for i = -1 step 1/10 until 1+eps: for j = -1 step 1/10 until 1+eps: draw ((i,-1)--(i,1)) scaled u; draw ((-1,j)--(1,j)) scaled u; endfor; endfor; draw rp scaled u withcolor darkred withpen pencircle scaled 2bp; % Draw the grid and curve after map z->z^2 draw image( for i = -1 step 1/10 until 1+eps: for j = 0 step 1/10 until 1+eps: draw (sq(((i,0)--(i,1)),1/100)) scaled u; draw (sq(((-1,j)--(1,j)),1/100)) scaled u; endfor; endfor; draw (sq(rp,1/100)) scaled u withcolor darkred withpen pencircle scaled 2bp; ) xshifted 2.5u; \stopMPpage \stoptext
On Fri, Dec 7, 2018 at 9:06 AM Mikael P. Sundqvist
On Tue, Dec 4, 2018 at 6:03 PM Hans Hagen
wrote: Hi,
As most mechanism are reasonable okay now we can look into what future versions of ConteXt should provide in terms of functionality. The (luatex) engine is also more of less finished or at least stable in terms of functionality.
One possible area of further development is graphics so I'd like to know if there are (reasonable) demands for more graphics support using metapost. Alan and I are on-and-off working on some extensions and one of the things we discuss is visualization of data. The question is of course what should be done in the lua/mp/tex combination and what externally but the combination has some advantages. There has been presentations and discussions at the last meeting and graphics is always a nice topic, and also kind of rewarding in terms of development.
Of course other demands can be formulated too, but these then need to come with well defined descriptions (or mockup examples).
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net
___________________________________________________________________________________
Hi,
I don't know if what I describe below is along the lines you ask for, but here comes two wishes:
1) Full support for drawing implicit curve plots. For some curves, like a lemniscate (https://en.wikipedia.org/wiki/Lemniscate_of_Bernoulli) one can easily succeed by using a parametrisation, but sometimes one end up with equations and to find a parametrisation might be difficult (not to say impossible).
sure, see eg https://math.stackexchange.com/questions/904782/is-there-a-general-way-to-pa... -- luigi
On Fri, 7 Dec 2018 09:06:03 +0100
"Mikael P. Sundqvist"
2) Support for transforming images in a more general way. With the zscaled, slanted, ... we are able to transform any object in an affine way. It would be nice to be able to transform any object in a more general way (i.e. by a mapping defined by the user). The example code below shows what happens in the complex plane with a grid and a curve when the mapping z to z^2 is applied.
I have generalized my rewrite of the MP graph macros to handle any arbitrary mapping from data space to drawing (2D) space. At present, I have only considered the simple functions of log (and sqrt) scales as well as polar coordinates (x,y) = f(theta,r) with f(theta,r) = (r sin theta, r cos theta) as I have real use cases for these. I also consider a simple 3D->2D mapping. It would be very easy to transform z = a+ib to z^2 for example, as you show, The approach transforms a picture, applying to all stroked and filled paths, as well as to the *position* of text objects. I have not looked into somehow transforming a bitmap image.
Perhaps I am missing something, but I'm not able to apply this to a piece of text for example, or to apply it directly to a picture. Instead, I have to loop over all separate paths. I think the ideal would be to have a "ftransformed" (or with some other name), and then just define a function (as fun in the example below), and then be able to do "draw X ftransformed fun;", where X is some(any?) general object. Is that doable?
for i within pic : ... endfor So, yes, easy to write a primary (but I don't like the name "ftransformed"). Using lua helpers can make this efficient. Alan
On Fri, Dec 7, 2018 at 4:15 PM Alan Braslau
On Fri, 7 Dec 2018 09:06:03 +0100 "Mikael P. Sundqvist"
wrote: 2) Support for transforming images in a more general way. With the zscaled, slanted, ... we are able to transform any object in an affine way. It would be nice to be able to transform any object in a more general way (i.e. by a mapping defined by the user). The example code below shows what happens in the complex plane with a grid and a curve when the mapping z to z^2 is applied.
I have generalized my rewrite of the MP graph macros to handle any arbitrary mapping from data space to drawing (2D) space. At present, I have only considered the simple functions of log (and sqrt) scales as well as polar coordinates (x,y) = f(theta,r) with f(theta,r) = (r sin theta, r cos theta) as I have real use cases for these.
Sounds interesting. Do you have any "test document" to show the work in progress?
I also consider a simple 3D->2D mapping.
That sounds awesome!! The time working with colors as 3D might come to an end! :)
It would be very easy to transform z = a+ib to z^2 for example, as you show,
The approach transforms a picture, applying to all stroked and filled paths, as well as to the *position* of text objects. I have not looked into somehow transforming a bitmap image.
You emphasize "position". Does it mean it will not be possible to transform the shape of the letter?
Perhaps I am missing something, but I'm not able to apply this to a piece of text for example, or to apply it directly to a picture. Instead, I have to loop over all separate paths. I think the ideal would be to have a "ftransformed" (or with some other name), and then just define a function (as fun in the example below), and then be able to do "draw X ftransformed fun;", where X is some(any?) general object. Is that doable?
for i within pic : ... endfor
So, yes, easy to write a primary (but I don't like the name "ftransformed"). Using lua helpers can make this efficient.
OK, looping through the pic sounds like a good idea. The word ftransformed was made up while writing the email, and I agree it is not good (perhaps "mapped" is better). I trust that you will come up with something that fits well.
Alan
Yet another wish: 3) It would be nice to be able to plot some special functions. I'm thinking of the usual suspects, Airy, Bessel, Hypergeometric, Laguerre, Legendre, ... Could it be that one could have support via some lua library? /Mikael
On Sat, 8 Dec 2018 09:31:46 +0100
"Mikael P. Sundqvist"
3) It would be nice to be able to plot some special functions. I'm thinking of the usual suspects, Airy, Bessel, Hypergeometric, Laguerre, Legendre, ... Could it be that one could have support via some lua library?
I use ffi and libcerf (thank you Luigi!) For example (lots of other functions are available): \startluacode ffi = require("ffi") ffi.cdef[[ double j0(double x); double j1(double x); double jn(double x); ]] cerf = ffi.load(ffi.os == "OSX" and "/opt/local/lib/libcerf.dylib" or "cerf") \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
On Sat, Dec 8, 2018 at 4:15 PM Alan Braslau
On Sat, 8 Dec 2018 09:31:46 +0100 "Mikael P. Sundqvist"
wrote: 3) It would be nice to be able to plot some special functions. I'm thinking of the usual suspects, Airy, Bessel, Hypergeometric, Laguerre, Legendre, ... Could it be that one could have support via some lua library?
I use ffi and libcerf (thank you Luigi!) For example (lots of other functions are available):
\startluacode
ffi = require("ffi") ffi.cdef[[ double j0(double x); double j1(double x); double jn(double x); ]]
cerf = ffi.load(ffi.os == "OSX" and "/opt/local/lib/libcerf.dylib" or "cerf")
\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
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
On Wed, 12 Dec 2018 20:42:56 +0100
"Mikael P. Sundqvist"
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! Alan
On 13/12/18 8:56 AM, Alan Braslau wrote:
On Wed, 12 Dec 2018 20:42:56 +0100 "Mikael P. Sundqvist"
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#in... Your example also works if you remove libcerf (at least for me on Linux).
Alan ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
On Thu, 13 Dec 2018 09:02:05 +1300
Henri Menke
On 13/12/18 8:56 AM, Alan Braslau wrote:
On Wed, 12 Dec 2018 20:42:56 +0100 "Mikael P. Sundqvist"
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#in... Your example also works if you remove libcerf (at least for me on Linux).
I had stripped-down my example, for in fact I use the voigt and error functions from libcerf, and yes the Bessel functions from the standard C math library. One should note, by the way, that the C math library is more or less complete depending on the system, and not everyone uses gcc nor gnu... Alan
On 13/12/18 9:12 AM, Alan Braslau wrote:
On Thu, 13 Dec 2018 09:02:05 +1300 Henri Menke
wrote: On 13/12/18 8:56 AM, Alan Braslau wrote:
On Wed, 12 Dec 2018 20:42:56 +0100 "Mikael P. Sundqvist"
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#in... Your example also works if you remove libcerf (at least for me on Linux).
I had stripped-down my example, for in fact I use the voigt and error functions from libcerf, and yes the Bessel functions from the standard C math library. One should note, by the way, that the C math library is more or less complete depending on the system, and not everyone uses gcc nor gnu...
Sorry, my mistake, the Bessel functions are not a GCC extension but POSIX standard functions. http://pubs.opengroup.org/onlinepubs/9699919799/functions/j0.html Since TeX Live is always built on a POSIX platform (MSYS2 on Windows), you can expect j0 etc. to be available in LuaTeX.
Alan
On Thu, 13 Dec 2018 10:03:40 +1300
Henri Menke
Sorry, my mistake, the Bessel functions are not a GCC extension but POSIX standard functions. http://pubs.opengroup.org/onlinepubs/9699919799/functions/j0.html Since TeX Live is always built on a POSIX platform (MSYS2 on Windows), you can expect j0 etc. to be available in LuaTeX.
That is true for the Bessel functions, but not for some other "-lmath" functions (such as the erf), so they may depend on the system. Alan
On 13/12/18 10:39 AM, Alan Braslau wrote:
On Thu, 13 Dec 2018 10:03:40 +1300 Henri Menke
wrote: Sorry, my mistake, the Bessel functions are not a GCC extension but POSIX standard functions. http://pubs.opengroup.org/onlinepubs/9699919799/functions/j0.html Since TeX Live is always built on a POSIX platform (MSYS2 on Windows), you can expect j0 etc. to be available in LuaTeX.
That is true for the Bessel functions, but not for some other "-lmath" functions (such as the erf), so they may depend on the system.
erf definitely does not depend on the system. That is part of the C Standard library. https://en.cppreference.com/w/c/numeric/math/erf But in general you are right. The zoo of special functions in the Standard library and POSIX is rather limited. Personally I prefer using the GNU Scientific library if I need special functions. https://www.gnu.org/software/gsl/doc/html/index.html Earlier this year I wrote a TUGboat article about using GSL with FFI in LuaTeX. https://tug.org/TUGboat/tb39-1/tb121menke-ffi.pdf I also plan on submitting an abstract about that topic for TUG2019 in Palo Alto.
Alan
On Wed, Dec 12, 2018 at 9:02 PM Henri Menke
On 13/12/18 8:56 AM, Alan Braslau wrote:
On Wed, 12 Dec 2018 20:42:56 +0100 "Mikael P. Sundqvist"
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#in... 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
Hi Mikael, Thank you, as ell as Alan and Henri, for giving us a simple way to use Bessel functions, directly in ConTeXt. However I have a question, which may show my total ignorance of the maths libraries ffi and consorts: how do you specify the value of the integr $n$ when you want to use $J_{n}(x)$? Best regards: OK
On 12 Dec 2018, at 21:13, Mikael P. Sundqvist
wrote: On Wed, Dec 12, 2018 at 9:02 PM Henri Menke
wrote: On 13/12/18 8:56 AM, Alan Braslau wrote:
On Wed, 12 Dec 2018 20:42:56 +0100 "Mikael P. Sundqvist"
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#in... 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 ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
Of course, it is:
double jn(int n,double x);
and
vardef jn(expr n, x) = scantokens(lua("mp.quoted( ffi.C.jn(" & decimal n & "," & decimal x & "))")) enddef ;
Alan
(shows that I have yet to use jn ;-)
On Thu, 13 Dec 2018 14:32:39 +0100
Otared Kavian
Hi Mikael,
Thank you, as ell as Alan and Henri, for giving us a simple way to use Bessel functions, directly in ConTeXt. However I have a question, which may show my total ignorance of the maths libraries ffi and consorts: how do you specify the value of the integr $n$ when you want to use $J_{n}(x)$?
Best regards: OK
On 12 Dec 2018, at 21:13, Mikael P. Sundqvist
wrote: On Wed, Dec 12, 2018 at 9:02 PM Henri Menke
wrote: On 13/12/18 8:56 AM, Alan Braslau wrote:
On Wed, 12 Dec 2018 20:42:56 +0100 "Mikael P. Sundqvist"
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#in... 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 ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
On Thu, Dec 13, 2018 at 4:45 PM Alan Braslau
Of course, it is:
double jn(int n,double x);
and
vardef jn(expr n, x) = scantokens(lua("mp.quoted( ffi.C.jn(" & decimal n & "," & decimal x & "))")) enddef ;
Alan
(shows that I have yet to use jn ;-)
I often use this as reference source/texk/web2c/luatexdir/luaffi/test.lua -- luigi
On 14/12/18 5:07 AM, luigi scarso wrote:
On Thu, Dec 13, 2018 at 4:45 PM Alan Braslau
wrote: Of course, it is:
double jn(int n,double x);
and
vardef jn(expr n, x) = scantokens(lua("mp.quoted( ffi.C.jn(" & decimal n & "," & decimal x & "))")) enddef ;
Alan
(shows that I have yet to use jn ;-)
I often use this as reference source/texk/web2c/luatexdir/luaffi/test.lua
I have some Gists on GitHub using the FFI. Binding interpreters of other scripting languages (so far Python, R, Guile, and Lua): https://gist.github.com/hmenke/2d57a3aa1d3d59a265f935dd4b384c36 Rendering SVG to PDF using Cairo and rsvg2: https://gist.github.com/hmenke/9facc3fe5ede9ed46c1838a919f7376f#file-svg-to-... --- Some of the code on GitHub was inspired by answers of mine on the StackExchange network. Here is a collection of answers using FFI. All the answers from TeX Stack Exchange use LaTeX. ConTeXt is not so popular there. How to implement X11 code for LuaJIT's FFI? https://stackoverflow.com/a/53689893 How to plot a function in integral form with TikZ? https://tex.stackexchange.com/a/403797 https://tex.stackexchange.com/a/403794 Erf function in LaTeX https://tex.stackexchange.com/a/407087 Plot a factorial function https://tex.stackexchange.com/a/371899 Plot bessel functions https://tex.stackexchange.com/a/368692 https://tex.stackexchange.com/a/456772 https://tex.stackexchange.com/a/160749 (Lua) LaTeX & HeVeA with partly generated things https://tex.stackexchange.com/a/429994 How to include SVG diagrams in LaTeX? https://tex.stackexchange.com/a/408014
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
Hi Hans and list members, some time ago I asked Hans if he could implement a context analogon to the LaTeX asymptote package. This resulted in the context module asymptote. It would be a nice addition (if this is not implemented yet) if the following functionality could be implemented in this module: Writing a LaTeX file like the one attached using the asymptote package LaTeX and asymptote produce a pdf that contains a rendered version of the asymptote graphic and an interactive version of it as well. Both are embedded in the pdf file. The usually visible rendered pdf version can be made active (using Adobe Acrobat) if one clicks it – then the embedded interactive version gets visible and can be manipulated by the reader. The LaTeX user does not need to specify anything, all is simply done by the asymptote package. Could something like that be possible in ConTeXt, too? That would be really great! I suppose that asymptote is required to run twice to achieve that, one time to render the pdf version and a second time to render the prc file that contains the interactive version of the graphic. ConTeXt should then embed the interactive version of the graphic and the static one as well and should display the rendered pdf version until the reader clicks the static pdf version to make it active. Then the interactive graphic should get active and replace the static preview. You can see the desired behaviour in the attached pdf output of the LaTeX file. To compile the attached file using LaTeX and asymptote you can write in a terminal (after having navigated into the folder that contains the example file) pdflatex latex-asymptote asy latex-asymptote-*.asy pdflatex latex-asymptote Kind regards, Mathias Schickel
Am 04.12.2018 um 18:03 schrieb Hans Hagen
: Hi,
As most mechanism are reasonable okay now we can look into what future versions of ConteXt should provide in terms of functionality. The (luatex) engine is also more of less finished or at least stable in terms of functionality.
One possible area of further development is graphics so I'd like to know if there are (reasonable) demands for more graphics support using metapost. Alan and I are on-and-off working on some extensions and one of the things we discuss is visualization of data. The question is of course what should be done in the lua/mp/tex combination and what externally but the combination has some advantages. There has been presentations and discussions at the last meeting and graphics is always a nice topic, and also kind of rewarding in terms of development.
Of course other demands can be formulated too, but these then need to come with well defined descriptions (or mockup examples).
Hans
----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl ----------------------------------------------------------------- ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________
participants (9)
-
Alan Braslau
-
Hans Hagen
-
Henri Menke
-
luigi scarso
-
Mathias Schickel
-
Mikael P. Sundqvist
-
Otared Kavian
-
Procházka Lukáš Ing.
-
Taco Hoekwater