[texhax] LuaLaTeX: increase font expansion in narrow columns

Paul Isambert zappathustra at free.fr
Wed Oct 19 19:18:59 CEST 2011

Le 19/10/2011 14:23, Arno Trautmann a écrit :
> Paul Isambert wrote:
>> Alleged shepherd Philip TAYLOR wrote:
>>> "A man who would letter-space lower-case text
>>> would probably steal sheep" : F W Goudy.
>> Stealing sheep is better than starving to death. See attached file.
> Do you also have an example (font expansion) vs. (font expansion + 
> stolen sheep)? I find it hard to judge what the effect of sheep is in 
> that example.

Use the following when you want to steal sheep:

local g = node.new(node.id"glue")
local spec = node.new(node.id"glue_spec")
spec.width = tex.sp"0pt"
spec.stretch = tex.sp".5pt"
g.spec = spec

local p = node.new(node.id"penalty")

local function stealsheep (h)
   for n in node.traverse_id(node.id"glyph", h) do
     if n.prev and n.prev.id == node.id"glyph" then
       local g = node.copy(g)
       node.insert_before(h, n, g)
       node.insert_before(h, g, node.copy(p))
   return h

callback.register("pre_linebreak_filter", stealsheep)

The .5pt stretch (and null shrink) is totally arbitrary. Also, the code 
isn't very good (it doesn't handle discretionary nodes, nor glyphs 
separated by a font kern), but it's just to give an idea. It is easily 
amended if you wish to do that.

> Sticking to font expansion, I wondered if the following could work in 
> theory:
> • as changing the expansion is not possible, change the font in narrow 
> lines, i.e. load the font twice with different expansions.
> • in post_linebreak_filter, collect all subsequent narrow lines
> • pack them back into one hlist, change the font to the one with 
> larger expansion, break this hlist into a paragraph with the same 
> number of lines as before.

Which means create a paragraph with narrow lines and no \parfillskip 
(obviously). Plus the same number of lines. Plus you have to remove 
existing hyphenation. But that's doable :)

> • put that list of hlists back into the vertikal list.
> I don't have to mention that I am not able to even try to translate 
> this into code, do I? …

You can do that, Arno. You said what needed to be done, translating it 
into code is the easiest part.

> Also, related to this question: Is there any technical documentation 
> on how pdfTeX (or, if it differs in that case, LuaTeX) breaks lines 
> into paragraphs using font expansion and character protrusion? I mean 
> something like the corresponding chapter in the TeXbook – I'd like to 
> understand at which point and how font expansion is taken into account 
> in the line breaking.

If you ever find that, I'll be glad to know.


More information about the texhax mailing list