From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/110309 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "Jairo A. del Rio" Newsgroups: gmane.comp.tex.context Subject: Re: Getting dimensions in Lua Date: Mon, 18 Jan 2021 05:12:02 -0500 Message-ID: References: <61e180c9-cdee-8020-ce19-0b6a752db3df@xs4all.nl> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0762459616844092522==" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27988"; mail-complaints-to="usenet@ciao.gmane.io" To: Hans Hagen , mailing list for ConTeXt users Original-X-From: ntg-context-bounces@ntg.nl Mon Jan 18 11:15:11 2021 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 1l1RZ0-00078L-Sk for gctc-ntg-context-518@m.gmane-mx.org; Mon, 18 Jan 2021 11:15:10 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 224DE1C1F7A; Mon, 18 Jan 2021 11:12:17 +0100 (CET) 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 bd0x2bWJwzfn; Mon, 18 Jan 2021 11:12:16 +0100 (CET) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 3AF181C1F6F; Mon, 18 Jan 2021 11:12:16 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 0AC1A1C1F6D for ; Mon, 18 Jan 2021 11:12:15 +0100 (CET) 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 k_I7EFUpUgDc for ; Mon, 18 Jan 2021 11:12:14 +0100 (CET) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.128.41; helo=mail-wm1-f41.google.com; envelope-from=jairoadelrio6@gmail.com; receiver= Original-Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 2BC551C1F62 for ; Mon, 18 Jan 2021 11:12:14 +0100 (CET) Original-Received: by mail-wm1-f41.google.com with SMTP id y187so13274435wmd.3 for ; Mon, 18 Jan 2021 02:12:14 -0800 (PST) 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; bh=zffiXjUSiodzflrydIARr5+eE2GppgBBjSPEp1dLzrI=; b=ciQkIE/MNhWUnhFEklQvRs3vOlALkIMQBSb/EET8O47kf5o1YIBKxma9GhV5jg2QlB C5msaBlGmzRcJd9w2d+XOR/iZHa3uMSBniM0pybsWWdN+xW5KH4LTn/E7OEJQFf/vk+x 0Bpd2RWKrILqQNTxh9SUCK1Px0OwJccFLX+bLdlYveqSeSHu69qLeRtVA6Qt84ccGU1N 49tMy4/6dKlJmjETJuwn5RrZHYQLJ6BVVlXWq5ZjkjvmXnPfQWqBmMjlNWf1XtiJElPp g0g7Wxy+Ls0e9ZkkLfPjxDnhvUbCyNftMRUMbLkGShY/atUslvOorYRpZ4ItobLKGUsu njMw== 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; bh=zffiXjUSiodzflrydIARr5+eE2GppgBBjSPEp1dLzrI=; b=Ht3sBWUDhBNPUKpDW08PzqtDdgKS8/mGo1i8sZkJSWT4ujP6RxopAwQhYRM9q+ykIH 8UEkK9HE2jJYoUOjv8EsMJxZv64EpIZ7FuNEdWFO8JwuPeADKxDsTGbjQA3hTQL7IY5x 5IxFZRxyfNh7krIZU03Mwh5H86MiWadF+0ANSQ3LtUp73P4RBxoBx+j77cCyZLfVVsBJ DSh3/bx/2ZsusgUgYF61O7xtFMr1vNgAyHsSJ/qQH7PBT87vBDMu1PujXFGiASadTTnD 9+Ja53N8wS58dhldjoIYm594WVvr5AD51ULElH3V98CNVY9sAdYZQL1i9H7M/DuYKPCA SNbw== X-Gm-Message-State: AOAM530K5KkMD9Y4YEKhfKpy+FDwzVJM+tmAyMY4EdKnjV8F3FYezEiZ cCYeW0QnjTW28nyW1+3Z8pzRIXpA9bz+OfZ48iPC2G5+k/g= X-Google-Smtp-Source: ABdhPJyOLRVqXZfR3kD/MKKqX2p25IljlIwxH+jcGrOfhlfC+/d3j9evfE13bfBLkcowxzR7Zxj4CoABk0/cRU7d/yg= X-Received: by 2002:a7b:c94e:: with SMTP id i14mr9386936wml.26.1610964733858; Mon, 18 Jan 2021 02:12:13 -0800 (PST) In-Reply-To: <61e180c9-cdee-8020-ce19-0b6a752db3df@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:110309 Archived-At: --===============0762459616844092522== Content-Type: multipart/alternative; boundary="000000000000b5146c05b929f484" --000000000000b5146c05b929f484 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable To be wikified (by me, obviously). Thank you for such a great number of alternatives. Jairo :) El lun, 18 de ene. de 2021 a la(s) 04:45, Hans Hagen (j.hagen@xs4all.nl) escribi=C3=B3: > On 1/18/2021 1:58 AM, Jairo A. del Rio wrote: > > Hi, list. > > > > I want to get some dimensions in Lua. See, for instance > > > > \starttext > > > > \the\dimexpr\availablehsize\relax %say, 426pt > > > > \stoptext > > > > Is there an equivalent in ConTeXt for Lua, i.e. without passing values > > from TeX or, at least, using only Lua commands? Thank you in advance. > tex being tex, there is always a way ... > > 1: \number\dimexpr\availablehsize\relax > > 2: \startluacode > > token.set_macro(tex.ctxcatcodes,"temp","\\scratchdimen\\availablehsize") > token.expand_macro("temp") > context(tex.getdimen("scratchdimen")) > \stopluacode > > 3: \startluacode > > token.set_macro(tex.ctxcatcodes,"temp","\\scratchdimen\\availablehsize") > tex.runlocal("temp") > context(tex.getdimen("scratchdimen")) > \stopluacode > > 4: \startluacode > tex.print("\\scratchdimen\\availablehsize") > tex.pushlocal() > tex.poplocal() > context(tex.getdimen("scratchdimen")) > \stopluacode > > 5: \startluacode > tex.print("\\dimensiondef\\temp\\availablehsize") > tex.pushlocal() > tex.poplocal() > context(tex.getdimensionvalue("temp")) > \stopluacode > > \def\calculateavailablehsize{\dimensiondef\temp\availablehsize} > > 6: \startluacode > token.expand_macro("calculateavailablehsize") > context(tex.getdimensionvalue("temp")) > \stopluacode > > \newtoks\tcalculateavailablehsize > \tcalculateavailablehsize{\dimensiondef\temp\availablehsize} > > 7: \startluacode -- mkiv > tex.runtoks("tcalculateavailablehsize") > context(tex.getdimensionvalue("temp")) > \stopluacode > > i'm (still) considering a way to flag a macro to be an expression (or > value) but there are several variants possible but normally it takes a > while before i decide what makes most sense (as i need to apply it in > real code to see if it looks nice) > > 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 > ----------------------------------------------------------------- > --000000000000b5146c05b929f484 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
To be wikified (by me, obviously). Thank you for such= a great number of alternatives.

