From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
"Jairo A. del Rio" <jairoadelrio6@gmail.com>
Subject: Re: Getting dimensions in Lua
Date: Mon, 18 Jan 2021 10:45:23 +0100 [thread overview]
Message-ID: <61e180c9-cdee-8020-ce19-0b6a752db3df@xs4all.nl> (raw)
In-Reply-To: <CAKyqqaasrMrsa-LMKbH8R2zrEOW82ketAYKW4xYJbRvyMwrFyg@mail.gmail.com>
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
-----------------------------------------------------------------
___________________________________________________________________________________
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
___________________________________________________________________________________
next prev parent reply other threads:[~2021-01-18 9:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-18 0:58 Jairo A. del Rio
2021-01-18 9:45 ` Hans Hagen [this message]
2021-01-18 10:02 ` Taco Hoekwater
2021-01-18 10:10 ` Jairo A. del Rio
2021-01-18 10:12 ` Jairo A. del Rio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=61e180c9-cdee-8020-ce19-0b6a752db3df@xs4all.nl \
--to=j.hagen@xs4all.nl \
--cc=jairoadelrio6@gmail.com \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).