From ff5980dec90c5ddcc3eba477897ddbf6c36388d1 Mon Sep 17 00:00:00 2001 From: Pablo Emilio Escobar Gaviria Date: Thu, 28 Jan 2021 16:06:46 -0300 Subject: [PATCH 1/2] Added calls to replace_wl_with_plain_text in boxes_to_text and boxes_to_xml for String and Symbol --- mathics/core/evaluation.py | 4 +++- mathics/core/expression.py | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/mathics/core/evaluation.py b/mathics/core/evaluation.py index acbef039cb..37e098a8f4 100644 --- a/mathics/core/evaluation.py +++ b/mathics/core/evaluation.py @@ -233,7 +233,8 @@ def __init__( definitions=None, output=None, format="text", - catch_interrupt=True + catch_interrupt=True, + use_unicode=True ) -> None: from mathics.core.definitions import Definitions from mathics.core.expression import Symbol @@ -247,6 +248,7 @@ def __init__( self.stopped = False self.out = [] self.output = output if output else Output() + self.use_unicode = use_unicode self.listeners = {} self.options = None self.predetermined_out = None diff --git a/mathics/core/expression.py b/mathics/core/expression.py index 263690d680..02a8371497 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -14,7 +14,7 @@ from typing import Any from itertools import chain from bisect import bisect_left - +from mathics_scanner.characters import replace_wl_with_plain_text from mathics.core.numbers import get_type, dps, prec, min_prec, machine_precision from mathics.core.convert import sympy_symbol_prefix, SympyExpression @@ -1793,7 +1793,16 @@ def do_copy(self) -> 'Symbol': return Symbol(self.name) def boxes_to_text(self, **options) -> str: - return str(self.name) + name = str(self.name) + + if "evaluation" in options: + e = options["evaluation"] + return replace_wl_with_plain_text(name, use_unicode=e.use_unicode) + else: + return name + + def boxes_to_xml(self, **options) -> str: + return replace_wl_with_plain_text(str(self.name)) def atom_to_boxes(self, f, evaluation) -> 'String': return String(evaluation.definitions.shorten_name(self.name)) @@ -2528,6 +2537,10 @@ def boxes_to_text(self, show_string_characters=False, **options) -> str: value.startswith('"') and value.endswith('"')): value = value[1:-1] + if "evaluation" in options: + e = options["evaluation"] + value = replace_wl_with_plain_text(value, e.use_unicode) + return value def boxes_to_xml(self, show_string_characters=False, **options) -> str: @@ -2543,7 +2556,7 @@ def boxes_to_xml(self, show_string_characters=False, **options) -> str: text = self.value def render(format, string): - encoded_text = encode_mathml(string) + encoded_text = encode_mathml(replace_wl_with_plain_text(string)) return format % encoded_text if text.startswith('"') and text.endswith('"'): From bed02984235377f507eed4f3b5a00e53df2c6f3b Mon Sep 17 00:00:00 2001 From: Pablo Emilio Escobar Gaviria Date: Thu, 28 Jan 2021 17:48:46 -0300 Subject: [PATCH 2/2] Fixed test-cases --- mathics/builtin/importexport.py | 2 +- mathics/builtin/logic.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mathics/builtin/importexport.py b/mathics/builtin/importexport.py index 1c56c3eba3..16dd5d5d8d 100644 --- a/mathics/builtin/importexport.py +++ b/mathics/builtin/importexport.py @@ -1357,7 +1357,7 @@ class B64Encode(Builtin): >> System`Convert`B64Dump`B64Encode["∫ f  x"] = 4oirIGYg752MIHg= >> System`Convert`B64Dump`B64Decode[%] - = ∫ f  x + = ∫ f 𝑑 x """ context = "System`Convert`B64Dump`" diff --git a/mathics/builtin/logic.py b/mathics/builtin/logic.py index c35fc2cf2f..2789055d04 100644 --- a/mathics/builtin/logic.py +++ b/mathics/builtin/logic.py @@ -138,7 +138,7 @@ class Implies(BinaryOperator): If an expression does not evaluate to 'True' or 'False', 'Implies' returns a result in symbolic form: >> Implies[a, Implies[b, Implies[True, c]]] - = a \uF523 b \uF523 c + = a ⟹ b ⟹ c """ operator = '\uF523' @@ -172,7 +172,7 @@ class Equivalent(BinaryOperator): If all expressions do not evaluate to 'True' or 'False', 'Equivalent' returns a result in symbolic form: >> Equivalent[a, b, c] - = a \u29E6 b \u29E6 c + = a ⇔ b ⇔ c Otherwise, 'Equivalent' returns a result in DNF >> Equivalent[a, b, True, c] = a && b && c