Skip to content

Commit bee14ae

Browse files
committed
2d_print support
2 parents c37afe7 + 03dc038 commit bee14ae

File tree

8 files changed

+1256
-1
lines changed

8 files changed

+1256
-1
lines changed

mathics/builtin/box/layout.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ class GridBox(BoxExpression):
146146
# >> MathMLForm[TableForm[{{a,b},{c,d}}]]
147147
# = ...
148148
"""
149+
149150
options = {"ColumnAlignments": "Center"}
150151
summary_text = "low-level representation of an arbitrary 2D layout"
151152

@@ -211,6 +212,33 @@ def eval_display(boxexpr, evaluation):
211212
return boxexpr.elements[0]
212213

213214

215+
class PaneBox(BoxExpression):
216+
"""
217+
<url>
218+
:WMA link:
219+
https://reference.wolfram.com/language/ref/InterpretationBox.html</url>
220+
221+
<dl>
222+
<dt>'PaneBox[expr]'
223+
<dd> is a low-level box construct, used in OutputForm.
224+
</dl>
225+
226+
"""
227+
228+
attributes = A_HOLD_ALL_COMPLETE | A_PROTECTED | A_READ_PROTECTED
229+
summary_text = "box associated to panel"
230+
231+
def apply_display(boxexpr, evaluation, expression):
232+
"""ToExpression[boxexpr_PaneBox, form_]"""
233+
return Expression(expression.head, boxexpr.elements[0], form).evaluate(
234+
evaluation
235+
)
236+
237+
def apply_display(boxexpr, evaluation):
238+
"""DisplayForm[boxexpr_PaneBox]"""
239+
return boxexpr.elements[0]
240+
241+
214242
class RowBox(BoxExpression):
215243
"""
216244
<url>

mathics/builtin/forms/output.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
from math import ceil
1717
from typing import Optional
1818

19-
from mathics.builtin.box.layout import GridBox, RowBox, to_boxes
19+
from mathics.builtin.box.layout import (
20+
GridBox,
21+
InterpretationBox,
22+
PaneBox,
23+
RowBox,
24+
to_boxes,
25+
)
2026
from mathics.builtin.forms.base import FormBaseClass
2127
from mathics.builtin.makeboxes import MakeBoxes, NumberForm_to_String
2228
from mathics.builtin.tensors import get_dimensions
@@ -29,6 +35,7 @@
2935
StringFromPython,
3036
)
3137
from mathics.core.builtin import Builtin
38+
from mathics.core.convert.prettyprint import expression_to_2d_text
3239
from mathics.core.evaluation import Evaluation
3340
from mathics.core.expression import BoxError, Expression
3441
from mathics.core.list import ListExpression
@@ -561,8 +568,18 @@ class OutputForm(FormBaseClass):
561568
= -Graphics-
562569
"""
563570

571+
formats = {"OutputForm[s_String]": "s"}
564572
summary_text = "plain-text output format"
565573

574+
def eval_makeboxes(self, expr, form, evaluation):
575+
"""MakeBoxes[OutputForm[expr_], form_]"""
576+
print(" eval Makeboxes outputform")
577+
text2d = expression_to_2d_text(expr, evaluation, form).text
578+
elem1 = PaneBox(String(text2d))
579+
elem2 = Expression(SymbolOutputForm, expr)
580+
result = InterpretationBox(elem1, elem2)
581+
return result
582+
566583

567584
class PythonForm(FormBaseClass):
568585
"""

0 commit comments

Comments
 (0)