[luatex] linebreak_filter example implementation
Paul Isambert
zappathustra at free.fr
Mon Jun 10 19:13:13 CEST 2013
Élie Roux <elie.roux at telecom-bretagne.eu> a écrit:
> > 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:
>
> ok:
>
> 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
> spacing...
>
> Do you see any solution? You've hacked LuaTeX quite a lot, I'm sure you
> will have more ideas than I do!
Well, modifying linebreak_filter would be a good idea indeed :)
Otherwise, you could put the clef in a \cleaders:
\newbox\clefbox
\setbox\clefbox=\hbox{<clef>}
\def\clef{\cleaders\copy\clefbox\hskip\wd\clefbox}
note ... note ... \clef ... note ... note
then it will automatically disappear at the beginning of a line. Of
course the above code is cumbersome, all the more as <clef> won’t
interact with surrounding glyphs if that must happen (e.g. spacing).
So you could use the symbol as usual, and then in pre_linebreak_filter
(i.e. after kerning, ligaturing, etc., have occurred, i.e. after the
glyph has been processed) turn the sublist made of that glyph and
associated material into an hlist, and create a leader node pointing
to it (really, a glue with a “leader” field pointing to the created
box).
I guess it’ll work, and it’s much simpler than tinkering with the
algorithm (all the more as the Lua version is much slower than the TeX
version, if I remember correctly a recent paper by Hans).
> > 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?
No (somewhere on a hard drive, perhaps); I guess Hans is the person to
ask.
Best,
Paul
More information about the luatex
mailing list