XML serialization

For compatability reasons with the XML technology, TeXmacs also supports the serialization of TeXmacs documents in the XML format. However, the XML format is generally more verbose and less readable than the default TeXmacs format. In order to save or load a file in the XML format (using the .tmml extension), you may use FileExportXML resp. FileImportXML.

It should be noticed that TeXmacs documents do not match a predefined DTD, since the appropriate DTD for a document depends on its style. The XML format therefore merely provides an XML representation for TeXmacs trees. The syntax has both been designed to be close to the tree structure and use conventional XML notations which are well supported by standard tools.

The encoding for strings

The leafs of TeXmacs trees are traslated from the universal TeXmacs encoding into Unicode. Characters without Unicode equivalents are represented as entities (in the future, we rather plan to create a tmsym tag for representing such characters).

XML representation of regular tags

Trees with a single child are simply represented by the corresponding XML tag. In the case when a tree has several children, then each child is enclosed into a tm-arg tag. For instance, sqrt (x + y) is simply represented as

<sqrt>y+z</sqrt>

whereas the fraction

1
2
is represented as

<frac>
  <tm-arg>1</tm-arg>
  <tm-arg>2</tm-arg>
</frac>

In the above example, the whitespace is ignored. Whitespace may be preserved by setting the standard xml:space attribute to preserve.

Special tags

Some tags are represented in a special way in XML. The concat tag is simply represented by a textual concatenation. For instance,

1
2
+ sqrt ( x + y ) is represented as

<frac><tm-arg>1</tm-arg><tm-arg>2</tm-arg></frac>+<sqrt>y+z</sqrt>

The document tag is not explicitly exported. Instead, each paragraph argument is enclosed within a tm-par tag. For instance, the quotation

Ik ben de blauwbilgorgel.

Als ik niet wok of worgel,

is represented as

<quote-env>
  <tm-par>
    Ik ben de blauwbilgorgel.
  </tm-par>
  <tm-par>
    Als ik niet wok of worgel,
  </tm-par>
</quote-env>

A with tag with only string attributes and values is represented using the standard XML attribute notation. For instance, “some blue text” would be represented as

some <with color="blue">blue</with> text

Conversily, TeXmacs provides the attr primitive in order to represent attributes of XML tags. For instance, the XML fragment

some <mytag beast="heary">special</mytag> text

would be imported as “some <my-tag|<attr|beast|heary>|special> text”. This will make it possible, in principle, to use TeXmacs as an editor of general XML files.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".