Skip to content Skip to navigation

Connexions

You are here: Home » Content » Preparing for writing MathML

Navigation

Content Actions

  • Download module PDF
  • Add to ...
    Add the module to:
    • My Favorites
    • A lens
    • An external social bookmarking service
    • My Favorites (What is 'My Favorites'?)
      'My Favorites' is a special kind of lens which you can use to bookmark modules and collections directly in Connexions. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need a Connexions account to use 'My Favorites'.
    • A lens (What is a lens?)

      Definition of a lens

      Lenses

      A lens is a custom view of Connexions content. You can think of it as a fancy kind of list that will let you see Connexions through the eyes of organizations and people you trust.

      What is in a lens?

      Lens makers point to Connexions materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

      Who can create a lens?

      Any individual Connexions member, a community, or a respected organization.

    • External bookmarks
  • E-mail the author

Recently Viewed

Preparing for writing MathML

Module by: Sunil Kumar Singh

This course heavily relies on practicing codes in MathML. For this reason, a frame work enabling practice in desktop environment is planned, which does not require any specialized tool or software. The requirement for practicing MathML is two fold : (i) a text editor that composes code lines as plain text without introducing any formatting characters and (ii) a browser that is capable to implement MathML.

It is recommended to use an advanced text editor like MS Word to handle the first task. We shall use it in a specialized mode to serve our purpose. Use of advanced text editor, as against editors designed to save file as plain text like notepad available on Windows platform, is recommended. This preference is mainly owing tot to the advanced editing facilities available and the ease of inserting mathematical symbols available in professional text editor. Subsequently, we shall also learn to use macros available with advanced editors to replicate basic code blocks.

The other issue of using a MathML enabled browser is extremely important as mathML rendering would ,otherwise, be severely distorted. Most of the advanced browser has inherent capability in this regard or with available plug-ins. This aspect, however, may not be overlooked for implementation of MathML features in its complete manifestation – particularly when such browsers are available free and takes less than 5 minutes to install on the desktop.

We must understand that MathML specifications are W3C guidelines for the renderer (the product or program that displays content like browsers). It is, therefore, always likely that there are differences in details in the style of presentation by different browsers – even though they are MathML compatible. Notwithstanding the subtle differences, the browsers should be capable to implement MathML codes and hence the requirement of one such to experiment with MathML codes.

Further, we need a separate folder to work with the tutorials and experiment with MathML codes. In the following paragraphs, we enlist precise instructions to prepare the enviorment for MathML code testing :

1: Create a separate working folder for experimenting with the mathML codes (say C:/MathML/testing).

2: In case, you do not have MathML compatible browser already installed on your desktop, download Mozilla Firefox form www.mozilla.org . Install the same by double clicking the Firefox executable setup file. While installing, let the set up program fetches your preferences and other parameters from the browser already installed on the desktop. The set up program shall eventually ask you to whether set Firefox as the default browser on your desktop. For the time being, you may choose to retain the already installed browser as the default one.

2: Ensure that all fonts required for rendering MathML is installed on your computer. In case, you are using Mozilla browser, visit Mozilla web page http://www.mozilla.org/projects/mathml/fonts/. The page lists “Fonts to Install”. Click the “font installer” hyper link and download the font installer on your desk top. Once the installer is downloaded, just open the same to install the fonts.

3: Visit www.w3.org/Math/testsuite . It gives you vast array of MathML examples to work with. The website provides codes of hundreds of examples. At certain stage of this course, you may like to copy and paste the codes to your desktop to confirm results. Besides, it is a repository of about 900 entity references used to display symbols and implement mathematical ideas. On the testsuite web page, click the link named "testsuite.zip" to download the same in the desktop folder created for the course. Store the zip file for use in future.

Note:

The official documentation of mathML is available at W3C web site www.w3.org/TR/MathML2 .

Creating a mathML enabled document

Here, we present the steps to generate MathML codes in MS Word desktop editor. The idea right now is not to explain MathML codes, but to show the way to create a proper document with MathML codes and implement the same in the MathML enabled browser on your desktop.

As the codes need to be free from formatting details and other encoding, the file created is saved as plain text with Unicode(UTF-8) specification. As such, the file should be saved as plain text file with extension “xml” in order to view the implementation in the browser.

Once the document has been created, the same can be tested in MathML supported browser like Mozilla’s Firefox. When MathML codes display the output to the satisfaction, then block of codes starting with <m:math> tag and ending with </m:math> tag can be copied and pasted in the XML document for publication purposes or be saved for future use. Now, proceed with the steps given here to create a mathML enabled “xml” document.

1: Open MS Word. Open a new document. Write exactly or copy/paste the following markup lines in the new document :


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE math 
    PUBLIC "-//W3C//DTD MathML 2.0//EN"
           "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"
>

<document xmlns:m="http://www.w3.org/1998/Math/MathML">


</document>
	  

2: Write the next top most “xml” element of the document between “document” tags.


<content> 


</content>
	  

