On 8/9/2025 5:34 PM, vm via ntg-context wrote:
A while ago in one of the online meetings it was pointed out that one can feed aa point list in metafun using a lua table.
I haven't been able to figure out how to do that.
Has any one a hint?

At presnt I use a script to generate the path directly in MP but easily run out of memory tokens when the drawing is complex enough.

is there a way to define a function to draw a particular line passing its coords and pen and color?

do_line(path, pen, color)

where path is a list of x,y points?




8<---
\usecolors[crayola]
\startMPpage[offset=5mm]
path p;
pen q[];
q[1] := pencircle xscaled 0.3mm yscaled 0.20mm  ;
q[2] := pencircle xscaled 0.3mm yscaled 0.35mm  ;
q[3] := pencircle xscaled 0.3mm yscaled 0.50mm  ;
q[4] := pencircle xscaled 0.3mm yscaled 0.65mm  ;
q[5] := pencircle xscaled 0.3mm yscaled 0.80mm  ;
p := (447,531)..(440,534)..(436,541)..(440,547)..(448,546)..(455,542).. (458,535)..(447,531); draw p withpen q[1] rotated 25 withcolor "black"; p := (67,373)..(69,380)..(67,373)..(64,365)..(67,373); draw p withpen q[5] rotated 30 withcolor "black";
p := (64,91)..(64,91); draw p withpen q[1] rotated 34 withcolor "black";
p := (131,133)..(131,133); draw p withpen q[1] rotated 30 withcolor "black";

...

p := (436,264)..(433,271)..(430,279)..(426,286)..(422,293)..(418,299).. (414,306)..(410,313)..(408,321)..(416,323)..(422,319)..(428,312).. (434,306)..(432,313)..(429,321)..(429,329)..(435,335)..(442,338).. (448,344)..(451,352)..(451,359)..(455,350)..(457,341)..(459,332).. (460,323)..(461,313)..(462,303)..(462,294)..(461,285)..(460,277).. (457,267)..(452,259)..(447,252)..(440,254)..(436,264); draw p withpen q[4] rotated 27 withcolor "black"; p := (266,464)..(262,470)..(263,478)..(271,478)..(274,471)..(266,464); draw p withpen q[5] rotated 35 withcolor "black"; p := (108,401)..(108,408)..(106,401)..(104,393)..(108,401); draw p withpen q[5] rotated 30 withcolor "black";

you can store the path as table at the lua end (e.g. document.mypath) and then use "mp.path" to print from a lua call at the mp end; or as string and print with "mp.print" or bypass the parser with "mp.inject.path" or ... (grep for these in the tree)

the reason why you can run out of tokens is that every character becomes 8 bytes (token with link) when tex read in the blob; printing from lua avoids this, as then we have utf strings or direct path objects; of course storing a { x, y } subtable in lua takes more then token links but it doesn't exhaust token memory (which btw you can bump to more)

often when this out of memory occurs you are doing something extreme and maybe even conceptually dubious so might as well rethink a bit

technically we could pick up the blob at the tex end more efficiently which can then intefrefe with expansion of macros if one uses these on purpose; i might provide that as variant but its not really worth the trouble (i have it as disabled experiment because i have no time to test or pass megabytes of mp code this way) and it is again something one has to explain to users (token speak)

an alternative is to write the mp to a temporary file and let mp read that one (should also be fast)

of course all this depends on the use case (for instance, we can also store efficient vectors in lua and apply matrix operations to them and then render them in which case mp only sees the abstraction and the pdf is also more efficient but then your pen trickery is not applicable)

(keith is an example of a user who pushes this all to the limits so his test cases are our torture tests; mikael and i operate somewhere in the middle)

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 / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to