Français

<mtext>

Add text inside a formula

  • MathML
  • accessibility
  • semantics

<mtext> — Text in the formula

The <mtext> element inserts readable text inside a MathML expression. It is used for labels ("if", "for all"), units ("kg", "m/s") or any textual annotation within a formula.

When to use it

You want to add a word or unit in a formula without it being interpreted as a variable. <mi>kg</mi> would be read as the product of two variables k and g. <mtext>kg</mtext> is read as the text "kg". Use <mtext> for anything that is not an identifier, a number, or a mathematical operator.

What you gain

Accessibility: screen readers read the content of <mtext> as ordinary text, distinct from variables and operators. The intent is clear.

Code example

<math display="block">
  <mrow>
    <mi>F</mi>
    <mo>=</mo>
    <mn>9.81</mn>
    <mtext>&nbsp;kg&#x22C5;m/s</mtext>
    <msup>
      <mrow></mrow>
      <mn>2</mn>
    </msup>
  </mrow>
</math>
 
<math>
  <mrow>
    <mi>x</mi>
    <mo>=</mo>
    <mn>1</mn>
    <mtext>&nbsp;if&nbsp;</mtext>
    <mi>n</mi>
    <mo>&gt;</mo>
    <mn>0</mn>
  </mrow>
</math>

Further reading