public final class MathMLUtilities extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
ANNOTATION_LOCAL_NAME |
static String |
ANNOTATION_XML_LOCAL_NAME |
| Constructor and Description |
|---|
MathMLUtilities() |
| Modifier and Type | Method and Description |
|---|---|
static void |
convertExplicitFencesToMfenced(Document document)
Converts explicit fences generated by SnuggleTeX back to
mfenced. |
static void |
convertMfencedToExplicitFences(Document document)
Replaces every deprecated MathML
mfenced element in the supplied document with
its explicit mrow/mo equivalent. |
static void |
ensureMathMLContainer(Element mathElement) |
static Element |
ensureMathMLDocument(Document document)
Checks that the given DOM
Document contains a single MathML math
Element. |
static String |
extractAnnotationString(Element mathElement,
String encodingAttribute)
Extracts the first textual annotation found having the given encoding attribute from
the given MathML
math element, if such an annotation is found. |
static NodeList |
extractAnnotationXML(Element mathElement,
String encodingAttribute)
Extracts the first XML-based annotation having the given encoding attribute from the given MathML
math element, if such an annotation is found. |
static Element |
extractFirstSemanticsBranch(Element mathElement) |
static boolean |
isMathMLElement(Node node)
Convenience method to test whether the given DOM
Node node is a MathML element
having any localName. |
static boolean |
isMathMLElement(Node node,
String localName)
Convenience method to test whether the given DOM
Node node is a MathML element
having the given localName. |
static Document |
isolateAnnotationXML(Element mathElement,
String encodingAttribute)
"Isolates" the XML annotation having the given encoding by producing a copy of the MathML
element with only the given annotation contents as children.
|
static Document |
isolateAnnotationXML(UnwrappedParallelMathMLDOM unwrappedDOM,
String encodingAttribute)
Version of
isolateAnnotationXML(Element, String) that works on an
UnwrappedParallelMathMLDOM. |
static Document |
isolateFirstSemanticsBranch(Element mathElement)
"Isolates" the first <semantics/> branch of an annotation MathML element
by producing a copy of the MathML element with a single child containing
only the first child of the <semantics/> element.
|
static Document |
isolateFirstSemanticsBranch(UnwrappedParallelMathMLDOM unwrappedDOM)
Version of
isolateFirstSemanticsBranch(Element) that works on an
UnwrappedParallelMathMLDOM. |
static Document |
parseMathMLDocumentString(String mathmlDocument)
Convenience method that parses a MathML document specified as a UTF-8-encoded String.
|
static String |
serializeDocument(Document document)
Convenience method that serializes the given DOM Document as a String (encoded in UTF-8),
indenting the results and omitting the XML declaration, which is a reasonable way of
serializing a MathML document.
|
static String |
serializeDocument(Document document,
boolean indent,
boolean omitXMLDeclaration)
Deprecated.
Use one of the alternative methods, including
serializeDocument(Document, SerializationSpecifier) for ultimate control. |
static String |
serializeDocument(Document document,
SerializationSpecifier serializationOptions)
Convenience method that serializes the given DOM Document as a String, using the
specified
SerializationSpecifier, creating any XSLT stylesheet required for
serialization on an ad hoc basis. |
static String |
serializeDocument(Document document,
SerializationSpecifier serializationOptions,
StylesheetManager stylesheetManager)
Convenience method that serializes the given DOM Document as a String, using the
specified
SerializationSpecifier and given StylesheetManager to manage
any XSLT stylesheets required to serialize properly. |
static String |
serializeDocument(Document document,
String encoding)
Convenience method that serializes the given DOM Document as a String, using the
specified encoding, indenting the results and omitting the XML declaration,
which is a reasonable way of serializing a MathML document.
|
static String |
serializeDocument(Document document,
String encoding,
boolean indent)
Convenience method that serializes the given DOM Document as a String, using the
specified encoding and indentation options and omitting the XML declaration,
which is a reasonable way of serializing a MathML document.
|
static String |
serializeDocument(Document document,
String encoding,
boolean indent,
boolean omitXMLDeclaration)
Deprecated.
Use one of the alternative methods, including
serializeDocument(Document, SerializationSpecifier) for ultimate control. |
static String |
serializeElement(Element element)
Convenience method that serializes the given DOM Element as a String (encoded in UTF-8),
indenting the results and omitting the XML declaration, which is a reasonable way of
serializing MathML.
|
static String |
serializeElement(Element element,
boolean indent)
Convenience method that serializes the given DOM Element as a String, indenting if
specified and omitting the XML declaration which is a reasonable way of serializing MathML.
|
static String |
serializeElement(Element element,
boolean indent,
boolean omitXMLDeclaration)
Deprecated.
Use one of the alternative methods, including
serializeElement(Element, SerializationSpecifier) for ultimate control. |
static String |
serializeElement(Element element,
SerializationSpecifier serializationOptions)
Convenience method that serializes the given DOM Element as a String, using the given
SerializationSpecifier, creating any XSLT stylesheet required for
serialization on an ad hoc basis. |
static String |
serializeElement(Element element,
SerializationSpecifier serializationOptions,
StylesheetManager stylesheetManager)
Convenience method that serializes the given DOM Element as a String, using the given
SerializationSpecifier and given StylesheetManager to manage
any XSLT stylesheets required to serialize properly. |
static String |
serializeElement(Element element,
String encoding)
Convenience method that serializes the given DOM Element as a String, using
the given encoding, indenting the results and omitting the XML declaration,
which is a reasonable way of serializing MathML.
|
static String |
serializeElement(Element element,
String encoding,
boolean indent)
Convenience method that serializes the given DOM Element as a String, using
the given parameters.
|
static String |
serializeElement(Element element,
String encoding,
boolean indent,
boolean omitXMLDeclaration)
|
static UnwrappedParallelMathMLDOM |
unwrapParallelMathMLDOM(Element mathElement)
Convenience method to unwrap at MathML DOM Object containing top-level parallel markup,
as defined Section 5.3.1 of the MathML 2.0 specification.
|
public static final String ANNOTATION_LOCAL_NAME
public static final String ANNOTATION_XML_LOCAL_NAME
public static Document parseMathMLDocumentString(String mathmlDocument) throws IOException, SAXException
IOExceptionSAXExceptionpublic static void convertMfencedToExplicitFences(Document document)
mfenced element in the supplied document with
its explicit mrow/mo equivalent. The document is modified in place.public static void convertExplicitFencesToMfenced(Document document)
mfenced. This exists for
compatibility with the legacy up-conversion stylesheets and modifies the document in place.public static String serializeDocument(Document document)
document - DOM document to serialize, must not be nullpublic static String serializeDocument(Document document, SerializationSpecifier serializationOptions)
SerializationSpecifier, creating any XSLT stylesheet required for
serialization on an ad hoc basis.document - DOM document to serialize, must not be nullserializationOptions - desired SerializationOptions, may be null.public static String serializeDocument(Document document, SerializationSpecifier serializationOptions, StylesheetManager stylesheetManager)
SerializationSpecifier and given StylesheetManager to manage
any XSLT stylesheets required to serialize properly.document - DOM document to serialize, must not be nullserializationOptions - desired SerializationOptions, may be null.public static String serializeDocument(Document document, String encoding)
document - DOM document to serialize, must not be nullencoding - desired encoding, null is interpreted as UTF-8.public static String serializeDocument(Document document, String encoding, boolean indent)
document - DOM document to serialize, must not be nullencoding - desired encoding, null is interpreted as UTF-8.@Deprecated public static String serializeDocument(Document document, boolean indent, boolean omitXMLDeclaration)
serializeDocument(Document, SerializationSpecifier) for ultimate control.document - DOM element to serializeindent - whether to indent the results or notomitXMLDeclaration - whether to omit the XML declaration or not.@Deprecated public static String serializeDocument(Document document, String encoding, boolean indent, boolean omitXMLDeclaration)
serializeDocument(Document, SerializationSpecifier) for ultimate control.document - DOM element to serializeencoding - desired encoding, null is interpreted as UTF-8.indent - whether to indent the results or notomitXMLDeclaration - whether to omit the XML declaration or not.public static String serializeElement(Element element)
element - DOM element to serialize, must not be null.public static String serializeElement(Element element, SerializationSpecifier serializationOptions)
SerializationSpecifier, creating any XSLT stylesheet required for
serialization on an ad hoc basis.element - DOM element to serialize, must not be null.serializationOptions - SerializationSpecifier, may be null.public static String serializeElement(Element element, SerializationSpecifier serializationOptions, StylesheetManager stylesheetManager)
SerializationSpecifier and given StylesheetManager to manage
any XSLT stylesheets required to serialize properly.element - DOM element to serialize, must not be null.serializationOptions - SerializationSpecifier, may be null.stylesheetManager - StylesheetManager, must not be nullpublic static String serializeElement(Element element, String encoding)
element - DOM element to serializeencoding - desired encoding, null is interpreted as UTF-8.public static String serializeElement(Element element, boolean indent)
element - DOM element to serializeindent - whether to indent or not@Deprecated public static String serializeElement(Element element, boolean indent, boolean omitXMLDeclaration)
serializeElement(Element, SerializationSpecifier) for ultimate control.element - DOM element to serializeindent - whether to indent the results or notomitXMLDeclaration - whether to omit the XML declaration or not.@Deprecated public static String serializeElement(Element element, String encoding, boolean indent, boolean omitXMLDeclaration)
serializeElement(Element, SerializationSpecifier) or
serializeElement(Element, SerializationSpecifier, StylesheetManager)element - DOM element to serializeencoding - desired encoding, null is interpreted as UTF-8.indent - whether to indent the results or notomitXMLDeclaration - whether to omit the XML declaration or not.public static String serializeElement(Element element, String encoding, boolean indent)
(This can be used in more general cases than MathML, through experienced programmers may want more control over what happens here.)
element - DOM element to serializeencoding - desired encoding, null is interpreted as UTF-8.indent - whether to indent the results or notpublic static boolean isMathMLElement(Node node)
Node node is a MathML element
having any localName.node - Node to testIllegalArgumentException - if node is null.public static boolean isMathMLElement(Node node, String localName)
Node node is a MathML element
having the given localName.node - Node to testlocalName - MathML local name to test for, such as mi or math,
or null to indicate "any name in the MathML namespace".IllegalArgumentException - if node is null.public static void ensureMathMLContainer(Element mathElement)
public static Element ensureMathMLDocument(Document document)
Document contains a single MathML math
Element. If so, the Element is returned. Otherwise, an IllegalArgumentException is
thrown.public static UnwrappedParallelMathMLDOM unwrapParallelMathMLDOM(Element mathElement)
If there is no parallel markup detected then null if returned.
If the given element is null or is not a MathML "math" element, then an IllegalArgumentException
is thrown.
public static String extractAnnotationString(Element mathElement, String encodingAttribute)
math element, if such an annotation is found.
This assumes the following structure:
<math>
<semantics>
...
<annotation encoding="...">text</annotation>
</semantics>
</math>
mathElement - public static NodeList extractAnnotationXML(Element mathElement, String encodingAttribute)
math element, if such an annotation is found.
This assumes the following structure:
<math>
<semantics>
...
<annotation-xml encoding="...">XML annotation</annotation>
</semantics>
</math>
mathElement - annotation-xml element, or null if no such annotation found.public static Document isolateFirstSemanticsBranch(Element mathElement)
For example:
<math>
<semantics>
<mi>x</mi>
<annotation-xml encoding='blah'><x/></annotation-xml>
</semantics>
</math>
results in:
<math>
<mi>x</mi>
</math>
math
element is not annotated.IllegalArgumentException - if passed null or the given element is not a
math element.public static Document isolateFirstSemanticsBranch(UnwrappedParallelMathMLDOM unwrappedDOM)
isolateFirstSemanticsBranch(Element) that works on an
UnwrappedParallelMathMLDOM.IllegalArgumentException - if passed null.public static Document isolateAnnotationXML(Element mathElement, String encodingAttribute)
For example:
<math>
<semantics>
<mi>x</mi>
<annotation-xml encoding='blah'><x/></annotation-xml>
</semantics>
</math>
results in:
<math>
<x/>
</math>
math
element is not annotated or does not have the required annotation.IllegalArgumentException - if passed null or the given element is not a
math element.public static Document isolateAnnotationXML(UnwrappedParallelMathMLDOM unwrappedDOM, String encodingAttribute)
isolateAnnotationXML(Element, String) that works on an
UnwrappedParallelMathMLDOM.IllegalArgumentException - if passed null.Copyright © 2008–2026 The University of Edinburgh. All rights reserved.