[luatex] lua-inputenc

Javier Múgica javier at digi21.eu
Wed Feb 18 11:53:21 CET 2009


I didn't conect to the internet in the past days and haven't red the
whole discussion, so may be this was already pointed:

In order to run my old LaTeX documents with luatex I also thought
about the writing an inputenc, registering differnt callbacks for
process_input_buffer according to the encoding, but then I realized
that it was much easier to simply register a function for
process_input_buffer in such a way as to change from byte to utf-8,
and then just let LateX inputenc (or whatever code) to handle the
input encoding.

Now I don't have the code with me, but Is was fairly simple and I
think I can write it now:

\directlua0{
function byte-to-utf8(string c)
  local b=string.byte(c)
  if b<128 then
     return c
  end
  if b<192 then
    return string.char(194, b)
  else
    return string.char(194,b-64)
  end
end

callback.register(
function process_input_buffer(buffer)
  return string.gsub(buffer,"(.)",byte-to-utf8)
end
)
}

Note that if your document and the macros just contained something
like \catcode`á=\active  \defá{<code>} then the function byte-to-utf8
coud just translate the input bytes to _any_ valid utf-8. But that is
not the case of Latex inputenc, which has code something like

\RegisterInputChar{125}{<code>}

so the right conversion is mandatory.

I have compiled several documents, including a whole books with
several auxiliary files, and It runs without problem.

--Javier A.


More information about the luatex mailing list