mathml
Generate MathML from symbolic expression
Description
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
.
Examples
MathML from Symbolic Expression
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> '
Inline Display of MathML
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> '
Add Tooltips for Symbols to Generated MathML
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 hovering your mouse on J displays a tooltip containing besselj.
Modify Generated MathML with Symbolic Preferences
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');
Input Arguments
f
— Input
symbolic number | symbolic variable | symbolic array | symbolic function | symbolic expression
Input, specified as a symbolic number, variable, array, function, or expression.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: mathml(f,'Tooltips',true)
DisplayInline
— Inline MathML display
false
(default) | true
Inline MathML display, specified as the comma-separated pair
consisting of 'DisplayInline'
and either
true
or false
(default).
Tooltips
— tooltips
false
(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.
Version History
Introduced in R2018b
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)