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.

and the document itself is processed with:<br />

\xmlprocessfile{main}{demo.xml}{} % optional setup<br />

<strong>The</strong> setup xml:article can look as follows:<br />

\startxmlsetups xml:article<br />

\section{\xmltext{#1}{/title}}<br />

\xmlall{#1}{!(title|author)}<br />

\blank author: \xmltext{#1}{/author}<br />

\stopxmlsetups<br />

Here #1 refers to the current node in the xml tree, in this case the root element, article.<br />

<strong>The</strong> second argument <strong>of</strong> \xmltext and \xmlall is a path expression, comparable with<br />

xpath: /title means: the title element anchored to the current root (#1), and !(title|author)<br />

is the negation <strong>of</strong> (complement to) title or author. Such expressions<br />

can be more complex that the one above, like:<br />

\xmlfirst{#1}{/one/(alpha|beta)/two/text()}<br />

which returns the content <strong>of</strong> the rst element that satises one <strong>of</strong> the paths (nested tree):<br />

/one/alpha/two<br />

/one/beta/two<br />

<strong>The</strong>re is a whole bunch <strong>of</strong> commands like \xmltext that lter content and pipe it into<br />

TEX. <strong>The</strong>se are calling Lua functions. This is no manual, so we will not discuss them here.<br />

However, it is important to realize that we have to associate setups (consider them free<br />

formatted macros) to at least one element in order to get started. Also, xml inclusions<br />

have to be dealt with before assigning the setups. <strong>The</strong>se are simple one-line commands.<br />

You can also assign defaults to elements, which saves some work.<br />

Because we can use Lua to access the tree and manipulate content, we can now implement<br />

parts <strong>of</strong> xml handling in Lua. An example <strong>of</strong> this is dealing with so-called Cals tables.<br />

This is done in approximately 150 lines <strong>of</strong> Lua code, loaded at runtime in a module. This<br />

time the association uses functions instead <strong>of</strong> setups and those functions will pipe data<br />

back to TEX. In the module you will nd:<br />

\startxmlsetups xml:cals:process<br />

\xmlsetfunction {\xmldocument} {cals:table} {lxml.cals.table}<br />

\stopxmlsetups<br />

\xmlregistersetup{xml:cals:process}<br />

\xmlregisterns{cals}{cals}<br />

210 <strong>The</strong> <strong>luaTEX</strong> Mix

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

Saved successfully!

Ooh no, something went wrong!