Note that “document” and “content” are the only XML elements i.e. the pair of tags, used for practicing MathML code. All other code lines, as detailed below, shall be MathML codes.

3: Write “math” MathML element between “content tags” with an example coding to display mathematical construct : v = AB t v = AB t .

4: For the time being, write exactly or copy / paste the code lines as given below and place them between “content” tags :

Example 1: Displaying mathematical content


	    
  <content>
    <m:math display="block">
           <m:mrow> 
              <m:mi mathvariant="bold">v</m:mi>
              <m:mo>=</m:mo> 
              <m:mfrac> 
                <m:mi mathvariant="bold">AB</m:mi>
                <m:mi>t</m:mi>
              </m:mfrac> 
          </m:mrow>
     </m:math> 
  </content>
	    
	  

5: Click File from Word’s top menu and select “save as”. A dialog box appears. Look at the "Save as type" option. Select “Plain Text” option from the drop down menu. Give a name to the file such as “test.xml”. Ensure that you have provided “xml” extension. Click “Save” button available at the right hand corner (also visible in the figure below).

Figure 1: Select “plain text” from drop-down and give a name with xml extension
Saving options
Saving options (savingoption.JPG)

6: "File Conversion" dialog box appears as shown below. Select the radio button “Other encoding”; Select “Unicode(UTF-8)” option as shown. Click “OK” button. Save the document to the folder you have created for the tutorial.

Figure 2: Select “other coding” radio button and "Unicode(UTF-8)" option
File conversion
File conversion (fileconversion.JPG)

7: Using “My Computer” or Window Explorer go to the tutorial folder, where you saved the document in earlier step. Select the file and right click the mouse. Select the option “open with”.

Figure 3: Select “Open with” from drop-down and select the mathML compatible browser
Opening with mathML enabled document
Opening with mathML enabled document (openingwithfirefox.JPG)

8: If MathML compatible browser is not in the list, select “Choose program” and include the browser that you have downloaded for the purpose. The executable file of the MathML compatible browser must be in the “Program files” folder on your desktop.

9: The mathML code is implemented by the browser as shown below :

v = AB t v = AB t

This completes the basic of creating a “xml” document to implement MathML codes. Subsequently, when you are satisfied by the implementation, you may copy the MathML code lines and paste the same in the document to be published.

Context of MathML

Presentation of mathematical content has been a problem for text editors and web renderers, owing largely to the requirement of (i) arrangement of characters and symbols of different sizes (ii) their staggered alignment and (iii) overall structural arrangement different form normal text. As a consequence, MathML markup has been developed to address the needs of the web authors, overcoming these requirements.

The marking up of MathML tags, however, itself is inherently a lengthy and error prone proposition, requiring frequent and repeated testing in order to compose a “well formed” mark up code. A simple notation such as x 10 x 10 may require 6 lines of coding with strict adherence to the syntax and grammar of the mark up language.

Indeed, development of MathML is not targeted for direct use. In the language of Web Consortium (W3C) “……….. Instead, it is anticipated that authors will use equation editors, conversion programs, and other specialized software tools to generate MathML. Alternatively, some renderers and systems supporting mathematics may convert other kinds of input directly included in Web pages into MathML on the fly, in response to a cut-and-paste operation…….”.

Though, using tailored software is the easiest way around, but a general understanding of the mathML mark up language may let you grasp the environment of mathematical content publication and at the same time let you be independent of the individual software adaptation issues; while simultaneously letting you continue with developing codes in an organized and efficient manner. If you adapt well to the MathML, there is every chance that you might not use a specialized tool at all.

General features of mathML coding

1: MathML tries to capture the requirement of both presentation and content (meaning) of mathmatical expression. Take the example of trigonometric function “sin x”. Simply stated it is an identifier “sin” and a character “x”, which are separated by a white space. From the perspective of mathematics, however, “sin” is a function, which operates on an operand “x”. The two aspects are different when perceived from the angle of presentation and interpretation. MathML provides coding frame work for both these aspects through two different sets of mark-up called “Presentation” and “Content” mark-ups. As pointed out earlier, we would, however, be limited to the presentation mark-up.

2: MathML elements are preceded with “m:”, specifying the namespace for implementing the codes by the renderers i.e. browsers. A namespace associates a unique global identifier (usually a URL) with a particular set of tags and their usage rules.

3: MathML coding is case sensitive. Mostly, it is lower case coding, unless stated otherwise.

4: MathML markup adheres to the HTML markup structure. Most elements begin with a start tag and end with an end tag. Example : </m:mi>a</m:mi>. Ofcourse, there are also few empty tags.

5: MathML implementation is very touchy about the syntax and structure. A start tag must always be closed by an end tag. There are few varieties in the manner they are closed, but then they all must be closed. Empty elements, for example, are closed in the beginning itself.

6: There is no white space allowed between enclosing angles of a tag. The code parser i.e. the browser would not accept a space inside the angles of the tag like < mi>. It should be written without white space as <mi>.

Comments, questions, feedback, criticisms?

Send feedback