Dear lua experts, For our repository of hyphenation patterns I would like to create a document that: - reads in a file with hyphenation patterns - reads in plain text file (say one word per line) - creates output such as "hy{\nicehyphen}phen{\nicehyphen}ation" for each word I'm testing eshyph-test.tex by Javier Bezos from http://www.ctan.org/tex-archive/language/spanish/hyphen/base/ (trying to run it with ConTeXt :), but I don't understand how exactly the callbacks work. For example, I cannot get the following code to work in ConTeXt (but it works with luatex in TL 09): \starttext \directlua{ callback.register('pre_linebreak_filter', function(h, groupcode) return true end) } abc \stoptext ! LuaTeX error ...text/tex/texmf-context/tex/context/base/luat-cbk.lua:39: attempt to call global 'format' (a nil value) stack traceback: ...text/tex/texmf-context/tex/context/base/luat-cbk.lua:39: in function <...text/tex/texmf-context/tex/context/base/luat-cbk.lua:38> (tail call): ? <\directlua >:1: in main chunk. l.8 } ? Here's the code that runs in luatex (it's all just a simplified Javier's code) and prints hyphenated words to terminal. Is there some more elegant way to do it? Is there a way to print it back to the document (I understand the problem why the currect approach would fail to work directly)? And why does it fail in ConTeXt? Thanks a lot for any hints, Mojca % one needs to create an arbitrary file words.txt, even if it just contains two words \directlua{\unexpanded{ local glyph = node.id('glyph') local disc = node.id('disc') local glue = node.id('glue') callback.register('pre_linebreak_filter', function(h, groupcode) word = '' for t in node.traverse(h) do if node.id(t.id) == glyph and t.subtype == 0 then word = word .. unicode.utf8.char(t.char) elseif node.id(t.id) == disc then word = word .. '-' elseif node.id(t.id) == glue then word = word .. ' ' end end % texio.write_nl('NODE type=' .. node.type(t.id) .. ' subtype=' .. t.subtype ) % if t.id == glyph then % texio.write(' font=' .. t.font .. ' char=' .. unicode.utf8.char(t.char)) % end texio.write_nl(' -- ' .. word) return true end) }} % \pdfnoligatures \hbadness=10000 \hfuzz=\maxdimen \def\p#1{#1\setbox0\vbox{\hsize0pt #1}} \directlua{\unexpanded{ local words = io.open('words.txt') for w in words:lines() do tex.print('\\p{' .. w .. '}') end words:close() }} \bye
Mojca Miklavec wrote:
Dear lua experts,
For our repository of hyphenation patterns I would like to create a document that: - reads in a file with hyphenation patterns - reads in plain text file (say one word per line) - creates output such as "hy{\nicehyphen}phen{\nicehyphen}ation" for each word
I'm testing eshyph-test.tex by Javier Bezos from http://www.ctan.org/tex-archive/language/spanish/hyphen/base/ (trying to run it with ConTeXt :), but I don't understand how exactly the callbacks work. For example, I cannot get the following code to work in ConTeXt (but it works with luatex in TL 09):
IIRC, Hans blocks access to callback.register() to prevent users from destroying ConTeXt internals. Best wishes, Taco
participants (2)
-
Mojca Miklavec
-
Taco Hoekwater