Message Boards Message Boards

0
|
5244 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Why MathMLForm[Hold[y+x]] x+y even with ClearAttributes[Plus,Orderless]?

Posted 9 years ago

There seems to be a strange interaction between MathML and canonical ordering / Attribute settings. Sometimes I want to turn off the canonical reordering. I know I can do things like ClearAttributes, but the settings don't seem to carry over into MathMLForm. Even wrapping the expression in a Hold doesn't help. Is there no way to shut off this canonical form when generating MathML?? Thanks.

In[1]:= ClearAttributes[Plus, Orderless]                                                                                                             

In[2]:= y+x                                                                                                                                          

Out[2]= y + x

In[3]:= MathMLForm[y+x]                                                                                                                              

Out[3]//MathMLForm= 
                     <mrow>
                      <mi>x</mi>
                      <mo>+</mo>
                      <mi>y</mi>
                     </mrow>


In[4]:= MathMLForm[Hold[y+x]]                                                                                                                        

Out[4]//MathMLForm= <math>
                     <mrow>
                      <mi>Hold</mi>
                      <mo>[</mo>
                      <mrow>
                       <mi>x</mi>
                       <mo>+</mo>
                       <mi>y</mi>
                      </mrow>
                      <mo>]</mo>
                     </mrow>
                    </math>

Since the web site evaluates the mathML, here is Out[3] without the math .../math brackets.

                 <mrow>
                  <mi>x</mi>
                  <mo>+</mo>
                  <mi>y</mi>
                 </mrow>
POSTED BY: Elaine Kant
2 Replies

Many, many thanks!! I never would have suspected.

POSTED BY: Elaine Kant

This is kinda a tricky problem. Too many functions try to do smart things.

I prefer to use HoldForm:

MathMLForm[HoldForm[y + x]]

<math>
 <semantics>
  <mrow>
   <mi>y</mi>
   <mo>+</mo>
   <mi>x</mi>
  </mrow>
  <annotation encoding='Mathematica'>TagBox[RowBox[List[&quot;y&quot;, &quot;+&quot;,
   &quot;x&quot;]], HoldForm]</annotation>
 </semantics>
</math>

And delete the annotation tags.

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract