ASCIIMath Tutorial

ASCIIMath Tutorial

James Gray - The Open University

This tutorial and accompanying symbol list introduce the ASCIIMath notation and some points of good practice in writing mathematics. To display the mathematics correctly, this page requires Internet Explorer 6 with MathPlayer installed, or Mozilla/Firefox/Netscape 7+ with MathML fonts installed (e.g. download the MIT MathML font packages). If you have these installed you should see a familiar formula here:

`x=(-b +- sqrt(b^2 - 4ac))/(2a)`

1. Words and Equations

ASCIIMath works by transforming the text you type into mathematics. To see how it works, type this text

Note:
The \` key is normally next to the 1 key on the keyboard.
    The area of a triangle with base `b` 
    and height `h` is `1/2 bh`. The area 
    of a circle with radius `r` is `pi r^2`.

into this text box:



It is also possible to put the mathematics between dollar signs like this: \$E=mc^2\$. There is no difference in the output.

As you type, the output appears in the grey coloured area next to the text entry box. We want to type mathematics and text, so to indicate mathematics we enclose it between left-quotes, like this: \`E=mc^2\`. Because you type the mathematics directly, it is quick and easy to include a lot of mathematics in your text.

It is easier to read longer formulae if you put them on a separate line, as you can see in the text box below (and the output to the right). Take a look at any standard mathematics book to see the use of mathematics in the text and on separate lines.

Einstein's famous formula is

`E=mc^2`,

where `E` is energy, `m` is mass and `c` is the speed of light.

Try removing the blank lines above and below the equation in the text box above. After doing this, the equation will no longer appear on a separate line in the output. This is intentional, as sometimes you will want to type an equation on a separate line (for easy editing) without that occurring in the output.

2. Symbols

If you need to use a mathematical symbol, look it up in the symbol list. ASCIIMath has standard functions predefined, so to get `sin x` just type \`sin x\` and `ln x` type \`ln x\`.

Remember left-quotes (i.e. \`) are used to indicate mathematics.

Greek letters are produced by typing the name of the letter, e.g. \`alpha\` gives `alpha` and \`beta\` gives `beta`. To get capital Greek letters, capitalise the first letter of the name, e.g. \`Sigma\` gives `Sigma`, whereas \`sigma\` gives `sigma`.

For addition and subtraction, just use the symbols on the keyboard. For division, type \`3 -: 4\` to get `3-: 4` or \`3//4\` to get `3//4`. There are several symbols for multiplication and these are shown in the box below.

Typing `2xx7 = 14` and `2 times 7 =14` gives the same output.

You might also want to write this as `2*7=14` or even `2**7=14`.

Type the following expressions, referring to the symbol list if necessary.

`\ \ \ \ \ ` `int cos x dx` `\ \ \ \ \ \ \ \ ` `f @ g (x)` `\ \ \ \ \ \ \ \ ` `x in RR` `\ \ \ \ \ \ \ \ ` `phi: A -> B`


To check your answers, hang the mouse pointer over one of the expressions above. After a couple of seconds a box will appear showing the ASCIIMath used to type the expression. You can always use this to see the ASCIIMath.

3. Indices, subscripts, fractions and brackets

