From 103e0ed8cdd823807a3d5baa69179b585c026e67 Mon Sep 17 00:00:00 2001 From: Juan Mauricio Matera Date: Tue, 1 Sep 2026 17:56:42 -0300 Subject: [PATCH 1/7] improve test --- test/format/test_makeboxes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/format/test_makeboxes.py b/test/format/test_makeboxes.py index 6969d3854..6604e000a 100644 --- a/test/format/test_makeboxes.py +++ b/test/format/test_makeboxes.py @@ -199,7 +199,7 @@ def test_makeboxes_others_fail(str_expr, str_expected, msg): ), ( r"MakeBoxes[OutputForm[G[F[3.002]]], StandardForm]", - r'InterpretationBox[PaneBox["\"G[{Formatted f, {3.002}, Standard}]\""], G[{Formatted f, {3.002}, Standard}], Editable -> False]', + r'InterpretationBox[PaneBox["\"G[{Formatted f, {3.002}, Standard}]\""], OutputForm[G[F[3.002]]], Editable -> False]', "with the defined OutputForm", ), ( @@ -215,8 +215,8 @@ def test_makeboxes_others_fail(str_expr, str_expected, msg): # InterpretationBox is now used here... = InterpretationBox[PaneBox["\"G[{Formatted f, {3.002}, Output}]\""], OutputForm[G[F[3.002`]]], Rule[Editable, False]] ( r"MakeBoxes[OutputForm[G[F[3.002]]], StandardForm]", - r'RowBox[{"G","[",RowBox[{"{",RowBox[{"\"Formatted f\"",", ",RowBox[{"{","3.002","}"}],", ","\"Standard\""}],"}"}],"]"}]', - "Test Custom OutputForm", + r'InterpretationBox[PaneBox["\"G[{Formatted f, {3.002}, Output}]\""], OutputForm[G[F[3.002]]], Rule[Editable, False]]', + "Test Custom OutputForm xxxx", ), ( r"ClearAll[F]; MakeBoxes[G[F[2.]], StandardForm]", From 7bdeada7d1dd83278a94ddc42e4bdb9cc0781ef4 Mon Sep 17 00:00:00 2001 From: Juan Mauricio Matera Date: Tue, 1 Sep 2026 19:39:17 -0300 Subject: [PATCH 2/7] partial --- mathics/format/box/formatvalues.py | 20 ++++++-------------- mathics/format/form/inputform.py | 9 +++++++++ mathics/format/form/outputform.py | 4 +++- test/builtin/test_forms.py | 5 +++-- test/format/test_makeboxes.py | 8 +++++--- test/test_session.py | 4 +++- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/mathics/format/box/formatvalues.py b/mathics/format/box/formatvalues.py index 90210bcfd..909a605e4 100644 --- a/mathics/format/box/formatvalues.py +++ b/mathics/format/box/formatvalues.py @@ -64,7 +64,7 @@ def do_format_element( Applies formats associated to the expression and removes superfluous enclosing formats. """ - from mathics.core.definitions import OUTPUT_FORMS + from mathics.core.definitions import BOX_FORMS, OUTPUT_FORMS head: BaseElement @@ -73,20 +73,16 @@ def do_format_element( expr = element head = element.get_head() # use element.head elements = element.get_elements() - include_form = False # If the expression is enclosed by a Format - # takes the form from the expression and - # removes the format from the expression. + # leave it as it is. MakeBoxes is going to + # solve it later... + if head in BOX_FORMS and len(elements) == 1 and isinstance(head, Symbol): + return do_format_element(elements[0], evaluation, head) if head in OUTPUT_FORMS and len(elements) == 1 and isinstance(head, Symbol): - expr = elements[0] - if not form.sameQ(head): - form = head - include_form = True + return expr # If form is Fullform, return it without changes if form is SymbolFullForm: - if include_form: - expr = Expression(form, expr) return expr # Repeated and RepeatedNull confuse the formatter, @@ -136,8 +132,6 @@ def format_expr(expr): if formatted is not None: do_format_fn = _element_formatters.get(type(formatted), do_format_element) result = do_format_fn(formatted, evaluation, form) - if include_form and result is not None: - result = Expression(form, result) return result # If the expression is still enclosed by a Format, @@ -175,8 +169,6 @@ def format_expr(expr): head = do_format(expr_head, evaluation, form) or expr_head expr = to_expression_with_specialization(head, *new_elements) - if include_form: - expr = Expression(form, expr) return expr finally: evaluation.dec_recursion_depth() diff --git a/mathics/format/form/inputform.py b/mathics/format/form/inputform.py index 80c8f5e6d..b25dfc8ad 100644 --- a/mathics/format/form/inputform.py +++ b/mathics/format/form/inputform.py @@ -197,6 +197,15 @@ def _infix_expression_to_inputform_text( return result +@register_inputform("System`OutputForm") +def outputform(expr: Expression, evaluation: Evaluation, **kwargs): + from .outputform import render_output_form + + if len(expr.elements) != 1: + raise _WrongFormattedExpression + return render_output_form(expr.elements[0], evaluation, **kwargs) + + @register_inputform("System`Prefix") def _prefix_expression_to_inputform_text( expr: Expression, evaluation: Evaluation, **kwargs diff --git a/mathics/format/form/outputform.py b/mathics/format/form/outputform.py index 3e6d3774e..5a94d37fe 100644 --- a/mathics/format/form/outputform.py +++ b/mathics/format/form/outputform.py @@ -442,7 +442,9 @@ def _infix_outputform_text(expr: Expression, evaluation: Evaluation, **kwargs) - @register_outputform("System`InputForm") def inputform(expr: Expression, evaluation: Evaluation, **kwargs): - return render_input_form(expr, evaluation, **kwargs) + if len(expr.elements) != 1: + raise _WrongFormattedExpression + return render_input_form(expr.elements[0], evaluation, **kwargs) @register_outputform("System`List") diff --git a/test/builtin/test_forms.py b/test/builtin/test_forms.py index 16650ebcb..e822bbd1d 100644 --- a/test/builtin/test_forms.py +++ b/test/builtin/test_forms.py @@ -24,7 +24,8 @@ def test_makeboxes_form(expr, form, head, subhead): Check the structure of the result of MakeBoxes on expressions with different forms. """ - expr = session.evaluate("MakeBoxes[{form}[{expr}]]") + expr = session.evaluate(f"MakeBoxes[{form}[{expr}]]") + print(f"MakeBoxes[{form}[{expr}]] ->{expr}") assert expr.get_head_name() == f"System`{head}" assert expr.elements[0].get_head_name() == f"System`{subhead}" @@ -391,7 +392,7 @@ def test_makeboxes_form(expr, form, head, subhead): ( "{{2*a, 0},{0,0}}//MatrixForm", None, - "2 \u2062 a 0\n\n0 0\n", + "2 a 0\n\n0 0\n", "Issue #182", ), ## diff --git a/test/format/test_makeboxes.py b/test/format/test_makeboxes.py index 6604e000a..1626df519 100644 --- a/test/format/test_makeboxes.py +++ b/test/format/test_makeboxes.py @@ -172,6 +172,7 @@ def test_makeboxes_others_fail(str_expr, str_expected, msg): @pytest.mark.parametrize( ("str_expr", "str_expected", "msg"), [ + (None, None, None), ( r"MakeBoxes[G[F[2.]], StandardForm]", r'RowBox[{"G","[",RowBox[{"F","[","2.`","]"}],"]"}]', @@ -216,7 +217,7 @@ def test_makeboxes_others_fail(str_expr, str_expected, msg): ( r"MakeBoxes[OutputForm[G[F[3.002]]], StandardForm]", r'InterpretationBox[PaneBox["\"G[{Formatted f, {3.002}, Output}]\""], OutputForm[G[F[3.002]]], Rule[Editable, False]]', - "Test Custom OutputForm xxxx", + "Test Custom OutputForm", ), ( r"ClearAll[F]; MakeBoxes[G[F[2.]], StandardForm]", @@ -225,8 +226,8 @@ def test_makeboxes_others_fail(str_expr, str_expected, msg): ), ( r"MakeBoxes[F[x_], fmt_]=.; MakeBoxes[G[F[2.]], StandardForm]", - r'RowBox[{"G","[",RowBox[{"F","[","2.","]"}],"]"}]', - "Clear MakeBoxes rule", + r'RowBox[{"G", "[", RowBox[{"F", "[", "2.`", "]"}], "]"}]', + "Clear MakeBoxes rule - Fails because <> does not clear the rule.", ), ], ) @@ -260,6 +261,7 @@ def test_makeboxes_custom(str_expr, str_expected, msg): @pytest.mark.parametrize( ("str_expr", "str_expected", "msg"), [ + (None, None, None), ( r'MakeBoxes[F[x__], fmt_] := RowBox[{"F", "<~", RowBox[MakeBoxes[#1, fmt] & /@ List[x]], "~>"}]', "Null", diff --git a/test/test_session.py b/test/test_session.py index 08d779a1f..7e5276e84 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -8,10 +8,12 @@ from mathics.core.atoms import Integer1, Integer2, IntegerM1 from mathics.core.evaluation import Result from mathics.core.expression import Expression +from mathics.core.load_builtin import import_and_load_builtins from mathics.core.symbols import Symbol, SymbolNull from mathics.core.systemsymbols import SymbolDirectedInfinity, SymbolPower, SymbolTimes from mathics.session import MathicsSession +import_and_load_builtins() session = MathicsSession() @@ -53,10 +55,10 @@ def test_session_format_evaluation(): result = session.evaluate("a/b") assert session.format_result(form="unformatted").sameQ(result) assert session.format_result(form="text") == "a / b" - assert session.format_result(form="latex") == "\\frac{a}{b}" assert session.format_result(form="xml") == ( '\n \n a\n b\n \n' ) + assert session.format_result(form="latex") == "\\frac{a}{b}" def test_session_parse(): From a1e1b003f36ac54c510aca6cf7c45811b51067b0 Mon Sep 17 00:00:00 2001 From: Juan Mauricio Matera Date: Tue, 1 Sep 2026 22:04:15 -0300 Subject: [PATCH 3/7] passing tests --- mathics/builtin/forms/print.py | 5 +++-- mathics/format/box/formatvalues.py | 32 +++++++++++++++++++++--------- mathics/format/box/makeboxes.py | 9 ++++++++- test/builtin/test_forms.py | 5 ++--- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/mathics/builtin/forms/print.py b/mathics/builtin/forms/print.py index 685a16d54..ce5a1d406 100644 --- a/mathics/builtin/forms/print.py +++ b/mathics/builtin/forms/print.py @@ -19,6 +19,7 @@ from mathics.core.expression import Expression from mathics.core.symbols import SymbolFalse, SymbolTrue from mathics.core.systemsymbols import SymbolInputForm, SymbolOutputForm +from mathics.format.box.formatvalues import do_format_element from mathics.format.box.makeboxes import is_print_form_callback from mathics.format.form import render_input_form, render_output_form @@ -256,8 +257,8 @@ def eval_makeboxes_outputform(expr: BaseElement, evaluation: Evaluation, **kwarg """ Build a 2D representation of the expression using only keyboard characters. """ - - text_outputform = str(render_output_form(expr, evaluation, **kwargs)) + f_expr = do_format_element(expr, evaluation, SymbolOutputForm) + text_outputform = str(render_output_form(f_expr, evaluation, **kwargs)) pane = PaneBox(String('"' + text_outputform + '"')) return InterpretationBox( pane, Expression(SymbolOutputForm, expr), **{"System`Editable": SymbolFalse} diff --git a/mathics/format/box/formatvalues.py b/mathics/format/box/formatvalues.py index 909a605e4..37ea3c2d1 100644 --- a/mathics/format/box/formatvalues.py +++ b/mathics/format/box/formatvalues.py @@ -30,7 +30,7 @@ SymbolRepeatedNull, SymbolTimes, ) -from mathics.core.systemsymbols import SymbolMinus +from mathics.core.systemsymbols import SymbolInputForm, SymbolMinus, SymbolOutputForm # These Strings are used in Boxing output StringElipsis = String("...") @@ -64,7 +64,7 @@ def do_format_element( Applies formats associated to the expression and removes superfluous enclosing formats. """ - from mathics.core.definitions import BOX_FORMS, OUTPUT_FORMS + from mathics.core.definitions import OUTPUT_FORMS head: BaseElement @@ -73,16 +73,26 @@ def do_format_element( expr = element head = element.get_head() # use element.head elements = element.get_elements() - # If the expression is enclosed by a Format - # leave it as it is. MakeBoxes is going to - # solve it later... - if head in BOX_FORMS and len(elements) == 1 and isinstance(head, Symbol): - return do_format_element(elements[0], evaluation, head) - if head in OUTPUT_FORMS and len(elements) == 1 and isinstance(head, Symbol): - return expr + include_form = False + + if elements is not None and len(elements) == 1: + # Special cases: SymbolInputForm and SymbolOutputForm + # are only processed from MakeBoxes, using the explicit + # form parameter. + if head in (SymbolInputForm, SymbolOutputForm): + return expr + # If the expression is enclosed by other Format + # takes the form from the expression and + # removes the format from the expression. + if head in OUTPUT_FORMS and isinstance(head, Symbol): + expr = elements[0] + form = head + include_form = True # If form is Fullform, return it without changes if form is SymbolFullForm: + if include_form: + expr = Expression(form, expr) return expr # Repeated and RepeatedNull confuse the formatter, @@ -132,6 +142,8 @@ def format_expr(expr): if formatted is not None: do_format_fn = _element_formatters.get(type(formatted), do_format_element) result = do_format_fn(formatted, evaluation, form) + if include_form and result is not None: + result = Expression(form, result) return result # If the expression is still enclosed by a Format, @@ -169,6 +181,8 @@ def format_expr(expr): head = do_format(expr_head, evaluation, form) or expr_head expr = to_expression_with_specialization(head, *new_elements) + if include_form: + expr = Expression(form, expr) return expr finally: evaluation.dec_recursion_depth() diff --git a/mathics/format/box/makeboxes.py b/mathics/format/box/makeboxes.py index 38c7a01c0..5d0f1ad81 100644 --- a/mathics/format/box/makeboxes.py +++ b/mathics/format/box/makeboxes.py @@ -26,6 +26,8 @@ from mathics.core.systemsymbols import ( # SymbolRule, SymbolRuleDelayed, SymbolAborted, SymbolComplex, + SymbolInputForm, + SymbolOutputForm, SymbolParentForm, SymbolRational, SymbolStandardForm, @@ -332,7 +334,12 @@ def format_element( """ was_boxing = evaluation.is_boxing evaluation.is_boxing = True - formatted_expr = do_format(element, evaluation, form) + # InputForm and OutputForm do format in the MakeBoxes implementation. + if form in (SymbolInputForm, SymbolOutputForm): + formatted_expr = element + else: + formatted_expr = do_format(element, evaluation, form) + if form not in evaluation.definitions.boxforms: formatted_expr = Expression(form, formatted_expr) form = SymbolStandardForm diff --git a/test/builtin/test_forms.py b/test/builtin/test_forms.py index e822bbd1d..16650ebcb 100644 --- a/test/builtin/test_forms.py +++ b/test/builtin/test_forms.py @@ -24,8 +24,7 @@ def test_makeboxes_form(expr, form, head, subhead): Check the structure of the result of MakeBoxes on expressions with different forms. """ - expr = session.evaluate(f"MakeBoxes[{form}[{expr}]]") - print(f"MakeBoxes[{form}[{expr}]] ->{expr}") + expr = session.evaluate("MakeBoxes[{form}[{expr}]]") assert expr.get_head_name() == f"System`{head}" assert expr.elements[0].get_head_name() == f"System`{subhead}" @@ -392,7 +391,7 @@ def test_makeboxes_form(expr, form, head, subhead): ( "{{2*a, 0},{0,0}}//MatrixForm", None, - "2 a 0\n\n0 0\n", + "2 \u2062 a 0\n\n0 0\n", "Issue #182", ), ## From e6f89c5bf5f7da830a81b306b8a2e14090c7bb74 Mon Sep 17 00:00:00 2001 From: Juan Mauricio Matera Date: Tue, 1 Sep 2026 22:55:09 -0300 Subject: [PATCH 4/7] FormatValues --- mathics/builtin/assignments/clear.py | 10 +++++++++- mathics/core/assignment.py | 15 ++++++++++++--- mathics/core/definitions.py | 18 ++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/mathics/builtin/assignments/clear.py b/mathics/builtin/assignments/clear.py index b31bbae06..a03c57bd4 100644 --- a/mathics/builtin/assignments/clear.py +++ b/mathics/builtin/assignments/clear.py @@ -258,7 +258,6 @@ class Unset(PostfixOperator): def eval(self, expr, evaluation): "Unset[expr_]" - head = expr.get_head() if head in SYSTEM_SYMBOL_VALUES: if len(expr.elements) != 1: @@ -284,6 +283,15 @@ def eval(self, expr, evaluation): return SymbolFailed return SymbolNull + def eval(self, expr, evaluation): + "Unset[expr:MakeBoxes[_, _]]" + if not evaluation.definitions.unset_format( + "System`MakeBoxes", "_MakeBoxes", expr + ): + evaluation.message("Unset", "norep", expr, Symbol("System`MakeBoxes")) + return SymbolFailed + return SymbolNull + SYSTEM_SYMBOL_VALUES = symbol_set( SymbolDownValues, diff --git a/mathics/core/assignment.py b/mathics/core/assignment.py index f25dec5eb..d273518c7 100644 --- a/mathics/core/assignment.py +++ b/mathics/core/assignment.py @@ -115,13 +115,22 @@ def get_symbol_values( except KeyError: return ListExpression() - elements = [] + elements: list[BaseElement] = [] if position == "formatvalues": format_rules = definition.formatvalues for key, rules in format_rules.items(): - if key == "System`MakeBoxes": - elements.extend(rules) + if key == "_MakeBoxes": + elements.extend( + ( + Expression( + SymbolRuleDelayed, + Expression(SymbolHoldPattern, rule.pattern.expr), + rule.replace, + ) + for rule in rules + ) + ) continue if key: elements.extend( diff --git a/mathics/core/definitions.py b/mathics/core/definitions.py index 46624b2e6..3059d6081 100644 --- a/mathics/core/definitions.py +++ b/mathics/core/definitions.py @@ -107,6 +107,15 @@ def add_rule(self, rule: BaseRule) -> bool: return self.add_rule_at(rule, pos) return False + def remove_format_rule(self, lhs: BaseElement, form: str) -> bool: + """Remove a rule""" + format_rule_list = self.formatvalues.get(form, []) + for index, existing in enumerate(format_rule_list): + if existing.pattern.expr.sameQ(lhs): + del format_rule_list[index] + return True + return False + def remove_rule(self, lhs: BaseElement) -> bool: """Remove a rule""" position = get_tag_position(lhs, self.name) @@ -810,6 +819,15 @@ def unset(self, name: str, expr: BaseElement) -> bool: self.clear_definitions_cache(name) return result + def unset_format(self, name: str, form: str, expr: BaseElement) -> bool: + """Remove the rule corresponding to the expression `expr` in + the format `form` of the Definition `name`""" + definition = self.get_user_definition(self.lookup_name(name)) + result = definition.remove_format_rule(expr, form) + self.mark_changed(definition) + self.clear_definitions_cache(name) + return result + def get_config_value( self, name: str, default: Optional[int] = None ) -> Optional[int]: From 1f763823bfbc0ab2a3dd88d15167fb38c27e45e2 Mon Sep 17 00:00:00 2001 From: Juan Mauricio Matera Date: Tue, 1 Sep 2026 23:10:57 -0300 Subject: [PATCH 5/7] rename method --- mathics/builtin/assignments/clear.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathics/builtin/assignments/clear.py b/mathics/builtin/assignments/clear.py index a03c57bd4..8bd15bf65 100644 --- a/mathics/builtin/assignments/clear.py +++ b/mathics/builtin/assignments/clear.py @@ -283,7 +283,7 @@ def eval(self, expr, evaluation): return SymbolFailed return SymbolNull - def eval(self, expr, evaluation): + def eval_unset_makeboxes(self, expr, evaluation): "Unset[expr:MakeBoxes[_, _]]" if not evaluation.definitions.unset_format( "System`MakeBoxes", "_MakeBoxes", expr From a418d9c03ae835dae430683fbca18ad83010a71c Mon Sep 17 00:00:00 2001 From: Juan Mauricio Matera Date: Wed, 2 Sep 2026 08:24:55 -0300 Subject: [PATCH 6/7] ruff + restore test_session from trivial change --- mathics/builtin/assignments/clear.py | 20 ++------------------ mathics/core/systemsymbols.py | 10 ++++++++++ test/test_session.py | 4 +--- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/mathics/builtin/assignments/clear.py b/mathics/builtin/assignments/clear.py index 8bd15bf65..0777b699a 100644 --- a/mathics/builtin/assignments/clear.py +++ b/mathics/builtin/assignments/clear.py @@ -17,18 +17,13 @@ ) from mathics.core.builtin import Builtin, PostfixOperator from mathics.core.expression import Expression -from mathics.core.symbols import Atom, Symbol, SymbolNull, symbol_set +from mathics.core.symbols import Atom, Symbol, SymbolNull from mathics.core.systemsymbols import ( + SYSTEM_SYMBOL_VALUES, SymbolContext, SymbolContextPath, - SymbolDownValues, SymbolFailed, - SymbolMessages, - SymbolNValues, SymbolOptions, - SymbolOwnValues, - SymbolSubValues, - SymbolUpValues, ) @@ -291,14 +286,3 @@ def eval_unset_makeboxes(self, expr, evaluation): evaluation.message("Unset", "norep", expr, Symbol("System`MakeBoxes")) return SymbolFailed return SymbolNull - - -SYSTEM_SYMBOL_VALUES = symbol_set( - SymbolDownValues, - SymbolMessages, - SymbolNValues, - SymbolOptions, - SymbolOwnValues, - SymbolSubValues, - SymbolUpValues, -) diff --git a/mathics/core/systemsymbols.py b/mathics/core/systemsymbols.py index 234bf694d..cfbd92b87 100644 --- a/mathics/core/systemsymbols.py +++ b/mathics/core/systemsymbols.py @@ -447,3 +447,13 @@ SymbolRepeated, SymbolRepeatedNull, ) + +SYSTEM_SYMBOL_VALUES = symbol_set( + SymbolDownValues, + SymbolMessages, + SymbolNValues, + SymbolOptions, + SymbolOwnValues, + SymbolSubValues, + SymbolUpValues, +) diff --git a/test/test_session.py b/test/test_session.py index 7e5276e84..08d779a1f 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -8,12 +8,10 @@ from mathics.core.atoms import Integer1, Integer2, IntegerM1 from mathics.core.evaluation import Result from mathics.core.expression import Expression -from mathics.core.load_builtin import import_and_load_builtins from mathics.core.symbols import Symbol, SymbolNull from mathics.core.systemsymbols import SymbolDirectedInfinity, SymbolPower, SymbolTimes from mathics.session import MathicsSession -import_and_load_builtins() session = MathicsSession() @@ -55,10 +53,10 @@ def test_session_format_evaluation(): result = session.evaluate("a/b") assert session.format_result(form="unformatted").sameQ(result) assert session.format_result(form="text") == "a / b" + assert session.format_result(form="latex") == "\\frac{a}{b}" assert session.format_result(form="xml") == ( '\n \n a\n b\n \n' ) - assert session.format_result(form="latex") == "\\frac{a}{b}" def test_session_parse(): From 8aba73eb41c81497ffea18659daa27d76c79dd24 Mon Sep 17 00:00:00 2001 From: Juan Mauricio Matera Date: Wed, 2 Sep 2026 09:11:16 -0300 Subject: [PATCH 7/7] ruff --- SYMBOLS_MANIFEST.txt | 2 +- mathics/builtin/box/graphics3d.py | 4 ++-- mathics/builtin/drawing/graphics3d.py | 4 ++-- mathics/core/systemsymbols.py | 2 ++ mathics/doc/latex/testing-sample.tex | 2 +- mathics/eval/options/values.py | 2 +- mathics/format/box/graphics.py | 5 +++++ mathics/format/render/asy.py | 8 ++++---- mathics/format/render/json.py | 8 ++++---- test/builtin/assumptions/test_assumptions.py | 2 +- test/builtin/drawing/test_plot.py | 2 +- test/core/convert/test_sympy.py | 11 +---------- test/format/test_makeboxes.py | 2 -- test/timings/test_regressions.py | 3 --- 14 files changed, 25 insertions(+), 32 deletions(-) diff --git a/SYMBOLS_MANIFEST.txt b/SYMBOLS_MANIFEST.txt index 87a2cbf3e..2cc62f2b3 100644 --- a/SYMBOLS_MANIFEST.txt +++ b/SYMBOLS_MANIFEST.txt @@ -1131,7 +1131,7 @@ System`Sow System`Span System`SparseArray System`Sphere -System`Sphere3DBox +System`SphereBox System`SphericalBesselJ System`SphericalBesselY System`SphericalHankelH1 diff --git a/mathics/builtin/box/graphics3d.py b/mathics/builtin/box/graphics3d.py index ab6f33cb1..b362a94a4 100644 --- a/mathics/builtin/box/graphics3d.py +++ b/mathics/builtin/box/graphics3d.py @@ -271,7 +271,7 @@ def _apply_boxscaling(self, boxscale): coords.scale(boxscale) -class Sphere3DBox(GraphicsElementBox): +class SphereBox(GraphicsElementBox): # summary_text = "box representation for a sphere" # We have no documentation for this (yet). @@ -359,7 +359,7 @@ def _apply_boxscaling(self, boxscale): Symbol("Line3DBox"): Line3DBox, Symbol("Point3DBox"): Point3DBox, Symbol("Polygon3DBox"): Polygon3DBox, - Symbol("Sphere3DBox"): Sphere3DBox, + Symbol("SphereBox"): SphereBox, Symbol("Tube3DBox"): Tube3DBox, } ) diff --git a/mathics/builtin/drawing/graphics3d.py b/mathics/builtin/drawing/graphics3d.py index e384d476f..73cf69f62 100644 --- a/mathics/builtin/drawing/graphics3d.py +++ b/mathics/builtin/drawing/graphics3d.py @@ -88,7 +88,7 @@ class Graphics3D(Graphics): . size(6.6667cm, 6.6667cm); . currentprojection=perspective(2.6,-4.8,4.0); . currentlight=light(rgb(0.5,0.5,0.5), specular=red, (2,0,2), (2,2,2), (0,2,2)); - . // Sphere3DBox + . // SphereBox . draw(surface(sphere((0, 0, 0), 1)), rgb(1,1,1)+opacity(1)); . draw(((-1,-1,-1)--(1,-1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1)); . draw(((-1,1,-1)--(1,1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1)); @@ -130,7 +130,7 @@ class Graphics3D(Graphics): "ViewProjection": "Automatic", "ViewRange": "All", "ViewVector": "Automatic", - "ViewVertical": "{0,0,1}", + "ViewVertical": "{0.,0.,1.}", } ) diff --git a/mathics/core/systemsymbols.py b/mathics/core/systemsymbols.py index cfbd92b87..9309b0a4a 100644 --- a/mathics/core/systemsymbols.py +++ b/mathics/core/systemsymbols.py @@ -348,6 +348,8 @@ SymbolSortBy: Final[Symbol] = Symbol("System`SortBy") SymbolSpan: Final[Symbol] = Symbol("System`Span") SymbolSparseArray: Final[Symbol] = Symbol("System`SparseArray") +SymbolSphere: Final[Symbol] = Symbol("System`Sphere") +SymbolSphereBox: Final[Symbol] = Symbol("System`SphereBox") SymbolSphericalRegion: Final[Symbol] = Symbol("System`SphericalRegion") SymbolSplit: Final[Symbol] = Symbol("System`Split") SymbolSqrt: Final[Symbol] = Symbol("System`Sqrt") diff --git a/mathics/doc/latex/testing-sample.tex b/mathics/doc/latex/testing-sample.tex index d2231553e..24716f925 100644 --- a/mathics/doc/latex/testing-sample.tex +++ b/mathics/doc/latex/testing-sample.tex @@ -31,7 +31,7 @@ \section*{TestSection} size(6.6667cm, 6.6667cm); currentprojection=perspective(2.6,-4.8,4.0); currentlight=light(rgb(0.5,0.5,0.5), specular=red, (2,0,2), (2,2,2), (0,2,2)); -// Sphere3DBox +// SphereBox draw(surface(sphere((0, 0, 0), 1)), rgb(0.0,0.6666666666666667,0.0)); draw(((-1,-1,-1)--(1,-1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1)); draw(((-1,1,-1)--(1,1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1)); diff --git a/mathics/eval/options/values.py b/mathics/eval/options/values.py index c59c97756..220361bff 100644 --- a/mathics/eval/options/values.py +++ b/mathics/eval/options/values.py @@ -1,5 +1,5 @@ from mathics.core.parser import parse_builtin_rule -from mathics.core.symbols import SymbolList, strip_context +from mathics.core.symbols import strip_context def filter_non_default_values(builtin): diff --git a/mathics/format/box/graphics.py b/mathics/format/box/graphics.py index 20a345ed6..edb698374 100644 --- a/mathics/format/box/graphics.py +++ b/mathics/format/box/graphics.py @@ -39,6 +39,8 @@ SymbolGraphics, SymbolInset, SymbolOffset, + SymbolSphere, + SymbolSphereBox, SymbolStyle, SymbolText, ) @@ -956,6 +958,9 @@ def primitives_to_boxes( ], ) + # Sphere-> SphereBox, no Sphere3DBox... + if head is SymbolSphere: + return Expression(SymbolSphereBox, *content.elements) if head in ELEMENT_HEADS: if head is SymbolText: head = SymbolInset diff --git a/mathics/format/render/asy.py b/mathics/format/render/asy.py index 28f479470..4b0e12bfb 100644 --- a/mathics/format/render/asy.py +++ b/mathics/format/render/asy.py @@ -26,7 +26,7 @@ Line3DBox, Point3DBox, Polygon3DBox, - Sphere3DBox, + SphereBox, Tube3DBox, ) from mathics.builtin.box.uniform_polyhedra import UniformPolyhedron3DBox @@ -700,14 +700,14 @@ def roundbox(box: RoundBox): add_render_function(RoundBox) -def sphere3dbox(box: Sphere3DBox, **options) -> str: +def spherebox(box: SphereBox, **options) -> str: # l = box.style.get_line_width(face_element=True) face_color = box.face_color.to_js() if box.face_color else (1, 1, 1) opacity = box.face_opacity color_str = build_3d_pen_color(face_color, opacity) - return "// Sphere3DBox\n" + "\n".join( + return "// SphereBox\n" + "\n".join( "draw(surface(sphere({0}, {1})), {2});".format( tuple(coord.pos()[0]), box.radius, color_str ) @@ -715,7 +715,7 @@ def sphere3dbox(box: Sphere3DBox, **options) -> str: ) -add_render_function(Sphere3DBox) +add_render_function(SphereBox) def tube_3d_box(box: Tube3DBox, **options) -> str: diff --git a/mathics/format/render/json.py b/mathics/format/render/json.py index 8ffff74ed..e08d2b05c 100644 --- a/mathics/format/render/json.py +++ b/mathics/format/render/json.py @@ -15,7 +15,7 @@ Line3DBox, Point3DBox, Polygon3DBox, - Sphere3DBox, + SphereBox, Tube3DBox, ) from mathics.builtin.box.uniform_polyhedra import UniformPolyhedron3DBox @@ -271,7 +271,7 @@ def polygon_3d_box(box: Polygon3DBox) -> list: add_render_function(Polygon3DBox, polygon_3d_box) -def sphere_3d_box(box: Sphere3DBox) -> list: +def sphere_3d_box(box: SphereBox) -> list: face_color = box.face_color.to_js() if len(face_color) < 4 and box.face_opacity: face_color = face_color + [box.face_opacity.opacity] @@ -281,11 +281,11 @@ def sphere_3d_box(box: Sphere3DBox) -> list: face_color, {"radius": box.radius}, ) - # print("### json Sphere3DBox", data) + # print("### json SphereBox", data) return data -add_render_function(Sphere3DBox, sphere_3d_box) +add_render_function(SphereBox, sphere_3d_box) def uniform_polyhedron_3d_box(box: UniformPolyhedron3DBox) -> list: diff --git a/test/builtin/assumptions/test_assumptions.py b/test/builtin/assumptions/test_assumptions.py index e331af528..bde383848 100644 --- a/test/builtin/assumptions/test_assumptions.py +++ b/test/builtin/assumptions/test_assumptions.py @@ -152,7 +152,7 @@ def test_assumptions_integrate(str_expr, str_expected, message): LIST_TEST_ASSUMPTIONS_INTEGRATE_FAILING, ) @pytest.mark.xfail(reason="the Assumptions with Integrate is not fully working") -def test_assumptions_integrate(str_expr, str_expected, message): +def test_assumptions_integrate2(str_expr, str_expected, message): check_evaluation(str_expr, str_expected) diff --git a/test/builtin/drawing/test_plot.py b/test/builtin/drawing/test_plot.py index c293cab30..db7fced86 100644 --- a/test/builtin/drawing/test_plot.py +++ b/test/builtin/drawing/test_plot.py @@ -184,7 +184,7 @@ def test__listplot(): "size(6.6667cm, 6.6667cm);\n" "currentprojection=perspective(2.6,-4.8,4.0);\n" "currentlight=light(rgb(0.5,0.5,0.5), background=rgb(1, 0.1, 0.1), specular=red, (2,0,2), (2,2,2), (0,2,2));\n" - "// Sphere3DBox\n" + "// SphereBox\n" "draw(surface(sphere((0, 0, 0), 1)), rgb(1,1,1)+opacity(1));\n" "draw(((-1,-1,-1)--(1,-1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1));\n" "draw(((-1,1,-1)--(1,1,-1)), rgb(0.4, 0.4, 0.4)+linewidth(1));\n" diff --git a/test/core/convert/test_sympy.py b/test/core/convert/test_sympy.py index ce1117838..35df0c7c2 100644 --- a/test/core/convert/test_sympy.py +++ b/test/core/convert/test_sympy.py @@ -39,16 +39,7 @@ Symbol_F = Symbol("Global`F") Symbol_G = Symbol("Global`G") -from mathics.core.expression import Expression -from mathics.core.expression_predefined import MATHICS3_COMPLEX_INFINITY -from mathics.core.symbols import ( - Symbol, - SymbolNull, - SymbolPlus, - SymbolPower, - SymbolTimes, -) -from mathics.core.systemsymbols import SymbolE, SymbolExp, SymbolI, SymbolPi, SymbolSin +from mathics.core.symbols import Symbol Symbol_a = Symbol("Global`a") Symbol_b = Symbol("Global`b") diff --git a/test/format/test_makeboxes.py b/test/format/test_makeboxes.py index 1626df519..8925fada3 100644 --- a/test/format/test_makeboxes.py +++ b/test/format/test_makeboxes.py @@ -88,7 +88,6 @@ def test_makeboxes_precedence(str_expr, str_expected, msg): ("str_expr", "str_expected", "msg"), list(makeboxes_basic_forms_iterator("Graphics")), ) -@skip_or_fail def test_makeboxes_graphics(str_expr, str_expected, msg): """ # TODO: Constructing boxes from Real which are currently failing @@ -231,7 +230,6 @@ def test_makeboxes_others_fail(str_expr, str_expected, msg): ), ], ) -@skip_or_fail def test_makeboxes_custom(str_expr, str_expected, msg): """ These tests checks the behaviour of MakeBoxes. diff --git a/test/timings/test_regressions.py b/test/timings/test_regressions.py index 096000980..968e84e66 100644 --- a/test/timings/test_regressions.py +++ b/test/timings/test_regressions.py @@ -152,9 +152,6 @@ param_ids = [name for name, _, _, _ in BENCHMARK_TASKS] -import pytest - - @pytest.mark.skipif( not os.environ.get("BENCHMARKS", 0), reason="benchmarks not required" )