[luatex] Luatex tutorial
Paul Isambert
zappathustra at free.fr
Wed Aug 29 10:37:57 CEST 2012
Mikoláš Štrajt <strajt9 at seznam.cz> a écrit:
> If someone can post some easy simple and/or practical example it
> will be nice.
I've just remembered the following code. The motivation is that last
lines whose width is smaller than the paragraph's indentation are
unpleasant. The code adds an infinite penalty before each space (starting
at the end of the paragraph) if the following material isn't large
enough to make a proper last line, thus making that space unbreakable.
In other words, a paragraph ending with e.g.:
... bigword a b.
becomes
... bigword~a~b.
(The ~ is the unbreakable space in TeX.)
Note that "node.dimensions(a, b)" measures from "a" to the node
preceding "b".
Best,
Paul
\directlua{
local GLYF = node.id"glyph"
local GLUE = node.id"glue"
local function gluelastword (head)
% Get the last node of the list.
local last = node.slide(head)
% Skip the \parfillskip glue and associated penalty.
while last and not(last.id == GLYF) do
last = last.prev
end
if last then
local prev, last = last.prev, last.next
while prev do
if prev.id == GLUE then
if node.dimensions(prev.next, last) <= tex.parindent then
local p = node.new"penalty"
p.penalty = 10000
head = node.insert_before(head, prev, p)
else
break
end
end
prev = prev.prev
end
end
return head
end
callback.register("pre_linebreak_filter", gluelastword)
}
More information about the luatex
mailing list