Skip to content

Commit

Permalink
Use defined System Symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Aug 3, 2024
1 parent 6097500 commit e195f17
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions mathics_django/web/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
SymbolFullForm,
SymbolGraphics,
SymbolGraphics3D,
SymbolInputForm,
SymbolMathMLForm,
SymbolOutputForm,
SymbolStandardForm,
Expand Down Expand Up @@ -84,31 +85,31 @@ def eval_boxes(result, fn: Callable, obj, **options):
result = expr.elements[0].format(obj, expr_type)
return result.boxes_to_text()
elif expr_head is SymbolGraphics:
result = Expression(SymbolStandardForm, expr).format(obj, "System`MathMLForm")
result = Expression(SymbolStandardForm, expr).format(obj, SymbolMathMLForm)

# This part was derived from and the same as evaluation.py format_output.

use_quotes = get_settings_value(obj.definitions, "Settings`$QuotedStrings")

if format == "text":
result = expr.format(obj, "System`OutputForm")
result = expr.format(obj, SymbolOutputForm)
result = eval_boxes(result, result.boxes_to_text, obj)

if use_quotes:
result = '"' + result + '"'

return result
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)
if expr_head is SymbolCompiledFunction:
result = expr.format(obj, "System`OutputForm")
result = expr.format(obj, SymbolOutputForm)
elif expr_head is SymbolString:
result = expr.format(obj, "System`InputForm")
result = expr.format(obj, SymbolInputForm)
result = result.boxes_to_text()

if not use_quotes:
Expand All @@ -118,16 +119,14 @@ def eval_boxes(result, fn: Callable, obj, **options):
return result
elif expr_head is SymbolGraphics3D:
form_expr = Expression(SymbolStandardForm, expr)
result = form_expr.format(obj, "System`StandardForm")
result = form_expr.format(obj, SymbolStandardForm)
return eval_boxes(result, result.boxes_to_js, obj)
elif expr_head is SymbolGraphics:
form_expr = Expression(SymbolStandardForm, expr)
result = form_expr.format(obj, "System`StandardForm")
result = form_expr.format(obj, SymbolStandardForm)
return eval_boxes(result, result.boxes_to_svg, obj)
else:
result = Expression(SymbolStandardForm, expr).format(
obj, "System`MathMLForm"
)
result = Expression(SymbolStandardForm, expr).format(obj, SymbolMathMLForm)
else:
raise ValueError

Expand Down

0 comments on commit e195f17

Please sign in to comment.