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
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 hovering your mouse on J displays a tooltip containing besselj.

Modify generated MathML by using the sympref function.
Generate the MathML form of the expression π with the default symbolic setting.
sympref('default');
chr = mathml(sym(pi))chr =
'<math xmlns='http://www.w3.org/1998/Math/MathML' display='block'>
<mi>π</mi>
</math>
'Set 'FloatingPointOutput' 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' 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 settings that 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
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)
Inline MathML display, specified as the comma-separated pair
consisting of 'DisplayInline' and either
true or false
(default).
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 Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)