MathML: Difference between revisions

Content deleted Content added
Browser support: Chrome now supports it and so does Edge
EricAMeyer (talk | contribs)
Overhaul of Presentation and semantics and Example sections, with some other adjustments throughout
Line 107:
==Presentation and semantics==
MathML deals not only with the ''presentation'' but also the ''meaning'' of formula components (the latter part of MathML is known as "Content MathML"). Because the meaning of the equation is preserved separate from the presentation, how the content is communicated can be left up to the user. For example, web pages with MathML embedded in them can be viewed as normal web pages with many browsers, but visually impaired users can also have the same MathML read to them through the use of [[screen readers]] (e.g. using the [[MathPlayer]] [[Plug-in (computing)|plugin]] for [[Internet Explorer]] or [[Firefox]], [[Opera (web browser)|Opera]] 9.50 build 9656+ or the Fire Vox extension for Firefox). Newer versions of [[JAWS (screen reader)|JAWS]] support MathML voicing as well as braille output.<ref>{{Cite web|title=JAWS Version 16|url=https://support.freedomscientific.com/downloads/jaws/JAWSWhatsNew?version=16|url-status=live}}</ref>
 
The quality of rendering of MathML in a browser depends on the installed fonts. The [[STIX Fonts project]] have released a comprehensive set of mathematical fonts under an open license. The [[Cambria Math]] font supplied with Microsoft Windows had a slightly more limited support.<ref name="Vismor">{{Citation|url=https://vismor.com/documents/site_implementation/viewing_mathematics/viewing_mathematics.php|title=Viewing Mathematics on the Internet|access-date=13 April 2011|first=Timothy|last=Vismor}}</ref>
 
A valid MathML document typically consists of the XML declaration, [[Document type declaration|DOCTYPE]] declaration, and document element.
The document body then contains MathML expressions which appear in &lt;{{code| math>}} elements as needed in the document. Often, MathML will be embedded in more general documents, such as [[HTML]], [[DocBook]], or other [[XML]] schemas. A complete document that consists of just the MathML example above, is shown here:
 
===Presentation MathML===
Presentation MathML focuses on the display of an equation, and has about 30 elements. The elements' names all begin with {{code|m}}. A Presentation MathML expression is built up out of ''tokens'' that are combined using higher-level elements, which control their layout. (thereFiner aredetails alsoof aboutpresentation 50are attributes,affected whichby mainlyclose controlto fine50 details)attributes.
 
Token elements generally only contain characters (not other elements). They include:
Line 115 ⟶ 120:
* {{code|<mo>+</mo>}} – operators;
* {{code|<mn>2</mn>}} – numbers.
* {{code|<mtext>nonsuch zerothat</mtext>}} – text.
 
Note, however, that these token elements may be used as extension points, allowing markup in host languages.
Line 135 ⟶ 140:
The full specification of MathML entities<ref>{{Cite web|url=http://www.w3.org/TR/MathML3/chapter7.html|title=Characters, Entities and Fonts|website=www.w3.org}}</ref> is closely coordinated with the corresponding specifications for use with HTML and XML in general.<ref>{{Cite web|url=http://www.w3.org/TR/xml-entity-names/Overview.html|title=XML Entity Definitions for Characters (2nd Edition)|website=www.w3.org}}</ref>
 
Thus, the expression <math forcemathmode=mathml>a x^2+b x+c</math> requires two layout elements: one to create the overall horizontal row and one for the superscripted exponent. Including onlyHowever, the layoutindividual elementstokens andalso thehave to be identified as identifiers (not{{code|<mi>}}), yetoperators marked('{{code|<mo>}}), upor numbers ({{code|<mn>}}). bareAdding tokensthe token markup, the structurefull looksform likeends up this:as
 
<syntaxhighlight lang="xml">
<mrow>
a &InvisibleTimes; <msup>x 2</msup>
+ b &InvisibleTimes; x
+ c
</mrow>
</syntaxhighlight>
 
However, the individual tokens also have to be identified as identifiers (mi), operators (mo), or numbers (mn). Adding the token markup, the full form ends up as
 
<syntaxhighlight lang="xml">
Line 155 ⟶ 150:
</syntaxhighlight>
 
A valid MathMLcomplete document typicallythat consists of just the XMLMathML declaration, [[Document type declaration|DOCTYPE]]example declarationabove, andis documentshown element.here:
The document body then contains MathML expressions which appear in &lt;math> elements as needed in the document. Often, MathML will be embedded in more general documents, such as [[HTML]], [[DocBook]], or other [[XML]] schemas. A complete document that consists of just the MathML example above, is shown here:
 
<syntaxhighlight lang="xml">
Line 203 ⟶ 197:
</syntaxhighlight>
 
Content MathML is nearly [[isomorphic]] to [[Binary expression tree|expressions]] in a [[Functional programming|functional language]] such as [[Scheme (programming language)|Scheme]] and other dialects of [[Lisp (programming language)|Lisp]]. {{tag|apply}} amounts to Scheme's {{code|(...)}}, and the many operator and function elements amount to Scheme functions. With this trivial literal transformation, plus un-tagging the individual tokens, the example above becomes:
<syntaxhighlight lang="scheme">
(plus
Line 216 ⟶ 210:
According to the OM Society,<ref name="OpenMath">{{Cite web|url=https://www.openmath.org/|title=OpenMath Home · OpenMath|website=www.openmath.org}}</ref> OpenMath Content Dictionaries can be employed as collections of symbols and identifiers with declarations of their semantics{{snd}}names, descriptions and rules. A 2018 paper presented at the [[Special Interest Group on Information Retrieval|SIGIR]] conference<ref name="SchubotzScharpfGipp2018">{{cite journal|author1=Moritz Schubotz|author2=Philipp Scharpf|author3=Bela Gipp|title=Representing Mathematical Formulae in Content MathML using Wikidata.|url=http://ceur-ws.org/Vol-2132/paper5.pdf|date=2018|journal=Birndl@sigir}}</ref> proposed that the semantic knowledge base [[Wikidata]] could be used as an OpenMath Content Dictionary to link semantic elements of a mathematical formula to unique and language-independent Wikidata items.
 
==Example and comparison to other formats==
The well-known [[quadratic formula]] could be represented in Presentation MathML as an expression tree made up from layout elements like ''mfrac'' or ''msqrt'' elements:
: <math>x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}</math>
 
would be marked up using [[LaTeX]] syntax like this:
<syntaxhighlight lang="latex">
x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
</syntaxhighlight>
in [[eqn (software)|troff/eqn]] like this:
x = {-b +- sqrt{b sup 2 – 4ac}} over 2a
in [[Apache OpenOffice Math]] and [[LibreOffice Math]] like this (all three are valid):
x = {-b plusminus sqrt {b^2 – 4 ac}} over {2 a}
x = {-b +- sqrt {b^2 – 4ac}} over {2a}
x = {-b ± sqrt {b^2 – 4ac}} over {2a}
in [[AsciiMath]] like this:
x = (-b +- sqrt(b^2 - 4ac))/(2a)
The above equation could be represented in Presentation MathML as an expression tree made up from layout elements like ''mfrac'' or ''msqrt'' elements:
<syntaxhighlight lang="xml">
<math mode="display" xmlns="http://www.w3.org/1998/Math/MathML">
Line 271 ⟶ 251:
This example uses the {{tag|annotation|open}} element, which can be used to embed a semantic annotation in non-XML format, for example to store the formula in the format used by an equation editor such as [[StarMath]] or the markup using [[LaTeX]] syntax. The {{code|encoding}} field is usually a [[MIME type]], although most of the equation encodings don't have such a registration; freeform text may be used in such case.
 
Although less compact than TeXother formats, the XML structuring promisesof toMathML makemakes itits content widely usable and accessible, allows near-instant display in applications such as [[Web browser]]s, and facilitates an interpretation of its meaning in mathematical software products. MathML is not intended to be written or edited directly by humans.<ref>{{cite web
| url = http://www.w3.org/TR/REC-MathML/#abstract
| title = Mathematical Markup Language (MathML) 1.01 Specification (Abstract)
Line 316 ⟶ 296:
[[File:MathMLxhtml.png|thumb|435px|A rendering of the formula for a circle in MathML+XHTML using Firefox 22 on Mac OS X]]
 
Inline MathML is also supported in [[HTML5]] files in the current versions of [[WebKit]] ([[Safari (web browser)|Safari]] and [[JavaFX|JavaFX/WebView]] ), [[Gecko (software)|Gecko]] ([[Firefox]]). There is no need to specify namespaces likeas there was in the [[XHTML]].
{{clear}}
 
Line 356 ⟶ 336:
 
The [[KHTML]]-based [[Konqueror]] currently does not provide support for MathML.<ref>{{citation |url=http://bugs.kde.org/show_bug.cgi?id=30526 |title=Bug 30526 – MathML support for Konqi}}</ref>
 
The quality of rendering of MathML in a browser depends on the installed fonts. The [[STIX Fonts project]] have released a comprehensive set of mathematical fonts under an open license. The [[Cambria Math]] font supplied with Microsoft Windows had a slightly more limited support.<ref name="Vismor">{{Citation|url=https://vismor.com/documents/site_implementation/viewing_mathematics/viewing_mathematics.php|title=Viewing Mathematics on the Internet|access-date=13 April 2011|first=Timothy|last=Vismor}}</ref>
 
 
 
Line 509 ⟶ 486:
 
==Other standards==
Another standard called [[OpenMath]] that has been more specifically designed (largely by the same people who devised Content MathML) more specifically for storing formulae semantically can also be used to complement MathML. OpenMath data can be embedded in MathML using the {{code|1=<annotation-xml encoding="OpenMath">}} element. OpenMath ''content dictionaries'' can be used to define the meaning of {{code|<csymbol>}} elements. The following would define ''P''<sub>1</sub>(''x'') to be the first [[Legendre polynomial]]
<syntaxhighlight lang="xml">
<apply>
Line 519 ⟶ 496:
</syntaxhighlight>
 
The [[OMDoc]] format has been created for markup of larger mathematical structures than formulae, from statements like definitions, theorems, proofs, orand exampleexamples, to complete theories and even entire text books. Formulae in OMDoc documents can either be written in Content MathML or in OpenMath; for presentation, they are converted to Presentation MathML.
 
The [[International Organization for Standardization|ISO]]/[[International Electrotechnical Commission|IEC]] standard [[Office Open XML]] (OOXML) defines a different XML math syntax, derived from [[Microsoft Office]] products. However, it is partially compatible<ref>{{Citation| url=http://dpcarlisle.blogspot.com/2007/04/xhtml-and-mathml-from-office-20007.html
Line 527 ⟶ 504:
| date=9 May 2007
| access-date=20 September 2007
}}</ref> through relatively simple [[XSL Transformations]].
 
== See also ==