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.

METAPOST<br />

<br />

<br />

This already gives us a rather basic way to manipulate documents and this method is even<br />

not that slow because we bypass TEX reading from le.<br />

\startluacode<br />

document.str = " hello world "<br />

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

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

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

\stopluacode<br />

Watch the extra print argument, we need this because otherwise the verbatim mode will<br />

not work out well.<br />

hello world <br />

An optional second argument <strong>of</strong> the converter determines if we deal with a root element.<br />

\startluacode<br />

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

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

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

\stopluacode<br />

Now we get this:<br />

hello world <br />

You can save a (manipulated) xml table with the command:<br />

\startluacode<br />

xml.save(document.xml,"newfile.xml")<br />

\stopluacode<br />

<strong>The</strong>se examples show that you can manipulate les from within your document. If you<br />

want to convert the table to just a string, you can use xml.tostring. Actually, this<br />

method is automatically used for occasions where Lua wants to print an xml table or<br />

wants to join string snippets.<br />

<strong>The</strong> reason why I wrote the xml parser is that we need it in the utilities (so it has to provide<br />

access to the content <strong>of</strong> elements) as well as in the text processing (so it needs to<br />

provide some manipulation features). To serve both we have implemented a subset <strong>of</strong><br />

what standard xml tools qualify as path based searching.<br />

XML revisioned 133

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

Saved successfully!

Ooh no, something went wrong!