From: Hans Hagen <j.hagen@xs4all.nl>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>,
Jano Kula <jano.kula@gmail.com>
Subject: Re: Setting and measuring boxes TeX/Lua
Date: Wed, 25 Nov 2020 21:25:28 +0100 [thread overview]
Message-ID: <c5d37026-7daa-aa46-f336-b66f1aafafa7@xs4all.nl> (raw)
In-Reply-To: <CAPefzZ22=w_XEy2obNYP5VNc7=sqTOd87cVb-mgMQNO-k+CKwg@mail.gmail.com>
On 11/25/2020 7:31 PM, Jano Kula wrote:
> Hello!
>
> I would like to set framed boxes, measure their dimensions and proceed
> based on the measurement. It is a combination of TeX and Lua ends.
>
> * Boxes are set on the TeX side. Stacking boxes (hbox, framed, vbox)
> in Lua looked too complex.
> * The content of the inner box is set on the Lua side (some computations).
>
> On TeX side boxes and their dimensions are accessible, but not at Lua
> side, until luacode is finished (iterations over boxes happen here). I
> would say Hans already named the problem in the list: /that is always
> tricky as what happens is postponing till the group ends/.
>
> Do you have an idea how to expand the box sooner or would you use a
> different approach?
>
> Sorry for longer MWE (attached also).
>
> Thank you,
> Jano
>
> \def\StartBox{\setbox0=\hbox\bgroup% open hbox
> \framed[frame=on]\bgroup% open framed
> \vbox\bgroup% open vbox (\par needed)
> }
> \def\StopBox{\egroup\egroup\egroup% close vbox, framed, hbox
> \setvariable{Test}{Height}{\the\ht0}%
> }%
>
> \startluacode
> ctx = context
>
> function TestBox()
> ctx("TeX Box: ") ctx.copy(false,0)ctx.par()
> ctx("TeX Getvar: ") ctx.getvariable("Test", "Height")ctx.par()
> var = tokens.getters.macro(tokens.getters.macro("??variables") ..
> "Test:Height")
> ctx("Lua Type: ") ctx(type(var))ctx.par()
> ctx("Lua Value: ") ctx(var)ctx.par()
> end
> \stopluacode
>
> \starttext
>
> \startluacode
> ctx.bold("First luacode (more boxes)")ctx.par()
> ctx.StartBox()
> ctx("AAA")ctx.par()
> ctx("BBB")ctx.par()
> ctx.StopBox()
> TestBox()
> ctx.StartBox()
> ctx("CCC")ctx.par()
> ctx.StopBox()
> TestBox()
> \stopluacode
>
> \blank[4*big]
>
> \startluacode
> ctx.bold("Second luacode (last content of box0)")ctx.par()
> TestBox()
> \stopluacode
>
> \stoptext
\startluacode
context.stepwise (function()
ctx.bold("First luacode (more boxes)")ctx.par()
ctx.StartBox()
ctx("AAA")ctx.par()
ctx("BBB")ctx.par()
ctx.StopBox()
context.step()
TestBox()
context.step()
ctx.StartBox()
ctx("CCC")ctx.par()
ctx.StopBox()
context.step()
TestBox()
context.step()
end)
\stopluacode
-----------------------------------------------------------------
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:[~2020-11-25 20:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-25 18:31 Jano Kula
2020-11-25 20:25 ` Hans Hagen [this message]
2020-11-25 21:28 ` Jano Kula
2020-11-26 8:18 ` Hans Hagen
2020-11-27 16:47 ` Jano Kula
2020-11-27 18:05 ` Hans Hagen
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=c5d37026-7daa-aa46-f336-b66f1aafafa7@xs4all.nl \
--to=j.hagen@xs4all.nl \
--cc=jano.kula@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).