⬆️ ⬇️

HTML5 MathMl

Before the release of HTML5, the use of formulas was a real punishment. Judge for yourself: in 2005, it was necessary to have on hand either a special browser, or break the text into the actual HTML and insert from images or PDF. Search and other editing and / or displaying / paper operations was an ambiguous task, which was devoted to whole monographs .



In 2012, it was already easier. Now you can connect the necessary plug-ins (Firemath for FireFox and Daum Equation Editor for Chrome). But the ambiguity of standards (and support) actually forced to write the same article for each of the browsers (and for their versions). Or meet users with a magic greeting “Your browser needs to be updated / supplemented with an extension”.



Uncomfortable? - Yes! Took a lot of time to find a universal solution? - Yes! Makes you think about which type of recording is better (presentation or content), which converter to use (and there are only a well-known from a dozen and a half)? - YES! YES! YES!

')

As a result, the publication work turned into mastering two or three markup lexicons and studying the work of at least one recoder program.



Now, with the advent of HTML5, everything has become much easier. A new <math> container has appeared in it.

Each valid MathML instance must be inside this container.

It does not allow attachments, but there can be an arbitrary number of other child elements inside.



Tag Attributes



In addition to the following attributes, the <math> accepts any attributes from <mstyle> .



class id style

Subject to use with style sheets .

dir

Indicates the direction of the formula: ltr - from left to right or rtl - from right to left.

ref

Used to set a hyperlink to the specified URI.

mathbackground

Background color. You can use #rgb , #rrggbb and HTML color names .

mathcolor

Text color. You can use #rgb , #rrggbb and HTML color names .

display

This attribute defines the output method. Possible values:





The default is inline .



mode <span title = "This deprecated API is no longer used, but it probably still works."





Outdated display attribute value.

Possible values ​​are display (which has the same effect as display="block" ) and inline .

overflow

Determines how the expression behaves if the text is too long and does not fit in the specified width range.

Possible values: linebreak (default), scroll , elide , truncate , scale .



Examples
Pythagorean theorem



HTML5 Presentation



 <!DOCTYPE html> <html> <head> <title>MathML in HTML5</title> </head> <body> <math> <mrow> <mrow> <msup> <mi>a</mi> <mn>2</mn> </msup> <mo>+</mo> <msup> <mi>b</mi> <mn>2</mn> </msup> </mrow> <mo>=</mo> <msup> <mi>c</mi> <mn>2</mn> </msup> </mrow> </math> </body> </html> 




XHTML view



 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>MathML in XHTML</title> </head> <body> <math xmlns="http://www.w3.org/1998/Math/MathML"> <mrow> <mrow> <msup> <mi>a</mi> <mn>2</mn> </msup> <mo>+</mo> <msup> <mi>b</mi> <mn>2</mn> </msup> </mrow> <mo>=</mo> <msup> <mi>c</mi> <mn>2</mn> </msup> </mrow> </math> </body> </html> 


Notes: XHTML documents with MathML must be submitted as application/xhtml+xml . You can easily achieve this by adding the .xhtml extension to local files. For Apache servers, you can configure the .htaccess file for this extension to the correct MIME type. Since we saved our MathML as an XML document, you need to be sure of a well-formed XML document.





Browser Support

Browser Support



Full versions

ElementChromeFirefox (Gecko)Internet ExplorerOperaSafari
Xhtml description(only 24th)1.0 (1.7 and up)9.55.1
HTML5 description(only 24th)4.0 (2.0)5.1
dir12.0 (12.0)
hrefWebKit bug 857337.0 (7.0)WebKit bug 85733
mathbackground(only 24th)4.0 (2.0)5.1
mathcolor(only 24th)4.0 (2.0)5.1
overflow




Mobile Versions

ElementAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari mobile
Xhtml description1.0 (1.0)
HTML5 description4.0 (2.0)
dir12.0 (12.0)
href7.0 (7.0)
mathbackground4.0 (2.0)
mathcolor4.0 (2.0)
overflow






Gecko Core Features
Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4) introduced support for all MathML attributes for top-level elements (i.e., the same behavior as the <mstyle> element). However, the displaystyle attribute is not handled. Its support was added to Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5).



Alternative text descriptions ( alttext ) or links to an alternative image (attributes of altimg , altimg-width , altimg-height and altimg-valign ) are not currently implemented in Gecko.





Specifications
SpecificationStatusComment
MathML 3.0RecommendationCurrent specification
MathML 2.0RecommendationInitial specification




I hope the development of this necessary and useful tag will continue.



see also



Browser test for MathML support: here or here

Source: https://habr.com/ru/post/250981/



All Articles