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 ac2ff1b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions mathics_django/web/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
from mathics.core.expression import BoxError, Expression
from mathics.core.symbols import Symbol
from mathics.core.systemsymbols import (
SymbolBaseForm,
SymbolCompiledFunction,
SymbolFullForm,
SymbolGraphics,
SymbolGraphics3D,
SymbolInputForm,
SymbolMathMLForm,
SymbolOutputForm,
SymbolStandardForm,
Expand Down Expand Up @@ -84,31 +86,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 +120,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 ac2ff1b

Please sign in to comment.