[luatex] linebreak_filter example implementation

Élie Roux elie.roux at telecom-bretagne.eu
Mon Jun 10 16:09:22 CEST 2013

> Are you sure you can’t achieve whatever you want with
> pre_linebreak_filter (whose return value is passed to
> linebreak_filter) or post_linebreak_filter (which receives the return
> value of linebreak_filter)?

Pretty much yes, let me explain: it's in gregorio (gregorian chant 
scores), where clef changes (quite a big glyph, with spacings and 
another glyph associated to it) should not appear at the beginning of 
lines: if they are the first glyph of a line, they should not be printed 
(as they will be already printed in the localleftbox). For example:


some notes ... some notes clef change some notes ... some notes
new clef (localleftbox) some notes ... some notes

not ok:

some notes ... some notes
old clef (localleftbox) new clef some notes ... some notes

If a line breaks before new clef, I'll arrive in the not ok scheme. I 
could replace old clef by new clef in the localleftbox by hacking 
gregorio a bit; but if I remove the second new clef (the one not in 
localleftbox) in postlinebreak_filter, the line will have way too much 

Do you see any solution? You've hacked LuaTeX quite a lot, I'm sure you 
will have more ideas than I do!

> Otherwise, you can use the tex.linebreak() function, which does what
> linebreak_filter does by default:
>      local function myfunc (head, ...)
>        -- Do something.
>        local newhead = tex.linebreak(head)
>        -- Do something else.
>        return newhead
>      end
>      callback.register("linebreak_filter", myfunc)

Well, If I understand correctly, I cannot: I need to modify the 
algorithm a bit (so that it removes the glyph when it evaluates the 
length of lines, before taking a linebreak decision), which I cannot do 
with the tex.linebreak function...

> There is, or at least there was, a Lua version of the TeX algorithm,
> but as far as I’m concerned it lasted a few seconds only in my editor
> before I killed the buffer thinking “Ok, later.” Later never came,
> though. (Note however that I’ve never tried to read the TeX
> implementation to begin with, and I guess it’s mandatory if you want
> to understand anything.)

Hmmm... do you still have it?

Thank you,

More information about the luatex mailing list