Arabic mathematical notation

W3C Interest Group Note 31 January 2006

This version:
Latest version:
Previous version:
This is the first version
Azzeddine Lazrek, with Mustapha Eddahibi and Khalid Sami, Cadi Ayyad University - Marrakech, Morocco
Bruce R. Miller, National Institute of Standards and Technology, USA

This document is also available in these non-normative formats: XHTML+MathML version.


This Note analyzes potential problems with the use of MathML for the presentation of mathematics in the notations customarily used with Arabic, and related languages. The goal is to clarify avoidable implementation details that hinder such presentation, as well as to uncover genuine limitations in the specification. These limitations in the MathML specification may require extensions in future versions of the specification.

Status of this Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This Note is a self-contained discussion of Arabic mathematical notation in MathML. It provides guidelines for the handling of Arabic mathematical presentation using MathML 2 Recommendation (2nd Edition) [MathML22e] and suggests extensions for a future revision.

This Note has been written by participants in the Math Interest Group (W3C members only) which is part of the W3C Math activity. Please direct comments and report errors in this document to www-math@w3.org, a mailing list with a public archive.

Publication as a Interest Group Note does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

Table of Contents

1 Introduction
2 Some Features of Arabic Script
    2.1 Text Direction
    2.2 Glyph Shaping
    2.3 Mirroring
    2.4 Number Systems
3 Comparison of Mathematical Notations
    3.1 Arabic Notation; Moroccan Style
    3.2 Arabic Notation; Maghreb Style
    3.3 Arabic Notation; Machrek Style
    3.4 Additional Arabic Notations
    3.5 Persian
4 Proposals and Clarifications
    4.1 Clarification of bidirectional Algorithm for MathML
    4.2 Glyph Shaping
    4.3 Additional Mathvariants
    4.4 Mirroring
    4.5 Horizontal Stretchiness
    4.6 Additional Constructs
5 Conclusions and Future Work
6 Acknowledgments
7 Production Notes


A Localization Issues
    A.1 Number Systems
    A.2 Symbols Choice
B Implementation Issues
    B.1 Character Encoding
    B.2 Mathematical Fonts
    B.3 Symbol Stretching
    B.4 Software Tools
C Bibliography

1 Introduction

As the World Wide Web becomes more world wide, inclusion of the world's many languages, scripts and cultures becomes critical. Although the development of the Mathematical Markup Language (MathML) [MathML22e], was neither intentionally nor explicitly exclusive of non-European languages and scripts, the focus was on the notational schema used with European languages. Indeed, most of these notations are used unchanged in many other contexts. However, there are variations introduced in some languages, either for historical reasons, or to fit within various writing systems, which MathML should accommodate for improved international support (in particular educational material requiring these variations, or historical documents).

While European languages are written left to right (LTR), Arabic, among others, is written right to left (RTL). We will see that in Arabic mathematical texts many of the same notational constructs are used, but may be reversed or mirrored, depending on the cultural context; what we will call a mathematical directionality. The mathematical directionality is not necessarily the same as the text directionality. Moreover, since the mathematical material may commonly contain text and symbols coming from both Arabic and European languages, the question of how the Unicode bidirectional algorithm [UnicodeBiDi] should be applied arises. Finally, several additional symbols and writing styles may be used in special ways.

[Arabic Script samples]

Arabic Calligraphy is enriched by a variety of writing styles, as European writing benefits from a variety of fonts. The graphic above illustrates a variety of Arabic calligraphic styles; each word is the name of the corresponding style. In the same way that European mathematics broadens the set of distinct symbols available by using bold face, Fraktur or other styles, so does Arabic mathematics but typically by varying strokes, adding tails or other extensions.

A given piece of mathematics marked up in Content MathML ([MathML22e], chapter 4), is generally language-neutral — although the choices for variable names may imply a cultural context — it intends to represent the universal meaning of the mathematics. A given piece of mathematics marked up in Presentation MathML ([MathML22e], chapter 3), on the other hand, conveys the visual appearance of the expression. That appearance necessarily targets a specific language and notational conventions, indeed even of the scientific discipline involved. In this Note, we amplify and formalize this segregation of concerns: Presentation MathML should be a fairly literal representation of the visual notation to be used.

We relegate all localization issues — which symbol to use for summation, which name to use for tangent, what format to use for numbers — to the generator of the Presentation MathML, rather than the renderer. This avoids guessing, perhaps wrongly, what number is intended while deciding whether to replace periods by commas, for example. Thus, localization entails the choice of what text content to place within MathML's token elements, but that choice is already fixed within a given piece of Presentation MathML.

