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:
block
- means that this element will be displayed outside the current text range, as a block that can be located anywhere without changing the meaning of the text;inline
means that this element will be displayed within the current text range, and cannot be moved from it without changing the value of this text.
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
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 SupportBrowser Support
Full versions
Element | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|
Xhtml description | (only 24th) | 1.0 (1.7 and up) | | 9.5 | 5.1 |
HTML5 description | (only 24th) | 4.0 (2.0) | | | 5.1 |
dir | | 12.0 (12.0) | | | |
href | WebKit bug 85733 | 7.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
Element | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari mobile |
---|
Xhtml description | | | 1.0 (1.0) | | | |
HTML5 description | | | 4.0 (2.0) | | | |
dir | | | 12.0 (12.0) | | | |
href | | | 7.0 (7.0) | | | |
mathbackground | | | 4.0 (2.0) | | | |
mathcolor | | | 4.0 (2.0) | | | |
overflow | | | | | | |
Gecko Core FeaturesGecko 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.
SpecificationsSpecification | Status | Comment |
---|
MathML 3.0 | Recommendation | Current specification |
MathML 2.0 | Recommendation | Initial specification |
I hope the development of this necessary and useful tag will continue.
see also
Browser test for MathML support:
here or
here