<math>

1 位贡献者:

翻译正在进行中。

MathML的顶级元素是<math>。所有有效的MathML实例必须被包括在 <math> 标记中。另外不可以在一个 <math> 元素中嵌套第二个 <math> 元素,但是 <math> 元素中可以有任意多的子元素 。

属性

除了以下提到的属性, <math> 元素接受所有 <mstyle> 元素的属性。

class, id, style
用于配合样式表使用。
dir
公式的整体方向。取值可以是 ltr (从左到右) 或者 rtl (从右到左).
href
用于给公式设置一个超链接的URI。
mathbackground
背景颜色。你可以使用#rgb格式、 #rrggbb 格式和 HTML颜色名
mathcolor
公式的文本颜色。你可以使用#rgb格式、 #rrggbb 格式和 HTML颜色名
display
This enumerated attribute specifies how the enclosed MathML markup should be rendered. It can have one of the following values:
  • block, which means that this element will be displayed outside the current span of text, as a block that can be positioned anywhere without changing the meaning of the text;
  • inline, which means that this element will be displayed inside the current span of text, and cannot be moved out of it without changing the meaning of that text.

If not present, its default value is inline.

mode
Deprecated in favor of the display attribute.
Possible values are: display (which has the same effect as display="block") and inline.
overflow
Specifies how an expression behaves if it is too long to fit in the allowed width.
Possible values are: linebreak (default), scroll, elide, truncate, scale.

Examples

Theorem of Pythagoras

HTML5 notation

<!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 notation

<?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 served as application/xhtml+xml. You can achieve that easily by adding the .xhtml extension to your local files. For Apache servers you can configure your .htaccess file to map extensions to the correct Mime type. Since you notate your MathML in an XML document, also be sure you write a well-formed XML document.

Specifications

Specification Status Comment
MathML 3.0
The Top-Level math Element
Recommendation Current specification
MathML 2.0
The Top-Level math Element
Recommendation Initial specification

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
XHTML notation 未实现 1.0 (1.7 or earlier) 未实现 9.5 5.1
HTML5 notation 未实现 4.0 (2.0) 未实现 未实现 5.1
dir 未实现 12.0 (12.0) 未实现 未实现 未实现
href 未实现 7.0 (7.0) 未实现 未实现 未实现 [1]
mathbackground 未实现 4.0 (2.0) 未实现 未实现 5.1
mathcolor 未实现 4.0 (2.0) 未实现 未实现 5.1
overflow 未实现 未实现 未实现 未实现 未实现
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
XHTML notation 未实现 未实现 1.0 (1.0) 未实现 未实现 未实现
HTML5 notation 未实现 未实现 4.0 (2.0) 未实现 未实现 未实现
dir 未实现 未实现 12.0 (12.0) 未实现 未实现 未实现
href 未实现 未实现 7.0 (7.0) 未实现 未实现 未实现 [1]
mathbackground 未实现 未实现 4.0 (2.0) 未实现 未实现 未实现
mathcolor 未实现 未实现 4.0 (2.0) 未实现 未实现 未实现
overflow 未实现 未实现 未实现 未实现 未实现 未实现

[1] See bug 85733.

Gecko-specific notes

Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4) introduced support for accepting all MathML attributes on the top-level math element (i.e. the same behavior as a <mstyle> element). However, the displaystyle attribute was not taken into account and has been added in Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5).

A textual fall-back (alttext) or referring to an alternative image using the attributes altimg, altimg-width, altimg-height or altimg-valign is currently not implemented in Gecko.

See also

文档标签和贡献者

向此页面作出贡献: linmx0130
最后编辑者: linmx0130,