ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Setting and measuring boxes TeX/Lua
@ 2020-11-25 18:31 Jano Kula
  2020-11-25 20:25 ` Hans Hagen
  0 siblings, 1 reply; 6+ messages in thread
From: Jano Kula @ 2020-11-25 18:31 UTC (permalink / raw)
  To: mailing list for ConTeXt users


[-- 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
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-11-27 18:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25 18:31 Setting and measuring boxes TeX/Lua Jano Kula
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

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).