29.05.2014 Views

The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE

The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE

The history of luaTEX 2006–2009 / v 0.50 - Pragma ADE

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

XVII<br />

XML revisioned<br />

under construction<br />

the parser<br />

For quite a while ConTEXt has built-in support for xml processing and at <strong>Pragma</strong> <strong>ADE</strong> we<br />

use this extensively. One <strong>of</strong> the rst things I tried to deal with in Lua was xml, and now<br />

that we have LuaTEX up and running it's time to investigate this a bit more. First we'll have<br />

a look at the basic functions, the Lua side <strong>of</strong> the game.<br />

We load an xml le as follows (the document namespace is predened in ConTEXt):<br />

\startluacode<br />

document.xml = document.xml or { } -- define namespace<br />

document.xml = xml.load("mk-xml.xml") -- load the file<br />

\stopluacode<br />

<strong>The</strong> loader constructs a table representing the document structure, including whitespace,<br />

so let's serialize the code and see what shows up:<br />

\startluacode<br />

tex.sprint("\\starttyping")<br />

xml.serialize(document.xml, tex.sprint)<br />

tex.sprint("\\stoptyping")<br />

\stopluacode<br />

We can control the wat the serializer deals with the snippets, here we just print back to<br />

TEX.<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!