In this Note, we have attempted to examine all notational conventions in current use with Arabic and languages written using Arabic script, without giving preference to one form over another. We aim to clarify the specification of MathML, proposing extensions where needed, so that MathML has the broadest coverage possible. Nevertheless, an in-depth analysis of issues affecting other languages, particularly those written top to bottom is a topic for future study. The emphasis on Arabic languages is partly a reflection of an increased interest in, and usage of, MathML in Arabic language contexts that have highlighted the issues described here. Another topic for future study is how Content MathML might best support the transformation to appropriately localized Presentation MathML.

2 Some Features of Arabic Script

Before delving into mathematical notations, it will help to describe some of the features of Arabic script, and how Unicode deals with these features.

2.1 Text Direction

While European languages are written from left to right (LTR), Arabic is written from right to left (RTL). Unicode supports these scripts by not only defining codepoints for the individual characters of these languages, but by recording the directionality of each character.

When a mixture of LTR and RTL characters appear in text (ie. bidirectional or BiDi text, such as an English text that includes Arabic words), Unicode's bidirectional algorithm [UnicodeBiDi] describes the order in which the characters will be displayed. All adjacent strongly-typed RTL characters (such as a in a single Arabic word) will be presented in right-to-left order, and vice versa for strongly-typed LTR characters. A cluster of characters with the same directionality is called a directional run.

Within any given "paragraph", directional runs are then ordered according to the overall directional context. The bidirectional algorithm allows for higher-level protocols to determine which segments of a structured text constitute "paragraphs" in this sense. For example, in HTML block-level elements are taken as the paragraph segments. The top-level html tag determines the directional context which can be changed on lower-level elements using the dir attribute.

For a gentle introduction to bidirectional text, see [UnicodeBiDiIntro].

2.3 Mirroring

Some characters, viewed abstractly, have the same meaning in many languages, but the form used in RTL languages are the roughly the mirror image of the form used in LTR languages. Parentheses and quotation marks are such characters. Unicode deals with these cases by marking some codepoints as mirrored, meaning that an alternate glyph will be used for the character if it appears in a RTL context.

Note that mirrored symbols are not required by Unicode (See Mirroring in [UnicodeBiDi], section 6) to be literally the exact mirror image. Indeed, it is considered an important point of Arabic calligraphy that they are not: the feather's head (kalam) is a flat rectangle. The writer holds the pen so that the largest side makes an angle of approximately 70° with the baseline. This orientation is kept throughout the process of drawing the character. Furthermore, as Arabic writing goes from right to left, some boldness is produced around segments running from top left toward the bottom right and conversely, segments from top right to the bottom left will rather be slim. Thus, the Arabic sum symbol Arabic Sigma, for example, is not simply the mirror image Mirrored Sigma of sigma Sigma.

2.4 Number Systems

There are several decimal numeral systems in use in Arabic:

EuropeanU0030-U00390123456789Maghreb Arab (eg. Morocco), as well as European
Arabic-IndicU0660-U0669٠١٢٣٤٥٦٧٨٩[Image of Arabic-Indic Digits]Machrek Arab (eg. Egypt)
Eastern Arabic-IndicU06F0-U06F9۰۱۲۳۴۵۶۷۸۹[Image of Eastern Arabic-Indic Digits]Iran

3 Comparison of Mathematical Notations

We will explore the spectrum of notations by choosing some samples of mathematical content and comparing how they would typically be rendered for different languages and cultures. We begin with an expression formatted as it might be seen in both English and French contexts.

