Editing Traversing TeX nodes

From LuaTeXWiki

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
== Traversing TeX nodes ==
+
D6ZnzD  <a href="http://lippdztrobdy.com/">lippdztrobdy</a>, [url=http://lpynykdfzzuy.com/]lpynykdfzzuy[/url], [link=http://chynmakugbbj.com/]chynmakugbbj[/link], http://lhapzbrslbcu.com/
 
 
Put this code at the beginning of any TeX file:
 
 
 
<pre>
 
\directlua{
 
local glyph = node.id('glyph')
 
local hlist = node.id('hlist')
 
local vlist = node.id('vlist')
 
 
 
function gothru(h,prof)
 
  for t in node.traverse(h) do
 
    texio.write_nl(string.rep("...",prof) .. 'NODE type=' ..  node.type(t.id) .. ' subtype=' .. t.subtype )
 
    if t.id == hlist or t.id == vlist then
 
      texio.write(' w=' .. t.width .. ' h=' .. t.height .. ' d=' .. t.depth .. ' s=' .. t.shift )
 
  gothru(t.list,prof+1)
 
    end
 
    if t.id == glyph then
 
      texio.write(' font=' .. t.font .. ' char=' .. t.char .. ' width=' ..  font.fonts[t.font].characters[t.char]['width'])
 
    end
 
  end
 
end
 
 
 
callback.register('pre_linebreak_filter',
 
  function(h)
 
      gothru(h,0)
 
      return true
 
  end
 
  )
 
}
 
</pre>
 
 
 
It will display a list of all nodes on the terminal and in the log file. For example, for the document
 
 
 
<pre>
 
\font\x=omlgc
 
\x blε bla bla bla
 
</pre>
 
 
 
which contains a Greek letter (in UTF-8), you will get:
 
 
 
<pre>
 
This is luaTeX, Version 3.141592-snapshot-2007062922 (Web2C 7.5.6)
 
(
 
NODE type=whatsit subtype=6
 
NODE type=hlist subtype=0
 
NODE type=glyph subtype=0 font=51 char=98
 
NODE type=glyph subtype=0 font=51 char=108
 
NODE type=glyph subtype=0 font=51 char=941
 
NODE type=glue subtype=0
 
NODE type=glyph subtype=0 font=51 char=98
 
NODE type=glyph subtype=0 font=51 char=108
 
NODE type=glyph subtype=0 font=51 char=97
 
NODE type=glue subtype=0
 
NODE type=glyph subtype=0 font=51 char=98
 
NODE type=glyph subtype=0 font=51 char=108
 
NODE type=glyph subtype=0 font=51 char=97
 
NODE type=glue subtype=0
 
NODE type=glyph subtype=0 font=51 char=98
 
NODE type=glyph subtype=0 font=51 char=108
 
NODE type=glyph subtype=0 font=51 char=97
 
NODE type=glue subtype=0
 
Underfull \hbox (badness 10000) in paragraph at lines 14--15
 
 
 
[1] )
 
</pre>
 
 
 
Be aware of the fact that the nodes will be created only if the glyph requested indeed exists in the font.
 
 
 
[[User:Yannis.Haralambous|Yannis.Haralambous]] 02:52, 4 July 2007 (EDT)
 

Please note that all contributions to LuaTeXWiki are considered to be released under the GNU Free Documentation License 1.3 (see LuaTeXWiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)