Notice the brackets in \`e^(2x)\` don't appear in the output `e^(2x)`. In the expression `f^((3)) (x)` for the third derivative of `f`, we want the brackets to appear so we type \`f^((3))(x)\`.

To get an index we use the symbol ^, so for example \`x^2\` gives `x^2`. An index that is anything other than a number or a single letter requires brackets. So to get `e^(2x)` we type \`e^(2x)\`, because \`e^2x\` gives `e^2x`. However \`p^32\` gives `p^32` and \`x^alpha\` gives `x^alpha`.

The symbol _ is used for subscripts and they work in the same way as indices. So \`x_10\` gives `x_10` and it is necessary to use brackets in \`x_(ij)\` to get `x_(ij)`.


Remember you can check your answers by hanging the mouse over the expression.

Use the text box to type the expressions below.

`\ \ \ \ ` `e^x` `\ \ \ \ ` `pi^2` `\ \ \ \ ` `(x + 1)^2` `\ \ \ \ ` `x^3 + 4x^2 - 5` `\ \ \ \ ` `a_(nm)` `\ \ \ \ ` `x_2^3`


The index and subscript notation is used to put the upper and lower limits on integrals and sums, as in the examples below.

`sum_(k=1)^n k = 1+2+ cdots +n=(n(n+1))/2`

`int_0^1 x^2 dx`

As you can see above, the symbol \`/\` is used for fractions. Unless they are very simple expressions, the denominator and numerator must be enclosed in brackets (which don't appear in the output). So, for example

`\ \ \ \ ` `1/(x+1)`

is achieved by typing \`1/(x+1)\`. What do you think would be produced by typing \`1/x+1\`?

Both \`x_n/10\` and \`(x_n)/(10)\` give the same output, so sometimes it is not necessary to use brackets. Try typing the following expressions and experiment with using/missing out brackets to produce the same output.

`\ \ \ \ ` `(x+1)/(x+1)` `\ \ \ \ ` `(x+1)/x^2` `\ \ \ \ ` `1/3245` `\ \ \ \ ` `dy/dx` `\ \ \ \ ` `(ab)/(cd)`


Remember that we can get a one line fraction by using //.

You may wish to use this for fractions that appear as indices, because it is easier to read `e^(x//2)` than `e^(x/2)`.

Finally, use \`sqrt(x)\` for `\sqrt(x)` and \`root(x)(y)\` for `root(x)(y)`. Use the box below to type the formula for the solutions of the equation `ax^2+bx+c=0`, where `a !=0`.


[Hint: the formula appears at the top of this page and you may need to use the symbol list.]

4. Spaces, multiple lines and text

In some browsers, the words quad and qquad will produce longer spaces than a backslash and a space.

ASCIIMath should generate spaces that are about right in the output, but if you want to get an extra space in the mathematics you can use a backslash and a space i.e. \`\ \`. Extra spaces are especially useful when you want to put more than one expression on a line, as in the example below.

We set

`a=3, \ \ \ b=-3,\ \ ` and `\ \ c=2`.

Thus `(a+b)(c+b)=0`.

Notice that the punctuation of the sentence appears in the middle line even though it is mainly mathematical formulae. When beginning to type mathematics it might feel strange to include punctuation, but it is important to do so.

When answering questions that require several lines of working you may like to follow the format of the example below. Because the second, third and fourth lines have been indented it makes it clear that all lines are equal to `x`.

Using the quadratic formula, the roots of `x^2-6x+4=0` are

`x = (-6 +- sqrt((-6)^2 - 4 (1)(4)))/(2 xx 1)`

`\ \ = (-6 +- sqrt(36 - 16))/2`

`\ \ =(-6 +- sqrt(20))/2`

`\ \ = -0.8 or 2.2 \ \ \ `to 1 decimal place.

There is a full stop at the end of the last line in this example because it is at the end of a sentence, albeit a sentence with a lot of mathematics in it.

On the last line in the example above we have used the word "or". ASCIIMath recognises the words "or", "and" and "if". Any other words need to be enclosed in inverted commas or using \`text(some words)\`. Try removing the inverted commas in the example below to see their effect.


`sin = "opp"/"hyp" \ \ \ and \ \ \ cos = text(adj)/text(hyp)`.

5. Matrices and advanced alignment

The ASCIIMath notation for matrices is demonstrated below.

A `3xx3` matrix,`((1,2,3),(4,5,6),(7,8,9))`, and a `2xx1` matrix, or vector, `((1),(0))`.

The outer brackets determine the delimiters e.g. `|(a,b),(c,d)|=ad-bc`.

A general `m xx n` matrix `((a_(11), cdots , a_(1n)),(vdots, ddots, vdots),(a_(m1), cdots , a_(mn)))`

Alter the text in the box above so that it starts with

`\ \ \ \ \ `A `3 xx 2` matrix ,`((1,2),(3,4),(5,6))`,...

In the general `m xx n` matrix, we used \`cdots\` for centred dots. This can be useful when writing infinite series, for example

`e^x = 1+x+1/(2!)x^2 + 1/(3!)x^3 + cdots `.

Similarly, for low dots, as in `1, ldots, n` use \`...\` or \`ldots\`.

The matrix notation can be used for aligning material. When doing this, we will want to draw matrices without delimiters. For this purpose, we can type \`{:\` and \`:}\` to get invisible brackets. This is necessary when defining a function by cases.

`|x|= {(x , if x ge 0 text(,)),(-x , if x <0.):}`

Notice the use of \`text( )\` round the comma after `x ge 0` to indicate that it really is a comma and not part of the matrix syntax. Try to write the matrix below and then try to write the function definition using a matrix with two invisible brackets.

You can look up symbols in the symbol list.

`((1,2,3,4),(a,b,c,d))` `\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ` `{:(f:,[0,6], ->, RR),( ,x ,|->, x^2+1):}`


Acknowledgements

The ASCIIMath syntax and javascripts were developed by Peter Jipsen (Chapman University). Further information can be found at the ASCIIMath Homepage.

The javascripts for this page were adapted from Peter Jipsen's ASCIIMath email editor by Keith Brunton at Edinburgh University.