Blog de Frédéric

To content | To menu | To search

Tag - mathzilla

Entries feed - Comments feed

Thursday, April 7 2011

Arabic mathematics in Mathzilla

I have just modified a bit the Mathzilla add-ons to experiment with writing arabic math...

Arabic math in Mathzilla

Monday, November 15 2010

Mozilla MathML Add-ons

I've released two betas of Mozilla MathML add-ons for trunk builds:

  1. MathParser: mathparser-0.1.xpi (Linux x86_64, 95.7 KB)
  2. Mathzilla: mathzilla-0.1.xpi (168.85 KB)

MathParser adds an XPCOM component to parse mathematical expressions into MathML and should be usable with any Mozilla application. Two modes are available: simple or itex (see part 1 and part 2). Mathzilla is an add-on for Firefox, based on jetpack 0.8. It requires MathParser to be installed and provides the following features that people interested in MathML are likely to appreciate:

  • A tiny MathML editor. It's basically an interface for MathParser, with an input field and a MathML rendering of the output.
  • Conversion of Content MathML, based on David Carlisle's ctop.xsl. A good workaround for bug 276028.
  • Conversion of PNG images into MathML. Of course, this works only on websites that provide the LaTeX source as alt text. In particular, it is usable on Wikipedia and hence allows to workaround Wikimedia's bug 6383.
  • A copy MathML formula item in the context menu. For the moment, I've only tested the text/unicode flavor, so I'm not sure the application/mathml+xml flavor works. See bug 539506 and transferring MathML for more information. Of course, this allows to copy the MathML outputs of the three previous features ;-)

Some screenshots:

MathML Testsuite, testing content markup.
Content Markup of the MathML testsuite transformed into Presentation Markup using ctop.xsl.

Interface of Mathzilla  Parser, LaTeX input.
The interface of the Mathzilla parser, with Unicode-friendly itex input.

MathML formula on Wikipedia.
Wikipedia's page on Fourier series with PNG images transformed into presentation MathML.

Tuesday, October 5 2010

An XPCOM component to parse mathematical expressions into MathML (part 2)

So I'm finally done with the implementation of itex2MML in my mathparser. The current set of patches is available here and can be used in any Mozilla product based on mozilla-central. For those who don't know, itex2MML is a converter from a LaTeX-like syntax to MathML which was originally written, about ten years ago, by Paul Gartside for the Mozilla MathML Project. It has been maintained since then by Jacques Distler, who has made a great work to improve and extend it (and has also reported several bugs that helped us to make our MathML layout engine better ;-). Hence it is a mature tool and it is worth being based on it in order to provide a decent LaTeX-like parser.

You can find a list of itex2MML commands as well as various examples. All itex2MML commands are supported in my mathparser, except inclusion of SVG graphics, XML entities and obsolete maction's commands. There are also some additional features such that support for Unicode characters in the LaTeX input. Below are random demos:

$$\int_M K\;dA+\int_{\partial M}k_g\;ds=2\pi\chi(M), \, $$

M K dA + M k g ds = 2 π χ ( M ) ,

$$\oint_S \mathbf{E} \cdot \mathrm{d}\mathbf{A} = \frac{Q}{\varepsilon_0},$$

S E d A = Q ε 0 ,

$$u = \root{3}{-{q \over 2} \pm \sqrt{{q^2 \over 4} + {p^3 \over 27}}}$$

u = q 2 ± q 2 4 + p 3 27 3

$$\frac{a_0}{2} + \sum_{n=1}^\infty \, [a_n \cos(n x) + b_n \sin(n x)]$$

a 0 2 + n = 1 [ a n cos ( n x ) + b n sin ( n x ) ]

Thursday, September 16 2010

An XPCOM component to parse mathematical expressions into MathML (part 1)

I have started to write a math parser usable by Mozilla-based applications. In particular, this could help to add math editing features to Mozilla's editors (BlueGriffon™, Komposer or Thunderbird etc). Of course, it will also be usable by Mozilla's extensions, such that Firemath. I will probably give more details in subsequent blog posts but the main ideas are given in that one.

First, the parser is usable through classical XPCOM calls. With the current interface, we get something like (in Javascript):

mathparser =
  Components.classes['@mozilla.org/editor/mathparser;1'].
  createInstance(Components.interfaces.nsIMathParser);

node = mathparser.parse(document, input,
  Components.interfaces.nsIMathParser.MATHPARSER_MODE_SIMPLE);

where input is a string representing a mathematical formula and node is the output MathML tree. Note the third parameter of the parse function, which allows to choose a parser mode. For the moment, I have only written one for very basic formulas. However, I plan to add at least a LaTeX-like mode.

As an example, if we provide the following input strings "{∑_{i=1}^{+∞} 1/n^2} = π^2/6" and "{∫_0^{+∞} {ⅆx}/{4(x+1)√x}} = π/4" the parser outputs:

i = 1 + 1 n 2 = π 2 6 0 + x 4 ( x + 1 ) x = π 4

Note that the core engine is produced using the famous parser generator Bison and hence it will be easy to adapt the work of itex2MML. The lexical analyzer is written directly and we get a very nice feature: unicode support! If people are interested, I have some patches applyable to mozilla-central...