-
-
Notifications
You must be signed in to change notification settings - Fork 65
MathML tweaks #1661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
MathML tweaks #1661
Conversation
672183d to
95d09f2
Compare
| "\u2146", | ||
| "\u301a", # [[ | ||
| "\u301b", # ]] | ||
| "\u00d7", # \[Times] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't this be picked up from character tables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. I have to check if we are not doing already that.
| "\u2062", | ||
| "\u222b", | ||
| "\u2146", | ||
| "\u301a", # [[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recently, RightDoubleBracket and LeftDoubleBracket were tagged as operators. I suspect that these can now be picked up from the character tables.
mathics/format/render/mathml.py
Outdated
| _options.update(options) | ||
| options = _options | ||
| return "<mfrac>%s %s</mfrac>" % ( | ||
| return "<mfrac>\n%s\n %s\n</mfrac>" % ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a typographic difference here, or is this simply to make human comprehension easier when looking at the text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is just human readability, and helps to compare with WMA output, which split the output in lines. Also, WMA uses indentation for the different levels, which we are not supporting right now. For example
In[1]:= a^b/c//MathMLForm
Out[1]//MathMLForm= <math>
<mfrac>
<msup>
<mi>a</mi>
<mi>b</mi>
</msup>
<mi>c</mi>
</mfrac>
</math>
while in Mathics3
In[1]:= a^b/c//MathMLForm
Out[1]//MathMLForm= <mfrac>
<msup>
<mi>a</mi>
<mi>b</mi>
</msup>
<mi>c</mi>
</mfrac>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having the output split in lines, we can add the indentation later, or remove it from the WMA output for doing the comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is just human readability, and helps to compare with WMA output, which split the output in lines. Also, WMA uses indentation for the different levels, which we are not supporting right now. For example
In[1]:= a^b/c//MathMLForm Out[1]//MathMLForm= <math> <mfrac> <msup> <mi>a</mi> <mi>b</mi> </msup> <mi>c</mi> </mfrac> </math>while in Mathics3
In[1]:= a^b/c//MathMLForm Out[1]//MathMLForm= <mfrac> <msup> <mi>a</mi> <mi>b</mi> </msup> <mi>c</mi> </mfrac>
Ok. Got it. I was not opposed to it, but just wondered about the intention. (BTW, adding a comment to this effect will help others from wondering or thinking about this.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is where to leave the comment. Maybe in the head of the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did realize that indentation is something that can be done on the fly. The question is if we want to do it. I had my doubts about adding the line breaks, because -differently from WMA graphics interface- we use mathml form to render output. So, adding complexity and length to the output makes harder to the browser show the output.
On the other hand, adding the line breaks makes easier the comparison between Mathics3 and WMA results. So, I proposed an intermediate format.
It's okay to discuss approaches before coding and PR's.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so, thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BoxExpression should have an integer "nesting_level" attribute, and that value times the string value of an indent is what prefaces the tags after a "\n".
INDENT_SPACES = " " # or "\t" or whatever
(f"\n{self.nesting_level * INDENT_SPACES}).join(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, but the first thing is that we want to indent the mathml code. A way to achieve that is to use an argument for the render functions tracking the indentation level of the context. If we agree that it a good idea, I can implement it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is set in a BoxExpresssion object, MathML rendering can pick up this attribute using its self parameter.
| for line in text.split("\n"): | ||
| outtext += render("<mtext>%s</mtext>", line) | ||
| return outtext | ||
| return "".join( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where getting the proper indent level would be done.
This PR makes some tweaks on how mathml output is render.
InterpretationBoxto work withInputFormandOutputForm.OutputForm[s_String]format rule.format-tests-WMA.yamlwith more tests compared against WS.format-tests.yamlaccordingly.