We provide the Sentido formula editor as a plugin for the TinyMCE richtext editor.
Initialization
Load the "sentido" plugin and add the "sentido" action to some toolbar, e.g.:
tinyMCE.init({
...
theme : "advanced",
...
theme_advanced_buttons3 : "fontselect,...,undo,redo,|,sentido,|,charmap,...",
...
plugins : "sentido,...",
...
});
Editing
Representation of Formulae
Sentido uses OpenMath? as an internal representation of formulae. As OpenMath? cannot directly be embedded into the HTML that TinyMCE expects, the Sentido plugin expects formulae to be wrapped into HTML: The formula
<OMOBJ xmlns="http://www.openmath.org/OpenMath">
<OMA>
<OMS cd="arith1" name="plus"/>
<OMI>1</OMI>
<OMV name="x"/>
</OMA>
</OMOBJ>
must be encoded as follows:
<span lang="x-xml-openmath"><OMOBJ xmlns="http://www.openmath.org/OpenMath"><OMA>...</OMOBJ></span>
XSLT templates for this translation are available from the developers.
Obtaining Content from the Editor
To avoid interferences with other editor plugins, the above representation of formulae is only created during the "save" operation, not while the editor is still in use. The "save" operation is automatically triggered when the editor is part of a form that is to be submitted. However, in Ajax applications this is usually not the case; therefore a bit more manual action is required:
var inst = tinyMCE.getInstanceById('id_of_textfield');
/* TODO: It would be most efficient to first find out whether the
editing field actually contains any <span class="mceItemSentido"> */
var unparsed_text = inst.getContent();
tinyMCE.triggerSave(); // <-- trigger the "save" action
var rich_text = inst.getContent();
// even safer: restore the original, not rewritten content (may not be necessary)
inst.setContent(unparsed_text);
