Generate MathML from symbolic expression
uses additional options specified by one or more name-value pair arguments. For
example, generate MathML for inline display by specifying
chr
= mathml(f
,Name,Value
)DisplayInline
as true
.
Generate MathML from a symbolic expression.
syms x f = 1/exp(x^2); chr = mathml(f)
chr = '<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'> <msup> <mo>ⅇ</mo> <mrow> <mo>-</mo> <msup> <mi>x</mi> <mn>2</mn> </msup> </mrow> </msup> </math> '
Generate MathML for inline display by specifying
DisplayInline
as true
.
syms x f = 1/exp(x^2); chr = mathml(f,'DisplayInline',true)
chr = '<math xmlns='http://www.w3.org/1998/Math/MathML'> <msup> <mo>ⅇ</mo> <mrow> <mo>-</mo> <msup> <mi>x</mi> <mn>2</mn> </msup> </mrow> </msup> </math> '
Use MathML tooltips for units and some special functions to
provide more information. Generate tooltips by specifying
Tooltips
as true
.
syms nu x f = besselj(nu,x); chr = mathml(f,'Tooltips',true)
chr = '<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'> <mrow> <msub> <maction actiontype='tooltip'> <mo>J</mo> <mtext>besselj</mtext> </maction> <mi>ν</mi> </msub> <mrow> <mo form='prefix'>(</mo> <mi>x</mi> <mo form='postfix'>)</mo> </mrow> </mrow> </math> '
When you use MathML in a web page, then pausing on J displays a tooltip containing besselj.
Modify generated MathML by setting symbolic preferences using
the sympref
function.
Generate the MathML form of the expression π with the default symbolic preference.
sympref('default'); chr = mathml(sym(pi))
chr = '<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'> <mi>π</mi> </math> '
Set the 'FloatingPointOutput'
preference to
true
to return symbolic output in floating-point
format. Generate the MathML form of π in
floating-point format.
sympref('FloatingPointOutput',true); chr = mathml(sym(pi))
chr = '<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'> <mn>3.1416</mn> </math> '
Now change the output order of a symbolic polynomial. Create a symbolic
polynomial and set 'PolynomialDisplayStyle'
preference to
'ascend'
. Generate MathML form of the polynomial
sorted in ascending
order.
syms x; poly = x^2 - 2*x + 1; sympref('PolynomialDisplayStyle','ascend'); chr = mathml(poly)
chr = '<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'> <mrow> <mn>1</mn> <mo>-</mo> <mrow> <mn>2</mn> <mo form='infix'>⁢</mo> <mi>x</mi> </mrow> <mo>+</mo> <msup> <mi>x</mi> <mn>2</mn> </msup> </mrow> </math> '
The preferences you set using sympref
persist through
your current and future MATLAB® sessions. Restore the default values by specifying the
'default'
option.
sympref('default');
f
— InputInput, specified as a symbolic number, variable, array, function, or expression.
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
mathml(f,'Tooltips',true)
'DisplayInline'
— Inline MathML displayfalse
(default) | true
Inline MathML display, specified as the comma-separated pair
consisting of 'DisplayInline'
and either
true
or false
(default).
'Tooltips'
— tooltipsfalse
(default) | true
Tooltips in MathML output, specified as the comma-separated pair
consisting of 'Tooltips'
and either
true
or false
(default).
mathml
adds tooltips for units and some special
functions.