English[Image of formula in English style] f ( x ) = { i = 1 s x i if  x < 0 1 s x i d x if  x S tan π otherwise  ( with  π 3.141 )
French[Image of formula in French style] f ( x ) = { i = 1 s x i si  x < 0 1 s x i d x si x E tg π sinon  ( avec  π 3,141 )

Structurally, the expressions are identical. The differences in names, number formatting and of course the language used for the connecting words are all due to localization. They are effected purely by differing textual content within the MathML token elements.

In the following sections, we will examine three common styles used for mathematics within Arabic texts. The terms Moroccan, Maghreb and Machrek will be used to indicate the general geographic areas where these styles are used, but there are no clearly defined borders between the regions.

3.1 Arabic Notation; Moroccan Style

The current way of writing mathematical expressions in Morocco, is closely related to the French style:

Moroccan[Image of formula in Moroccan style] f ( x ) = { i = 1 s x i إذاكان  x < 0 1 s x i d x إذاكان  x E tg π غيرذلك  ( π 3,141 مع )

Although the mathematics would be embedded within a RTL language (Arabic), its directionality is still LTR. The connecting words and phrases within the math, however, are RTL Arabic, and should be subject to glyph shaping (although some current MathML renderers are not doing this). Thus these phrases should appear as "إذاكان" (for "if"), "غيرذلك" (for "otherwise") and "مع" (for "with").

Also, the indication is that the bidirectional algorithm [UnicodeBiDi] should be applied to individual text and token elements, rather than at a higher level as in HTML; that is, the token elements act as paragraph segments. Even with these considerations, the ordering of phrases within the last clause (for "otherwise (with pi=3.141)") is problematic. The obvious markup sandwiching an mrow for "pi=3.141" between two mtext's for "otherwise (with" and ")", respectively, would yield an incorrect ordering. A correct rendering seems to require the possibility of embedding math within mtext, which is not possible in MathML 2.0. But even then, the desired ordering would need to be marked up as two separate mtext elements: one for "otherwise", and one for "(with pi=3.141)". The Math Interest Group is currently considering the possibilities of such embedding. The example above was marked up by artificially placing the Arabic word for "with" after the "pi=3.141".

Given such issues, it is sometimes advantageous to minimize the use of connecting phrases, with preference to simple punctuation, such as:

Moroccan[Image of simplified formula in Moroccan style] f ( x ) = { i = 1 s x i x < 0 1 s x i d x x E tg π ( π 3,141 )

4 Proposals and Clarifications

4.1 Clarification of bidirectional Algorithm for MathML

The following summarizes how directionality should be applied to MathML and, in particular, describes how the bidirectional algorithm should be applied (it falls into class HL4; See Higher Level Protocols: HL4 in [UnicodeBiDi], section 4.3).

  • The overall mathematical directionality should be determined by a (new) dir attribute on the outermost math element which takes one of the values ltr or rtl; the default is ltr. If this attribute is rtl the layout of all Layout, Script, Limit, Table and Matrix schemata should proceed from right to left. This includes such effects as the surd of an mroot starting from the right. When the mathematical directionality is ltr, the layout should conform to the current MathML specification.

  • The text content of each Token element should be treated as a separate directional segment and the bidirectional algorithm should be applied to each independently. The initial directional context for each Token element is determined by the mathematical directionality. This latter property should assure that individual mirrored symbols are treated correctly.

As an example, consider the MathML fragment:

<mn>1</mn> <mo>+</mo> <mi> BEHP </mi> <mo>-</mo> <mn>2</mn>

Some browsers mis-apply the bidirectional algorithm to the expression as a whole, as in HTML. Applying the HTML algorithm would set the first two items LTR, but then switch directions upon encountering the letter BEHP; thus the last three items are reversed.

Right [Image of expression rendered correctly] 1+ب-2
Wrong[Image of expression rendered incorrectly]

4.3 Additional Mathvariants

For single character tokens, additional styles, besides isolated, are used to enlarge the set of available distinct symbols, just as the bold and Fraktur styles are used in European mathematics. The styles used in Arabic mathematics are "tailed", "looped" and "stretched", in addition to the "initial" style applied to the individual character. Furthermore, the "double-struck" style is commonly used. The following table shows the character JEEM in the various styles, in both dotted and undotted forms (see below):

dottedDotted JEEM isolated formDotted JEEM initial formDotted JEEM tailed formDotted JEEM looped formDotted JEEM stretched formDotted JEEM double-struck
undottedUndotted JEEM ISOLATEDUndotted JEEM initial formUndotted JEEM tailed formUndotted JEEM looped formUndotted JEEM stretched formUndotted JEEM double-struck

It is proposed to consider the mathvariant "normal", when applied to Arabic, to mean the result of glyph shaping, and in particular, the "isolated" style for single character tokens. It is also proposed to add the following values allowed for mathvariant: "initial", "tailed", "looped" and "stretched".

It is not expected to be meaningful to apply the "bold", "italic", "fraktur", "script", "sans-serif" or "monospace" mathvariants (or combinations) to Arabic (although there is some sentiment for allowing "bold" and "italic"). Nor is it meaningful to apply any mathvariant other than "normal" to multicharacter tokens, which should have glyph shaping applied. The current MathML specification points out that the only combinations of characters and mathvariant that have an unambiguous interpretation are those that correspond to the SMP Math Alphanumeric Symbols. An analogous argument is to be made for Arabic and the proposed Arabic Math Alphabetic Symbols [UnicodeProposition] (not yet part of Unicode).

Both dotted and undotted alphabetic symbols are encountered in this Note. The choice of which type to use is up to local preferences, however; documents use either dotted or undotted symbols, but not a mixture, and in particular, the dots are not used to indicate semantic distinctions. Thus, it is not felt that dotting is a good candidate for a mathvariant value, but rather should be accommodated by the choice of symbol fonts available to user's browser, or possibly through CSS.

4.5 Horizontal Stretchiness

In Arabic mathematics, the sum, product and limit are commonly stretched horizontally to the same width as the limits (over or under) that apply to them. Such stretching does occasionally appear, but is rare, in European mathematics. In Horizontal Stretching Rules of MathML ([MathML22e] section, standard allows for such horizontal stretching of some symbols at the discretion of the rendering agent. In this Note, we simply encourage developers to implement this feature for the appropriate Arabic symbols.

5 Conclusions and Future Work

This Note describes the notational issues encountered in presenting mathematics within Arabic and other RTL languages, in particular focusing on how these notations differ from the model described by MathML2. To the best of our knowledge, the unique notations described here cover all known differences.

This Note also proposes enhancements to be considered in a future revision of the MathML specification. These enhancements would allow Presentation MathML to be used to conveniently incorporate mathematics into Arabic documents in a style conventionally used by Arabic speaking authors.

The successful use of mathematics in Arabic texts will also require, in addition to the extensions proposed here, that the appropriate codepoints are included in Unicode, and that those codepoints are correctly marked as mirrored. Some proposals ([UnicodeProposition],[ArabicMathUnicode]) have already been made.

6 Acknowledgments

This document has been produced by the members of the Math Interest Group. The chairs of this Interest Group are David Carlisle (invited expert) and Robert Miner (Design Science, Inc.). Other members of the Working Group are (at the time of writing): Isam Ayoubi (invited expert), Laurent Bernardin (Waterloo Maple Inc.), Stephane Dalmas (Institut National de Recherche en Informatique et en Automatique), Stan Devitt (invited expert), Max Froumentin (W3C), Patrick D F Ion (invited expert), Azzeddine LAZREK (invited expert), Paul Libbrecht (German Research Center for Artificial Intelligence), Manolis Mavrikis (University of Edinburgh), Bruce Miller (National Institute of Standards and Technology), Luca Padovani (University of Bologna), Neil Soiffer (Design Science, Inc.), Stephen Watt (Waterloo Maple Inc.)

The editors would also like to thank Richard Ishida for initiating the contacts that lead to the writing of this Note, and for many constructive comments on a draft of it.

7 Production Notes

The images of Arabic and Persian expressions were composed using the RyDArab system [RyDArab], and the FarsiTeX system [FarsiTeX], respectively.

A Localization Issues

This section discusses some of the localization issues encountered in this Note. Authors of MathML may want to consider these issues when composing documents. Additionally, it may be worth parameterizing converters from Content MathML to Presentation MathML so that they take into account the target language, locale, and conceivably the scientific discipline involved as well.

B Implementation Issues

This section describes issues that an implementor of an Arabic-enhanced MathML specification would encounter, and possible strategies for dealing with them.

B.2 Mathematical Fonts

Some font families are designed to meet with the requirements of typesetting mathematical documents in an Arabic notation. The RamzArab Arabic mathematical font [RamzArab] aims to provide a complete and homogeneous Arabic font family, in the OpenType format, respecting Arabic calligraphy rules.

Although letters in "tailed" and "stretched" forms are semantically distinct from the "initial" forms, they can be simulated by connecting with a particular final form of HEH and the final form of ALEF, respectively, and applying glyph shaping. This technique may be useful when an insufficient variety of fonts is available.

Implementors are encouraged to make it feasible for users to choose dotted or undotted mathematical symbol fonts easily in accord with local tastes.

C Bibliography

David Carlisle, Patrick Ion, Robert Miner, Nico Poppelier, Mathematical Markup Language (MathML) Version 2.0 (2nd Edition) World Wide Web Consortium Working Draft 19. December 2002 (http://www.w3.org/TR/MathML2/)
Richard Ishida, What you need to know about the bidi algorithm and inline markup http://www.w3.org/International/articles/inline-bidi-markup/
Mohamed Jamal Eddine Benatia, Azzeddine Lazrek, Khalid Sami, Arabic mathematical symbols in Unicode, IUC 27, Berlin, Germany, April 6-8, 2005. (http://www.ucam.ac.ma/fssm/rydarab/doc/communic/unicodem.pdf)
Azzeddine Lazrek, RyDArab-Typesetting Arabic mathematical expressions, TUGboat, Volume 25 (2004), No. 2, 2004. (http://www.ucam.ac.ma/fssm/rydarab/doc/communic/tugryd.pdf)
Mostafa Banouni, Mohamed Elyaakoubi, Azzeddine Lazrek, Dynamic Arabic mathematical fonts, LNCS, Volume 3130, pp. 149-157, 2004. (http://www.ucam.ac.ma/fssm/rydarab/doc/communic/tugfontm.pdf)
Behdad Esfahbod, Roozbeh Pournader, FarsiTeX and the Iranian TeX community. (http://www.tug.org/TUGboat/Articles/tb23-1/farsitex.pdf)
Mustapha Eddahibi, Azzeddine Lazrek, Khalid Sami, Arabic mathematical e-documents, LNCS, Volume 3130, pp. 158-168, 2004. (http://www.ucam.ac.ma/fssm/rydarab/doc/communic/tugmathm.pdf)