Skip to content

Commit

Permalink
Use Symbols where it makes more sense
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Aug 5, 2024
1 parent 43e28cb commit 701082c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions mathicsscript/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
Format Mathics objects
"""

from typing import Callable
import math
import networkx as nx
import random
from tempfile import NamedTemporaryFile
from typing import Callable

import networkx as nx
from mathics.core.atoms import String

from mathics.core.symbols import Symbol
from mathics.core.systemsymbols import (
SymbolExport,
Expand All @@ -19,6 +18,7 @@
SymbolGraphics3D,
SymbolImage,
SymbolMathMLForm,
SymbolOutputForm,
SymbolPlot,
SymbolStandardForm,
SymbolTeXForm,
Expand Down Expand Up @@ -88,7 +88,7 @@ def eval_boxes(result, fn: Callable, obj, **options):
if isinstance(format, dict):
return dict((k, obj.format_output(expr, f)) for k, f in format.items())

from mathics.core.expression import Expression, BoxError
from mathics.core.expression import BoxError, Expression

expr_type = expr.get_head_name()
expr_head = expr.get_head()
Expand Down Expand Up @@ -156,16 +156,16 @@ def eval_boxes(result, fn: Callable, obj, **options):
return expr_type

if format == "text":
result = expr.format(obj, "System`OutputForm")
result = expr.format(obj, SymbolOutputForm)
elif format == "xml":
result = Expression(SymbolStandardForm, expr).format(obj, "System`MathMLForm")
result = Expression(SymbolStandardForm, expr).format(obj, SymbolMathMLForm)
elif format == "tex":
result = Expression(SymbolStandardForm, expr).format(obj, "System`TeXForm")
result = Expression(SymbolStandardForm, expr).format(obj, SymbolTeXForm)
elif format == "unformatted":
if expr_head is PyMathicsGraph and hasattr(expr, "G"):
return format_graph(expr.G)
else:
result = expr.format(obj, "System`OutputForm")
result = expr.format(obj, SymbolOutputForm)
else:
raise ValueError

Expand All @@ -187,7 +187,6 @@ def eval_boxes(result, fn: Callable, obj, **options):
def hierarchy_pos(
G, root=None, width=1.0, vert_gap=0.2, vert_loc=0, leaf_vs_root_factor=0.5
):

"""Position nodes in tree layout. The root is at the top.
Based on Joel's answer at https://stackoverflow.com/a/29597209/2966723,
Expand Down

0 comments on commit 701082c

Please sign in to comment.