[luatex] Typesetting URLs

Heilmann, Till A. till.heilmann at unibas.ch
Wed May 18 12:14:37 CEST 2011


Sorry to bother you again with this, guys, but apparently something has changed with LuaTeX beta 0.70 so that Paul's and Ulrike's code to typeset URLs (see below) doesn't work when the string contains a _ character (this problem was corrected by Ulrike a few days ago but now seems to have resurfaced). Any thoughts on this?

Thanks and best regards,
--Till

\documentclass{article}
\def\makeother#1{\catcode`#1=12 }
\def\url{%
    \begingroup
    \catcode`\%=12
    \URL
    }
\newbox\urlbox
\def\URL#1{%
  \setbox\urlbox=\hbox{%
    \directlua{%
      tex.sprint(-2,"\luatexluaescapestring{\unexpanded{#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"}%
    }
\urladdbreakpoint{_}{both}
\begin{document}
\url{_}
\end{document}


More information about the luatex mailing list