-- Replace "char1", etc., with the clefs' codepoints. local clefs = { -- [char1] = true, -- [char2] = true, -- ... } local function getnodes (n) -- Set start and stop to the first and last nodes composing the -- sublist associated with the clef (e.g. spacing, associated -- glyph...). Here the default code sets the clef as the only such -- node. local start, stop = n, n return start, stop end local function leaderize (head) local n = head while n do if n.id == node.id("glyph") and clefs[n.char] then -- Detach the node(s) from the list. local start, stop = getnodes (n) local prev, next = start.prev, stop.next start.prev, stop.next = nil, nil -- Create a box containing the clef. local b = node.hpack(start) -- Create a cleader whose width is the same as the box. local l = node.new(node.id("glue")) l.subtype, l.leader = 101, b -- A glue's dimensions are held in a spec node. l.spec = node.new(node.id("glue_spec")) l.spec.width = b.width -- Insert the leader node in the list. l.next = next if next then next.prev = l end if prev then l.prev, prev.next = prev, l else head = l end n = next else n = n.next end end return head end callback.register("pre_linebreak_filter", leaderize)