diff --git a/mathics/builtin/forms/print.py b/mathics/builtin/forms/print.py index 2e47e2fe9..685a16d54 100644 --- a/mathics/builtin/forms/print.py +++ b/mathics/builtin/forms/print.py @@ -161,7 +161,6 @@ class OutputForm(FormBaseClass): in_outputforms = True in_printforms = True - formats = {"OutputForm[s_String]": "s"} summary_text = "format expression in plain text" diff --git a/mathics/doc/doc_entries.py b/mathics/doc/doc_entries.py index a16f2acf2..11b777947 100644 --- a/mathics/doc/doc_entries.py +++ b/mathics/doc/doc_entries.py @@ -10,7 +10,6 @@ import logging import re from abc import ABC -from os import getenv from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Sequence, Tuple from mathics.core.evaluation import Message, Print, _Out diff --git a/mathics/format/box/outputforms.py b/mathics/format/box/outputforms.py index 60d187f4d..a248d127f 100644 --- a/mathics/format/box/outputforms.py +++ b/mathics/format/box/outputforms.py @@ -30,7 +30,7 @@ def eval_mathmlform(expr: BaseElement, evaluation: Evaluation) -> BoxElementMixi boxes = format_element(expr, evaluation, SymbolTraditionalForm) try: - mathml = boxes.boxes_to_mathml(evaluation=evaluation) + mathml = boxes.boxes_to_mathml(evaluation=evaluation, _indent_level=1) except BoxError: evaluation.message( "General", @@ -44,9 +44,15 @@ def eval_mathmlform(expr: BaseElement, evaluation: Evaluation) -> BoxElementMixi # #convert_box(boxes) query = evaluation.parse("Settings`$UseSansSerif") usesansserif = query.evaluate(evaluation).to_python() - if not is_a_picture: - if isinstance(usesansserif, bool) and usesansserif: - mathml = '%s' % mathml + if is_a_picture: + usesansserif = False + elif not isinstance(usesansserif, bool): + usesansserif = False + + if usesansserif: + mathml = '\n%s\n' % mathml + else: + mathml = "\n%s\n" % mathml mathml = '%s' % mathml # convert_box(boxes) return InterpretationBox( diff --git a/mathics/format/render/mathml.py b/mathics/format/render/mathml.py index 9ef9f0ee0..e69a7945a 100644 --- a/mathics/format/render/mathml.py +++ b/mathics/format/render/mathml.py @@ -2,11 +2,31 @@ """ Mathics3 Box rendering to MathML strings. -MathML rendering is usually initiated via MathMLForm[]. -""" +MathML formatting is usually initiated in Mathics via MathMLForm[]. + +For readability, and following WMA MathML generated code, tags \ +containing sub-tags are split on several lines, one by +sub element, and indented according to the level of the part. \ +For example, the Box expression + +>> FractionBox[RowBox[{"a", "+", SuperscriptBox["b", "c"]}], "d"] + +produces +``` + + + a + + + + b + c + + + d + +``` -# Please see the developer note in __init__ about the use of "%s" in -# format strings. +""" import base64 @@ -72,15 +92,22 @@ def encode_mathml(text: str) -> str: named_characters["DifferentialD"], } + add_conversion_fn(FormBox, convert_inner_box) def fractionbox(box: FractionBox, **options) -> str: # Note: values set in `options` take precedence over `box_options` + indent_level = options.get("_indent_level", 0) + indent_spaces = " " * indent_level child_options = {**options, **box.box_options} + child_options["_indent_level"] = indent_level + 1 num_text = convert_box_to_format(box.num, **child_options) den_text = convert_box_to_format(box.den, **child_options) - return "%s %s" % (num_text, den_text) + return f"{indent_spaces}\n%s\n%s\n{indent_spaces}" % ( + num_text, + den_text, + ) add_conversion_fn(FractionBox, fractionbox) @@ -88,8 +115,17 @@ def fractionbox(box: FractionBox, **options) -> str: def graphics3dbox(box: Graphics3DBox, elements=None, **options) -> str: """Turn the Graphics3DBox into a MathML string""" - result = box.boxes_to_js(**options) - result = f"{result}" + indent_level = options.get("_indent_level", 0) + indent_spaces = " " * indent_level + result = box.box_to_js(**options) + result = ( + f"{indent_spaces}\n" + f"\n" + f"{indent_spaces} \n" + f"{indent_spaces} {result}\n" + f"{indent_spaces} \n\n" + f"{indent_spaces}" + ) return result @@ -115,22 +151,25 @@ def graphicsbox(box: GraphicsBox, elements=None, **options) -> str: int(box.boxheight), base64.b64encode(svg_body.encode("utf8")).decode("utf8"), ) - # print("boxes_to_mathml", mathml) + indent_level = options.get("_indent_level", 0) + if indent_level: + mathml = " " * indent_level + mathml + # print("box_to_mathml", mathml) return mathml add_conversion_fn(GraphicsBox, graphicsbox) -def gridbox(box: GridBox, elements=None, **box_options) -> str: +def gridbox(box: GridBox, elements=None, **super_options) -> str: if not elements: elements = box._elements - evaluation = box_options.get("evaluation") - items, options = box.get_array(elements, evaluation) + evaluation = super_options.get("evaluation") + items, box_options = box.get_array(elements, evaluation) num_fields = max(len(item) if isinstance(item, tuple) else 1 for item in items) attrs = {} - column_alignments = options["System`ColumnAlignments"].get_name() + column_alignments = box_options["System`ColumnAlignments"].get_name() try: attrs["columnalign"] = { "System`Center": "center", @@ -141,36 +180,71 @@ def gridbox(box: GridBox, elements=None, **box_options) -> str: # invalid column alignment raise BoxConstructError joined_attrs = " ".join(f'{name}="{value}"' for name, value in attrs.items()) - result = f"\n" + indent_level = super_options.get("_indent_level", 0) + indent_spaces = " " * indent_level + child_options = {**super_options, **box_options} + child_options["_indent_level"] = indent_level + 3 + result = f"{indent_spaces}\n" + for row in items: - result += "" + result += f"{indent_spaces} " if isinstance(row, tuple): for item in row: item.inside_list = True - result += f"%s" % convert_box_to_format( - item, **box_options + result += ( + f"\n{indent_spaces} \n%s\n{indent_spaces} " + % convert_box_to_format(item, **child_options) ) else: row.inside_list = True result += ( - f"%s" - % convert_box_to_format(item, **box_options) + f"\n{indent_spaces} \n%s\n{indent_spaces} " + % convert_box_to_format(row, **child_options) ) - - result += "\n" - result += "" + result += f"\n{indent_spaces} \n" + result += f"{indent_spaces}" # print(f"gridbox: {result}") return result add_conversion_fn(GridBox, gridbox) -add_conversion_fn(InterpretationBox, convert_inner_box) + + +def interpretation_box(box: InterpretationBox, **options): + origin = box.expr + child_options = {**options, **box.box_options} + box = box.inner_box + if origin.has_form("InputForm", None): + # InputForm produce outputs of the form + # InterpretationBox[Style[_String, ...], origin_InputForm, opts___] + assert isinstance(box, StyleBox), f"box={box} is not a StyleBox" + box = box.inner_box + child_options["System`ShowStringCharacters"] = SymbolTrue + assert isinstance(box, String) + elif origin.has_form("OutputForm", None): + # OutputForm produce outputs of the form + # InterpretationBox[PaneBox[_String, ...], origin_OutputForm, opts___] + assert box.has_form("PaneBox", 1, None) + box = box.inner_box + assert isinstance(box, String) + # Remove the outer quotes + box = String(box.value) + + return convert_box_to_format(box, **child_options) + + +add_conversion_fn(InterpretationBox, interpretation_box) def pane_box(box: PaneBox, **options): - content = convert_inner_box_field(box, **options) - options = box.box_options - size = options.get("System`ImageSize", SymbolAutomatic).to_python() + """render a PaneBox into mathml code""" + indent_level = options.get("_indent_level", 0) + indent_spaces = " " * indent_level + child_options = {**options, **box.box_options} + child_options["_indent_level"] = indent_level + 1 + + content = convert_inner_box_field(box, **child_options) + size = child_options.get("System`ImageSize", SymbolAutomatic).to_python() if size is SymbolAutomatic: width = "" height = "" @@ -198,8 +272,8 @@ def pane_box(box: PaneBox, **options): dims += "overflow:hidden;" dims = f' style="{dims}" ' if dims: - return f"\n{content}\n" - return content + return f"{indent_spaces}\n{content}\n{indent_spaces}" + return f"{indent_spaces}{content}" add_conversion_fn(PaneBox, pane_box) @@ -207,7 +281,11 @@ def pane_box(box: PaneBox, **options): def rowbox(box: RowBox, **options) -> str: # Note: values set in `options` take precedence over `box_options` + indent_level = options.get("_indent_level", 0) + indent_spaces = " " * indent_level + child_options = {**box.box_options, **options} + child_options["_indent_level"] = indent_level + 1 result = [] inside_row = box.inside_row @@ -238,21 +316,27 @@ def is_list_interior(content): result.append(convert_box_to_format(element, **child_options)) # print(f"mrow: {result}") - - return "%s" % " ".join(result) + return f"{indent_spaces}\n%s\n{indent_spaces}" % ("\n".join(result),) add_conversion_fn(RowBox, rowbox) def sqrtbox(box: SqrtBox, **options): + # Note: values set in `options` take precedence over `box_options` + indent_level = options.get("_indent_level", 0) + indent_spaces = " " * indent_level + child_options = {**options, **box.box_options} + child_options["_indent_level"] = indent_level + 1 if box.index: - return " %s %s " % ( - convert_inner_box_field(box, "radicand", **options), - convert_inner_box_field(box, "index", **options), + return f"{indent_spaces}\n%s\n%s\n{indent_spaces}" % ( + convert_inner_box_field(box, "radicand", **child_options), + convert_inner_box_field(box, "index", **child_options), ) - - return " %s " % convert_inner_box_field(box, "radicand", **options) + return ( + f"{indent_spaces}\n%s\n{indent_spaces}" + % convert_inner_box_field(box, "radicand", **child_options) + ) add_conversion_fn(SqrtBox, sqrtbox) @@ -269,18 +353,18 @@ def string(s: String, **options) -> str: if number_as_text is None: number_as_text = SymbolFalse + indent_level = options.get("_indent_level", 0) + indent_spaces = " " * indent_level + def render(format, string): encoded_text = encode_mathml(string) - return format % encoded_text + return indent_spaces + format % encoded_text if text.startswith('"') and text.endswith('"'): - if show_string_characters: - return render("%s", text[1:-1]) - else: - outtext = "" - for line in text[1:-1].split("\n"): - outtext += render("%s", line) - return outtext + text = text[1:-1] + if not show_string_characters: + return render("%s", text) + return render("%s", text) elif ( text and (number_as_text is SymbolFalse) @@ -295,11 +379,7 @@ def render(format, string): # Mathics-Django: if text == "": return "" - if text == "\u2146": - return render( - '%s', text - ) - if text == "\u2062": + if text == named_characters["InvisibleTimes"]: return render( '%s', text ) @@ -307,19 +387,23 @@ def render(format, string): elif is_symbol_name(text): return render("%s", text) else: - outtext = "" - for line in text.split("\n"): - outtext += render("%s", line) - return outtext + return "".join( + render("%s", line) for line in text.split("\n") + ) add_conversion_fn(String, string) def subscriptbox(box: SubscriptBox, **options): - return "%s %s" % ( - convert_inner_box_field(box, "base", **options), - convert_inner_box_field(box, "subindex", **options), + # Note: values set in `options` take precedence over `box_options` + indent_level = options.get("_indent_level", 0) + indent_spaces = " " * indent_level + child_options = {**options, **box.box_options} + child_options["_indent_level"] = indent_level + 1 + return f"{indent_spaces}\n%s\n%s\n{indent_spaces}" % ( + convert_inner_box_field(box, "base", **child_options), + convert_inner_box_field(box, "subindex", **child_options), ) @@ -328,11 +412,15 @@ def subscriptbox(box: SubscriptBox, **options): def subsuperscriptbox(box: SubsuperscriptBox, **options): # Note: values set in `options` take precedence over `box_options` + indent_level = options.get("_indent_level", 0) + indent_spaces = " " * indent_level + child_options = {**options, **box.box_options} + child_options["_indent_level"] = indent_level + 1 box.base.inside_row = box.subindex.inside_row = box.superindex.inside_row = True - return "%s %s %s" % ( - convert_inner_box_field(box, "base", **options), - convert_inner_box_field(box, "subindex", **options), - convert_inner_box_field(box, "superindex", **options), + return f"{indent_spaces}\n%s\n%s\n%s\n{indent_spaces}" % ( + convert_inner_box_field(box, "base", **child_options), + convert_inner_box_field(box, "subindex", **child_options), + convert_inner_box_field(box, "superindex", **child_options), ) @@ -341,9 +429,13 @@ def subsuperscriptbox(box: SubsuperscriptBox, **options): def superscriptbox(box: SuperscriptBox, **options): # Note: values set in `options` take precedence over `box_options` - return "%s %s" % ( - convert_inner_box_field(box, "base", **options), - convert_inner_box_field(box, "superindex", **options), + indent_level = options.get("_indent_level", 0) + indent_spaces = " " * indent_level + child_options = {**options, **box.box_options} + child_options["_indent_level"] = indent_level + 1 + return f"{indent_spaces}\n%s\n%s\n{indent_spaces}" % ( + convert_inner_box_field(box, "base", **child_options), + convert_inner_box_field(box, "superindex", **child_options), ) diff --git a/test/builtin/box/test_custom_boxexpression.py b/test/builtin/box/test_custom_boxexpression.py index aaac0e8d2..c33447cea 100644 --- a/test/builtin/box/test_custom_boxexpression.py +++ b/test/builtin/box/test_custom_boxexpression.py @@ -6,7 +6,7 @@ from mathics.core.builtin import Predefined from mathics.core.evaluation import Evaluation from mathics.core.expression import Expression -from mathics.core.rules import BaseRule, FunctionApplyRule, Rule +from mathics.core.rules import FunctionApplyRule from mathics.core.symbols import Symbol SymbolCustomGraphicsBox = Symbol("CustomGraphicsBox") diff --git a/test/builtin/test_system.py b/test/builtin/test_system.py index 9868cba7f..0008f2615 100644 --- a/test/builtin/test_system.py +++ b/test/builtin/test_system.py @@ -4,7 +4,6 @@ """ -import os from test.helper import check_evaluation import pytest diff --git a/test/format/format_tests-WMA.yaml b/test/format/format_tests-WMA.yaml index 4a00ee4b1..975084146 100644 --- a/test/format/format_tests-WMA.yaml +++ b/test/format/format_tests-WMA.yaml @@ -23,7 +23,6 @@ # because we use both in documentation and in the web interface. # - '"-7.32"': msg: A String with a number latex: @@ -402,36 +401,15 @@ Graphics[{}]: Grid[{{a,b},{c,d}}]: msg: GridBox latex: - InputForm: \text{Grid[\{\{a, b\}, \{c, d\}\}]} + InputForm: '\text{Grid[$\{\{$a, b$\}$, $\{$c, d$\}\}$]}' OutputForm: \begin{array}{cc} a & b\\ c & d\end{array} - StandardForm: \begin{array}{cc} a & b\\ c & d\end{array} - TraditionalForm: \begin{array}{cc} a & b\\ c & d\end{array} + StandardForm: "\\begin{array}{cc}\n a & b\\\\\n c & d\n\\end{array}" + TraditionalForm: "\\begin{array}{cc}\n a & b\\\\\n c & d\n\\end{array}" mathml: - InputForm: Grid [ { { - a b } - { c - d } } ] - OutputForm: ' - - ab - - cd - - ' - StandardForm: ' - - ab - - cd - - ' - TraditionalForm: ' - - ab - - cd - - ' + InputForm: 'Grid [ { { a b } { c d } } ]' + StandardForm: "\n \n \n a\n \n \n b\n \n \n \n \n c\n \n \n d\n \n \n " + TraditionalForm: "\n ab\n + cd\n " text: InputForm: Grid[{{a, b}, {c, d}}] OutputForm: 'a b @@ -556,12 +534,8 @@ Subscript[a, 4]: - Subscript [ a 4 ] - Fragile! - OutputForm: - - Subscript [ a - 4 ] - - Fragile! - StandardForm: a 4 - TraditionalForm: a 4 + StandardForm: "\n a\n 4\n " + TraditionalForm: "\n a\n 4\n " text: InputForm: Subscript[a, 4] OutputForm: "a\n 4" @@ -583,8 +557,8 @@ Subsuperscript[a, p, q]: p q ] OutputForm: Subsuperscript [ a p q ] - StandardForm: a p q - TraditionalForm: a p q + StandardForm: "\n a\n p\n q\n " + TraditionalForm: "\n a\n p\n q\n " text: InputForm: Subsuperscript[a, p, q] OutputForm: " q\na\n p" @@ -703,15 +677,13 @@ a^(g[b]/c): latex: InputForm: \text{a${}^{\wedge}$(g[b]/c)} OutputForm: a\text{ ${}^{\wedge}$ }\left(g(b)\text{ / }c\right) - StandardForm: a^{\frac{g(b)}{c}} + StandardForm: a^{\frac{g[b]}{c}} TraditionalForm: a^{\frac{g(b)}{c}} mathml: - InputForm: a ^ ( b -  /  c ) - OutputForm: a  ^  ( - b  /  c ) - StandardForm: a b c - TraditionalForm: a g ( b ) c + InputForm: 'a^(g[b]/c)' + OutputForm: '<><>' + StandardForm: "\n a\n \n \n g\n [\n b\n ]\n \n c\n \n " + TraditionalForm: "\n a\n \n \n g\n \n (\n b\n )\n \n c\n \n " text: InputForm: a^(g[b]/c) OutputForm: " g[b]/c\na" @@ -727,12 +699,55 @@ a^4: StandardForm: a^4 TraditionalForm: a^4 mathml: - InputForm: a ^ 4 - OutputForm: a  ^  4 - StandardForm: a 4 - TraditionalForm: a 4 + InputForm: a^4 + StandardForm: "\n a\n 4\n " + TraditionalForm: "\n a\n 4\n " text: InputForm: a^4 OutputForm: " 4\na" StandardForm: "\\!\\(\\*SuperscriptBox[\"a\", \"4\"]\\)" TraditionalForm: "\\!\\(\\*FormBox[SuperscriptBox[\"a\", \"4\"], TraditionalForm]\\)" + + +Optional[x__]: + msg: Optional with one argument + latex: + System`OutputForm: '\text{x$\_\_$.}' + System`StandardForm: '\text{x$\_\_$.}' + mathml: + System`OutputForm: 'x__.' + System`StandardForm: 'x__.' + text: + System`InputForm: 'x__.' + System`OutputForm: 'x__.' + System`StandardForm: '\!\(\*RowBox[{"Optional", "[", "x__", "]"}]\)' + System`TraditionalForm: '\!\(\*FormBox[RowBox[{"Optional", "[", "x__", "]"}], TraditionalForm]\)' + + +Optional[x__, a+b]: + msg: Optional with two arguments + latex: + System`OutputForm: '\text{x$\_\_$:a + b}' + System`StandardForm: '\text{x$\_\_$}:a+b' + mathml: + System`OutputForm: 'x__ : a + b' + text: + System`InputForm: 'x__:a + b' + System`OutputForm: 'x__:a + b' + System`StandardForm: '\!\(\*RowBox[{"x__", ":", RowBox[{"a", "+", "b"}]}]\)' + System`TraditionalForm: '\!\(\*FormBox[RowBox[{"x__", ":", RowBox[{"a", "+", "b"}]}], TraditionalForm]\)' + + +a+PrecedenceForm[b+c,10]: + msg: "PrecedenceForm" + latex: + System`OutputForm: '\text{a + (b + c)}' + System`StandardForm: 'a+(b+c)' + mathml: + System`OutputForm: 'a + (b + c)' + System`StandardForm: "\n a\n +\n \n (\n \n b\n +\n c\n \n )\n \n " + text: + System`InputForm: 'a + PrecedenceForm[b + c, 10]' + System`OutputForm: 'a + (b + c)' + System`StandardForm: '\!\(\*RowBox[{"a", "+", RowBox[{"(", TagBox[RowBox[{"b", "+", "c"}], Function[PrecedenceForm[Slot[1], 10]]], ")"}]}]\)' + System`TraditionalForm: '\!\(\*FormBox[RowBox[{"a", "+", RowBox[{"(", TagBox[RowBox[{"b", "+", "c"}], Function[PrecedenceForm[Slot[1], 10]]], ")"}]}], TraditionalForm]\)' diff --git a/test/format/format_tests.yaml b/test/format/format_tests.yaml index 14d511606..569bb769b 100644 --- a/test/format/format_tests.yaml +++ b/test/format/format_tests.yaml @@ -139,8 +139,8 @@ mathml: System`InputForm: -4 System`OutputForm: -4 - System`StandardForm: - 4 - System`TraditionalForm: - 4 + System`StandardForm: "\n -\n 4\n" + System`TraditionalForm: "\n -\n 4\n" text: System`InputForm: '-4' System`OutputForm: '-4' @@ -158,8 +158,8 @@ mathml: System`InputForm: -4.32 System`OutputForm: -4.32 - System`StandardForm: - 4.32 - System`TraditionalForm: - 4.32 + System`StandardForm: "\n -\n 4.32\n" + System`TraditionalForm: "\n -\n 4.32\n" text: System`InputForm: '-4.32' System`OutputForm: '-4.32' @@ -177,8 +177,8 @@ mathml: System`InputForm: -4.33 System`OutputForm: -4.3 - System`StandardForm: - 4.33 - System`TraditionalForm: - 4.33 + System`StandardForm: "\n -\n 4.33\n" + System`TraditionalForm: "\n -\n 4.33\n" text: System`InputForm: -4.33`2. System`OutputForm: '-4.3' @@ -196,8 +196,8 @@ mathml: System`InputForm: -4.32 System`OutputForm: -4.320 - System`StandardForm: - 4.32 - System`TraditionalForm: - 4.32 + System`StandardForm: "\n -\n 4.32\n" + System`TraditionalForm: "\n -\n 4.32\n" text: System`InputForm: -4.32`4. System`OutputForm: '-4.320' @@ -271,11 +271,12 @@ System`OutputForm: - '1 / (1 + 1 / (1 + 1 / a))' - Fragile! - System`StandardForm: &id001 - - 1 1 + 1 1 - + 1 a + System`StandardForm: + - "\n 1\n \n 1\n +\n \n 1\n \n 1\n +\n \n 1\n a\n \n \n \n \n" + - Fragile! + System`TraditionalForm: + - "\n 1\n \n 1\n +\n \n 1\n \n 1\n +\n \n 1\n a\n \n \n \n \n" - Fragile! - System`TraditionalForm: *id001 text: System`InputForm: 1/(1 + 1/(1 + 1/a)) System`OutputForm: 1 / (1 + 1 / (1 + 1 / a)) @@ -293,14 +294,8 @@ mathml: System`InputForm: <|a -> x, b -> y, c -> <|d -> t|>|> System`OutputForm: '<|a -> x, b -> y, c -> <|d -> t|>|>' - System`StandardForm: <| a -> - x , b -> y - , c -> <| d - -> t |> |> - System`TraditionalForm: <| a -> - x , b -> y - , c -> <| d - -> t |> |> + System`StandardForm: "\n <|\n \n \n a\n ->\n x\n \n ,\n \n b\n ->\n y\n \n ,\n \n c\n ->\n \n <|\n \n d\n ->\n t\n \n |>\n \n \n \n |>\n" + System`TraditionalForm: "\n <|\n \n \n a\n ->\n x\n \n ,\n \n b\n ->\n y\n \n ,\n \n c\n ->\n \n <|\n \n d\n ->\n t\n \n |>\n \n \n \n |>\n" text: System`InputForm: <|a -> x, b -> y, c -> <|d -> t|>|> System`OutputForm: <|a -> x, b -> y, c -> <|d -> t|>|> @@ -316,18 +311,10 @@ Association[a -> x, b -> y, c -> Association[d -> t, Association[e -> u]]]: System`StandardForm: '\langle\vert a->x, b->y, c->\langle\vert d->t, e->u\vert\rangle \vert\rangle' System`TraditionalForm: '\langle\vert a->x, b->y, c->\langle\vert d->t, e->u\vert\rangle \vert\rangle' mathml: - System`InputForm: <|a -> x, b -> y, c -> <|d -> t, e -> u|>|> + System`InputForm: "<|a -> x, b -> y, c -> <|d -> t, e -> u|>|>" System`OutputForm: '<|a -> x, b -> y, c -> <|d -> t, e -> u|>|>' - System`StandardForm: <| a -> - x , b -> y - , c -> <| d - -> t , e -> - u |> |> - System`TraditionalForm: <| a -> - x , b -> y - , c -> <| d - -> t , e -> - u |> |> + System`StandardForm: "\n <|\n \n \n a\n ->\n x\n \n ,\n \n b\n ->\n y\n \n ,\n \n c\n ->\n \n <|\n \n \n d\n ->\n t\n \n ,\n \n e\n ->\n u\n \n \n |>\n \n \n \n |>\n" + System`TraditionalForm: "\n <|\n \n \n a\n ->\n x\n \n ,\n \n b\n ->\n y\n \n ,\n \n c\n ->\n \n <|\n \n \n d\n ->\n t\n \n ,\n \n e\n ->\n u\n \n \n |>\n \n \n \n |>\n" text: System`InputForm: <|a -> x, b -> y, c -> <|d -> t, e -> u|>|> System`OutputForm: <|a -> x, b -> y, c -> <|d -> t, e -> u|>|> @@ -345,11 +332,8 @@ Complex[1.09*^12, 3.]: mathml: System`InputForm: 1.09*^12 + 3.*I System`OutputForm: '1.09×10^12 + 3. I' - System`StandardForm: 1.09 *^ 12 - + 3.   I - System`TraditionalForm: "1.09 \xD7 10\ - \ 12 + 3. \u2062 I" + System`StandardForm: "\n \n 1.09\n *^\n 12\n \n +\n \n 3.\n  \n I\n \n" + System`TraditionalForm: "\n \n 1.09\n ×\n \n 10\n 12\n \n \n +\n \n 3.\n \n I\n \n" text: System`InputForm: 1.09*^12 + 3.*I System`OutputForm: "1.09\xD710^12 + 3. I" @@ -475,19 +459,9 @@ Graphics[{}]: \ \\text{Portuguese} & \\text{Ol\\`{a}!}\\\\ \\text{English} & \\text{Hi!}\\end{array}" mathml: System`InputForm: "Grid[{{"Spanish", "Hola!"}, {"Portuguese", "Olà!"}, {"English", "Hi!"}}]" - System`OutputForm: 'Spanish      Hola!Portuguese   Olà!English      Hi!' - System`StandardForm: "\nSpanishHola!\n\ - PortugueseOl\xE0!\nEnglishHi!\n\ - " - System`TraditionalForm: "\nSpanishHola!\n\ - PortugueseOl\xE0!\nEnglishHi!\n\ - " + System`OutputForm: 'Spanish      Hola!Portuguese   Olà!English      Hi!' + System`StandardForm: "\n \n \n Spanish\n \n \n Hola!\n \n \n \n \n Portuguese\n \n \n Olà!\n \n \n \n \n English\n \n \n Hi!\n \n \n" + System`TraditionalForm: "\n \n \n Spanish\n \n \n Hola!\n \n \n \n \n Portuguese\n \n \n Olà!\n \n \n \n \n English\n \n \n Hi!\n \n \n" text: System`InputForm: "Grid[{{\"Spanish\", \"Hola!\"}, {\"Portuguese\", \"Ol\xE0!\"\ }, {\"English\", \"Hi!\"}}]" @@ -514,21 +488,9 @@ Grid[{{a,b},{c,d}}]: ' mathml: System`InputForm: Grid[{{a, b}, {c, d}}] - System`OutputForm: 'a   bc   d' - System`StandardForm: ' - - ab - - cd - - ' - System`TraditionalForm: ' - - ab - - cd - - ' + System`OutputForm: 'a   bc   d' + System`StandardForm: "\n \n \n a\n \n \n b\n \n \n \n \n c\n \n \n d\n \n \n" + System`TraditionalForm: "\n \n \n a\n \n \n b\n \n \n \n \n c\n \n \n d\n \n \n" text: System`InputForm: Grid[{{a, b}, {c, d}}] System`OutputForm: 'a b @@ -559,11 +521,15 @@ Integrate[F[x], {x, a, g[b]}]: System`StandardForm: \int_a^{g[b]} F[x] \, dx System`TraditionalForm: \int_a^{g(b)} F(x) \, dx mathml: - System`InputForm: Integrate[F[x], {x, a, g[b]}] + System`InputForm: 'Integrate[F[x], {x, a, g[b]}]' System`OutputForm: 'Integrate[F[x], {x, a, g[b]}]' + System`StandardForm: "\n \n \n a\n \n g\n [\n b\n ]\n \n \n \u2062\n \n F\n [\n x\n ]\n \n \u2062\n \n 𝑑\n x\n \n" + System`TraditionalForm: "\n \n \n a\n \n g\n (\n b\n )\n \n \n \u2062\n \n F\n (\n x\n )\n \n \u2062\n \n 𝑑\n x\n \n" text: + System`InputForm: Integrate[F[x], {x, a, g[b]}] System`OutputForm: Integrate[F[x], {x, a, g[b]}] - + System`StandardForm: 'Subsuperscript[∫, a, g[b]]⁢F[x]⁢𝑑x' + System`TraditionalForm: 'Subsuperscript[∫, a, g(b)]⁢F(x)⁢𝑑x' MatrixForm[{{a,b},{c,d}}]: msg: GridBox in a matrix @@ -581,21 +547,9 @@ MatrixForm[{{a,b},{c,d}}]: System`TraditionalForm: \left(\begin{array}{cc} a & b\\ c & d\end{array}\right) mathml: System`InputForm: MatrixForm[{{a, b}, {c, d}}] - System`OutputForm: 'a   bc   d' - System`StandardForm: '( - - ab - - cd - - )' - System`TraditionalForm: '( - - ab - - cd - - )' + System`OutputForm: 'a   bc   d' + System`StandardForm: "\n (\n \n \n \n a\n \n \n b\n \n \n \n \n c\n \n \n d\n \n \n \n )\n" + System`TraditionalForm: "\n (\n \n \n \n a\n \n \n b\n \n \n \n \n c\n \n \n d\n \n \n \n )\n" text: System`InputForm: MatrixForm[{{a, b}, {c, d}}] System`OutputForm: 'a b @@ -627,17 +581,17 @@ Sqrt[1/(1+1/(1+1/a))]: System`TraditionalForm: \sqrt{\frac{1}{1+\frac{1}{1+\frac{1}{a}}}} mathml: System`InputForm: - - Sqrt[1/(1 + 1/(1 + 1/a))] + - Sqrt[1/(1 + 1/(1 + 1/a))] - Fragile! System`OutputForm: - 'Sqrt[1 / (1 + 1 / (1 + 1 / a))]' - Fragile! - System`StandardForm: &id002 - - 1 1 + 1 1 - + 1 a - + System`StandardForm: + - "\n \n 1\n \n 1\n +\n \n 1\n \n 1\n +\n \n 1\n a\n \n \n \n \n \n" - Fragile! - System`TraditionalForm: *id002 + System`TraditionalForm: + - "\n \n 1\n \n 1\n +\n \n 1\n \n 1\n +\n \n 1\n a\n \n \n \n \n \n" + - Fragile! text: System`InputForm: Sqrt[1/(1 + 1/(1 + 1/a))] System`OutputForm: Sqrt[1 / (1 + 1 / (1 + 1 / a))] @@ -659,8 +613,8 @@ Subscript[a, 4]: System`OutputForm: - 'Subscript[a, 4]' - Fragile! - System`StandardForm: a 4 - System`TraditionalForm: a 4 + System`StandardForm: "\n a\n 4\n" + System`TraditionalForm: "\n a\n 4\n" text: System`InputForm: Subscript[a, 4] System`OutputForm: Subscript[a, 4] @@ -680,8 +634,8 @@ Subsuperscript[a, p, q]: mathml: System`InputForm: Subsuperscript[a, p, q] System`OutputForm: 'Subsuperscript[a, p, q]' - System`StandardForm: a p q - System`TraditionalForm: a p q + System`StandardForm: "\n a\n p\n q\n" + System`TraditionalForm: "\n a\n p\n q\n" text: System`InputForm: Subsuperscript[a, p, q] System`OutputForm: Subsuperscript[a, p, q] @@ -741,21 +695,9 @@ TableForm[{{a,b},{c,d}}]: System`TraditionalForm: \begin{array}{cc} a & b\\ c & d\end{array} mathml: System`InputForm: TableForm[{{a, b}, {c, d}}] - System`OutputForm: 'a   bc   d' - System`StandardForm: ' - - ab - - cd - - ' - System`TraditionalForm: ' - - ab - - cd - - ' + System`OutputForm: 'a   bc   d' + System`StandardForm: "\n \n \n a\n \n \n b\n \n \n \n \n c\n \n \n d\n \n \n" + System`TraditionalForm: "\n \n \n a\n \n \n b\n \n \n \n \n c\n \n \n d\n \n \n" text: System`InputForm: TableForm[{{a, b}, {c, d}}] System`OutputForm: 'a b @@ -845,7 +787,7 @@ a^(g[b]/c): mathml: System`InputForm: a^(g[b]/c) System`OutputForm: 'a ^ (g[b] / c)' - System`TraditionalForm: a g ( b ) c + System`TraditionalForm: "\n a\n \n \n g\n (\n b\n )\n \n c\n \n" text: System`InputForm: a^(g[b]/c) System`OutputForm: a ^ (g[b] / c) @@ -863,8 +805,8 @@ a^4: mathml: System`InputForm: 'a^4' System`OutputForm: 'a ^ 4' - System`StandardForm: a 4 - System`TraditionalForm: a 4 + System`StandardForm: "\n a\n 4\n" + System`TraditionalForm: "\n a\n 4\n" text: System`InputForm: a^4 System`OutputForm: a ^ 4 @@ -908,7 +850,7 @@ a+PrecedenceForm[b+c,10]: System`StandardForm: 'a+(b+c)' mathml: System`OutputForm: 'a + (b + c)' - System`StandardForm: 'a + ( b + c )' + System`StandardForm: "\n a\n +\n \n (\n \n b\n +\n c\n \n )\n \n" text: System`InputForm: 'a + (PrecedenceForm[b + c, 10])' System`OutputForm: 'a + (b + c)' diff --git a/test/format/test_boxexpressions.py b/test/format/test_boxexpressions.py index 53f4ff6a8..4f4597fd2 100644 --- a/test/format/test_boxexpressions.py +++ b/test/format/test_boxexpressions.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from test.helper import check_evaluation, session +from test.helper import session import pytest diff --git a/test/format/test_svg.py b/test/format/test_svg.py index 395b6cead..0665a2008 100644 --- a/test/format/test_svg.py +++ b/test/format/test_svg.py @@ -57,8 +57,6 @@ def extract_svg_body(svg): def get_svg(expression): - from mathics.format.box.graphics import prepare_elements as prepare_elements2d - options = {} boxes = MakeBoxes(expression).evaluate(evaluation) format_fn = lookup_method(boxes, "svg") diff --git a/test/test_session.py b/test/test_session.py index 132d1617c..08d779a1f 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -55,11 +55,12 @@ def test_session_format_evaluation(): assert session.format_result(form="text") == "a / b" assert session.format_result(form="latex") == "\\frac{a}{b}" assert session.format_result(form="xml") == ( - '' "a b" "" + '\n \n a\n b\n \n' ) def test_session_parse(): + session.reset() parsed = session.parse("a/b") expected = Expression( SymbolTimes,