davidcarlisle / web-xslt

XSLT and javascript code intended mostly for manipulating MathML and OpenMath.
Other
69 stars 25 forks source link

ctop[ff].xsl: some issues with the unary/binary minus operator #5

Open agarny opened 9 years ago

agarny commented 9 years ago

I have been using ctop[ff].xsl for quite some time and I have found it to be very useful (so thanks a lot for it indeed!), but I have recently come across what I believe are some issues with the unary/binary minus operator.

I have thus found some issues with the following equations:

a=-(b+c)+d

<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML">
    <apply>
        <eq />
        <ci>a</ci>
        <apply>
            <plus />
            <apply>
                <minus />
                <apply>
                    <plus />
                    <ci>b</ci>
                    <ci>c</ci>
                </apply>
            </apply>
            <ci>d</ci>
        </apply>
    </apply>
</math>

which gets converted to:

<math xmlns="http://www.w3.org/1998/Math/MathML">
    <mrow>
        <mrow>
            <mi mathvariant="italic">a</mi>
        </mrow>
        <mo>=</mo>
        <mrow>
            <mo>−</mo>
            <mrow>
                <mo>(</mo>
                <mrow>
                    <mi mathvariant="italic">b</mi>
                </mrow>
                <mo>+</mo>
                <mrow>
                    <mi mathvariant="italic">c</mi>
                </mrow>
                <mo>)</mo>
            </mrow>
            <mo>+</mo>
            <mrow>
                <mi mathvariant="italic">d</mi>
            </mrow>
        </mrow>
    </mrow>
</math>

and renders as:

a=-b+c+d

A couple of other equations that don't get converted properly are:

a=-(b*c)+d   --->   a=-c+d
a=d-(b+c)    --->   a=d-b+c

Then, we have the following equations that keep their unnecessary parentheses after conversion:

a=-(b*c)   --->   a=-(bc)
a=-(b/c)   --->   a=-(b/c)

I am no XSL expert, but I have come up with a version of your ctop[ff].xsl file that addresses all of the above points. I wouldn't be surprised if there was a better way of doing things, so feel free to suggest a better solution.

Here is the version of your ctop[ff].xsl that I am currently using in my project. As you will see, besides my 'fixes', I have also made a few other modifications to your original ctop[ff].xsl file, but they don't affect the issue at hand (I tested the above equations using both your and 'my' version of your ctop[ff].xsl file).

davidcarlisle commented 9 years ago

Thanks, I'll have a look and report back here.

On 29 September 2015 at 15:16, Alan Garny notifications@github.com wrote:

I have been using ctop[ff].xsl for quite some time and I have found it to be very useful (so thanks a lot for it indeed!), but I have recently come across what I believe are some issues with the unary/binary minus operator.

I have thus found some issues with the following equations:

a=-(b+c)+d

<?xml version="1.0" encoding="UTF-8"?>

a b c d

which gets converted to:

a = ( b + c ) + d

and renders as:

a=-b+c+d

A couple of other equations that don't get converted properly are:

a=-(b*c)+d ---> a=-c+d a=d-(b+c) ---> a=d-b+c

Then, we have the following equations that keep their unnecessary parentheses after conversion:

a=-(b*c) ---> a=-(bc) a=-(b/c) ---> a=-(b/c)

I am no XSL expert, but I have come up with a version of your ctop[ff].xsl file that addresses all of the above points. I wouldn't be surprised if there was a better way of doing things, so feel free to suggest a better solution.

Here https://github.com/opencor/opencor/blob/250187784368149b55bc1d8f7126184f4ed4fd90/src/plugins/miscellaneous/Core/res/web-xslt/ctopff.xsl is the version of your ctop[ff].xsl that I am currently using in my project. As you will see, besides my 'fixes', I have also made a few other modifications to your original ctop[ff].xsl file, but they don't affect the issue at hand (I tested the above equations using both your and 'my' version of your ctop[ff].xsl file).

— Reply to this email directly or view it on GitHub https://github.com/davidcarlisle/web-xslt/issues/5.

http://dpcarlisle.blogspot.com/

agarny commented 9 years ago

FWIW, I have come across another issue (still related to the minus operator; see https://github.com/opencor/opencor/issues/774). In any case, here is the version of ctopff.xsl that I am now using.