This is a follow-up question connected to this: Non-breakable space after isolated one letter
After testing proposed solution on plain text, the finalizer works. However, after using it in document containing sectioning commands (\title, but even others) ConTeXt process crashes.
MWE:
\startluacode
function userdata.prevent_single_letter(head)
local cur = head
while cur do
if cur.id == node.id("glyph") then
if cur.prev.id == node.id("glue") and cur.next.id == node.id("glue") then
local p = node.new("penalty")
p.penalty = 10000
-- This is for debugging only, but then you have to
-- remove the last node.insert_after line:
--local w = node.new("whatsit","pdf_literal")
--w.data = "q 1 0 1 RG 1 0 1 rg 0 0 m 0 5 l 2 5 l 2 0 l b Q"
--node.insert_after(head,cur,w)
--node.insert_after(head,w,p)
node.insert_after(head,cur,p)
end
end
cur = cur.next
end
return head, true
end
\stopluacode
\startluacode
nodes.tasks.appendaction("processors", "before", "userdata.prevent_single_letter")
\stopluacode
\starttext
\title[title:poznamky]{Notes z Con\TeX{}t}
Filling text filling text filling text filling text filling text filling text filling text fil V text
\stoptext
Even more trubling is, that I am unable to get any meaningfull error message other than the issue is caused by \title. The only readable error message I am getting from console:
hpack filter: error: [\directlua]:6: attempt to index a nil value (field 'prev')
I have no idea what is hpack_filter. In order to next time be able to debug issues I am hitting upon a little better, what reference for ConTeXt should I use?
hpack_filteris described p. 173. Note that there are more than 50 manuals shipped with ConTeXt, so which one you should read depend on your issue. – sztruks Jul 30 '20 at 15:49if cur.prev.id == ...byif cur.prev and cur.next and cur.prev.id == .... The problem here is that theprevfield does not exist but it tries to index it anyway to get theidfield which is not allowed. – Henri Menke Jul 31 '20 at 01:19