This tutorial is designed to be a hands-on introduction to MathML, whichmeans its full of real-world examples for you to experiment with. To getstarted, create a new text file called hello-mathml.html
, open itwith your favorite text editor, and add the following code.
This empty HTML5 page will serve as our template for the rest of thetutorial. Code snippets from the upcoming sections can be pasted into the
element, and you should be able to open the page withyour browser to view the rendered mathematical notation.
Also notice the element that includes theMathJax library (no download required). If youre using a browser withMathML support, feel free to remove itbut, remember that this will makeyour content inaccessible to IE and Chrome.
Basic Algebra
Just as HTML uses tags to define headings and paragraphs, MathML uses themto describe the various parts of a mathematical expression. This moduleexplores the fundamental elements of MathML: variables, operators, radicals,and fractions. By the end of this module, you should be able combine these intobasic algebraic expressions.
While this tutorial focuses on Presentation Markup, not all of theelements well encounter are purely aesthetic. For instance, thei
in (discussed below) stands foridentifier, which is really more semantic than presentational.
As well see throughout this tutorial, typographic decisions oftencarry mathematical meaning. This makes it hard to draw a clear line betweenpresentation and content.
Variables
Well begin by creating a single variable with MathML. Replace the comment in the with the followingcode.
xmlns=
'http://www.w3.org/1998/Math/MathML'
display=
'block'
>
x
The tag begins a new MathML expression, and itshould always use the above URI for its xmlns
attribute. Thedisplay
attribute determines how the expression is rendered. Itsvalue can be either block
or inline
, as describedbelow.
Value | Description |
---|
block | Render the expression as its own paragraph |
inline | Render the expression in the same line as surrounding text |
Well use block
expressions for the majority of thistutorial, deferring inline elements to the module.
Next, the element defines a MathMLidentifier, which can be a function name, a constant, or avariable. In this case, we used the letter x
as theidentifiers value, which your browser should render as thefollowing.
Numbers
MathML uses the element to represent numericliterals, which can be either integers or real numbers (digits with a decimalpoint). Underneath our existing element, try addingthe following expression.
xmlns=
'http://www.w3.org/1998/Math/MathML'
display=
'block'
>
3 x
Notice that your browser rendered the number 3
with an uprightfont, while it decided the x
identifier should be italicized:
Even though were working with Presentation Markup, the and elements do carry semanticmeaning. This lets a MathML reader make certain assumptions about how totypeset their contents (e.g., italicizing variable names). Well learnhow to control these stylistic assumptions in .
Operators
For now, lets move on to the element formarking up operators. Again, the following expression should be added below theexisting examples in your hello-mathml.html
file.
xmlns=
'http://www.w3.org/1998/Math/MathML'
display=
'block'
>
3 x - 2 y
This example uses for a minus sign, but itsmeant to denote any kind of operator-like entity including=
, +
, , ,and even parentheses and commas. Explicitly delimiting operators helps MathMLviewers make important layout decisions like where to break lines.
Its important to note that traditional typography differentiateshyphens from minus signs, which are longer. In the above HTML code, we used ahyphen, but since we put it in an element, the browserinferred that we were trying to create a minus sign.
Operator Entities
To represent special symbols like minus signs, HTML offers several characterentities dedicated to mathematics. A few of the most common operators areincluded below.
Symbol | Entity | Hex | Description |
---|
Subtraction |
Multiplication |
Division |
Not equal |