[luatex] getting previous glyphs

Paul Isambert zappathustra at free.fr
Thu Dec 4 10:32:22 CET 2014


If I understand correctly, you want to turn every input of the form

  KKK<uuuu>

into

  \ruby{KKK}{uuuu}

A simple solution would be to use the process_input_buffer callback with a function like:

function ruby (line)
  return line:gsub("(K+)<(u+)>", "\\ruby{%1}{%2}")
end

The hard part of course is to figure out the pattern matching the sequences of K's and u's.
You might have to use LPEG. Also, this won't work if the pattern crosses line ends, since
process_input_buffer processes lines one at a time (then you might want to consider the
open_read_file callback).

I'm sorry I can't be more specific, but I'm on a computer without LuaTeX.

Best,
Paul

----- Mail original -----
> De: "Norbert Preining" <preining at logic.at>
> À: luatex at tug.org
> Envoyé: Jeudi 4 Décembre 2014 03:25:58
> Objet: [luatex] getting previous glyphs
> 
> Hi everyone,
> 
> I am trying to write some macros to convert Aozora (Japanese
> literature
> site) formatted text to something I can feed through luatex.
> 
> In the Aozora format, ruby-annotations (the reading of Kanji written
> on top of the Kanji) are written *after* the word, like in
> 	nnnKKK<uuuuu>
> where
> 	nnn
> 		are some *non* Kanji (Hiragana, Roman, etc)
> 	KKK
> 		are Kanji
> 	< >
> 		are Japanese angle brakets
> 	uuuu
> 		reading in Hiragana
> 
> TO make things worse, if there is the need to separate some Kanjis
> from each other, then a | (in Jpanaese version) is added:
> 	KK|KKK<uuuu>
> in this example all the K's are Kanji, but the ruby should only
> be applied to the group of three K after the |
> 
> Now, luatexja, in particalur luatexja-ruby, provides a handy
> \ruby{KKK}{uuuu} macro, but for getting the KKK I have to read
> backwards somehow.
> 
> As we are already in luatex, do you have any idea how to achieve
> this easily?
> 
> Thanks for any hint
> 
> Norbert
> 
> ------------------------------------------------------------------------
> PREINING, Norbert
>                               http://www.preining.info
> JAIST, Japan                                 TeX Live & Debian
> Developer
> GPG: 0x860CDC13   fp: F7D8 A928 26E3 16A1 9FA0  ACF0 6CAC A448 860C
> DC13
> ------------------------------------------------------------------------
> 



More information about the luatex mailing list