MakeBoxes OutputForm / FullForm#1163
Conversation
|
In this PR, I partially mimic this behavior for OutputForm and FullForm by modifying |
c4a373d to
a35983e
Compare
| return boxexpr.elements[0] | ||
|
|
||
|
|
||
| class PaneBox(BoxExpression): |
There was a problem hiding this comment.
Why is the class called PaneBox when the WMA link goes to InterpretationBox?
I can't find PaneBox mentioned in WMA docs.
There was a problem hiding this comment.
In[1]:= MakeBoxes[OutputForm[a^2/b],StandardForm]
2
a
Out[1]= InterpretationBox[PaneBox[" 2\na\n--\nb"], --, Editable -> False]
b
A PaneBox is a block of multiline text, which by default is "centered".
It can be produced by applying MakeBoxes to a Pane expression:
In[2]:= MakeBoxes[Pane["hola\nHello",10],StandardForm]
Out[2]= PaneBox["hola\nHello", ImageSize -> 10]
There was a problem hiding this comment.
Ok - thanks for the information. Given this, it seems this is more like a Pane than it is an InterpretationBox. I see that Information[PaneBox] gives information.
Are there any other Boxes in this category? (Like ParentBox, it exists but is not documented). I can't find any, but I feel we've encountered this kind of situation where there is something that exists but is not documented. If so, how did we handle things there?
But as for changing the link say from InterpretationBox to Pane (if that turns out to be the better thing to do), that is not urgent right now.
This PR is large and I think this PR should come after we work out some simple basics of MakeBoxes.
Also, the PR title is misleading because a lot of this is about character-based formatting on top of stuff related to MakeBoxes.
There was a problem hiding this comment.
Probably this can be reformulated in small pieces. One of them is #1316
|
|
||
| inner = str(self.value) | ||
| if f in SYSTEM_SYMBOLS_INPUT_OR_FULL_FORM: | ||
| if f in ("System`InputForm", "System`FullForm"): |
There was a problem hiding this comment.
Can instance (f, SymblInputForm, SymbolFullForm) be used instead?
There was a problem hiding this comment.
For some reason, this method receives strings instead symbols as input. We can change this, too.
There was a problem hiding this comment.
(I would not be surprised if there is a conversion or access function to go from an Expression symbol into a string. If so, this was one of the many ways that the original code was hideously slow.)
There was a problem hiding this comment.
BTW I noticed recently that Expression.replace_vars is another place where strings are used instead of Symbol.
|
|
||
| def eval_makeboxes_outputform(expr, evaluation, form): | ||
| """ | ||
| Build a 2D text representation of the expression. |
There was a problem hiding this comment.
If 2D is synonymous with str(...) on line 136, then something feels very wrong about putting this in mathics.eval.makeboxes. 2D is a formatting kind of thing, not a Boxing kind of thing.
There was a problem hiding this comment.
Thinking about this more. For high-level form handling and boxing, which largely involve Mathics3 (simple and compound) expressions, these should be done in separate directories, e.g., mathics.form and mathics.box.
This is the idea I am trying to elaborate and test in the "Character2D" branches.
In WMA, "formatting" is the result of "render" a
Boxexpression, and box expressions are generated by evaluatingMakeBoxes[expr]in a way that is different from the standard evaluation.In WMA, the "normal" evaluation of the expression
MakeBoxes[expr, form]discards any user definition and always proceed as follows:expr.For example:
Notice that evaluating
MakeBoxes[F[x], StandardForm]does not returns the (down) valueRowBox[...](which is what happens in Mathics) but applies first the format rule. Then, MakeBoxes rules are applied over the result of formatting.Notice also that MakeBoxes rules are looked first in the FormValues of the head of the resulting expression, and then in the downvaloes of MakeBoxes.
Here we reset the StandardForm of F in terms of
Fs, and set a "UpValue" for MakeBoxes[Fs]:Now, when the REPL wants to format
F[1], uses theOutputFormBut if we ask for the StandardForm
MakeBoxes looks in FormatValues[Fs] for a rule. Setting a DownValue for MakeBoxes does not have any effect, because the rules are first looked in the FormatValues of
Fs.Here we see that UpSet[MakeBoxes[...], ....] stores the second argument as FormatValues instead of Upvalues: