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.

This will save the content <strong>of</strong> the author element and ush it when the end tag article is<br />

seen. So, given previous denitions, we will get the title, some text and then the author.<br />

You may argue that instead we should use for instance xslt but even then a mapping is<br />

needed from the xml to TEX, and it's a matter <strong>of</strong> taste where the burden is put.<br />

Because ConTEXt also wants to support standards like MathML, there are some more<br />

mechanisms but these are hidden from the user. And although these do a good job in<br />

most cases, the code associated with the solutions has never been satisfying.<br />

Supporting xml this way is doable, and ConTEXt has used this method for many years in<br />

fairly complex situations. However, now that we have Lua available, it is possible to see<br />

if some things can be done simpler (or differently).<br />

After some experimenting I decided to write a full blown xml parser in Lua, but contrary to<br />

the stream based approach, this time the whole tree is loaded in memory. Although this<br />

uses more memory than a streaming solution, in practice the difference is not signicant<br />

because <strong>of</strong>ten in MkII we also needed to store whole chunks.<br />

Loading xml les in memory is real fast and once it is done we can have access to the<br />

elements in a way similar to xpath. We can selectively pipe data to TEX and manipulate<br />

content using TEX or Lua. In most cases this is faster than the stream-based method. Interesting<br />

is that we can do this without linking to existing xml libraries, and as a result we<br />

are pretty independent.<br />

So how does this look from the perspective <strong>of</strong> the user? Say that we have the simple<br />

article denition stored in demo.xml.<br />

<br />

<br />

Whatever<br />

Someone<br />

some text<br />

<br />

This time we associate so called setups with the elements. Each element can have its own<br />

setup, and we can use expressions to assign them. Here we have just one such setup:<br />

\startxmlsetups xml:document<br />

\xmlsetsetup{main}{article}{xml:article}<br />

\stopxmlsetups<br />

When loading the document it will automatically be associated with the tag main. <strong>The</strong><br />

previous rule associates setup xml:article with the article element in tree main.<br />

We need to register this setup so that it will be applied to the document after loading:<br />

\xmlregistersetup{xml:document}<br />

<strong>The</strong> <strong>luaTEX</strong> Mix 209

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

Saved successfully!

Ooh no, something went wrong!