[luatex] Kerning: when does it not work?

Heilmann, Till A. till.heilmann at unibas.ch
Thu May 5 09:06:19 CEST 2011


Well, there are some problems with Paul's code, after all: The  
underscore character _ cannot be part of a URL *if* it occurs inside  
a footnote (see below). I have not checked for errors with other  
characters yet.

Best,
--Till

\documentclass{article}
\def\makeother#1{\catcode`#1=12 }
\def\url{%
    \begingroup
    \let\do\makeother \dospecials
    \catcode`\{=1 \catcode`\}=2
    \URL
    }
\newbox\urlbox
\def\URL#1{%
    \setbox\urlbox=\hbox{#1}%
    \directlua{%
      local box = tex.box["urlbox"].list
      local glyf, disc = node.id("glyph"), node.id("disc")
      for n in node.traverse_id(disc, box) do
        node.remove(box, n)
      end
      for n in node.traverse_id(glyf, box) do
        local b = url.breakpoints[n.char]
        if b == "before" then
          url.before(box, n)
        elseif b == "after" then
          url.after(box, n)
        elseif b == "both" then
          url.before(box, n)
          url.after(box, n)
        end
      end}%
    \unhbox\urlbox
    \endgroup
    }

\directlua{
local id, copy, insert_before, insert_after = node.id, node.copy,  
node.insert_before, node.insert_after

url = {}
url.breakpoints = {}
local penalty = node.new(id("penalty"))
penalty.penalty = 0

function url.before (l, n)
    if n.prev then
      if n.prev.id == id("kern") and n.prev.subtype == 0 then
        n = n.prev
      end
      insert_before(l, n, copy(penalty))
    end
end

function url.after(l, n)
    if n.next then
      insert_after(l, n, copy(penalty))
    end
end
}

\def\urladdbreakpoint#1#2{%
    \directlua{url.breakpoints[\the\numexpr`#1] = "#2"}%
    }
\begin{document}
\footnote{\url{_}}
\end{document}


More information about the luatex mailing list