* How to properly pass TeX/Lua data to MetaPost/MetaFun? @ 2020-08-09 15:39 Jairo A. del Rio 2020-08-09 17:46 ` Hans Hagen 0 siblings, 1 reply; 5+ messages in thread From: Jairo A. del Rio @ 2020-08-09 15:39 UTC (permalink / raw) To: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 796 bytes --] Hi, list! I'm doing the following to scale squares and other stuff in MetaPost/MetaFun. Although the following kinda works (maybe I'm just lucky with this), I want to know how to do a better piece from it. I'm concerned with passing data from Lua and TeX to Metapost and better ways to do it in ConTeXt. Thank you in advance. \starttext My text \startMPinitializations numeric myunit; myunit := \the\dimexpr1em\relax; \stopMPinitializations \startluacode userdata = userdata or {} userdata.dummydata = { {1, 2}, {3, 4} } context.startMPcode() for j=1,#userdata.dummydata do for i=1,#userdata.dummydata[1] do context("draw unitsquare scaled myunit shifted ((%d,%d)*myunit);", userdata.dummydata[i][j], userdata.dummydata[i][j]) end end context.stopMPcode() \stopluacode \stoptext Jairo :) [-- Attachment #1.2: Type: text/html, Size: 1094 bytes --] [-- Attachment #2: Type: text/plain, Size: 493 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to properly pass TeX/Lua data to MetaPost/MetaFun? 2020-08-09 15:39 How to properly pass TeX/Lua data to MetaPost/MetaFun? Jairo A. del Rio @ 2020-08-09 17:46 ` Hans Hagen 2020-08-09 18:03 ` Jairo A. del Rio 0 siblings, 1 reply; 5+ messages in thread From: Hans Hagen @ 2020-08-09 17:46 UTC (permalink / raw) To: mailing list for ConTeXt users, Jairo A. del Rio On 8/9/2020 5:39 PM, Jairo A. del Rio wrote: > Hi, list! I'm doing the following to scale squares and other stuff in > MetaPost/MetaFun. Although the following kinda works (maybe I'm just > lucky with this), I want to know how to do a better piece from it. I'm > concerned with passing data from Lua and TeX to Metapost and better ways > to do it in ConTeXt. Thank you in advance. > > \starttext > My text > > \startMPinitializations > numeric myunit; > myunit := \the\dimexpr1em\relax; > \stopMPinitializations > \startluacode > > userdata = userdata or {} > userdata.dummydata = { {1, 2}, {3, 4} } > > context.startMPcode() > > for j=1,#userdata.dummydata do > for i=1,#userdata.dummydata[1] do > context("draw unitsquare scaled myunit shifted ((%d,%d)*myunit);", > userdata.dummydata[i][j], userdata.dummydata[i][j]) > end > end > > context.stopMPcode() > > \stopluacode > \stoptext Something: \starttext \startluacode userdata = userdata or {} userdata.dummydata = { {1, 2}, {3, 4} } function MP.GetI() mp.print(#userdata.dummydata) end function MP.GetJ(i) mp.print(#userdata.dummydata[i]) end function MP.GetIJ(i,j) mp.pair(userdata.dummydata[i][j],userdata.dummydata[i][j]) end \stopluacode \startMPcode numeric myunit ; myunit := EmWidth; for i = 1 upto lua.MP.GetI() : for j = 1 upto lua.MP.GetJ(i) : draw unitsquare scaled myunit shifted (myunit * (lua.MP.GetIJ(i,j))); endfor ; endfor ; \stopMPcode \stoptext There are of course also other ways but this is more educational as start. 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to properly pass TeX/Lua data to MetaPost/MetaFun? 2020-08-09 17:46 ` Hans Hagen @ 2020-08-09 18:03 ` Jairo A. del Rio 2020-08-09 18:05 ` Hans Hagen 0 siblings, 1 reply; 5+ messages in thread From: Jairo A. del Rio @ 2020-08-09 18:03 UTC (permalink / raw) To: Hans Hagen; +Cc: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 2492 bytes --] Oh, thank you a lot, Hans, that's a really cleaner way than mine. One more question, is there something similar to EmWidth for \textwidth or \linewidth? Better, a better way to access TeX dimensions? Thank you again. Jairo :) El dom., 9 de ago. de 2020 a la(s) 12:46, Hans Hagen (j.hagen@xs4all.nl) escribió: > On 8/9/2020 5:39 PM, Jairo A. del Rio wrote: > > Hi, list! I'm doing the following to scale squares and other stuff in > > MetaPost/MetaFun. Although the following kinda works (maybe I'm just > > lucky with this), I want to know how to do a better piece from it. I'm > > concerned with passing data from Lua and TeX to Metapost and better ways > > to do it in ConTeXt. Thank you in advance. > > > > \starttext > > My text > > > > \startMPinitializations > > numeric myunit; > > myunit := \the\dimexpr1em\relax; > > \stopMPinitializations > > \startluacode > > > > userdata = userdata or {} > > userdata.dummydata = { {1, 2}, {3, 4} } > > > > context.startMPcode() > > > > for j=1,#userdata.dummydata do > > for i=1,#userdata.dummydata[1] do > > context("draw unitsquare scaled myunit shifted ((%d,%d)*myunit);", > > userdata.dummydata[i][j], userdata.dummydata[i][j]) > > end > > end > > > > context.stopMPcode() > > > > \stopluacode > > \stoptext > Something: > > \starttext > > \startluacode > > userdata = userdata or {} > userdata.dummydata = { {1, 2}, {3, 4} } > > function MP.GetI() > mp.print(#userdata.dummydata) > end > function MP.GetJ(i) > mp.print(#userdata.dummydata[i]) > end > function MP.GetIJ(i,j) > mp.pair(userdata.dummydata[i][j],userdata.dummydata[i][j]) > end > > \stopluacode > > \startMPcode > numeric myunit ; myunit := EmWidth; > for i = 1 upto lua.MP.GetI() : > for j = 1 upto lua.MP.GetJ(i) : > draw unitsquare scaled myunit shifted (myunit * > (lua.MP.GetIJ(i,j))); > endfor ; > endfor ; > \stopMPcode > > \stoptext > > There are of course also other ways but this is more educational as start. > > 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 > ----------------------------------------------------------------- > [-- Attachment #1.2: Type: text/html, Size: 3306 bytes --] [-- Attachment #2: Type: text/plain, Size: 493 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to properly pass TeX/Lua data to MetaPost/MetaFun? 2020-08-09 18:03 ` Jairo A. del Rio @ 2020-08-09 18:05 ` Hans Hagen 2020-08-09 18:08 ` Jairo A. del Rio 0 siblings, 1 reply; 5+ messages in thread From: Hans Hagen @ 2020-08-09 18:05 UTC (permalink / raw) To: Jairo A. del Rio; +Cc: mailing list for ConTeXt users On 8/9/2020 8:03 PM, Jairo A. del Rio wrote: > Oh, thank you a lot, Hans, that's a really cleaner way than mine. One > more question, is there something similar to EmWidth for \textwidth or > \linewidth? Better, a better way to access TeX dimensions? Thank you again. When you grep for EmWidth ... LineWidth TextWidth and plenty more like that 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: How to properly pass TeX/Lua data to MetaPost/MetaFun? 2020-08-09 18:05 ` Hans Hagen @ 2020-08-09 18:08 ` Jairo A. del Rio 0 siblings, 0 replies; 5+ messages in thread From: Jairo A. del Rio @ 2020-08-09 18:08 UTC (permalink / raw) To: Hans Hagen; +Cc: mailing list for ConTeXt users [-- Attachment #1.1: Type: text/plain, Size: 905 bytes --] Nice, I'm reading results right now. Thank you a lot, Hans. Jairo :) El dom., 9 de ago. de 2020 a la(s) 13:05, Hans Hagen (j.hagen@xs4all.nl) escribió: > On 8/9/2020 8:03 PM, Jairo A. del Rio wrote: > > Oh, thank you a lot, Hans, that's a really cleaner way than mine. One > > more question, is there something similar to EmWidth for \textwidth or > > \linewidth? Better, a better way to access TeX dimensions? Thank you > again. > When you grep for EmWidth ... > > LineWidth > TextWidth > > and plenty more like that > > 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 > ----------------------------------------------------------------- > [-- Attachment #1.2: Type: text/html, Size: 1422 bytes --] [-- Attachment #2: Type: text/plain, Size: 493 bytes --] ___________________________________________________________________________________ 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 ___________________________________________________________________________________ ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-08-09 18:08 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-08-09 15:39 How to properly pass TeX/Lua data to MetaPost/MetaFun? Jairo A. del Rio 2020-08-09 17:46 ` Hans Hagen 2020-08-09 18:03 ` Jairo A. del Rio 2020-08-09 18:05 ` Hans Hagen 2020-08-09 18:08 ` Jairo A. del Rio
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).