From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/108306 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Jairo A. del Rio" Newsgroups: gmane.comp.tex.context Subject: Re: How to properly pass TeX/Lua data to MetaPost/MetaFun? Date: Sun, 9 Aug 2020 13:03:00 -0500 Message-ID: References: <8673baf5-0390-7731-c983-1eb9e47a4165@xs4all.nl> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6372665014193362465==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29305"; mail-complaints-to="usenet@ciao.gmane.io" Cc: mailing list for ConTeXt users To: Hans Hagen Original-X-From: ntg-context-bounces@ntg.nl Sun Aug 09 20:03:43 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1k4pfZ-0007V6-2N for gctc-ntg-context-518@m.gmane-mx.org; Sun, 09 Aug 2020 20:03:41 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 578D61A7D4D; Sun, 9 Aug 2020 20:03:17 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NRuRcrnag21a; Sun, 9 Aug 2020 20:03:14 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id ACC821A7D41; Sun, 9 Aug 2020 20:03:14 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 2871C1A7B4A for ; Sun, 9 Aug 2020 20:03:13 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2YMI5xxeOmMF for ; Sun, 9 Aug 2020 20:03:12 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.128.49; helo=mail-wm1-f49.google.com; envelope-from=jairoadelrio6@gmail.com; receiver= Original-Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 426591A7863 for ; Sun, 9 Aug 2020 20:03:12 +0200 (CEST) Original-Received: by mail-wm1-f49.google.com with SMTP id k20so6290381wmi.5 for ; Sun, 09 Aug 2020 11:03:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qcsUtz+oJY2aq0gHAOrKGsOvPev2AoNHjjd5Jlgk6Uc=; b=AIUumHLQvrehJD8l0MC1ebpZAaLdxEc1tx2Ls0y242YlxpdhMqW73LC1zuRyw7SaXm Ohp4N85RF+fUGlF4xKaht5iB0X7vizYrom4EsbwwoBMqMqKyRukYUj+YBk1AU3B2Iwt1 3yL3KrKfto2XWPX0h8SkZNH7OtuGb2phPAeiYpKf9lzzz69SY8PxBQXZgrhg1tLAxoT9 F7fEfGicynsn0SjI9a5NJ8B/6AoF1WPtqjA5KcBFtGaQKrlFYEElZQI+ps+76A2NovDA pkfiHNHexhpfPgeHvKoyAYdVKwYEbmqVrQwmG0Jap0GKpk08mC1+x4zA14a1os3sdYJv 6SuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qcsUtz+oJY2aq0gHAOrKGsOvPev2AoNHjjd5Jlgk6Uc=; b=WI7dhx0pCykyIq9A3El1/TGpcHklbkC1kqrsRu5E6u3VDp7vgMjUxrNdIJmF989n5M MTc3COWQaQ6dKyWLv4fj0Z7JiVnIdmSqk1Jme5uL9ws9z2uVjzPg9Cztq5Tm+qYtBUN+ 0GisNW83Wayb7Xv0saAysWJ2rpmFeccPoFy4MeUJI3dzQFhO9RosWUD0VY+vA8VvWtqA Tisqgb1KhyMueM+yhuwB/Iz/6kbLwvyPmB+5qlRdSh8UhAD8BLxG9WTexG0+RTfg98ej p5RfeEkRgX+xMQ4PctpKK2c7vfg8n3wWxEmwUbMv2Hs2rsGGjc1WN96K0Xbnpv+aollQ FaoA== X-Gm-Message-State: AOAM530awyqk5PLZOzRhMhYNVwFnqSl9Onb7KssAmWUODG3n7OsQSCZd mql3uWZb0WGDqUJVKvlzT7aYhdRPkvURSYLisVZ1m7aZ X-Google-Smtp-Source: ABdhPJxPPAzOr+7LGbED/FWTMWuuqUJTjSqLy3HGEFDbTJ1tMEb8OCGyLqmKjLLGUFp5pMmOgRA8R4DiL2QjSIp9yTo= X-Received: by 2002:a1c:3dd6:: with SMTP id k205mr21778297wma.21.1596996191782; Sun, 09 Aug 2020 11:03:11 -0700 (PDT) In-Reply-To: <8673baf5-0390-7731-c983-1eb9e47a4165@xs4all.nl> X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:108306 Archived-At: --===============6372665014193362465== Content-Type: multipart/alternative; boundary="000000000000b80c7905ac75a629" --000000000000b80c7905ac75a629 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=C3=B3: > 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 way= s > > to do it in ConTeXt. Thank you in advance. > > > > \starttext > > My text > > > > \startMPinitializations > > numeric myunit; > > myunit :=3D \the\dimexpr1em\relax; > > \stopMPinitializations > > \startluacode > > > > userdata =3D userdata or {} > > userdata.dummydata =3D { {1, 2}, {3, 4} } > > > > context.startMPcode() > > > > for j=3D1,#userdata.dummydata do > > for i=3D1,#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 =3D userdata or {} > userdata.dummydata =3D { {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 :=3D EmWidth; > for i =3D 1 upto lua.MP.GetI() : > for j =3D 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 > ----------------------------------------------------------------- > --000000000000b80c7905ac75a629 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Oh, thank you a lot, Hans, that's a really cleane= r way than mine. One more question, is there something similar to EmWidth f= or \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=C3=B3:
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 ju= st
> lucky with this), I want to know how to do a better piece from it. I&#= 39;m
> concerned with passing data from Lua and TeX to Metapost and better wa= ys
> to do it in ConTeXt. Thank you in advance.
>
> \starttext
> My text
>
> \startMPinitializations
> numeric myunit;
> myunit :=3D \the\dimexpr1em\relax;
> \stopMPinitializations
> \startluacode
>
> userdata =3D userdata or {}
> userdata.dummydata =3D { {1, 2}, {3, 4} }
>
> context.startMPcode()
>
> for j=3D1,#userdata.dummydata do
> for i=3D1,#userdata.dummydata[1] do
> context("draw unitsquare scaled myunit shifted ((%d,%d)*myunit);&= quot;,
> userdata.dummydata[i][j], userdata.dummydata[i][j])
> end
> end
>
> context.stopMPcode()
>
> \stopluacode
> \stoptext
Something:

