Skip to content

Commit 845fb99

Browse files
committed
working
1 parent bee14ae commit 845fb99

File tree

8 files changed

+385
-143
lines changed

8 files changed

+385
-143
lines changed

mathics/builtin/arithfns/basic.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Integer1,
1515
Integer3,
1616
Integer310,
17+
Integer400,
1718
IntegerM1,
1819
Number,
1920
Rational,
@@ -48,6 +49,7 @@
4849
SymbolNull,
4950
SymbolPower,
5051
SymbolTimes,
52+
SymbolTrue,
5153
)
5254
from mathics.core.systemsymbols import (
5355
SymbolBlank,
@@ -152,7 +154,7 @@ class Divide(BinaryOperator):
152154
default_formats = False
153155

154156
formats = {
155-
(("InputForm", "OutputForm"), "Divide[x_, y_]"): (
157+
("InputForm", "Divide[x_, y_]"): (
156158
'Infix[{HoldForm[x], HoldForm[y]}, "/", 400, Left]'
157159
),
158160
}
@@ -166,9 +168,26 @@ class Divide(BinaryOperator):
166168
"FractionBox[MakeBoxes[x, f], MakeBoxes[y, f]]"
167169
),
168170
}
169-
170171
summary_text = "divide"
171172

173+
def format_outputform(self, x, y, evaluation):
174+
"OutputForm: Divide[x_, y_]"
175+
use_2d = (
176+
evaluation.definitions.get_ownvalues("System`$Use2DOutputForm")[0].replace
177+
is SymbolTrue
178+
)
179+
if not use_2d:
180+
return Expression(
181+
SymbolInfix,
182+
ListExpression(
183+
Expression(SymbolHoldForm, x), Expression(SymbolHoldForm, y)
184+
),
185+
String("/"),
186+
Integer400,
187+
SymbolLeft,
188+
)
189+
return None
190+
172191

173192
class Minus(PrefixOperator):
174193
"""
@@ -406,10 +425,21 @@ class Power(BinaryOperator, MPMathFunction):
406425
Expression(SymbolPattern, Symbol("x"), Expression(SymbolBlank)),
407426
RationalOneHalf,
408427
): "HoldForm[Sqrt[x]]",
409-
(("InputForm", "OutputForm"), "x_ ^ y_"): (
428+
(("InputForm",), "x_ ^ y_"): (
410429
'Infix[{HoldForm[x], HoldForm[y]}, "^", 590, Right]'
411430
),
412-
("", "x_ ^ y_"): (
431+
(("OutputForm",), "x_ ^ y_"): (
432+
"If[$Use2DOutputForm, "
433+
"Superscript[HoldForm[x], HoldForm[y]], "
434+
'Infix[{HoldForm[x], HoldForm[y]}, "^", 590, Right]]'
435+
),
436+
(
437+
(
438+
"StandardForm",
439+
"TraditionalForm",
440+
),
441+
"x_ ^ y_",
442+
): (
413443
"PrecedenceForm[Superscript[PrecedenceForm[HoldForm[x], 590],"
414444
" HoldForm[y]], 590]"
415445
),

mathics/builtin/forms/output.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
SymbolOutputForm,
6262
SymbolRowBox,
6363
SymbolRuleDelayed,
64+
SymbolStandardForm,
6465
SymbolSubscriptBox,
6566
SymbolSuperscriptBox,
6667
)
@@ -724,7 +725,7 @@ class TeXForm(FormBaseClass):
724725

725726
def eval_tex(self, expr, evaluation) -> Expression:
726727
"MakeBoxes[expr_, TeXForm]"
727-
boxes = MakeBoxes(expr).evaluate(evaluation)
728+
boxes = format_element(expr, evaluation, SymbolStandardForm)
728729
try:
729730
# Here we set ``show_string_characters`` to False, to reproduce
730731
# the standard behaviour in WMA. Remove this parameter to recover the

mathics/builtin/forms/variables.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,47 @@
33
44
"""
55

6-
from mathics.core.attributes import A_LOCKED, A_PROTECTED
6+
from mathics.core.attributes import A_LOCKED, A_NO_ATTRIBUTES, A_PROTECTED
77
from mathics.core.builtin import Predefined
88
from mathics.core.list import ListExpression
99

1010

11+
class Use2DOutputForm_(Predefined):
12+
r"""
13+
<dl>
14+
<dt>'$Use2DOutputForm'
15+
<dd>internal variable that controls if 'OutputForm[expr]' is shown \
16+
in one line (standard Mathics behavior) or \
17+
or in a prettyform-like multiline output (the standard way in WMA).
18+
The default value is 'False', keeping the standard Mathics behavior.
19+
</dl>
20+
21+
>> $Use2DOutputForm
22+
= False
23+
>> OutputForm[a^b]
24+
= a ^ b
25+
>> $Use2DOutputForm = True; OutputForm[a ^ b]
26+
=
27+
. b
28+
. a
29+
30+
Notice that without the 'OutputForm' wrapper, we fall back to the normal
31+
behavior:
32+
>> a ^ b
33+
= Superscript[a, b]
34+
Setting the variable back to False go back to the normal behavior:
35+
>> $Use2DOutputForm = False; OutputForm[a ^ b]
36+
= a ^ b
37+
"""
38+
39+
attributes = A_NO_ATTRIBUTES
40+
name = "$Use2DOutputForm"
41+
rules = {
42+
"$Use2DOutputForm": "False",
43+
}
44+
summary_text = "use the 2D OutputForm"
45+
46+
1147
class PrintForms_(Predefined):
1248
r"""
1349
<dl>

mathics/core/atoms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ def is_zero(self) -> bool:
330330
Integer2 = Integer(2)
331331
Integer3 = Integer(3)
332332
Integer310 = Integer(310)
333+
Integer400 = Integer(400)
333334
Integer10 = Integer(10)
334335
IntegerM1 = Integer(-1)
335336

0 commit comments

Comments
 (0)