[luatex] small script to change initial letter forms

Paul Isambert zappathustra at free.fr
Mon Jan 30 08:39:21 CET 2012


Pablo Rodríguez <oinos at web.de> a écrit:
> 
> Hi there,
> 
> there is a typographical tradition of typesetting Greek using different
> glyphs for initial and medial/final forms of beta, theta and phi.
> 
> The forms are the following (initial and medial/final):
> 
> 	βϐ ϑθ ϕφ
> 
> OpenType allows this feature to be enabled in the font, but many fonts
> which have both glyph forms lack the proper OpenType feature.

The easiest solution might be to apply a feature file to the font file:

http://www.adobe.com/devnet/opentype/afdko/topic_feature_file_syntax.html

(I've never done that myself so I just give the link.)

> I guess the substitution could be performed with a small luatex script
> that could be part of Lua(La)TeX or ConTeXt documents.

Indeed:


local mid = {
 [0x03B2] = 0x03D0,
 [0x03D0] = 0x03D0,
 [0x03B8] = 0x03D1,
 [0x03D1] = 0x03D1,
 [0x03C6] = 0x03D5,
 [0x03D5] = 0x03D5
 }

local init = {
 [0x03D0] = 0x03B2,
 [0x03B2] = 0x03B2,
 [0x03D1] = 0x03B8,
 [0x03B8] = 0x03B8,
 [0x03D5] = 0x03C6,
 [0x03C6] = 0x03C6
 }

local char = node.id("glyph")

callback.register("ligaturing",
function (head)
  for n in node.traverse_id(char, head) do
    local m, i = mid[n.char], init[n.char]
    if m then
      local prev = n.prev
      if prev and prev.id == char and prev.char >= 0x0370 then
        n.char = m
      else
        n.char = i
      end
    end
  end
  node.ligaturing(head)
end)



The script looks for beta, theta and phi in whatever form and use the
appropriate glyph depending on what precedes (under the possibly
simplistic assumption that an initial letter is something that is not
preceded by a glyph node with a Greek character, i.e. with Unicode
codepoint >= 0x0370).

You can use whatever form in whatever position, the script normalizes it
all, so that even ``φιλοσοϕία'' will be turned to ``ϕιλοσοφία''.

I use the brutal callback-registration form; replace it with whatever
goes in the format you're using (is that problematic for you?).

Best,
Paul



More information about the luatex mailing list