Thursday 21 January 2010

MathML on the Clipboard

I got a new machine at work with Windows 7 on it.

One of the more interesting applications coming with Windows 7 is the Math Input Panel. This is designed for pen input on a tablet-style device and performs pretty impressively accurate recognition of mathematical expressions. While designed for a tablet, it also works pretty well if you are just “writing” the expression with a finger on a small laptop trackpad, which is how I have been using it.

The Math Input Panel is designed with a very simple interface with virtually no customisation options. It offers no way of saving the expressions generated and just offers a simple insert button that tries to insert the math expression at the insertion point in a currently open application. This works well for Word 2007 which accepts MathML from the clipboard and transparently converts it to its internal form and renders it, but other more generic tools such as XML editors that could use the MathML do not accept MathML from the clipboard in this way. Unlike MathPlayer or Word, The Math Input Panel doesn't offer fallback text representations of the XML markup on the clipboard. Marko Panic, the program manager for the development of this tool confirmed to me that this was a design decision as they didn't want the end user to be faced with raw XML. This is not unreasonable but not what I wanted personally (I like to see my XML raw:-). Marko confirmed that the MathML is on the clipboard and it should be possible to extract it with a few lines of code, or if I wanted a more extensive customisation there was documentation of the API offered by the underlying DLL available at

I decided to brush up my C# forms programming and produced a small form that shows any MathML on the clipboard. The main code (everything apart from the boilerplate Visual Studio files) is available on google code While it's particularly useful to see the MathML generated by the Math Input panel, it also works with other applications, notably MathPlayer and Word, that place MathML on the clipboard.

While looking via Google for some programming tips on my form, I came across a very similar blog posting from last year. That form had some differences though (displaying the IE folding tree view of the XML) so I completed my form here. The screenshot shows the Math Input Panel interpreting my appalling handwriting, and the mmlclipboard form displaying the generated MathML.


Dimitre Novatchev said...

Wow... This is so impressive!

This alone can make me buy a new laptop (or is there a way to use it with a desktop)?

David Carlisle said...

Dimitre, what do you mean is impressive, The MIP or my three lines of code to extract the clipboard data?:-)

You can use a normal mouse to fake the pen input same as a trackpad, but it's perhaps more natural to "write" with a finger on a trackpad than with a desktop mouse.

You don't need a whole new machine though: it looks like for a few 10s of pounds or euros or dollars you can get a usb pen/tablet device these days to plug into an existing windows 7 desktop machine. (I haven't actually tried this).

Bob Mathews said...

Thanks David. MathType 6.6 also accepts input from the MIP, which you can launch directly from MathType or from Word. Since it's possible to launch the MIP from MathType, this also gives one an easy way to insert handwritten equations into PowerPoint.

David Carlisle said...

Bob, yes thanks. Hopefully now MathML3 is nearing the end game in the standardisation process and it does now define these clipboard flavours, more tools will look for these flavours on the clipboard to allow MathML-aware cut and paste.

That said, I wish MIP was a little bit more forgiving in the clipboard flavors it exports. While it's good to hear that the design science products support this they are math specific, it would be harder to argue that general tools such as oxygen or emacs (or even notepad) should be looking for MathML clipboard flavors and it would be nice if a future MIP exported something a bit more generic in addition to MathML, at least a generic XML label if they want to avoid using the text flavors.