Search code examples
mathmathml

Inline strings in MathML


How do add a string inline in MathML? The type of thing I am looking for is this:

This was created in Microsoft Word, without using MathML

Where the space at the start of the string (for small values of v) is preserved.

However, when I try to implement this in MathML, using <ms lquote="" rquote=""> for small values of v </ms>, it renders as this:

Evidently, it does not preserve spaces at the start of a string.

Is there any way around this?


Solution

  • I recommend <mtext> rather than <ms>, which isn't really intended for this use. Everything within <mtext> renders exactly as typed, and should be the same regardless of the rendering engine. Leading spaces are not considered whitespace in <mtext> and should be preserved.

    So specifically this:

        <mtext> for small values of v</mtext>
    

    If you want v to be italicized, either mark it up as <mi> or use a separate <mtext> block, with an attribute of mathvariant='italic'. It would seem the latter to be preferred.

    After I originally posted my reply, I noticed you said you typed your example in Word, without using MathML. Did you know Word's OMML equation editor (i.e., the one by clicking Equation on the Insert tab) can copy MathML? In fact, if you do type this as an OMML equation and copy it as MathML, the result is what I recommended. To get MathML by copying an OMML equation, with the insertion point inside any equation, in the Tools group of the Insert tab, click the dialog launcher. (That's the diagonal arrow in the lower right.) Near the top you'll see an option to "Copy as MathML".