Write vectors like you mean it

Every math class I took used an arrow like ⇀ over a variable name to denote a vector. But a lot of books use a really heavy bold to indicate a vector instead. I think it's because of the difficulty of printing a book with special symbols all over the place. Luckily now we have text shown on screens and easy composition tools so that's not an issue today and kids are taught how to put a "Rightwards Harpoon With Barb Upwards" over letters on the second day of keyboarding class. What? You were sick that day? Here, I'll explain.

Okay, it's not that easy. If only U+034F COMBINING GRAPHEME JOINER joined graphemes (which it does not). Unicode doesn't cover the case of generically putting one glyph over another, I'm not sure exactly why, but it sounds like what I want might be considered a Presentation Form. Too bad, I wish basic math notation was part of plain text but it's not. So we need a markup language.

MathML is the XML language that's built for writing stuff like this and up until now simple MathML examples have evaded me. But today I'm going to put a Rightwards Harpoon With Barb Upwards over a letter, like any high school student typing their physics homework should be able to do. Luckily, like SVG, MathML is being retrofitted into html5 and I have the lucky happenstance of writing this post in Firefox 4 beta 8, which renders MathML in html5. Other browsers may barf.

MathML has a presentational and content markup. It looks like the content markup is about calculating things and letting machines know they can interpret the MathML expression. That's not what I'm after today, I'm not going to make a mathematical expression, just one statement. In the presentational markup it quickly becomes clear that the mrow element does a lot of work and mo is the "magic operator" element (I'm sure that's not what it stands for but it certainly does seem to do layout by magic).

So the situation is this: it looks like we need an mrow containing the vector symbol, ⇀, and my variable name. After a little poking around I came up with this markup:

<math>
<mrow>
<mover>
<mi>
v
</mi>
<mo>
&RightVector;
</mo>
</mrow>
</math>

The Unicode character ⇀ (which is &#x21C0) should act the same as a named entity. I have an XML-brain though so I jumped into the Operator Dictionary and found the named entity that sounds like what I want: &RightVector;. The Operator Dictionary looks like an essential component of getting what an <mo> element might do. Using the entity is also pretty clear and may lead to valid XML if that's something you need. And here's what it looks like if your browser renders the markup above:

v

(this looks perfect to me in my current browser).

Getting this MathML that renders left me with one more question. If I just have the vector symbol in an mtext element, what happens if I want the arrow over-top some compound expression like uv (though I don't think I've ever seen this in a text book). Here it is: uv , and this renders exactly as I'd hope.

I also tried using an mtext element instead of the mo and that seems to work just fine. I'm not clear on what the difference between the two is yet but the description of mo sounded pretty convincing that it was the "right" element for this.
0
Your rating: None

yes that's the right markup, you can simplify it by missing out the mrow which isn't doing anything in that context. difference between mo and mtext is most noticeable for infix operators where mo will give operator specific spacing to one or both sides, whereas mtext is for inline bits of natural language text and so loses that spacing. If you know TeX, compare a + b and a \mbox{+} b.
the html5 entity set is based on (copied from the sources of) the entities spec which is updated a bit from mathml2, to take account of updates to Unicode and bugs and things,

http://www.w3.org/2003/entities/2007doc/

David

Hey, Thanks for the article (great writing) -- and your info, David. I should however point out, that your MathML example for \vector{u*v} probably isn't semantically correct, if u and v are different variables. I don't know MathML well but it should rather look something like

...
<mover>
     <mrow> <mi>u</mi> <mi>v</mi> </mrow>
     <mo> &RightArrow; </mo>
</mover>
...

If you want to, an invisbile multiplication operator could be added as well, but that seems unneccessary to me.

Anon