ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Arthur Reutenauer <arthur.reutenauer@normalesup.org>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Greek in luatex
Date: Thu, 13 Sep 2007 20:36:57 +0200	[thread overview]
Message-ID: <20070913183657.GC32644@phare.normalesup.org> (raw)
In-Reply-To: <46E9211B.5020206@elvenkind.com>

[-- Attachment #1: Type: text/plain, Size: 608 bytes --]

> I played a bit, see attachment. Surely Hans will want to improve on this 
> interface, so don't patch any of the core files just now.

  Fantastic!

  Now I played a bit with your file myself, and compared with the
behaviour of an OTP which has the same action: you can see that macros
arguments between square brackets are preserved by OTP, whereas your
function (obviously) converts everything unconditionally. How difficult
would it be to program the same behaviour, that is, make
collectors.handle pass to convert_babel only contiguous ranges of
characters that are situated outside matching brackets?

[-- Attachment #2: tokfilter_otp.tex --]
[-- Type: text/x-tex, Size: 2247 bytes --]

% engine=luatex

%D First a hack to the core. two changes:
%D * don't force end_cs to be \relax
%D * don't remove end_cs from the input stream

\ctxlua{
function collectors.install(tag,end_cs)
    collectors.data[tag] = { }
    local data   = collectors.data[tag]
    local call   = token.command_id("call")
    local endcs  = token.csname_id(end_cs)
    local expand = collectors.registered
    local get    = token.get_next
    while true do
        local t = get()
        local a, b = t[1], t[3]
        if b == endcs then
            tex.print('\\' ..end_cs)
            return
        elseif a == call and expand[b] then
            token.expand()
        else
            data[\string#data+1] = t
        end
    end
end 
}

%D a small extension to the core interface, to have a 
%D nice wrapper around the lua code

\ctxlua {
function collectors.handle(tag,handle)
    collectors.data[tag] = handle(collectors.data[tag])
end
}
\def\handletokens[#1][#2]{\ctxlua{collectors.handle("#1",#2)}}

%D Here starts the document-specific code

%D Start capturing tokens in the buffer named 'babel', stop
%D at \stopbabel

\def\startbabel 
  {\ctxlua{collectors.install("babel", "stopbabel")}}


%D The lua mutation function. str is a table containing the captured
%D tokens, each itself a three-item table (this is explained in the 
%D luatex manual)

\ctxlua {
function convert_babel(str)
    local t = { }
    for k,v in ipairs(str) do
        t[\string#t+1] = tokens.other('*')
        t[\string#t+1] = v
    end
    return t
end
}

%D convert the tokens using that lua function, then 
%D flush the result
\def\stopbabel  
  {\handletokens[babel][convert_babel]
   \flushtokens[babel]}

\usetypescript[palatino][ec]

\starttext

\section{With Taco's \type{\startbabel}}
\startbabel%
some stuff here \blank[medium] some other stuff

\switchtobodyfont[palatino]

\subsection{More stuff}

stuff stuff stuff
\stopbabel

\blank[big]

\section{With an \tt OTP}

% Do the same as convert_babel, with a simple OTP (stars.otp)
\ocp\stars=stars
\ocplist\StarsOCP=\addbeforeocplist1\stars\nullocplist

\pushocplist\StarsOCP

some stuff here \blank[medium] some other stuff

\switchtobodyfont[palatino]

\subsection{More stuff}

stuff stuff stuff

\stoptext

[-- Attachment #3: stars.ocp --]
[-- Type: application/octet-stream, Size: 60 bytes --]

[-- Attachment #4: stars.otp --]
[-- Type: application/vnd.oasis.opendocument.presentation-template, Size: 58 bytes --]

[-- Attachment #5: Type: text/plain, Size: 487 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  parent reply	other threads:[~2007-09-13 18:36 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-01 10:56 Thomas A. Schmitz
2007-09-11  6:47 ` Thomas A. Schmitz
2007-09-11 10:12   ` Hans Hagen
2007-09-13  1:15   ` Arthur Reutenauer
2007-09-13  7:03     ` Taco Hoekwater
2007-09-13 10:24       ` Arthur Reutenauer
2007-09-13 11:38         ` Taco Hoekwater
2007-09-13 12:54           ` Thomas A. Schmitz
2007-09-13 18:36           ` Arthur Reutenauer [this message]
2007-09-13 18:49             ` Hans Hagen
2007-09-13 19:24             ` Hans Hagen
2007-09-13 19:45               ` Arthur Reutenauer
2007-09-13 20:20                 ` Hans Hagen
2007-09-14  0:24                   ` Arthur Reutenauer
2007-09-13 20:38                 ` Thomas A. Schmitz
2007-09-13 21:05                   ` Hans Hagen
2007-09-13 21:52                     ` Taco Hoekwater
2007-09-15 23:22                   ` Arthur Reutenauer
2007-09-16  6:56                     ` Taco Hoekwater
2007-09-16  8:22                     ` Taco Hoekwater
2007-09-16 13:01                       ` Thomas A. Schmitz
2007-09-16 23:12                         ` Hans Hagen
2007-09-16 13:08                       ` Arthur Reutenauer
2007-09-16 13:44                         ` Thomas A. Schmitz
2007-09-17  8:48                     ` Hans Hagen
2007-09-13 17:42       ` Hans Hagen
2007-09-13  9:45     ` Thomas A. Schmitz
2007-09-13 10:49       ` Arthur Reutenauer
2007-09-13 12:51         ` Thomas A. Schmitz
2007-09-13 14:25         ` Taco Hoekwater
2007-09-13 17:51       ` Hans Hagen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070913183657.GC32644@phare.normalesup.org \
    --to=arthur.reutenauer@normalesup.org \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).