Mathematical and customized input |
The TeXmacs meta-format allows application output to contain structured text like mathematical formulas. In a similar way, you may use general TeXmacs content as the input for your application. By default, only the text part of such content is kept and sent to the application as a string. Moreover, all characters in the range 0–31 are ignored, except for '\t' and '\n' which are transformed into spaces. There are two methods to customize the way input is sent to your application. First of all, the configuration option
(:serializer ,routine)
specifies a scheme function for converting TeXmacs trees to string input for your application, thereby overriding the default method. This method allows you for instance to treat multi-line input in a particular way or the perform transformations on the TeXmacs tree.
The :serialize option is a very powerful, but also a very abstract way to customize input: it forces you to write a complete input transformation function. In many circumstances, the user really wants to rewrite two dimensional mathematical input to a more standard form, like rewriting
a |
b |
(plugin-input-converters myplugin
rules)
This command specifies input conversion rules for myplugin for “mathematical input” and reasonable defaults are provided by TeXmacs. Each rule is of one of the following two forms:
Given two strings symbol and conversion, the rule
(symbol conversion)
specifies that the TeXmacs symbol symbol should be converted to conversion.
Given a symbol tag and a
(tag routine)
specifies that routine will be used as
the conversion routine for tag. This
routine should just write a string to the standard output. The
The input plug-in demonstrates the use of customized mathematical input. It consists of the files
input/Makefile input/packages/session/input.ts input/progs/init-input.scm input/progs/input-input.scm input/src/input.cpp
The
(plugin-configure input
(:require (url-exists-in-path?
"input.bin"))
(:initialize (input-initialize))
(:launch "input.bin")
(:session "Input"))
Here input-initialize is an initialization routine which adds the new input conversion rules in a lazy way:
(define (input-initialize)
(import-from (texmacs plugin plugin-convert))
(lazy-input-converter (input-input) input))
In other words, the module input-input.scm will only be loaded when we explicitly request to make a conversion. The conversion rules in input-input.scm are given by
(plugin-input-converters input
(frac input-input-frac)
(special input-input-special)
("<vee>" "||")
("<wedge>" "&&"))
This will cause ∨ and ∧ to be rewritten as || and && respectively. Fractions
a |
b |
(define (input-input-frac t)
(display "((")
(plugin-input (car t))
(display "):(")
(plugin-input (cadr t))
(display "))"))
In the additional style file input.ts we also defined
some additional markup
<assign|special|<macro|body|<block|<tformat|<cwith|1|1|1|1|cell-background|pastel
green>|<table|<row|<cell|body>>>>>>>
This tag is rewritten using the special conversion rule
(define (input-input-special t)
(display "[[[SPECIAL:")
(plugin-input (car t))
(display "]]]"))
As to the
cout << DATA_BEGIN << "verbatim:";
cout << DATA_BEGIN << "command:(session-use-math-input #t)"
<< DATA_END;
cout << "Convert mathematical input into plain text";
cout << DATA_END;
fflush (stdout);
In the main loop, we content ourselves the reproduce the input as output:
char buffer[100];
cin.getline (buffer, 100, '\n');
cout << DATA_BEGIN << "verbatim:";
cout << buffer;
cout << DATA_END;
fflush (stdout);