A Basic HTML Mathematics Article

Kyle Siegrist

Abstract

This article describes how mathematical notation can be incorporated into an HTML document. This article can be used as a basic template, along with the CSS style sheet and the JavaScript file.

Keywords

Subject classification

  1. 00 general
  2. 00A miscellaneous
  3. 00A20 reference works

Main Contents

  1. Introduction
  2. Mathematical Expressions
    1. Variables
    2. Images
    3. Inline Expressions
    4. Displayed Expressions
    5. Examples

Ancillary Materials

1. Introduction

This article describes how mathematical notation can be included in a basic HTML document. This article can be used as a basic template, along with the CSS style sheet and the JavaScript file. If you have not already done so, please read the introductory article Mathematics with Structure and Style for basic information on best practices, HTML, CSS, and JavaScript.

Recall that the first part of an HTML document contains declarations about the type of HTML used, the document type definition, and the type of encoding. Some of this information is necessary for HTML validators to work properly. We recommend that a basic mathematics HTML document be saved with the extension html and have the following initial declarations:

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
···

2. Mathematical Expressions

If your document contains extensive mathematical notation, you should considering using MathML, the Mathematics Markup Language. Please see the companion document A Basic Article with MathML for more information.

HTML provides some limited markup for mathematical expressions, notably <var></var> for a variable, <sub></sub> for subscript and <sup></sup> for superscript. For anything complicated, you need to use images, perhaps in conjunction with HTML markup.

Special mathematical symbols (Greek letters, arrows, operators, relations, etc.) can be displayed by using HTML entity names. An entity name always starts with & (ampersand) and ends with ; (semicolon), so that for example, &alpha; is the markup for the Greek letter α. The symbols that display correctly depend on the browser and platform, on installed fonts, and other issues. Please see the tables of mathematical symbols for more information.

2.1 Variables

Our style sheet subclasses the <var></var> tag to indicate a couple of different types of variables:

Of course, you can change the style attributes, if you don't like them and you can add more subclasses.

2.2 Images

Images of mathematical expressions should be marked as follows:

<img class="math" src="URL" alt="alternative text" title="tool-tip text" width="m" height="n" />

Most of these attributes are standard ones, but some have special purposes:

Please see the tables of mathematical symbols for common symbols in image form. You can download all of these symbols is compressed form to use in your documents.

2.3 Inline mathematical expressions

An inline mathematical expression using HTML and/or images should be enclosed in the <span class="math"></span> tag. This has two important effects. First, the expression becomes a well-defined "object" in the document, accessible through the DOM. Second, of course, we can control the appearance of the expression with our CSS style sheet. One important style attribute is white-space: nowrap; which prevents the expression from breaking across lines.

2.4 Displayed mathematical expressions

A single, displayed, unlabeled mathematical expression should be enclosed in the <p class="math"></p> tag. Again, the expression is a well-defined object, tagged as a mathematical object, and we can control how it looks. Our style sheet centers the expression and makes sure that it does not break across lines.

A displayed, labeled mathematical expression can be marked using a special class of the table element. For example, the first labeled equation might be marked as follows:

<table class="math" id="Equation1">
    <tr>
        <td class="label">(1)</td>
        <td class="math">mathematical expression</td>
    </tr>
</table>

Note that the label is anchored with an id attribute, so that you can link back to it. You can easily modify this basic construction for displayed mathematical expressions consisting of several lines.

2.5 Examples

Example 1

Elements of 3-dimensional Euclidean space R3 can be thought of as vectors of the form v = (x, y, z) where x, y, and z are elements of R. We will let B(R3) denote the Borel sigma-algebra; that is, the sigma-algebra generated by the open sets.

The mathematical expressions in this example are written in HTML; note the different types of variables used.

Example 2

A quadratic function has the form f(x) = ax2 + bx + c where a, b, and c are constants and a ≠ 0. The roots are given below, in Equation 1.

The mathematical expressions in this example are written in HTML; try resizing your browser window and note that the expressions do not break across lines.

Example 3

A polynomial function of degree n has the form, where a0, a1, ..., an are constants and an ≠ 0.

f(x) = a0 + a1x + a2x2 + · · · + anxn

Again, the mathematical expressions in this example are written in HTML. Try resizing your browser window and note that the expressions does not break across lines.

Example 4

The quadratic equation a x^2 = b x + c has roots given by

(1) \frac{-b \+- \sqrt{b^2 - 4 a c}}{2a}

Note that the mathematical expressions in this example are images. Rest your cursor on the images to see the tool-tip description. Look at the properties of the image or the source code to see the alternative text in LaTeX.