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
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.
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.
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
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
<with|mode|math|<assign|foo|<macro|x|<frac|1|1+x>>>>
The
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
<assign|markup-output|<macro|body|<generic-output|<with|par-mode|center|body>>>>
This has the effect of centering the output in sessions started using