MathML
FromLatex
translate a LaTeX expression into MathML
Calling Sequence
Parameters
Description
Examples
Compatibility
FromLatex( latexstring )
FromLatex( latexstring, opts )
latexstring
-
a LaTeX expression as a string
opts
(optional) equation of the form output = o, where o is one of mathml and maple
This command converts a LaTeX expression to MathML, and optionally further processes it into a Maple expression.
By default, the command just converts the string to MathML. To convert the expression to a Maple expression, use the output = maple option. The default is output = mathml. This can be used if MathML is the intended final format, or if you want more control over how the MathML is imported into Maple, as shown in the final example below.
This example takes a LaTeX expression, converts it to MathML, and then to Maple
L≔\\cos (2\\theta) = \\cos^2 \\theta - \\sin^2 \\theta:
mml≔MathML:-FromLatex⁡L
mml≔<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mi>cos</mi><mo stretchy="false">(</mo><mn>2</mn><mi>θ</mi><mo stretchy="false">)</mo><mo>=</mo><msup><mi>cos</mi><mn>2</mn></msup><mi>θ</mi><mo>−</mo><msup><mi>sin</mi><mn>2</mn></msup><mi>θ</mi></mrow></math>
MathML:-Import⁡mml,source=calculator
cos⁡2⁢θ=cos⁡θ2−sin⁡θ2
You can achieve the same thing by passing the option output = maple.
MathML:-FromLatex⁡L,output=maple
Remember that backslash is an escape character, n means newline, t means tab, and \ means a backslash. When inputting expressions in a string, the backslashes will need to be doubled-up. This is not needed when reading strings from a file.
L≔\\frac{n!}{k!(n-k)!} = \\binom{n}{k}:
mml≔MathML:-FromLatex⁡L,output=maple
mml≔n!k!⁢n−k!=nk
Here is a nested fraction
L≔\\frac{\\frac{1}{x}+\\frac{1}{y}}{y-z}:
mml≔1x+1yy−z
If that fraction had numbers instead of variables, the converted expression would simplify. To see the structure, use the output=inert option, with will insert inert operators. Inert operators are prefixed with a % symbol, and don't evaluate.
L≔\\frac{\\frac{1}{2}+\\frac{1}{3}}{4-5}:
mml≔<math xmlns="http://www.w3.org/1998/Math/MathML" display="inline"><mrow><mfrac><mrow><mfrac><mrow><mn>1</mn></mrow><mrow><mn>2</mn></mrow></mfrac><mo>+</mo><mfrac><mrow><mn>1</mn></mrow><mrow><mn>3</mn></mrow></mfrac></mrow><mrow><mn>4</mn><mo>−</mo><mn>5</mn></mrow></mfrac></mrow></math>
iex≔MathML:-Import⁡mml,source=calculator,output=inert
iex≔12+134−5
value⁡iex
−56
The MathML[FromLatex] command was introduced in Maple 2025.
For more information on Maple 2025 changes, see Updates in Maple 2025.
See Also
latex
MathML:-Import
MathML[Export]
MathML[ExportContent]
Paste MathML
XMLTools
Download Help Document