Forum Bugs

MathML: Abs vertical bars have a large white-space on both sides

DanielPharos
When I use MathML's ABS function, I get large white-space (margins?) on both sides of the vertical bars. I've attached test-code, and a screenshot of the result. Switching fonts (I tried Arial) doesn't resolve this. Can this gap be made smaller?

I tried applying CSS to it, but I couldn't get it to work (and I've read that CSS is rather limited when applied to MathML?).

I've found that | can function as a workaround (the second line), but that kinda defeats the purpose of using MathML.
mikeday
Right, this could be due to the conversion of content MathML to presentation MathML, or due to the rendering of the presentation MathML. Do you need to use content MathML for this expression?
DanielPharos
Probably not, I could try the presentation MathML version. I'm not sure how to write this in presentation MathML, though? I just replace the entire apply/abs bit with <mo> &vert; </mo> ?
mikeday
Yes, inside an mrow. However, the operators dictionary (math/operators.xml) gives default space on both sides when the vertical bar is used as an infix operator:
<operator mo="|"
    form="infix" stretchy="true"
    lspace="thickmathspace" rspace="thickmathspace"/>

So you will need something like this:
<mo form="prefix">|</mo>...<mo form="postfix">|</mo>

Perhaps with explicit lspace/rspace attributes as well? We will need to change the content MathML transformation to do this.

Edited by mikeday

DanielPharos
Okay, I tried your suggestions, and it works! (See screenshot; last line.) I indeed needed to apply lspace- and rspace-attributes (I did them only to the left one, to show that they're needed):

<P>TEST FORMULA <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo form="prefix" lspace="0" rspace="0">|</mo><mi>&eta;</mi><mo form="postfix">|</mo><mo>&lt;</mo><mn>2.5</mn></mrow></math> blah blah.</P>

Interesting that the spec defines the vertical bar with a space around it. I guess it's supposed to be used for a bitwise OR operator (it's surrounded by such operators), not for absolute values. The spec suggests I should also set 'fence' though... Lemme try that too.
DanielPharos
No real visible change (see screenshot), but I guess it's needed for more complicated formulae. Here's my final code:

<P>TEST FORMULA <math xmlns="http://www.w3.org/1998/Math/MathML"><mrow><mo form="prefix" lspace="0em" rspace="0em" fence="true">|</mo><mi>&eta;</mi><mo form="postfix" lspace="0em" rspace="0em" fence="true">|</mo><mo>&lt;</mo><mn>2.5</mn></mrow></math> blah blah.</P>

I'll just replace all my <abs/>'s with this then, unless the fix for doing this with the content MathML version is coming soon?
mikeday
We can fix the problem by adding these definitions to the math/operators.xml file:
<operator mo="|"
    form="prefix" fence="true" stretchy="true"
    lspace="0em" rspace="0em"/>

<operator mo="|"
    form="postfix" fence="true" stretchy="true"
    lspace="0em" rspace="0em"/>

<operator mo="&VerticalBar;"
    form="prefix" fence="true" stretchy="true"
    lspace="0em" rspace="0em"/>

<operator mo="&VerticalBar;"
    form="postfix" fence="true" stretchy="true"
    lspace="0em" rspace="0em"/>

I've attached the complete file below. If you copy this into /usr/lib/prince/math on Linux/MacOS X or \Prince\Engine\math on Windows, it should fix the problem without any need to change your own markup or even add the form attribute.

By the way, it seems that the fence attribute doesn't actually affect the visual rendering, but may be used for other user agents, eg. perhaps text to speech systems.
DanielPharos
This is working perfectly! Thank you a lot, mikeday! :)
mikeday
These definitions are now added to the default operators.xml included in Prince 9 rev 4, available now.