Formatted and structured output

In the previous section, we have seen that output from applications is encapsulated in blocks of the form

DATA_BEGINformat:messageDATA_END

In fact, the message may recursively contain blocks of the same form. Currently implemented formats include verbatim, latex, html, ps, scheme. The scheme format is used for sending TeXmacs trees in the form of Scheme expressions.

The formula plug-in

The formula plug-in demonstrates the use of LaTeX as the output format. It consists of the files

    formula/Makefile
    formula/progs/init-formula.scm
    formula/src/formula.cpp

The body of the main loop of formula.cpp is given by

int i, nr;
cin >> nr;
cout << DATA_BEGIN << "latex:";
cout << "$";
for (i=1; i<nr; i++)
  cout << "x_{" << i << "}+";
cout << "x_{" << i << "}$";
cout << DATA_END;
fflush (stdout);

Similarly, the use of nested output blocks is demonstrated by the nested plug-in; see in particular the source file nested/src/nested.cpp.

Remark 1. At the moment, we only implemented LaTeX as a standard transmission format for mathematical formulas, because this is the format which is most widely used. In the future, we intend to implement more semantically secure formats, and we recommend you to keep in mind the possibility of sending your output in tree format.

Nevertheless, we enriched standard LaTeX with the \* and \bignone commands for multiplication and closing big operators. This allows us to distinguish between

    a \* (b + c)

(i.e. a multiplied by b + c) and

    f(x + y)

(i.e. f applied to x + y). Similarly, in

    \sum_{i=1}^m a_i \bignone + \sum_{j=1}^n b_j \bignone

the \bignone command is used in order to specify the scopes of the \sum operators.

It turns out that the systematic use of the \* and \bignone commands, in combination with clean LaTeX output for the remaining constructs, makes it a priori possible to associate an appropriate meaning to your output. In particular, this usually makes it possible to write additional routines for copying and pasting formulae between different systems.

The markup plug-in

It is important to remind that structured output can be combined with the power of TeXmacs as a structured editor. For instance, the markup plug-in demonstrates the definition of an additional tag foo, which is used as an additional primitive in the output of the application. More precisely, the markup plug-in consists of the following files:

    markup/Makefile
    markup/packages/session/markup.ts
    markup/progs/init-markup.scm
    markup/src/markup.cpp

The style package markup.ts contains the following definition for foo:

<with|mode|math|<assign|foo|<macro|x|<frac|1|1+x>>>>

The foo tag is used in the following way in the body of the main loop of markup.cpp:

char buffer[100];
cin.getline (buffer, 100, '\n');
cout << DATA_BEGIN << "latex:";
cout << "$\\foo{" << buffer << "}$";
cout << DATA_END;
fflush (stdout);

Notice that the style package markup.ts also defines the markup-output environment:

<assign|markup-output|<macro|body|<generic-output|<with|par-mode|center|body>>>>

This has the effect of centering the output in sessions started using TextSessionMarkup.

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".