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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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)