[luatex] Turning a string into a list of nodes.

Patrick Gundlach patrick at gundla.ch
Thu Nov 18 22:49:15 CET 2010


Hi Paul,

i do something like this (pseudo code): 

  local match = unicode.utf8.match

  for s in string.utfvalues(str) do
    char = unicode.utf8.char(s)
    if match(char,"%s") and last and last.id == 10 then -- is it 10, the glue node?? 
      -- double whitespace, \relax
    elseif match(char,"%s") then -- ws
      n = node.new("glue")
      n.spec = node.new("glue_spec")
      n.spec.width   = space -- calculated somewhere else
      n.spec.shrink  = shrink 
      n.spec.stretch = stretch

      if head then
        last.next = n
      else
        head = n
      end
      last = n

    else
      n = node.new("glyph")
      n.font = ... (set somewhere else)
      n.char = s
      n.lang = 0
      n.left = tex.lefthyphenmin
      n.right = tex.righthyphenmin

      if head then
        last.next = n
      else
        head = n
      end
      last = n
    end
  end


and then I use node.kerning() for kerning and lang.hyphenate() for inserting disc nodes.


Patrick




More information about the luatex mailing list