ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Jano Kula <jano.kula@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Setting and measuring boxes TeX/Lua
Date: Wed, 25 Nov 2020 19:31:40 +0100	[thread overview]
Message-ID: <CAPefzZ22=w_XEy2obNYP5VNc7=sqTOd87cVb-mgMQNO-k+CKwg@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1804 bytes --]

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

[-- Attachment #1.2: Type: text/html, Size: 2397 bytes --]

[-- Attachment #2: texbox-complex.tex --]
[-- Type: application/x-tex, Size: 1100 bytes --]

[-- Attachment #3: 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
___________________________________________________________________________________

             reply	other threads:[~2020-11-25 18:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-25 18:31 Jano Kula [this message]
2020-11-25 20:25 ` Hans Hagen
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='CAPefzZ22=w_XEy2obNYP5VNc7=sqTOd87cVb-mgMQNO-k+CKwg@mail.gmail.com' \
    --to=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).