![]() |
Scheme serialization | ![]() |
Users may write their own extensions to TeXmacs in the Scheme extension language. In that context, TeXmacs trees are usually represented by Scheme expressions. The Scheme syntax was designed to be predictable, easy to hand-edit, and expose the complete internal structure of the document. For instance, the formula \(x + y + \frac{1}{2} + \sqrt{y + z}\) is represented by
(with "mode" "math" (concat "x+y+" (frac "1" "2") "+" (sqrt "y+z"))) |
The Scheme representation may also be useful in order to represent complex macros with a lot of programmatic content. Finally, Scheme is the safest format when incorporating TeXmacs snippets into emails. Indeed, both the standard TeXmacs format and the XML serialization may be quite sensitive to white-space.
In order to save or load a document in Scheme format (using the .stm extension), you may use File\(\rightarrow\)Export\(\rightarrow\)TeXmacs Scheme resp. File\(\rightarrow\)Import\(\rightarrow\)TeXmacs Scheme. Files saved in Scheme format can easily be processed by external Scheme programs, in the same way as files saved in XML format can easily be processed by tools for processing XML, like XSLT.
In order to copy a document fragment to an email in Scheme format, you may use Edit\(\rightarrow\)Copy to\(\rightarrow\)TeXmacs Scheme. Similarly, you may paste external Scheme fragments into TeXmacs using Edit\(\rightarrow\)Paste from\(\rightarrow\)TeXmacs Scheme. The Scheme format may also be used interactively inside Scheme sessions or interactive commands. For instance, typing ⌘⌃⇧X followed by the interactive command
(insert '(frac "1" "2")) |
inserts the fraction
| 1 |
| 2 |
at the current cursor position.