[NTG-context] Using external libraries in LuaTeX

Taco Hoekwater taco at elvenkind.com
Thu Mar 18 07:43:48 CET 2010


Hi,


Graham Douglas wrote:
> 
> So, I was wondering if anyone has a minimal example they would be
> kind enough to share, or can give me a few pointers/guidelines so that I
> can start experimenting. In particular, I'm interested to call external
> libraries and inject the output from an external library into TeX for
> typesetting. For example, is it possible to load a library once, keep
> it loaded and access the library functions from different commands
> during the TeX run?

Here is a trivial example using LuaExpat:

\starttext
\startluacode
require "lxp";
text = '<p>hello world</p>'
callbacks = { EndElement = false,
              StartElement = false,
              Default = function (p, s) tex.sprint(s) end }
p = lxp.new(callbacks)
\stopluacode

Some xml output: \directlua{p:parse(text)}!.

\directlua{p:close()}
\stoptext

Disclosure: for this test, I copied lxp.so into the local directory
because I am not sure exactly how context mkiv searches for Lua cpath
files.

Best wishes,
Taco



More information about the ntg-context mailing list