Hi Taco Apologies if this is at all off-topic but I'd like to find out if the following is possible... Suppose I have some text in a \vbox {} say \setbox0 = \vbox{Some text that will be broken into lines...} I would like to access the node list of this \vbox and walk the node tree to emit (PostScript) code that will create an exact rendering of that typeset text, giving the same visual result you would see if the \vbox was placed directly into the main PDF generated by LuaTeX. I'm exploring node structures (using my GraphViz port and Patrick's viznodelist tool) but (as yet) don't understand how to traverse the nodelist such that you can output the typeset result. In particular, gaining access to (for example) the final set values of glue (skip) which occurs between words. This is a slightly unusual application but it would be much appreciated if you suggest how to go about doing this. In particular: the way you would traverse the node tree (which links to follow) to get the glyphs output in the right order and how to access or calculate the glue between words. Thank you as always for all your time and endless patience with so many questions. Very best wishes Graham
On 28-11-2010 7:05, Graham Douglas wrote:
Hi Taco
Apologies if this is at all off-topic but I'd like to find out if the following is possible...
Suppose I have some text in a \vbox {} say
\setbox0 = \vbox{Some text that will be broken into lines...}
at the lua end you can access that box: tex.box[0] (with width, height, depth, list etc fields) ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Thanks Hans. Sure, I've been doing this to generate the GraphViz diagrams etc plus hooking into various callbacks etc. What I don't yet quite understand is the correct navigation or link path to follow through the node structures and the best way to access or calculate glue (set) values for things like skip between words. All this reflects my currently hazy understanding of the liks + connections in the node graph. For example, see the attached PDF of the graph arising from a saimple example: \setbox0\vbox{Hello to Lua\TeX\ and another \vbox {here}} Even with this simple example the node traversal to render in the right order seems quite complex. Eg the TeX bit --- looping through the correct path to get the glyph order "TEX" For sure, you can work it out by following the graph, but what I'm interested to know is what the general case traversal algorithm would look like? Apologies for these fuzzy questions but this is early days for me with node traversal :-) Warm wishes Graham
On 28-11-2010 7:40, Graham Douglas wrote:
Thanks Hans.
Sure, I've been doing this to generate the GraphViz diagrams etc plus hooking into various callbacks etc. What I don't yet quite understand is the correct navigation or link path to follow through the node structures and the best way to access or calculate glue (set) values for things like skip between words.
that is just a multiplication factor; for the precise dealing of it you might want to look into the backend code (take the dvi related code at that is rather simple and discussed in the tex the program book as well; it might look more complex due to hz and protruding)
All this reflects my currently hazy understanding of the liks + connections in the node graph.
For example, see the attached PDF of the graph arising from a saimple example:
\setbox0\vbox{Hello to Lua\TeX\ and another \vbox {here}}
Even with this simple example the node traversal to render in the right order seems quite complex.
in general you loop recursively, i.e. in a typeset box you need to follow the list in hlist/vlist nodes; in backend related operations you also might need to go into the leader part of a rule of course whatsits are sort if special as they can represent anything it all depends on what you want to do but Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hans Hagen wrote:
On 28-11-2010 7:40, Graham Douglas wrote:
Thanks Hans.
Sure, I've been doing this to generate the GraphViz diagrams etc plus hooking into various callbacks etc. What I don't yet quite understand is the correct navigation or link path to follow through the node structures and the best way to access or calculate glue (set) values for things like skip between words.
that is just a multiplication factor; for the precise dealing of it you might want to look into the backend code (take the dvi related code at that is rather simple and discussed in the tex the program book as well; it might look more complex due to hz and protruding)
in general you loop recursively, i.e. in a typeset box you need to follow the list in hlist/vlist nodes; in backend related operations you also might need to go into the leader part of a rule
=========== Thanks Hans. For sure there is a lot of recursion here, but I just need to work out the order of traversal, when you recurse and once you get back to the top of each recursion where you go next, to do more recursion etc. What I was also wondering is whether the final set value of the glue is directly available, as was determined by LuaTeX. For example, page 89 of the beta 0.65 manual Taco gives an interesting example ======= node.dimensions(<number> glue_set, <number> glue_sign, <number> glue_order, <node> n, <node> t, <string> dir) This calling method takes glue settings into account and is especially useful for finding the actual width of a sublist of nodes that are already boxed ======== So I was curious to know if it is possible to get access to the glue set values as you traverse the list. Simplistically, as you traverse the list: .... see glpyhs (width, height, depth) --> emit PostScript to place glyph see interword skip (actual amount) --> emit PostScript to move by skip (or shift or kern) see glyphs etc So, all I want to do is traverse the node list and emit PostScript code to place glyphs and do skips/kerns/shifts etc to create a copy of the typeset text as would be placed in the final LuaTeX PDF Really just a toy exercise (no real application) through which I can gain understanding. For sure the other node types etc would need handling but I'm just interested (for now) in emitting PostScript to generate an exact copy of the typeset \vbox {} etc, as a way to understand the world of nodes etc. The final PostScript would just be made into a PDF for visual comparison. Many thanks and apologies if my explanations are unclear or confused (both likely!) Best wishes Graham
In particular, gaining access to (for example) the final set values of glue (skip) which occurs between words.
the hlists and vlists have glue_order glue_set glue_sign I am guessing that you only have to multiply list.glue_set with the data stored in the glue_spec nodes of that list (spec.width) if the list.glue_order is equal to the spec.*_order in the glue_spec node. The other cases are left to you as an exercise :) Patrick
On 11/28/2010 09:35 PM, Patrick Gundlach wrote:
In particular, gaining access to (for example) the final set values of glue (skip) which occurs between words.
the hlists and vlists have
glue_order glue_set glue_sign
I am guessing that you only have to multiply list.glue_set with the data stored in the glue_spec nodes of that list (spec.width) if the list.glue_order is equal to the spec.*_order in the glue_spec node. The other cases are left to you as an exercise :)
Thanks Patrick :) Best wishes, Taco
Huge thanks to everyone for their help and advice. Much appreciated. Now, off to do those exercises... ;-) Warm wishes Graham
Already answered in a private mail, but for the archive and others to correct the answer.
the way you would traverse the node tree (which links to follow) to get the glyphs output in the right order
I _think_ that the right order is loop over head.next if current_node == hlist or vlist then loop over head.list end do something with current node end loop Additional places to recurse into, depending on application: * disc nodes (components) * leader part of glue * sub_box and sub_mlist subnodes (?) * box_left, box_right in local_par node Patrick
participants (4)
-
Graham Douglas
-
Hans Hagen
-
Patrick Gundlach
-
Taco Hoekwater