<semantics>
The <semantics> MathML element associates annotations with a MathML expression, for example its text source as a lightweight markup language or mathematical meaning expressed in a special XML dialect. Typically, its structure is
- a first child which is a MathML expression to be annotated.
- subsequent
<annotation>or<annotation-xml>elements, the latter being reserved for XML formats such as OpenMath.
By default, only the first child of the <semantics> element is rendered while the others have their display set to none.
注意: 傳統的 MathML 規範允許渲染器根據可用的註釋決定預設渲染方式。以下確定可見子節點的規則已在某些瀏覽器中實現。有關 Presentation 和 Content MathML 之間的區別,請參閱 MathML 4。
- 如果沒有任何其他規則適用:預設情況下,僅渲染第一個子節點,該子節點應該是 Presentation MathML。
- 如果第一個子節點是 Presentation MathML 元素(
<annotation>或<annotation-xml>除外),則渲染第一個子節點。 - 如果沒有找到 Presentation MathML,則渲染
<semantics>的第一個<annotation>或<annotation-xml>子節點元素,這些元素沒有src屬性。對於<annotation-xml>元素,encoding屬性必須等於以下值之一"application/mathml-presentation+xml""MathML-Presentation""SVG1.1""text/html""image/svg+xml""application/xml".
請注意,這裡沒有提到 "application/mathml+xml",因為它不區分 Content 或 Presentation MathML。
屬性
<semantics>、<annotation> 和 <annotation-xml> 元素接受 全域性 MathML 屬性。此外,可以在 <annotation> 和 <annotation-xml> 元素上設定以下屬性
示例
html
<math display="block">
<semantics>
<!-- The first child is the MathML expression rendered by default. -->
<mrow>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo>
<mi>y</mi>
</mrow>
<!-- Annotate with "Content MathML", a dedicated XML dialect to
express the meaning of mathematical formulas. -->
<annotation-xml encoding="MathML-Content">
<apply>
<plus />
<apply>
<power />
<ci>x</ci>
<cn type="integer">2</cn>
</apply>
<ci>y</ci>
</apply>
</annotation-xml>
<!-- Annotate with a PNG image of the formula. -->
<annotation encoding="image/png" src="some/path/formula.png" />
<!-- Annotate with LaTeX, a lightweight markup language to write
mathematical formulas. -->
<annotation encoding="application/x-tex"> x^{2} + y </annotation>
</semantics>
</math>
規範
| 規範 |
|---|
| MathML Core # semantics-and-presentation |
瀏覽器相容性
BCD 表僅在瀏覽器中載入