[luatex] small script to change initial letter forms

Paul Isambert zappathustra at free.fr
Tue Jan 31 07:59:33 CET 2012

Pablo Rodríguez <oinos at web.de> a écrit:
> On 01/30/2012 08:39 AM, Paul Isambert wrote:
> > 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.)
> Thanks for the reply, Paul.
> I'm afraid that the feature file might be easy to create, but in order
> to make use of it you have to edit the font files (not allowed by
> copyright law [digital fonts are protected as computer programs).

Patrick has answered to that, and I suppose you will be following that
road (if you manage to do it in ConTeXt, and I can't see why you

> > I use the brutal callback-registration form; replace it with whatever
> > goes in the format you're using (is that problematic for you?).
> I tried to check what a callback.register might be on section 4.1 and I
> must admit... well... this is all Greek to me ;-).
> My question would be how could I apply this to the whole file text
> (excluding preamble and commands, only text to be typeset) and how can I
> apply this to a single command such as \greektext{βὰρβαρος}?
> Sorry, but I don't understand how I could do it.

You seem to be using ConTeXt, and I don't, so I'll be guessing from:

To add to a callback, you must first define the function properly:

-- The same blah blah as before here
-- ...
-- What's new:
function GreekSubst (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
        n.char = i
  return head

Then to add/remove the function:

nodes.tasks.appendaction("processors", "before", "GreekSubst")
nodes.tasks.removeaction("processors", "before", "GreekSubst")

(The quoting of the function like a string does suprise me, but I
suppose it is then retrieved from the _G environment afterward, or

So, to apply that to an entire document, just use "appendaction". Only
text to be typeset will be affected anyway, because the substitution
really takes place at the typesetting end.

As for the \greektext command, I don't think it is that useful, since
only text with Greek characters will be affected anyway in the whole
document. Anyway my fast answer would be:

  \directlua{nodes.tasks.appendaction("processors", "before", "GreekSubst")}%
  \directlua{nodes.tasks.removeaction("processors", "before", "GreekSubst")}%

(The \hbox trick is because you don't want to affect the entire
surrounding paragraph.)

Finally, if you're really a ConTeXt user, I suppose you'll generally get
better answers on the ConTeXt mailing list.


More information about the luatex mailing list