Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mathics/builtin/box/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def replace_vars(self, vars, options=None, in_scoping=True, in_function=True):

def sameQ(self, expr) -> bool:
"""Mathics SameQ"""
return expr.sameQ(self)
return expr.sameQ(self.to_expression())

def tex_block(self, tex, only_subsup=False):
if len(tex) == 1:
Expand Down
24 changes: 22 additions & 2 deletions mathics/builtin/forms/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@
"""
from typing import Optional

from mathics.builtin.box.layout import RowBox
from mathics.builtin.box.layout import RowBox, StyleBox, TagBox
from mathics.builtin.forms.base import FormBaseClass
from mathics.core.atoms import Integer, Real, String, StringFromPython
from mathics.core.builtin import Builtin
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.list import ListExpression
from mathics.core.number import dps
from mathics.core.symbols import Symbol, SymbolFalse, SymbolNull, SymbolTrue
from mathics.core.symbols import (
Symbol,
SymbolFalse,
SymbolFullForm,
SymbolNull,
SymbolTrue,
)
from mathics.core.systemsymbols import (
SymbolAutomatic,
SymbolInfinity,
Expand All @@ -37,6 +43,7 @@
StringLParen,
StringRParen,
eval_baseform,
eval_makeboxes_fullform,
eval_mathmlform,
eval_tableform,
eval_texform,
Expand Down Expand Up @@ -124,6 +131,19 @@ class FullForm(FormBaseClass):
in_printforms = True
summary_text = "underlying M-Expression representation"

def eval_makeboxes(self, expr, fmt, evaluation):
"""MakeBoxes[FullForm[expr_], fmt_]"""
fullform_box = eval_makeboxes_fullform(expr, evaluation)
style_box = StyleBox(
fullform_box,
**{
"System`ShowSpecialCharacters": SymbolFalse,
"System`ShowStringCharacters": SymbolTrue,
"System`NumberMarks": SymbolTrue,
},
)
return TagBox(style_box, SymbolFullForm)


class MathMLForm(FormBaseClass):
"""
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/makeboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class MakeBoxes(Builtin):
"MakeBoxes[(form:StandardForm|TraditionalForm|OutputForm|TeXForm|"
"MathMLForm)[expr_], StandardForm|TraditionalForm]": ("MakeBoxes[expr, form]"),
"MakeBoxes[(form:StandardForm|OutputForm|MathMLForm|TeXForm)[expr_], OutputForm]": "MakeBoxes[expr, form]",
"MakeBoxes[(form:FullForm|InputForm)[expr_], StandardForm|TraditionalForm|OutputForm]": "StyleBox[MakeBoxes[expr, form], ShowStringCharacters->True]",
"MakeBoxes[InputForm[expr_], StandardForm|TraditionalForm|OutputForm]": "StyleBox[MakeBoxes[expr, InputForm], ShowStringCharacters->True]",
"MakeBoxes[PrecedenceForm[expr_, prec_], f_]": "MakeBoxes[expr, f]",
"MakeBoxes[Style[expr_, OptionsPattern[Style]], f_]": (
"StyleBox[MakeBoxes[expr, f], "
Expand Down
10 changes: 10 additions & 0 deletions mathics/format/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
SubscriptBox,
SubsuperscriptBox,
SuperscriptBox,
TagBox,
)
from mathics.builtin.colors.color_directives import RGBColor
from mathics.core.atoms import String
Expand Down Expand Up @@ -629,3 +630,12 @@ def graphics3dbox(self, elements=None, **options) -> str:


add_conversion_fn(Graphics3DBox, graphics3dbox)


def tag_box(self, **options):
return lookup_conversion_method(self.elements[0], "latex")(
self.elements[0], **options
)


add_conversion_fn(TagBox, tag_box)
10 changes: 10 additions & 0 deletions mathics/format/mathml.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
SubscriptBox,
SubsuperscriptBox,
SuperscriptBox,
TagBox,
)
from mathics.core.atoms import String
from mathics.core.element import BoxElementMixin
Expand Down Expand Up @@ -367,3 +368,12 @@ def graphics3dbox(self, elements=None, **options) -> str:


add_conversion_fn(Graphics3DBox, graphics3dbox)


def tag_box(self, **options):
return lookup_conversion_method(self.elements[0], "mathml")(
self.elements[0], **options
)


add_conversion_fn(TagBox, tag_box)
8 changes: 8 additions & 0 deletions mathics/format/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
SubscriptBox,
SubsuperscriptBox,
SuperscriptBox,
TagBox,
)
from mathics.core.atoms import String
from mathics.core.exceptions import BoxConstructError
Expand Down Expand Up @@ -251,3 +252,10 @@ def graphics3dbox(self, elements=None, **options) -> str:


add_conversion_fn(Graphics3DBox, graphics3dbox)


def tag_box(self, **options):
return boxes_to_text(self.elements[0], **options)


add_conversion_fn(TagBox, tag_box)
25 changes: 25 additions & 0 deletions test/format/convert_yaml2json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/env python
"""
Convert a YAML file into a JSON file.
"""


import json
import sys

import yaml


def main():
filename = sys.argv[1]
name, ext = filename.split(".")
assert ext.upper() == "YAML"
with open(filename, "r") as strm:
test_dict = yaml.safe_load(strm)
with open(f"{name}.json", "w") as strm:
json.dump(test_dict, strm)
print("Done!")


if __name__ == "__main__":
main()
Loading
Loading