|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcox.jmatt.java.MathTools.MathXML
public class MathXML
This class provides XML and MathML Presentation markup utilities to the other MathTools classes. It contains quick methods to wrap number, operator, and identifier (variable) tags around single terms, as well as a method to wrap content in <mrow> tags. It contains two methods for generating fraction markup and the wrapMath() method which generates <math> tags complete with the MathML xmlns URI.
The uber-method here is parseMathML()
. It takes a String, optionally containing special formatting characters, and turns it into MathML.
It can distinguish between numbers, operators, and identifiers and will tag them appropriately. For multiplication it uses the Unicode 'dot operator' sequence,
and for division, the 'division sign' sequence. The wrapXML()
method can generate any tagged content and the escapeXML()
method
replaces certain common characters with their XML entity representations.
Note on Method Naming: Methods beginning with 'wrap' DO NOT parse their input before formatting. Methods named directly after MathML tags, e.g. mSub, mRoot,
DO parseMathML()
their parameters before adding them. This is done primarily because the parseMathML()
method makes use of some of
the 'wrap__()' methods. If subclassing, take this into account!
The name of this class, MathXML, was chosen to avoid possible conflict and confusion with other objects that might bear the name 'MathML.' This class is not and was not designed to be the end-all XML class. Rather, it provides sufficient XML/MathML to support the other MathTools classes. As with them, MathXML contains only static methods but provides a constructor for scripting applications.
Nested Class Summary | |
---|---|
static class |
MathXML.MathSymbol
This enum is used to hold Unicode math symbols and to provide them and their values in an easily accessible way. |
Field Summary | |
---|---|
static java.lang.String |
NSURI
String containing the MathML namespace URI. |
Constructor Summary | |
---|---|
MathXML()
Constructor provided for exposing to scripts. |
Method Summary | |
---|---|
static java.lang.String |
escapeXML(java.lang.String pData)
Replace certain characters with their XML escapes. |
static java.lang.String |
formatMonomial(java.lang.String pCoef,
java.lang.String pVar,
java.lang.String pExp,
boolean pSmart)
Format a monomial (single polynomial term). |
static java.lang.String |
getEntity(java.lang.String pSymbol)
This method returns a Unicode/XML entity escape for the requested symbol. |
MathXML_SCROB |
getSCROB()
Return a SCROB instance of this class. |
static MathXML.MathSymbol |
getSymbol(java.lang.String pSymbol)
Look up a MathSymbol constant based on a String. |
static java.lang.String |
mFrac(java.lang.String pNumerator,
java.lang.String pDenominator)
Convenience method for mFrac(null, pNumerator, pDenominator). |
static java.lang.String |
mFrac(java.lang.String pWhole,
java.lang.String pNumerator,
java.lang.String pDenominator)
This method generates an <mfrac> expression. |
static java.lang.String |
mOver(java.lang.String pBase,
java.lang.String pOver)
Overscript a term. |
static java.lang.String |
mRoot(java.lang.String pRadicand,
java.lang.String pIndex)
Create a <mroot> tag. |
static java.lang.String |
mSqrt(java.lang.String pRadicand)
Create a <msqrt> tag. |
static java.lang.String |
mSub(java.lang.String pBase,
java.lang.String pSub)
Subscript a term. |
static java.lang.String |
mSubSup(java.lang.String pBase,
java.lang.String pSub,
java.lang.String pSuper)
Create a <msubsup> element. |
static java.lang.String |
mSup(java.lang.String pBase,
java.lang.String pSuper)
Superscript a term. |
static java.lang.String |
mUnder(java.lang.String pBase,
java.lang.String pUnder)
Underscript a term. |
static java.lang.String |
mUnderOver(java.lang.String pBase,
java.lang.String pUnder,
java.lang.String pOver)
Under- and overscript a term. |
static java.lang.String |
parseMathML(java.lang.String pData)
This is MathXML's power method. |
static java.lang.String |
wrapMath(java.lang.String pContent,
java.lang.String pDisplay)
Wrap the <math> tags around MathML content. |
static java.lang.String |
wrapMI(java.lang.String pData)
Wrap something in identifier tags, <mi>. |
static java.lang.String |
wrapMN(java.lang.String pData)
Wrap something in number tags, <mn>. |
static java.lang.String |
wrapMO(java.lang.String pData)
Wrap something in operator tags, <mo>. |
static java.lang.String |
wrapRow(java.lang.String pData)
Wrap a math row, <mrow>. |
static java.lang.String |
wrapTag(java.lang.String pTag,
java.lang.String pContent)
Create an XML tag around the supplied content. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String NSURI
Constructor Detail |
---|
public MathXML()
Method Detail |
---|
public static java.lang.String escapeXML(java.lang.String pData)
pData
- The String to XML-escape.
public static MathXML.MathSymbol getSymbol(java.lang.String pSymbol)
MathSymbol
constant based on a String. This is an error-save way to do a lookup; if the symbol is not found the result is the
constant 'NOT_EXIST'. Any errors are reported at Debug level.
pSymbol
- The name of the MathSymbol to retrieve. It must EXACTLY MATCH the name of the symbol.
public static java.lang.String getEntity(java.lang.String pSymbol)
pSymbol
- The symbol to look up.
public static java.lang.String wrapMath(java.lang.String pContent, java.lang.String pDisplay)
pContent
- XML content to be wrapped in math tags.pDisplay
- The 'display=' attribute: 'inline', 'block', or null.
public static java.lang.String wrapTag(java.lang.String pTag, java.lang.String pContent)
wrapMath()
echo back to this one.
pTag
- The name of the tag to create.pContent
- The content to include in the tag.public static java.lang.String wrapMN(java.lang.String pData)
public static java.lang.String wrapMI(java.lang.String pData)
public static java.lang.String wrapMO(java.lang.String pData)
public static java.lang.String wrapRow(java.lang.String pData)
public static java.lang.String parseMathML(java.lang.String pData)
This is MathXML's power method. It parses a String containing one or more formatting characters and generates a MathML expression. The data String is broken down into space-separated tokens and parsed from left to right. The MathML is generated dynamically as the tokens are iterated.
The formatting characters are:
MathSymbol
escape based on the String value after the '$' sign.MathSymbol
escape as an identifier.MathSymbol
escape as an operator.If the input String is null or empty an empty <mrow> tag with a unique ID is returned.
CAUTION:Using more than one space to separate the tokens may confuse the parser!
pData
- The data String containing raw data to be parsed.
public static java.lang.String mFrac(java.lang.String pWhole, java.lang.String pNumerator, java.lang.String pDenominator)
This method generates an <mfrac> expression. If the whole part is not null or empty, the resulting expression is in a row. If so, just the <mfrac>
tag is generated. All three parts are sent to parseMathML()
before being included: if one of the components should be in a row it must be enclosed
in '@r' and '@R' to ensure proper parsing. The whole part need not be 'rowed' as it is automatically a part of a mrow tag.
NOTE: This method should not be confused with the 'MFraction' class. The former is a MathXML method for formatting fractions per MathML Presentation specification. The latter is a MathTools class encompassing the behavior AND presentation of fractions.
pWhole
- The whole part of the fraction. May be null or empty.pNumerator
- The numerator of the fraction.pDenominator
- The denominator of the fraction.
public static java.lang.String mFrac(java.lang.String pNumerator, java.lang.String pDenominator)
public static java.lang.String mSup(java.lang.String pBase, java.lang.String pSuper)
parseMathML()
before processing, so parser markup is allowed. If the superscript is null or empty
it is ignored and only pBase is parsed.
pBase
- The base to which the superscript is attached.pSuper
- The superscript to attach.
public static java.lang.String mSub(java.lang.String pBase, java.lang.String pSub)
parseMathML()
before processing, so parser markup is allowed. If the subscript is null or empty it
is ignored and only pBase is parsed.
pBase
- The base to which the subscript is attached.pSub
- The subscript to attach.
public static java.lang.String mSubSup(java.lang.String pBase, java.lang.String pSub, java.lang.String pSuper)
pBase
- The base to which the super- and subscript are attached.pSub
- The subscript to attach. Ignored if null or blank.pSuper
- The superscript to attach. Ignored if null or blank.
public static java.lang.String formatMonomial(java.lang.String pCoef, java.lang.String pVar, java.lang.String pExp, boolean pSmart)
pCoef
- The coefficient of the term.pVar
- The variable of the term. If it is null or blank both it and the exponent are ignored.pExp
- The exponent of the variable. If this can't be parsed as an int, the method reverts to 'raw' mode.pSmart
- true to activate 'smart' mode, false for 'raw' mode.
public static java.lang.String mOver(java.lang.String pBase, java.lang.String pOver)
parseMathML()
before processing, so parser markup is allowed. If the overscript is null or empty
it is ignored and only pBase is parsed.
pBase
- The base to which the overscript is attached.pOver
- The overscript to attach.
public static java.lang.String mUnder(java.lang.String pBase, java.lang.String pUnder)
parseMathML()
before processing, so parser markup is allowed. If the underscript is null or empty
it is ignored and only pBase is parsed.
pBase
- The base to which the underscript is attached.pUnder
- The underscript to attach.
public static java.lang.String mUnderOver(java.lang.String pBase, java.lang.String pUnder, java.lang.String pOver)
parseMathML()
before processing, so parser markup is allowed. If either *script is null
or empty the other is processed normally.
pBase
- The base to which the underscript is attached.pUnder
- The underscript to attach.
public static java.lang.String mSqrt(java.lang.String pRadicand)
public static java.lang.String mRoot(java.lang.String pRadicand, java.lang.String pIndex)
pRadicand
- The radicand of the resulting radical.pIndex
- The value of the root to be taken.
public MathXML_SCROB getSCROB()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |