![]() |
XML serialization | ![]() |
For compatibility 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 File\(\rightarrow\)Export\(\rightarrow\)Xml resp. File\(\rightarrow\)Import\(\rightarrow\)Xml. The conversion is implemented in Scheme in the directory
convert/tmml/
of $TEXMACS_PATH/progs.
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. A complete document is represented by a root element TeXmacs, whose version attribute contains the version of TeXmacs, and whose children represent the children of the top-level document tag (style, body, initial, etc.).
The leafs of TeXmacs trees are translated from the universal TeXmacs encoding into Unicode (UTF-8). Characters without Unicode equivalents are represented using a special tm-sym tag; for instance, the TeXmacs symbol <foo> would be represented as <tm-sym>foo</tm-sym>.
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{y + z}\) is simply represented as
<sqrt>y+z</sqrt> |
whereas the fraction \(\frac{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.
Some tags are represented in a special way in XML. The concat tag is simply represented by a textual concatenation. For instance, \(\frac{1}{2} + \sqrt{y + z}\) 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 |
Conversely, 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.
Finally, the binary content of a raw-data tag is encoded in base64 inside a tm-arg child of a raw-data element.