From e62ce6123eb94cc6e4edb7a0339790258c684031 Mon Sep 17 00:00:00 2001 From: mmatera Date: Tue, 30 Mar 2021 14:43:54 -0300 Subject: [PATCH 1/8] (ugly) labels come back to graphics adding filling to the text fix Export to svg --- mathics/autoload/formats/SVG/Export.m | 10 ++++----- mathics/builtin/graphics.py | 32 +++++++++++++++++---------- mathics/builtin/inout.py | 7 ++++-- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/mathics/autoload/formats/SVG/Export.m b/mathics/autoload/formats/SVG/Export.m index a1ca73ed28..ed4b485921 100644 --- a/mathics/autoload/formats/SVG/Export.m +++ b/mathics/autoload/formats/SVG/Export.m @@ -4,13 +4,13 @@ SVGExport[filename_, expr_, opts___] := - Module[{strm, data}, + Module[{strm, data, p}, strm = OpenWrite[filename]; If[strm === $Failed, Return[$Failed]]; - If[System`$UseSansSerif, - data = StringTake[ToString[MathMLForm[expr]],{23,-8}], - data = StringTake[ToString[MathMLForm[expr]],{23,-8}]]; - WriteString[strm, "" <> data <> ""]; + data=ToString[MathMLForm[expr]]; + p = StringPosition[data, "data:image/svg+xml;base64"][[1]][[2]]; + data = StringTake[data ,{p+2,-19}]; + WriteString[strm, System`Convert`B64Dump`B64Decode[data]]; Close[strm]; ] diff --git a/mathics/builtin/graphics.py b/mathics/builtin/graphics.py index bcf2404423..e37455542f 100644 --- a/mathics/builtin/graphics.py +++ b/mathics/builtin/graphics.py @@ -2592,11 +2592,19 @@ def extent(self): def to_svg(self): x, y = self.pos.pos() - content = self.content.boxes_to_xml(evaluation=self.graphics.evaluation) - style = create_css(font_color=self.color) + content = self.content.boxes_to_text(evaluation=self.graphics.evaluation) + style = create_css(font_color=self.color, edge_color=self.color, + face_color=self.color) + + # content = self.content.boxes_to_xml(evaluation=self.graphics.evaluation) + # style = create_css(font_color=self.color) + #svg = ( + # '' + # "%s") svg = ( - '' - "%s" + '' + '%s' + '' ) % (x, y, self.opos[0], self.opos[1], style, content) return svg @@ -3234,15 +3242,15 @@ def boxes_to_xml(self, leaves=None, **options): # mglyph, which is what we have been using, is bad because MathML standard changed. # metext does not work because the way in which we produce the svg images is also based on this outdated mglyph behaviour. - # template = "" - template = ( - '' - ) + #template = '' + template = '' return template % ( - int(width), - int(height), - base64.b64encode(svg_xml.encode("utf8")).decode("utf8"), - ) + # int(width), + # int(height), + int(width), + int(height), + base64.b64encode(svg_xml.encode("utf8")).decode("utf8"), + ) def axis_ticks(self, xmin, xmax): def round_to_zero(value): diff --git a/mathics/builtin/inout.py b/mathics/builtin/inout.py index 0b1cd5438f..fff86523f0 100644 --- a/mathics/builtin/inout.py +++ b/mathics/builtin/inout.py @@ -2092,12 +2092,15 @@ def apply_mathml(self, expr, evaluation) -> Expression: Expression("FullForm", boxes).evaluate(evaluation), ) xml = "" + is_a_picture = (xml[:6] == ' Date: Tue, 30 Mar 2021 16:09:47 -0300 Subject: [PATCH 2/8] fix Export to svg for general expressions --- mathics/autoload/formats/SVG/Export.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mathics/autoload/formats/SVG/Export.m b/mathics/autoload/formats/SVG/Export.m index ed4b485921..8c2d6e32cf 100644 --- a/mathics/autoload/formats/SVG/Export.m +++ b/mathics/autoload/formats/SVG/Export.m @@ -4,10 +4,12 @@ SVGExport[filename_, expr_, opts___] := - Module[{strm, data, p}, + Module[{strm, data, p, expr2}, strm = OpenWrite[filename]; If[strm === $Failed, Return[$Failed]]; - data=ToString[MathMLForm[expr]]; + expr2 = If[Head[expr]=!=System`Graphics, System`Graphics[{System`Inset[expr]}], expr]; + expr2= MathMLForm[expr2]; + data=ToString[expr2]; p = StringPosition[data, "data:image/svg+xml;base64"][[1]][[2]]; data = StringTake[data ,{p+2,-19}]; WriteString[strm, System`Convert`B64Dump`B64Decode[data]]; From 583ee0cf6ceb1ad32f620ff231ae6ae0382ede6c Mon Sep 17 00:00:00 2001 From: mmatera Date: Tue, 30 Mar 2021 16:37:33 -0300 Subject: [PATCH 3/8] fixing tests. fixing handling 2d expressions. blacken --- mathics/autoload/formats/SVG/Export.m | 2 +- mathics/builtin/graphics.py | 40 +++++++++++++++------------ mathics/builtin/inout.py | 4 +-- mathics/test.py | 32 +++++++++++++-------- 4 files changed, 47 insertions(+), 31 deletions(-) diff --git a/mathics/autoload/formats/SVG/Export.m b/mathics/autoload/formats/SVG/Export.m index 8c2d6e32cf..dda4aff422 100644 --- a/mathics/autoload/formats/SVG/Export.m +++ b/mathics/autoload/formats/SVG/Export.m @@ -7,7 +7,7 @@ Module[{strm, data, p, expr2}, strm = OpenWrite[filename]; If[strm === $Failed, Return[$Failed]]; - expr2 = If[Head[expr]=!=System`Graphics, System`Graphics[{System`Inset[expr]}], expr]; + expr2 = If[Head[expr]=!=System`Graphics, System`Graphics[{System`Inset[ToString[expr]]}], expr]; expr2= MathMLForm[expr2]; data=ToString[expr2]; p = StringPosition[data, "data:image/svg+xml;base64"][[1]][[2]]; diff --git a/mathics/builtin/graphics.py b/mathics/builtin/graphics.py index e37455542f..15e898501a 100644 --- a/mathics/builtin/graphics.py +++ b/mathics/builtin/graphics.py @@ -2593,19 +2593,23 @@ def extent(self): def to_svg(self): x, y = self.pos.pos() content = self.content.boxes_to_text(evaluation=self.graphics.evaluation) - style = create_css(font_color=self.color, edge_color=self.color, - face_color=self.color) - + style = create_css( + font_color=self.color, edge_color=self.color, face_color=self.color + ) + # content = self.content.boxes_to_xml(evaluation=self.graphics.evaluation) # style = create_css(font_color=self.color) - #svg = ( + # svg = ( # '' # "%s") - svg = ( - '' - '%s' - '' - ) % (x, y, self.opos[0], self.opos[1], style, content) + svg = ('' "%s" "") % ( + x, + y, + self.opos[0], + self.opos[1], + style, + content, + ) return svg def to_asy(self): @@ -3242,15 +3246,17 @@ def boxes_to_xml(self, leaves=None, **options): # mglyph, which is what we have been using, is bad because MathML standard changed. # metext does not work because the way in which we produce the svg images is also based on this outdated mglyph behaviour. - #template = '' - template = '' + # template = '' + template = ( + '' + ) return template % ( - # int(width), - # int(height), - int(width), - int(height), - base64.b64encode(svg_xml.encode("utf8")).decode("utf8"), - ) + # int(width), + # int(height), + int(width), + int(height), + base64.b64encode(svg_xml.encode("utf8")).decode("utf8"), + ) def axis_ticks(self, xmin, xmax): def round_to_zero(value): diff --git a/mathics/builtin/inout.py b/mathics/builtin/inout.py index fff86523f0..b66c5efaa9 100644 --- a/mathics/builtin/inout.py +++ b/mathics/builtin/inout.py @@ -2092,8 +2092,8 @@ def apply_mathml(self, expr, evaluation) -> Expression: Expression("FullForm", boxes).evaluate(evaluation), ) xml = "" - is_a_picture = (xml[:6] == '") + print(" <", line, ">") print("wanted_out=-------------------") for rr in wanted_out: for line in rr.text.splitlines(): - print(" <",line,">") + print(" <", line, ">") print("---------------------------------") - + if not compare(result, wanted): print("result =!=wanted") fail_msg = "Result: %s\nWanted: %s" % (result, wanted) @@ -124,7 +128,7 @@ def fail(why): else: for got, wanted in zip(out, wanted_out): if False: - print("got=<",got,"> wanted=<",wanted,">") + print("got=<", got, "> wanted=<", wanted, ">") if not got == wanted: output_ok = False break @@ -361,11 +365,19 @@ def main(): "--version", "-v", action="version", version="%(prog)s " + mathics.__version__ ) parser.add_argument( - "--sections", "-s", dest="section", metavar="SECTION", help="only test SECTION(s). " - "You can list multiple sections by adding a comma (and no space) in between section names." + "--sections", + "-s", + dest="section", + metavar="SECTION", + help="only test SECTION(s). " + "You can list multiple sections by adding a comma (and no space) in between section names.", ) parser.add_argument( - "--logfile", "-f", dest="logfilename", metavar="LOGFILENAME", help="stores the output in [logfilename]. " + "--logfile", + "-f", + dest="logfilename", + metavar="LOGFILENAME", + help="stores the output in [logfilename]. ", ) parser.add_argument( "--pymathics", @@ -428,7 +440,7 @@ def main(): # If a test for a specific section is called # just test it if args.logfilename: - logfile = open(args.logfilename,"wt") + logfile = open(args.logfilename, "wt") if args.section: sections = set(args.section.split(",")) @@ -442,9 +454,7 @@ def main(): print("Building pymathics documentation object") documentation.load_pymathics_doc() elif args.doc_only: - make_doc( - quiet=args.quiet, - ) + make_doc(quiet=args.quiet,) else: start_at = args.skip + 1 start_time = datetime.now() From 5aa0367be03d9e912f5c082fae33abeec87b1650 Mon Sep 17 00:00:00 2001 From: mmatera Date: Tue, 30 Mar 2021 18:48:57 -0300 Subject: [PATCH 4/8] improving the position of labels --- mathics/builtin/graphics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathics/builtin/graphics.py b/mathics/builtin/graphics.py index 15e898501a..5a092679fb 100644 --- a/mathics/builtin/graphics.py +++ b/mathics/builtin/graphics.py @@ -2602,7 +2602,7 @@ def to_svg(self): # svg = ( # '' # "%s") - svg = ('' "%s" "") % ( + svg = ('' "%s" "") % ( x, y, self.opos[0], From a69e301198822e8635053fdb03b833d1032e4293 Mon Sep 17 00:00:00 2001 From: mmatera Date: Thu, 1 Apr 2021 10:49:41 -0300 Subject: [PATCH 5/8] restoring mathics/test.py from mater --- mathics/test.py | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/mathics/test.py b/mathics/test.py index 033c78eb32..e8c31efd34 100644 --- a/mathics/test.py +++ b/mathics/test.py @@ -25,7 +25,6 @@ logfile = None - class TestOutput(Output): def max_stored_size(self, settings): return None @@ -45,10 +44,7 @@ def print_and_log(*args): if logfile: logfile.write(string) - def compare(result, wanted): - if wanted == "..." and result is not None: - return True if result == wanted: return True if result is None or wanted is None: @@ -108,13 +104,13 @@ def fail(why): print("out=-----------------") for rr in out: for line in rr.text.splitlines(): - print(" <", line, ">") + print(" <",line,">") print("wanted_out=-------------------") for rr in wanted_out: for line in rr.text.splitlines(): - print(" <", line, ">") + print(" <",line,">") print("---------------------------------") - + if not compare(result, wanted): print("result =!=wanted") fail_msg = "Result: %s\nWanted: %s" % (result, wanted) @@ -128,7 +124,7 @@ def fail(why): else: for got, wanted in zip(out, wanted_out): if False: - print("got=<", got, "> wanted=<", wanted, ">") + print("got=<",got,"> wanted=<",wanted,">") if not got == wanted: output_ok = False break @@ -365,19 +361,11 @@ def main(): "--version", "-v", action="version", version="%(prog)s " + mathics.__version__ ) parser.add_argument( - "--sections", - "-s", - dest="section", - metavar="SECTION", - help="only test SECTION(s). " - "You can list multiple sections by adding a comma (and no space) in between section names.", + "--sections", "-s", dest="section", metavar="SECTION", help="only test SECTION(s). " + "You can list multiple sections by adding a comma (and no space) in between section names." ) parser.add_argument( - "--logfile", - "-f", - dest="logfilename", - metavar="LOGFILENAME", - help="stores the output in [logfilename]. ", + "--logfile", "-f", dest="logfilename", metavar="LOGFILENAME", help="stores the output in [logfilename]. " ) parser.add_argument( "--pymathics", @@ -440,7 +428,7 @@ def main(): # If a test for a specific section is called # just test it if args.logfilename: - logfile = open(args.logfilename, "wt") + logfile = open(args.logfilename,"wt") if args.section: sections = set(args.section.split(",")) @@ -454,7 +442,9 @@ def main(): print("Building pymathics documentation object") documentation.load_pymathics_doc() elif args.doc_only: - make_doc(quiet=args.quiet,) + make_doc( + quiet=args.quiet, + ) else: start_at = args.skip + 1 start_time = datetime.now() From e2c0558283424cf1f5a605ba6fb583f101237707 Mon Sep 17 00:00:00 2001 From: mmatera Date: Thu, 1 Apr 2021 10:55:12 -0300 Subject: [PATCH 6/8] less kriptic code in xport --- mathics/autoload/formats/SVG/Export.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mathics/autoload/formats/SVG/Export.m b/mathics/autoload/formats/SVG/Export.m index dda4aff422..a57b5ba956 100644 --- a/mathics/autoload/formats/SVG/Export.m +++ b/mathics/autoload/formats/SVG/Export.m @@ -4,14 +4,16 @@ SVGExport[filename_, expr_, opts___] := - Module[{strm, data, p, expr2}, + Module[{strm, data, p, q, expr2}, strm = OpenWrite[filename]; If[strm === $Failed, Return[$Failed]]; expr2 = If[Head[expr]=!=System`Graphics, System`Graphics[{System`Inset[ToString[expr]]}], expr]; expr2= MathMLForm[expr2]; data=ToString[expr2]; p = StringPosition[data, "data:image/svg+xml;base64"][[1]][[2]]; - data = StringTake[data ,{p+2,-19}]; + (*Let's assume that the end of the string is reached just before the last quote. *) + q = StringPosition[data,"\""][[-1]][[-2]]; + data = StringTake[data ,{p+2,q-1}]; WriteString[strm, System`Convert`B64Dump`B64Decode[data]]; Close[strm]; ] From b122d284464b4713ff8934daefc6c50135dc006e Mon Sep 17 00:00:00 2001 From: mmatera Date: Thu, 1 Apr 2021 11:30:36 -0300 Subject: [PATCH 7/8] fixing the text --- mathics/builtin/importexport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mathics/builtin/importexport.py b/mathics/builtin/importexport.py index a52ed85bdf..57ad378d93 100644 --- a/mathics/builtin/importexport.py +++ b/mathics/builtin/importexport.py @@ -1917,8 +1917,8 @@ class ExportString(Builtin): . 2, . 3, . 4, - >> ExportString[Integrate[f[x],{x,0,2}], "SVG"] - = ... + >> ExportString[Integrate[f[x],{x,0,2}], "SVG"]//Head + = String """ options = { From a39f29710e12fa88229da2775c90bf59f6971a4d Mon Sep 17 00:00:00 2001 From: mmatera Date: Thu, 1 Apr 2021 21:41:53 -0300 Subject: [PATCH 8/8] xml->mathml --- mathics/builtin/base.py | 6 ++-- mathics/builtin/compilation.py | 6 ++-- mathics/builtin/graphics.py | 14 ++++---- mathics/builtin/graphics3d.py | 2 +- mathics/builtin/image.py | 6 ++-- mathics/builtin/inout.py | 6 ++-- mathics/builtin/strings.py | 2 +- mathics/core/evaluation.py | 2 +- mathics/core/expression.py | 62 +++++++++++++++++----------------- 9 files changed, 53 insertions(+), 53 deletions(-) diff --git a/mathics/builtin/base.py b/mathics/builtin/base.py index a4cc55063f..75e8cc112a 100644 --- a/mathics/builtin/base.py +++ b/mathics/builtin/base.py @@ -707,13 +707,13 @@ def get_option_values(self, leaves, **options): default[option] = parse_builtin_rule(value) return default - def boxes_to_text(self, leaves, **options) -> str: + def _boxes_to_text(self, leaves, **options) -> str: raise BoxConstructError - def boxes_to_xml(self, leaves, **options) -> str: + def _boxes_to_mathml(self, leaves, **options) -> str: raise BoxConstructError - def boxes_to_tex(self, leaves, **options) -> str: + def _boxes_to_tex(self, leaves, **options) -> str: raise BoxConstructError diff --git a/mathics/builtin/compilation.py b/mathics/builtin/compilation.py index b10d89a1e3..33233ec673 100644 --- a/mathics/builtin/compilation.py +++ b/mathics/builtin/compilation.py @@ -193,17 +193,17 @@ class CompiledCodeBox(BoxConstruct): Used internally by CompileCode[]. """ - def boxes_to_text(self, leaves=None, **options): + def _boxes_to_text(self, leaves=None, **options): if leaves is None: leaves = self._leaves return leaves[0].value - def boxes_to_xml(self, leaves=None, **options): + def _boxes_to_mathml(self, leaves=None, **options): if leaves is None: leaves = self._leaves return leaves[0].value - def boxes_to_tex(self, leaves=None, **options): + def _boxes_to_tex(self, leaves=None, **options): if leaves is None: leaves = self._leaves return leaves[0].value diff --git a/mathics/builtin/graphics.py b/mathics/builtin/graphics.py index 5a092679fb..61c29913d8 100644 --- a/mathics/builtin/graphics.py +++ b/mathics/builtin/graphics.py @@ -2577,7 +2577,7 @@ def init(self, graphics, style, item=None, content=None, pos=None, opos=(0, 0)): self.content = content self.pos = pos self.opos = opos - self.content_text = self.content.boxes_to_text( + self.content_text = self.content._boxes_to_text( evaluation=self.graphics.evaluation ) @@ -2592,12 +2592,12 @@ def extent(self): def to_svg(self): x, y = self.pos.pos() - content = self.content.boxes_to_text(evaluation=self.graphics.evaluation) + content = self.content._boxes_to_text(evaluation=self.graphics.evaluation) style = create_css( font_color=self.color, edge_color=self.color, face_color=self.color ) - # content = self.content.boxes_to_xml(evaluation=self.graphics.evaluation) + # content = self.content._boxes_to_mathml(evaluation=self.graphics.evaluation) # style = create_css(font_color=self.color) # svg = ( # '' @@ -2614,7 +2614,7 @@ def to_svg(self): def to_asy(self): x, y = self.pos.pos() - content = self.content.boxes_to_tex(evaluation=self.graphics.evaluation) + content = self.content._boxes_to_tex(evaluation=self.graphics.evaluation) pen = create_pens(edge_color=self.color) asy = 'label("$%s$", (%s,%s), (%s,%s), %s);' % ( content, @@ -2945,7 +2945,7 @@ class GraphicsBox(BoxConstruct): attributes = ("HoldAll", "ReadProtected") - def boxes_to_text(self, leaves=None, **options): + def _boxes_to_text(self, leaves=None, **options): if not leaves: leaves = self._leaves @@ -3152,7 +3152,7 @@ def get_range(min, max): return elements, calc_dimensions - def boxes_to_tex(self, leaves=None, **options): + def _boxes_to_tex(self, leaves=None, **options): if not leaves: leaves = self._leaves elements, calc_dimensions = self._prepare_elements( @@ -3207,7 +3207,7 @@ def boxes_to_tex(self, leaves=None, **options): return tex - def boxes_to_xml(self, leaves=None, **options): + def _boxes_to_mathml(self, leaves=None, **options): if not leaves: leaves = self._leaves elements, calc_dimensions = self._prepare_elements(leaves, options, neg_y=True) diff --git a/mathics/builtin/graphics3d.py b/mathics/builtin/graphics3d.py index 833c09fe47..8069a29220 100644 --- a/mathics/builtin/graphics3d.py +++ b/mathics/builtin/graphics3d.py @@ -625,7 +625,7 @@ def boxes_to_tex(self, leaves=None, **options): ) return tex - def boxes_to_xml(self, leaves=None, **options): + def _boxes_to_mathml(self, leaves=None, **options): if not leaves: leaves = self._leaves diff --git a/mathics/builtin/image.py b/mathics/builtin/image.py index 57a2438043..9279770d2b 100644 --- a/mathics/builtin/image.py +++ b/mathics/builtin/image.py @@ -2102,10 +2102,10 @@ def test(self, expr): class ImageBox(BoxConstruct): - def boxes_to_text(self, leaves=None, **options): + def _boxes_to_text(self, leaves=None, **options): return "-Image-" - def boxes_to_xml(self, leaves=None, **options): + def _boxes_to_mathml(self, leaves=None, **options): if leaves is None: leaves = self._leaves # see https://tools.ietf.org/html/rfc2397 @@ -2115,7 +2115,7 @@ def boxes_to_xml(self, leaves=None, **options): leaves[2].get_int_value(), ) - def boxes_to_tex(self, leaves=None, **options): + def _boxes_to_tex(self, leaves=None, **options): return "-Image-" diff --git a/mathics/builtin/inout.py b/mathics/builtin/inout.py index b66c5efaa9..2c9ea11a20 100644 --- a/mathics/builtin/inout.py +++ b/mathics/builtin/inout.py @@ -845,7 +845,7 @@ def boxes_to_tex(self, leaves=None, **box_options) -> str: result += r"\end{array}" return result - def boxes_to_xml(self, leaves=None, **box_options) -> str: + def _boxes_to_mathml(self, leaves=None, **box_options) -> str: if not leaves: leaves = self._leaves evaluation = box_options.get("evaluation") @@ -872,7 +872,7 @@ def boxes_to_xml(self, leaves=None, **box_options) -> str: for item in row: result += "{1}".format( joined_attrs, - item.evaluate(evaluation).boxes_to_xml(**new_box_options), + item.evaluate(evaluation)._boxes_to_mathml(**new_box_options), ) result += "\n" result += "" @@ -2084,7 +2084,7 @@ def apply_mathml(self, expr, evaluation) -> Expression: boxes = MakeBoxes(expr).evaluate(evaluation) try: - xml = boxes.boxes_to_xml(evaluation=evaluation) + xml = boxes._boxes_to_mathml(evaluation=evaluation) except BoxError: evaluation.message( "General", diff --git a/mathics/builtin/strings.py b/mathics/builtin/strings.py index 20682bbd5b..7530b0d06e 100644 --- a/mathics/builtin/strings.py +++ b/mathics/builtin/strings.py @@ -1645,7 +1645,7 @@ def apply(self, value, evaluation, **options): "ToString[value_, OptionsPattern[ToString]]" encoding = options["options"]["System`CharacterEncoding"] text = value.format(evaluation, "System`OutputForm", encoding=encoding) - text = text.boxes_to_text(evaluation=evaluation) + text = text._boxes_to_text(evaluation=evaluation) return String(text) diff --git a/mathics/core/evaluation.py b/mathics/core/evaluation.py index c8f3ceaa34..6e70e15af2 100644 --- a/mathics/core/evaluation.py +++ b/mathics/core/evaluation.py @@ -447,7 +447,7 @@ def format_output(self, expr, format=None): raise ValueError try: - boxes = result.boxes_to_text(evaluation=self) + boxes = Expression("ToString", result).evaluate(evaluation=self).value except BoxError: self.message( "General", "notboxes", Expression("FullForm", result).evaluate(self) diff --git a/mathics/core/expression.py b/mathics/core/expression.py index 3dfacdfd19..5bf97e7fa8 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -1453,7 +1453,7 @@ def process_style_box(self, options): else: return False, options - def boxes_to_text(self, **options) -> str: + def _boxes_to_text(self, **options) -> str: is_style, options = self.process_style_box(options) if is_style: return self._leaves[0].boxes_to_text(**options) @@ -1468,10 +1468,10 @@ def boxes_to_text(self, **options) -> str: else: raise BoxError(self, "text") - def boxes_to_xml(self, **options) -> str: + def _boxes_to_mathml(self, **options) -> str: is_style, options = self.process_style_box(options) if is_style: - return self._leaves[0].boxes_to_xml(**options) + return self._leaves[0]._boxes_to_mathml(**options) name = self._head.get_name() if ( name == "System`RowBox" @@ -1510,40 +1510,40 @@ def is_list_interior(content): options["inside_row"] = True for leaf in self._leaves[0].get_leaves(): - result.append(leaf.boxes_to_xml(**options)) + result.append(leaf._boxes_to_mathml(**options)) return "%s" % " ".join(result) else: options = options.copy() options["inside_row"] = True if name == "System`SuperscriptBox" and len(self._leaves) == 2: return "%s %s" % ( - self._leaves[0].boxes_to_xml(**options), - self._leaves[1].boxes_to_xml(**options), + self._leaves[0]._boxes_to_mathml(**options), + self._leaves[1]._boxes_to_mathml(**options), ) if name == "System`SubscriptBox" and len(self._leaves) == 2: return "%s %s" % ( - self._leaves[0].boxes_to_xml(**options), - self._leaves[1].boxes_to_xml(**options), + self._leaves[0]._boxes_to_mathml(**options), + self._leaves[1]._boxes_to_mathml(**options), ) if name == "System`SubsuperscriptBox" and len(self._leaves) == 3: return "%s %s %s" % ( - self._leaves[0].boxes_to_xml(**options), - self._leaves[1].boxes_to_xml(**options), - self._leaves[2].boxes_to_xml(**options), + self._leaves[0]._boxes_to_mathml(**options), + self._leaves[1]._boxes_to_mathml(**options), + self._leaves[2]._boxes_to_mathml(**options), ) elif name == "System`FractionBox" and len(self._leaves) == 2: return "%s %s" % ( - self._leaves[0].boxes_to_xml(**options), - self._leaves[1].boxes_to_xml(**options), + self._leaves[0]._boxes_to_mathml(**options), + self._leaves[1]._boxes_to_mathml(**options), ) elif name == "System`SqrtBox" and len(self._leaves) == 1: - return "%s" % (self._leaves[0].boxes_to_xml(**options)) + return "%s" % (self._leaves[0]._boxes_to_mathml(**options)) elif name == "System`GraphBox": - return "%s" % (self._leaves[0].boxes_to_xml(**options)) + return "%s" % (self._leaves[0]._boxes_to_mathml(**options)) else: raise BoxError(self, "xml") - def boxes_to_tex(self, **options) -> str: + def _boxes_to_tex(self, **options) -> str: def block(tex, only_subsup=False): if len(tex) == 1: return tex @@ -1905,7 +1905,7 @@ def __str__(self) -> str: def do_copy(self) -> "Symbol": return Symbol(self.name) - def boxes_to_text(self, **options) -> str: + def _boxes_to_text(self, **options) -> str: return str(self.name) def atom_to_boxes(self, f, evaluation) -> "String": @@ -2105,13 +2105,13 @@ def __new__(cls, value) -> "Integer": self.value = n return self - def boxes_to_text(self, **options) -> str: + def _boxes_to_text(self, **options) -> str: return str(self.value) - def boxes_to_xml(self, **options) -> str: - return self.make_boxes("MathMLForm").boxes_to_xml(**options) + def _boxes_to_mathml(self, **options) -> str: + return self.make_boxes("MathMLForm")._boxes_to_mathml(**options) - def boxes_to_tex(self, **options) -> str: + def _boxes_to_tex(self, **options) -> str: return str(self.value) def make_boxes(self, form) -> "String": @@ -2291,13 +2291,13 @@ def __new__(cls, value, p=None) -> "Real": else: return PrecisionReal.__new__(PrecisionReal, value) - def boxes_to_text(self, **options) -> str: + def _boxes_to_text(self, **options) -> str: return self.make_boxes("System`OutputForm").boxes_to_text(**options) - def boxes_to_xml(self, **options) -> str: - return self.make_boxes("System`MathMLForm").boxes_to_xml(**options) + def _boxes_to_mathml(self, **options) -> str: + return self.make_boxes("System`MathMLForm")._boxes_to_mathml(**options) - def boxes_to_tex(self, **options) -> str: + def _boxes_to_tex(self, **options) -> str: return self.make_boxes("System`TeXForm").boxes_to_tex(**options) def atom_to_boxes(self, f, evaluation): @@ -2715,7 +2715,7 @@ def __new__(cls, value): def __str__(self) -> str: return '"%s"' % self.value - def boxes_to_text(self, show_string_characters=False, **options) -> str: + def _boxes_to_text(self, show_string_characters=False, **options) -> str: value = self.value if ( @@ -2727,7 +2727,7 @@ def boxes_to_text(self, show_string_characters=False, **options) -> str: return value - def boxes_to_xml(self, show_string_characters=False, **options) -> str: + def _boxes_to_mathml(self, show_string_characters=False, **options) -> str: from mathics.core.parser import is_symbol_name from mathics.builtin import builtins_by_module @@ -2774,7 +2774,7 @@ def render(format, string): outtext += render("%s", line) return outtext - def boxes_to_tex(self, show_string_characters=False, **options) -> str: + def _boxes_to_tex(self, show_string_characters=False, **options) -> str: from mathics.builtin import builtins_by_module operators = set() @@ -2894,13 +2894,13 @@ def __new__(cls, value): def __str__(self) -> str: return base64.b64encode(self.value).decode("utf8") - def boxes_to_text(self, **options) -> str: + def _boxes_to_text(self, **options) -> str: return '"' + self.__str__() + '"' - def boxes_to_xml(self, **options) -> str: + def _boxes_to_mathml(self, **options) -> str: return encode_mathml(String('"' + self.__str__() + '"')) - def boxes_to_tex(self, **options) -> str: + def _boxes_to_tex(self, **options) -> str: return encode_tex(String('"' + self.__str__() + '"')) def atom_to_boxes(self, f, evaluation):