Notations module
The notations module in JOMDoc handles the rendering of OpenMath and Content MathML expressions to Presentation MathML. This process is carried in several steps, explained in detail in the following sections.
Notation Collection
The code here handles the collection of notations that should be applied in the rendering of a mathematical object. Notations are objects of the form
<notation>
<prototype>
...
</prototype>
<rendering>
...
</rendering>
</notation>
Notations can be collected from several different sources:
- SD - default source, loads default backup notations, which are applied in case no more specific notations are available.
- B - bundled notations files here.
- F - file containing notations, all notation elements from the specified file are collected.
- Doc - collect notations from the input document, but only those that are before and left of the element specified for rendering.
- EC - the notations to be collected are computed from the ec attribute of the element to be rendered. The effective EC is computed as a combination of all the parent's ec attributes. @ec contains a white space separated URIs to:
- specific elements in this document (#id)
- specific elements in another document (docURI#id)
- all elements in a document (docURI)
- CD - collect notations from content dictionaries (CDs). The URI to the respective CD is constructed from the cdbase and cd attributes. @cdbase is computed from the input element and it's parents, @cd is taken from the input element.
- D - collect notations from the theory in which the given element is found, and additionally from the imported theories.
Example code to create a notation collector and load it with different sources
NotationCollector coll = new NotationCollector(); // a collector is simply a vector, so you can add/remove sources coll.add(new NotationFile(file)); // F coll.add(InputDocument.getInstance()); // Doc
Rendering Sorting
Once the notation definitions have been collected, the prototypes are matched to a math object. Since it's possible that several different notations match one math object, it's necessary to select the most appropriate rendering for rendering the object, according to the available context.
Context Collection
The code here handles the collection of contextual information. Contextual information consists of key-value pairs.
Context sources from which contextual information can be collected:
- IC - collect intensional context attached to the input node with the ic attribute. The IC is represented as key-value pairs, in the form key=value;key=value;...
- GC - global context, specified in a separate file, with each key-value pair in a separate line.
key=value key=value ...
- MD - extract context from any available metadata. This available data include
- a combination of attached metadata elements to the input element or its parents
- a file containing metadata key-value pairs, with each key-value pair in a separate line (as for GC)
- CCF - denotes collection from cascading context files, which are analogous to cascading style sheets (CSS).
A context collector can be created and loaded with context sources analogous to the notation collector.
Tags Collection
The code here handles the collection of tags, which can be used for further refining the sorting of collected targets.
Tag sources:
- F - collect all tag elements from a specified file.
Sorting
According to collected additional information, the renderings are sorted from best matching to the least matching rendering. The match value of a rendering is computed by a distance function, which takes into account the amount of collected context that is matched to the context of the rendering (specified in its context or ic attribute). The renderings are first sorted according to the value computed by the distance function for the context collected by the context collector, and then according to the information specified by the collected tags.
Rendering
The rendering of a math object is the application of the selected prototype/rendering. When rendering a document two output formats are possible
- Normal Presentation MathML, and
- Presentation MathML in parallel markup, in which the original math object is preserved in the output, and interlinked with the corresponding parts of the presentation formula.
General workflow for rendering
- Get an instance of RendererFactory
- Set rendering options, like rendering format (parallel or substitution), generation of dynamic precedence bases elisions, direction of links in parallel markup
- Add sources to the render factory instance, from which to collect (Notation, Context, Tag)
- Get a Renderer instance, which can be used to render a document or specific element
Example code
RendererFactory f = RendererFactory.newInstance(); // setup rendering options f.setParallel(true); // add sources to factory f.addNotationSource(InputDocument.getInstance()); f.addContextSource(IntensionalContext.getInstance()); f.addTagSource(new TagFile(new File("file"))); Renderer renderer = f.newRenderer(); // obtain renderer Document result = renderer.render(document); // render XMLUtil.serialize(result, System.out); // write result to standard output
