ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* How to go through a vbox line by line in Lua?
@ 2017-04-26 21:10 Henri Menke
  2017-04-26 21:19 ` Hans Hagen
  0 siblings, 1 reply; 2+ messages in thread
From: Henri Menke @ 2017-04-26 21:10 UTC (permalink / raw)
  To: mailing list for ConTeXt users

Dear list,

Recently I answered a question on TeX.SX where it was necessary to go
through an already typeset vbox and examine it line by line.  Therefore
I used the macro \eatlines from Viktor Ei­jkhout's "TeX by Topic", here
a version tailored to my needs:

\def\eatlines{%
  \setbox\scratchbox=\lastbox
  \ifvoid\scratchbox\else
    \unskip\unpenalty
    {\eatlines}%
    \setbox\scratchbox=\hbox{\unhbox\scratchbox}%
    % Do something with scratchbox, e.g. examine width
  \fi
}

It is then used like

\vbox{ ... some content ... \par\eatlines}

The macro goes through all hboxes (lines) in the vertical list until
there is none left (\ifvoid) and unpacks each hbox into a new one.

I was wondering, can the same thing be done in Lua (with probably less
and more readable code)?

Kind regards,
Henri
___________________________________________________________________________________
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] 2+ messages in thread

* Re: How to go through a vbox line by line in Lua?
  2017-04-26 21:10 How to go through a vbox line by line in Lua? Henri Menke
@ 2017-04-26 21:19 ` Hans Hagen
  0 siblings, 0 replies; 2+ messages in thread
From: Hans Hagen @ 2017-04-26 21:19 UTC (permalink / raw)
  To: ntg-context

On 4/26/2017 11:10 PM, Henri Menke wrote:

> Recently I answered a question on TeX.SX where it was necessary to go
> through an already typeset vbox and examine it line by line.  Therefore
> I used the macro \eatlines from Viktor Ei­jkhout's "TeX by Topic", here
> a version tailored to my needs:
>
> \def\eatlines{%
>   \setbox\scratchbox=\lastbox
>   \ifvoid\scratchbox\else
>     \unskip\unpenalty
>     {\eatlines}%
>     \setbox\scratchbox=\hbox{\unhbox\scratchbox}%
>     % Do something with scratchbox, e.g. examine width
>   \fi
> }
>
> It is then used like
>
> \vbox{ ... some content ... \par\eatlines}
>
> The macro goes through all hboxes (lines) in the vertical list until
> there is none left (\ifvoid) and unpacks each hbox into a new one.
>
> I was wondering, can the same thing be done in Lua (with probably less
> and more readable code)?

it depends on what you want to do. In any case you neet to be aware of 
possible side effects then.

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
___________________________________________________________________________________

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

end of thread, other threads:[~2017-04-26 21:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-26 21:10 How to go through a vbox line by line in Lua? Henri Menke
2017-04-26 21:19 ` 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).