-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
MakeBoxes OutputForm / FullForm #1163
base: master
Are you sure you want to change the base?
Conversation
In this PR, I partially mimic this behavior for OutputForm and FullForm by modifying |
outputform and fullform following the WMA formatting steps
c4a373d
to
a35983e
Compare
@@ -188,6 +188,33 @@ def eval_display(boxexpr, evaluation): | |||
return boxexpr.elements[0] | |||
|
|||
|
|||
class PaneBox(BoxExpression): |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this can be reformulated in small pieces. One of them is #1316
This is the idea I am trying to elaborate and test in the "Character2D" branches.
In WMA, "formatting" is the result of "render" a
Box
expression, 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 theOutputForm
But 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: