How to go through a vbox line by line in Lua?
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 Eijkhout'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
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 Eijkhout'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 -----------------------------------------------------------------
participants (2)
-
Hans Hagen
-
Henri Menke