Jairo :)

El lun, 18 de ene= . de 2021 a la(s) 04:45, Hans Hagen (j= .hagen@xs4all.nl) escribi=C3=B3:
On 1/18/2021 1:58 AM, Jairo A. del Rio wrote:
> Hi, list.
>
> I want to get some dimensions in Lua. See, for instance
>
> \starttext
>
> \the\dimexpr\availablehsize\relax %say, 426pt
>
> \stoptext
>
> Is there an equivalent in ConTeXt for Lua, i.e. without passing values=
> from TeX or, at least, using only Lua commands? Thank you in advance.<= br> tex being tex, there is always a way ...

1: \number\dimexpr\availablehsize\relax

2: \startluacode

token.set_macro(tex.ctxcatcodes,"temp","\\scratchdimen\\avai= lablehsize")
=C2=A0 =C2=A0 =C2=A0token.expand_macro("temp")
=C2=A0 =C2=A0 =C2=A0context(tex.getdimen("scratchdimen"))
\stopluacode

3: \startluacode

token.set_macro(tex.ctxcatcodes,"temp","\\scratchdimen\\avai= lablehsize")
=C2=A0 =C2=A0 =C2=A0tex.runlocal("temp")
=C2=A0 =C2=A0 =C2=A0context(tex.getdimen("scratchdimen"))
\stopluacode

4: \startluacode
=C2=A0 =C2=A0 =C2=A0tex.print("\\scratchdimen\\availablehsize") =C2=A0 =C2=A0 =C2=A0tex.pushlocal()
=C2=A0 =C2=A0 =C2=A0tex.poplocal()
=C2=A0 =C2=A0 =C2=A0context(tex.getdimen("scratchdimen"))
\stopluacode

5: \startluacode
=C2=A0 =C2=A0 =C2=A0tex.print("\\dimensiondef\\temp\\availablehsize&qu= ot;)
=C2=A0 =C2=A0 =C2=A0tex.pushlocal()
=C2=A0 =C2=A0 =C2=A0tex.poplocal()
=C2=A0 =C2=A0 =C2=A0context(tex.getdimensionvalue("temp"))
\stopluacode

\def\calculateavailablehsize{\dimensiondef\temp\availablehsize}

6: \startluacode
=C2=A0 =C2=A0 =C2=A0token.expand_macro("calculateavailablehsize")=
=C2=A0 =C2=A0 =C2=A0context(tex.getdimensionvalue("temp"))
\stopluacode

\newtoks\tcalculateavailablehsize
\tcalculateavailablehsize{\dimensiondef\temp\availablehsize}

7: \startluacode -- mkiv
=C2=A0 =C2=A0 =C2=A0tex.runtoks("tcalculateavailablehsize")
=C2=A0 =C2=A0 =C2=A0context(tex.getdimensionvalue("temp"))
\stopluacode

i'm (still) considering a way to flag a macro to be an expression (or <= br> value) but there are several variants possible but normally it takes a
while before i decide what makes most sense (as i need to apply it in
real code to see if it looks nice)

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
-----------------------------------------------------------------
--000000000000b5146c05b929f484-- --===============0762459616844092522== 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== --===============0762459616844092522==--