\starttext

\startluacode

=C2=A0 =C2=A0 =C2=A0userdata =3D userdata or {}
=C2=A0 =C2=A0 =C2=A0userdata.dummydata =3D { {1, 2}, {3, 4} }

=C2=A0 =C2=A0 =C2=A0function MP.GetI()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mp.print(#userdata.dummydata)
=C2=A0 =C2=A0 =C2=A0end
=C2=A0 =C2=A0 =C2=A0function MP.GetJ(i)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mp.print(#userdata.dummydata[i])
=C2=A0 =C2=A0 =C2=A0end
=C2=A0 =C2=A0 =C2=A0function MP.GetIJ(i,j)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0mp.pair(userdata.dummydata[i][j],userdata= .dummydata[i][j])
=C2=A0 =C2=A0 =C2=A0end

\stopluacode

\startMPcode
=C2=A0 =C2=A0 =C2=A0numeric myunit ; myunit :=3D EmWidth;
=C2=A0 =C2=A0 =C2=A0for i =3D 1 upto lua.MP.GetI() :
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for j =3D 1 upto lua.MP.GetJ(i) :
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0draw unitsquare scaled myun= it shifted (myunit *
(lua.MP.GetIJ(i,j)));
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0endfor ;
=C2=A0 =C2=A0 =C2=A0endfor ;
\stopMPcode

\stoptext

There are of course also other ways but this is more educational as start.<= br>
Hans

-----------------------------------------------------------------
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0Hans Hagen | PRAGMA ADE
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Ridderstraat 27 | 80= 61 GH Hasselt | The Netherlands
=C2=A0 =C2=A0 =C2=A0 =C2=A0 tel: 038 477 53 69 | www.pragma-ade.nl | www.= pragma-pod.nl
-----------------------------------------------------------------
--000000000000b80c7905ac75a629-- --===============6372665014193362465== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============6372665014193362465==--